From 540c71433a463f14b0c1c54729ebcef1746bad80 Mon Sep 17 00:00:00 2001 From: Viatcheslav Ivanov Date: Fri, 22 Jun 2018 01:57:43 -0700 Subject: [PATCH 1/2] Add Traffic layer --- package.json | 1 + src/__tests__/index.spec.js | 2 + src/constants.js | 2 + src/index.js | 2 + src/macros/TransitLayer.jsx | 78 +++++++++++++++++++++++++++++++++++++ types/index.d.ts | 8 ++++ 6 files changed, 93 insertions(+) create mode 100644 src/macros/TransitLayer.jsx diff --git a/package.json b/package.json index e3d34ff9..d146dbe1 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "Rectangle", "StreetViewPanorama", "TrafficLayer", + "TransitLayer", "visualization/HeatmapLayer", "withGoogleMap", "withScriptjs" diff --git a/src/__tests__/index.spec.js b/src/__tests__/index.spec.js index 4c8536e5..17350030 100644 --- a/src/__tests__/index.spec.js +++ b/src/__tests__/index.spec.js @@ -16,6 +16,7 @@ describe("react-google-maps module (index.js)", () => { FusionTablesLayer, KmlLayer, TrafficLayer, + TransitLayer, BicyclingLayer, StreetViewPanorama, } = require("../") @@ -43,6 +44,7 @@ describe("react-google-maps module (index.js)", () => { expect(FusionTablesLayer).toBeDefined() expect(KmlLayer).toBeDefined() expect(TrafficLayer).toBeDefined() + expect(TransitLayer).toBeDefined() expect(BicyclingLayer).toBeDefined() expect(StreetViewPanorama).toBeDefined() }) diff --git a/src/constants.js b/src/constants.js index 40e4575e..d839e15f 100644 --- a/src/constants.js +++ b/src/constants.js @@ -43,3 +43,5 @@ export const TRAFFIC_LAYER = `__SECRET_TRAFFIC_LAYER_DO_NOT_USE_OR_YOU_WILL_BE_F 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` + +export const TRANSIT_LAYER = `__SECRET_TRANSIT_LAYER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED` diff --git a/src/index.js b/src/index.js index 2b40d439..b4ce45bb 100644 --- a/src/index.js +++ b/src/index.js @@ -31,3 +31,5 @@ export { default as TrafficLayer } from "./components/TrafficLayer" export { default as StreetViewPanorama } from "./components/StreetViewPanorama" export { default as BicyclingLayer } from "./components/BicyclingLayer" + +export { default as TransitLayer } from "./components/TransitLayer" diff --git a/src/macros/TransitLayer.jsx b/src/macros/TransitLayer.jsx new file mode 100644 index 00000000..7f8f3683 --- /dev/null +++ b/src/macros/TransitLayer.jsx @@ -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 = {} diff --git a/types/index.d.ts b/types/index.d.ts index bdf0fb1f..99779a9e 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -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 } from 'react-google-maps/lib/components/TransitLayer' } declare module 'react-google-maps/lib/withGoogleMap' { @@ -661,3 +662,10 @@ declare module 'react-google-maps/lib/components/visualization/HeatmapLayer' { getData(): google.maps.MVCArray } } + +declare module 'react-google-maps/lib/components/TransitLayer' { + import { Component } from 'react' + + export default class TrafficLayer extends Component { + } +} From 41622efb5b48a00bdca9beb7775192e18e51402d Mon Sep 17 00:00:00 2001 From: Viatcheslav Ivanov Date: Fri, 22 Jun 2018 02:09:55 -0700 Subject: [PATCH 2/2] test --- lib/constants.js | 3 +++ lib/index.js | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/constants.js b/lib/constants.js index 2ea5d7d9..63863136 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -69,3 +69,6 @@ var STREET_VIEW_PANORAMA = (exports.STREET_VIEW_PANORAMA = var BICYCLING_LAYER = (exports.BICYCLING_LAYER = "__SECRET_BICYCLING_LAYER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED") + +var TRANSIT_LAYER = (exports.TRANSIT_LAYER = + "__SECRET_TRANSIT_LAYER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED") diff --git a/lib/index.js b/lib/index.js index 7e5c6f4e..6e291185 100644 --- a/lib/index.js +++ b/lib/index.js @@ -157,6 +157,15 @@ Object.defineProperty(exports, "BicyclingLayer", { }, }) +var _TransitLayer = require("./components/TransitLayer") + +Object.defineProperty(exports, "TransitLayer", { + enumerable: true, + get: function get() { + return _interopRequireDefault(_TransitLayer).default + }, +}) + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj } }