Skip to content

Commit

Permalink
feat(GroundOverlay): add GroundOverlay component
Browse files Browse the repository at this point in the history
* Ref #624
  • Loading branch information
Simek authored and tomchentw committed Sep 21, 2017
1 parent 9f98237 commit d76a455
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
86 changes: 86 additions & 0 deletions src/macros/GroundOverlay.jsx
Original file line number Diff line number Diff line change
@@ -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 = {}

0 comments on commit d76a455

Please sign in to comment.