diff --git a/src/constants.js b/src/constants.js index 7ad4312e..56b9b7f3 100644 --- a/src/constants.js +++ b/src/constants.js @@ -26,6 +26,8 @@ export const INFO_WINDOW = `__SECRET_INFO_WINDOW_DO_NOT_USE_OR_YOU_WILL_BE_FIRED export const OVERLAY_VIEW = `__SECRET_OVERLAY_VIEW_DO_NOT_USE_OR_YOU_WILL_BE_FIRED` +export const GROUND_LAYER = `__SECRET_GROUND_LAYER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED` + export const DRAWING_MANAGER = `__SECRET_DRAWING_MANAGER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED` export const SEARCH_BOX = `__SECRET_SEARCH_BOX_DO_NOT_USE_OR_YOU_WILL_BE_FIRED` diff --git a/src/index.js b/src/index.js index ab915a81..d6232ff2 100644 --- a/src/index.js +++ b/src/index.js @@ -18,6 +18,8 @@ export { default as InfoWindow } from "./components/InfoWindow" export { default as OverlayView } from "./components/OverlayView" +export { default as GroundOverlay } from "./components/GroundOverlay" + export { default as DirectionsRenderer } from "./components/DirectionsRenderer" export { default as FusionTablesLayer } from "./components/FusionTablesLayer" diff --git a/src/macros/GroundOverlay.jsx b/src/macros/GroundOverlay.jsx new file mode 100644 index 00000000..e57261a0 --- /dev/null +++ b/src/macros/GroundOverlay.jsx @@ -0,0 +1,86 @@ +/* global google */ +import React from "react" +import PropTypes from "prop-types" + +import { + construct, + componentDidMount, + componentDidUpdate, + componentWillUnmount, +} from "../utils/MapChildHelper" + +import { MAP, GROUND_LAYER } from "../constants" + +export const __jscodeshiftPlaceholder__ = `{ + "eventMapOverrides": { + "onDblClick": "dblclick" + }, + "getInstanceFromComponent": "this.state[GROUND_LAYER]" +}` + +/** + * @url https://developers.google.com/maps/documentation/javascript/reference#GroundOverlay + */ +export class GroundOverlay extends React.PureComponent { + static propTypes = { + __jscodeshiftPlaceholder__: null, + /** + * @type string + */ + url: PropTypes.string.isRequired, + + /** + * @see https://developers.google.com/maps/documentation/javascript/reference#GroundOverlay + */ + bounds: PropTypes.object.isRequired, + } + + static contextTypes = { + [MAP]: PropTypes.object, + } + + /* + * @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#GroundOverlay + */ + constructor(props, context) { + super(props, context) + const groundOverlay = new google.maps.GroundOverlay(props.url, props.bounds) + construct(GroundOverlay.propTypes, updaterMap, this.props, groundOverlay) + groundOverlay.setMap(this.context[MAP]) + this.state = { + [GROUND_LAYER]: groundOverlay, + } + } + + componentDidMount() { + componentDidMount(this, this.state[GROUND_LAYER], eventMap) + } + + componentDidUpdate(prevProps) { + componentDidUpdate( + this, + this.state[GROUND_LAYER], + eventMap, + updaterMap, + prevProps + ) + } + + componentWillUnmount() { + componentWillUnmount(this) + const GroundOverlay = this.state[GROUND_LAYER] + if (GroundOverlay) { + GroundOverlay.setMap(null) + } + } + + render() { + return false + } +} + +export default GroundOverlay + +const eventMap = {} + +const updaterMap = {}