1.0.3 • Published 6 years ago

react-sgl v1.0.3

Weekly downloads
1
License
MIT
Repository
gitlab
Last release
6 years ago

react-sgl

npm package

Installation

npm install --save react-google-maps # or
yarn add react-google-maps

Use & Configuration

import { withMapConfig SGLMap, SGLMarker } from "react-sgl"

const MyMapComponent = withMapConfig((props) =>
  <SGLMap
    defaultZoom={8}
    defaultCenter={{ lat: -34.397, lng: 150.644 }}
  >
    <SGLMarker position={{ lat: -34.397, lng: 150.644 }} />
  </SGLMap>
))

<MyMapComponent
  mapsUrl: 'http://path-to-sgl/api/js.js',
  googleMapsKey: 'googlekey',
  bbox: '-48.900473,-26.252152,-48.889892,-26.243658'
/>

For simplicity, in this documentation, I will use recompose to simplify the component. It'll look something like this with recompose:

import { compose, withProps } from "recompose"
import { withMapConfig, SGLMap, SGLMarker } from "react-sgl"

const MyMapComponent = compose(
  withProps({
    mapsUrl: 'http://path-to-sgl/api/js.js',
    googleMapsKey: 'googlekey',
    bbox: '-48.900473,-26.252152,-48.889892,-26.243658'
  }),
  withMapConfig
)((props) =>
  <SGLMap
    defaultZoom={8}
    defaultCenter={{ lat: -34.397, lng: 150.644 }}
  >
    <Marker position={{ lat: -34.397, lng: 150.644 }} />
  </SGLMap>
))

<MyMapComponent isMarkerShown />

You can implement your own state transition logic with MyMapComponent!

import React from "react"
import { compose, withProps } from "recompose"
import { withMapConfig, SGLMap, SGLMarker } from "react-sgl"

const MyMapComponent = compose(
  withProps({
    mapsUrl: 'http://path-to-sgl/api/js.js',
    googleMapsKey: 'googlekey',
    bbox: '-48.900473,-26.252152,-48.889892,-26.243658'
  }),
  withMapConfig
)((props) =>
  <SGLMap
    defaultZoom={8}
    defaultCenter={{ lat: -34.397, lng: 150.644 }}
  >
    {props.isMarkerShown && <SGLMarker position={{ lat: -34.397, lng: 150.644 }} onClick={props.onMarkerClick} />}
  </SGLMap>
))

class MyFancyComponent extends React.PureComponent {
  state = {
    isMarkerShown: false,
  }

  componentDidMount() {
    this.delayedShowMarker()
  }

  delayedShowMarker = () => {
    setTimeout(() => {
      this.setState({ isMarkerShown: true })
    }, 3000)
  }

  handleMarkerClick = () => {
    this.setState({ isMarkerShown: false })
    this.delayedShowMarker()
  }

  render() {
    return (
      <MyMapComponent
        isMarkerShown={this.state.isMarkerShown}
        onMarkerClick={this.handleMarkerClick}
      />
    )
  }
}
1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.14.3

6 years ago

0.14.2

6 years ago

0.14.1

6 years ago

0.14.0

6 years ago

0.13.0

7 years ago

0.12.4

7 years ago

0.12.3

7 years ago

0.12.2

7 years ago

0.12.1

7 years ago

0.12.0

7 years ago

0.11.3

7 years ago

0.11.2

7 years ago

0.11.1

7 years ago

0.11.0

7 years ago

0.10.3

7 years ago

0.10.2

7 years ago

0.10.1

7 years ago

0.10.0

7 years ago

0.9.0

7 years ago

0.8.15

7 years ago

0.8.14

7 years ago

0.8.13

7 years ago

0.8.12

7 years ago

0.8.11

7 years ago

0.8.10

7 years ago

0.8.9

7 years ago

0.8.8

7 years ago

0.8.7

7 years ago

0.8.6

7 years ago

0.8.5

7 years ago

0.8.4

7 years ago

0.8.3

7 years ago

0.8.2

7 years ago

0.8.1

7 years ago

0.8.0

7 years ago

0.7.9

7 years ago

0.7.8

7 years ago

0.7.7

7 years ago

0.7.6

7 years ago

0.7.5

7 years ago

0.7.4

7 years ago

0.7.3

7 years ago

0.7.2

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago