-
Notifications
You must be signed in to change notification settings - Fork 936
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GroundOverlay): add GroundOverlay component
* Ref #624
- Loading branch information
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {} |