|
| 1 | +/* global google */ |
| 2 | +import React from "react" |
| 3 | +import PropTypes from "prop-types" |
| 4 | + |
| 5 | +import { |
| 6 | + construct, |
| 7 | + componentDidMount, |
| 8 | + componentDidUpdate, |
| 9 | + componentWillUnmount, |
| 10 | +} from "../utils/MapChildHelper" |
| 11 | + |
| 12 | +import { MAP, GROUND_LAYER } from "../constants" |
| 13 | + |
| 14 | +export const __jscodeshiftPlaceholder__ = `{ |
| 15 | + "eventMapOverrides": { |
| 16 | + "onDblClick": "dblclick" |
| 17 | + }, |
| 18 | + "getInstanceFromComponent": "this.state[GROUND_LAYER]" |
| 19 | +}` |
| 20 | + |
| 21 | +/** |
| 22 | + * @url https://developers.google.com/maps/documentation/javascript/reference#GroundOverlay |
| 23 | + */ |
| 24 | +export class GroundOverlay extends React.PureComponent { |
| 25 | + static propTypes = { |
| 26 | + __jscodeshiftPlaceholder__: null, |
| 27 | + /** |
| 28 | + * @type string |
| 29 | + */ |
| 30 | + url: PropTypes.string.isRequired, |
| 31 | + |
| 32 | + /** |
| 33 | + * @see https://developers.google.com/maps/documentation/javascript/reference#GroundOverlay |
| 34 | + */ |
| 35 | + bounds: PropTypes.object.isRequired, |
| 36 | + } |
| 37 | + |
| 38 | + static contextTypes = { |
| 39 | + [MAP]: PropTypes.object, |
| 40 | + } |
| 41 | + |
| 42 | + /* |
| 43 | + * @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#GroundOverlay |
| 44 | + */ |
| 45 | + constructor(props, context) { |
| 46 | + super(props, context) |
| 47 | + const groundOverlay = new google.maps.GroundOverlay(props.url, props.bounds) |
| 48 | + construct(GroundOverlay.propTypes, updaterMap, this.props, groundOverlay) |
| 49 | + groundOverlay.setMap(this.context[MAP]) |
| 50 | + this.state = { |
| 51 | + [GROUND_LAYER]: groundOverlay, |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + componentDidMount() { |
| 56 | + componentDidMount(this, this.state[GROUND_LAYER], eventMap) |
| 57 | + } |
| 58 | + |
| 59 | + componentDidUpdate(prevProps) { |
| 60 | + componentDidUpdate( |
| 61 | + this, |
| 62 | + this.state[GROUND_LAYER], |
| 63 | + eventMap, |
| 64 | + updaterMap, |
| 65 | + prevProps |
| 66 | + ) |
| 67 | + } |
| 68 | + |
| 69 | + componentWillUnmount() { |
| 70 | + componentWillUnmount(this) |
| 71 | + const GroundOverlay = this.state[GROUND_LAYER] |
| 72 | + if (GroundOverlay) { |
| 73 | + GroundOverlay.setMap(null) |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + render() { |
| 78 | + return false |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +export default GroundOverlay |
| 83 | + |
| 84 | +const eventMap = {} |
| 85 | + |
| 86 | +const updaterMap = {} |
0 commit comments