-
Notifications
You must be signed in to change notification settings - Fork 939
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add new component for _Google Maps BicyclingLayer_
- Loading branch information
Showing
5 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
### Usage | ||
|
||
```jsx static | ||
import { compose, withProps } from "recompose"; | ||
import { | ||
withScriptjs, | ||
withGoogleMap, | ||
GoogleMap, | ||
BicyclingLayer, | ||
} from "react-google-maps"; | ||
|
||
const MapWithABicyclingLayer = compose( | ||
withProps({ | ||
googleMapURL: "https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,drawing,places", | ||
loadingElement: <div style={{ height: `100%` }} />, | ||
containerElement: <div style={{ height: `400px` }} />, | ||
mapElement: <div style={{ height: `100%` }} />, | ||
}), | ||
withScriptjs, | ||
withGoogleMap | ||
)(props => | ||
<GoogleMap | ||
defaultZoom={8} | ||
defaultCenter={{ lat: 41.9, lng: -87.624 }} | ||
> | ||
<BicyclingLayer /> | ||
</GoogleMap> | ||
); | ||
|
||
<MapWithABicyclingLayer /> | ||
``` | ||
|
||
### Map with a BicyclingLayer | ||
|
||
```jsx | ||
const { compose, withProps } = require("recompose"); | ||
const { | ||
withScriptjs, | ||
withGoogleMap, | ||
GoogleMap, | ||
BicyclingLayer, | ||
} = require("../index"); | ||
|
||
const MapWithABicyclingLayer = compose( | ||
withProps({ | ||
googleMapURL: "https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,drawing,places", | ||
loadingElement: <div style={{ height: `100%` }} />, | ||
containerElement: <div style={{ height: `400px` }} />, | ||
mapElement: <div style={{ height: `100%` }} />, | ||
}), | ||
withScriptjs, | ||
withGoogleMap | ||
)(props => | ||
<GoogleMap | ||
defaultZoom={12} | ||
defaultCenter={{ lat: 34.17223, lng: -118.37897 }} | ||
> | ||
<BicyclingLayer autoUpdate /> | ||
</GoogleMap> | ||
); | ||
|
||
<MapWithABicyclingLayer /> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* global google */ | ||
import React from "react" | ||
import PropTypes from "prop-types" | ||
|
||
import { | ||
construct, | ||
componentDidMount, | ||
componentDidUpdate, | ||
componentWillUnmount, | ||
} from "../utils/MapChildHelper" | ||
|
||
import { MAP, BICYCLING_LAYER } from "../constants" | ||
|
||
export const __jscodeshiftPlaceholder__ = `{ | ||
"eventMapOverrides": { | ||
}, | ||
"getInstanceFromComponent": "this.state[BICYCLING_LAYER]" | ||
}` | ||
|
||
/** | ||
* @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#BicyclingLayer | ||
*/ | ||
export class BicyclingLayer extends React.PureComponent { | ||
static propTypes = { | ||
__jscodeshiftPlaceholder__: null, | ||
} | ||
|
||
static contextTypes = { | ||
[MAP]: PropTypes.object, | ||
} | ||
|
||
/* | ||
* @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#BicyclingLayer | ||
*/ | ||
constructor(props, context) { | ||
super(props, context) | ||
const bicyclingLayer = new google.maps.BicyclingLayer() | ||
construct(BicyclingLayer.propTypes, updaterMap, this.props, bicyclingLayer) | ||
bicyclingLayer.setMap(this.context[MAP]) | ||
this.state = { | ||
[BICYCLING_LAYER]: bicyclingLayer, | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
componentDidMount(this, this.state[BICYCLING_LAYER], eventMap) | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
componentDidUpdate( | ||
this, | ||
this.state[BICYCLING_LAYER], | ||
eventMap, | ||
updaterMap, | ||
prevProps | ||
) | ||
} | ||
|
||
componentWillUnmount() { | ||
componentWillUnmount(this) | ||
const bicyclingLayer = this.state[BICYCLING_LAYER] | ||
if (bicyclingLayer) { | ||
bicyclingLayer.setMap(null) | ||
} | ||
} | ||
|
||
render() { | ||
return false | ||
} | ||
} | ||
|
||
export default BicyclingLayer | ||
|
||
const eventMap = {} | ||
|
||
const updaterMap = {} |