Skip to content

Commit

Permalink
feat(BicyclingLayer):
Browse files Browse the repository at this point in the history
- Add new component for _Google Maps BicyclingLayer_
  • Loading branch information
davidmart authored and tomchentw committed Oct 10, 2017
1 parent c171ba8 commit 0ce9062
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe("react-google-maps module (index.js)", () => {
FusionTablesLayer,
KmlLayer,
TrafficLayer,
BicyclingLayer,
StreetViewPanorama,
} = require("../")

Expand All @@ -42,6 +43,7 @@ describe("react-google-maps module (index.js)", () => {
expect(FusionTablesLayer).toBeDefined()
expect(KmlLayer).toBeDefined()
expect(TrafficLayer).toBeDefined()
expect(BicyclingLayer).toBeDefined()
expect(StreetViewPanorama).toBeDefined()
})
})
63 changes: 63 additions & 0 deletions src/components/BicyclingLayer.md
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 />
```
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ export const INFO_BOX = `__SECRET_INFO_BOX_DO_NOT_USE_OR_YOU_WILL_BE_FIRED`
export const TRAFFIC_LAYER = `__SECRET_TRAFFIC_LAYER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED`

export const STREET_VIEW_PANORAMA = `__SECRET_STREET_VIEW_PANORAMA_DO_NOT_USE_OR_YOU_WILL_BE_FIRED`

export const BICYCLING_LAYER = `__SECRET_BICYCLING_LAYER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED`
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ export { default as KmlLayer } from "./components/KmlLayer"
export { default as TrafficLayer } from "./components/TrafficLayer"

export { default as StreetViewPanorama } from "./components/StreetViewPanorama"

export { default as BicyclingLayer } from "./components/BicyclingLayer"
76 changes: 76 additions & 0 deletions src/macros/BicyclingLayer.jsx
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 = {}

0 comments on commit 0ce9062

Please sign in to comment.