Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added transit layer #857

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions src/components/TransitLayer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* -----------------------------------------------------------------------------
* This file is auto-generated from the corresponding file at `src/macros/`.
* Please **DO NOT** edit this file directly when creating PRs.
* -----------------------------------------------------------------------------
*/
/* global google */
import React from "react"
import PropTypes from "prop-types"

import {
construct,
componentDidMount,
componentDidUpdate,
componentWillUnmount,
} from "../utils/MapChildHelper"

import { MAP, TRAFFIC_LAYER } from "../constants"

/**
* A wrapper around `google.maps.TransitLayer`
*
* @see https://developers.google.com/maps/documentation/javascript/3.exp/reference#TransitLayer
*/
export class TransitLayer extends React.PureComponent {
static propTypes = {
/**
* @type TransitLayerOptions
*/
defaultOptions: PropTypes.any,

/**
* @type TransitLayerOptions
*/
options: PropTypes.any,
}

static contextTypes = {
[MAP]: PropTypes.object,
}

/*
* @see https://developers.google.com/maps/documentation/javascript/3.exp/reference#TransitLayer
*/
constructor(props, context) {
super(props, context)
const transitLayer = new google.maps.TransitLayer()
construct(TransitLayer.propTypes, updaterMap, this.props, transitLayer)
transitLayer.setMap(this.context[MAP])
this.state = {
[TRAFFIC_LAYER]: transitLayer,
}
}

componentDidMount() {
componentDidMount(this, this.state[TRAFFIC_LAYER], eventMap)
}

componentDidUpdate(prevProps) {
componentDidUpdate(
this,
this.state[TRAFFIC_LAYER],
eventMap,
updaterMap,
prevProps
)
}

componentWillUnmount() {
componentWillUnmount(this)
const transitLayer = this.state[TRAFFIC_LAYER]
if (transitLayer) {
transitLayer.setMap(null)
}
}

render() {
return false
}
}

export default TransitLayer

const eventMap = {}

const updaterMap = {
options(instance, options) {
instance.setOptions(options)
},
}
31 changes: 31 additions & 0 deletions src/components/TransitLayer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
### Map with a TransitLayer

```jsx
const { compose, withProps } = require("recompose");
const {
withScriptjs,
withGoogleMap,
GoogleMap,
TransitLayer,
} = require("react-google-maps");

const MapWithATransitLayer = compose(
withProps({
googleMapURL: "https://maps.googleapis.com/maps/api/js?key=AIzaSyC4R6AN7SmujjPUIGKdyao2Kqitzr1kiRg&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 }}
>
<TransitLayer autoUpdate />
</GoogleMap>
);

<MapWithATransitLayer />
```
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ 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 TRANSIT_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`
78 changes: 78 additions & 0 deletions src/macros/TransitLayer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* global google */
import React from "react"
import PropTypes from "prop-types"

import {
construct,
componentDidMount,
componentDidUpdate,
componentWillUnmount,
} from "../utils/MapChildHelper"

import { MAP, TRANSIT_LAYER } from "../constants"

export const __jscodeshiftPlaceholder__ = `{
"eventMapOverrides": {
},
"getInstanceFromComponent": "this.state[TRANSIT_LAYER]"
}`

/**
* A wrapper around `google.maps.TransitLayer`
*
* @see https://developers.google.com/maps/documentation/javascript/3.exp/reference#TransitLayer
*/
export class TransitLayer extends React.PureComponent {
static propTypes = {
__jscodeshiftPlaceholder__: null,
}

static contextTypes = {
[MAP]: PropTypes.object,
}

/*
* @see https://developers.google.com/maps/documentation/javascript/3.exp/reference#TransitLayer
*/
constructor(props, context) {
super(props, context)
const transitLayer = new google.maps.TransitLayer()
construct(TransitLayer.propTypes, updaterMap, this.props, transitLayer)
transitLayer.setMap(this.context[MAP])
this.state = {
[TRANSIT_LAYER]: transitLayer,
}
}

componentDidMount() {
componentDidMount(this, this.state[TRANSIT_LAYER], eventMap)
}

componentDidUpdate(prevProps) {
componentDidUpdate(
this,
this.state[TRANSIT_LAYER],
eventMap,
updaterMap,
prevProps
)
}

componentWillUnmount() {
componentWillUnmount(this)
const transitLayer = this.state[TRANSIT_LAYER]
if (transitLayer) {
transitLayer.setMap(null)
}
}

render() {
return false
}
}

export default TransitLayer

const eventMap = {}

const updaterMap = {}
13 changes: 13 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ declare module 'react-google-maps' {
export { default as Rectangle, RectangleProps } from 'react-google-maps/lib/components/Rectangle'
export { default as StreetViewPanorama, StreetViewPanoramaProps } from 'react-google-maps/lib/components/StreetViewPanorama'
export { default as TrafficLayer, TrafficLayerProps } from 'react-google-maps/lib/components/TrafficLayer'
export { default as TransitLayer, TransitLayerProps } from 'react-google-maps/lib/components/TransitLayer'
}

declare module 'react-google-maps/lib/withGoogleMap' {
Expand Down Expand Up @@ -647,6 +648,18 @@ declare module 'react-google-maps/lib/components/TrafficLayer' {
}
}

declare module 'react-google-maps/lib/components/TransitLayer' {
import { Component } from 'react'

export interface TransitLayerProps {
defaultOptions?: google.maps.TransitLayerOptions
options?: google.maps.TransitLayerOptions
}

export default class TransitLayer extends Component<TransitLayerProps> {
}
}

declare module 'react-google-maps/lib/components/visualization/HeatmapLayer' {
import { Component } from 'react'

Expand Down