|
| 1 | +import invariant from "invariant" |
| 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 } from "../constants" |
| 13 | + |
| 14 | +export const __jscodeshiftPlaceholder__ = `{ |
| 15 | + "eventMapOverrides": { |
| 16 | + "onDblClick": "dblclick", |
| 17 | + "onDragEnd": "dragend", |
| 18 | + "onDragStart": "dragstart", |
| 19 | + "onMapTypeIdChanged": "maptypeid_changed", |
| 20 | + "onMouseMove": "mousemove", |
| 21 | + "onMouseOut": "mouseout", |
| 22 | + "onMouseOver": "mouseover", |
| 23 | + "onRightClick": "rightclick", |
| 24 | + "onTilesLoaded": "tilesloaded" |
| 25 | + }, |
| 26 | + "getInstanceFromComponent": "this.context[MAP]" |
| 27 | +}` |
| 28 | + |
| 29 | +/** |
| 30 | + * @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map |
| 31 | + */ |
| 32 | +export class Map extends React.PureComponent { |
| 33 | + static displayName = "GoogleMap" |
| 34 | + |
| 35 | + static propTypes = { |
| 36 | + __jscodeshiftPlaceholder__: null, |
| 37 | + } |
| 38 | + |
| 39 | + static contextTypes = { |
| 40 | + [MAP]: PropTypes.object, |
| 41 | + } |
| 42 | + |
| 43 | + /* |
| 44 | + * @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map |
| 45 | + */ |
| 46 | + fitBounds(...args) { |
| 47 | + return this.context[MAP].fitBounds(...args) |
| 48 | + } |
| 49 | + |
| 50 | + /* |
| 51 | + * @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map |
| 52 | + */ |
| 53 | + panBy(...args) { |
| 54 | + return this.context[MAP].panBy(...args) |
| 55 | + } |
| 56 | + |
| 57 | + /* |
| 58 | + * @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map |
| 59 | + */ |
| 60 | + panTo(...args) { |
| 61 | + return this.context[MAP].panTo(...args) |
| 62 | + } |
| 63 | + |
| 64 | + /* |
| 65 | + * @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map |
| 66 | + */ |
| 67 | + panToBounds(...args) { |
| 68 | + return this.context[MAP].panToBounds(...args) |
| 69 | + } |
| 70 | + |
| 71 | + /* |
| 72 | + * @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map |
| 73 | + */ |
| 74 | + constructor(props, context) { |
| 75 | + super(props, context) |
| 76 | + invariant( |
| 77 | + !!this.context[MAP], |
| 78 | + `Did you wrap <GoogleMap> component with withGoogleMap() HOC?` |
| 79 | + ) |
| 80 | + construct(GoogleMap.propTypes, updaterMap, this.props, this.context[MAP]) |
| 81 | + } |
| 82 | + |
| 83 | + componentDidMount() { |
| 84 | + componentDidMount(this, this.context[MAP], eventMap) |
| 85 | + } |
| 86 | + |
| 87 | + componentDidUpdate(prevProps) { |
| 88 | + componentDidUpdate(this, this.context[MAP], eventMap, updaterMap, prevProps) |
| 89 | + } |
| 90 | + |
| 91 | + componentWillUnmount() { |
| 92 | + componentWillUnmount(this) |
| 93 | + } |
| 94 | + |
| 95 | + render() { |
| 96 | + const { children } = this.props |
| 97 | + return <div>{children}</div> |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +export const GoogleMap = Map |
| 102 | + |
| 103 | +export default Map |
| 104 | + |
| 105 | +const eventMap = {} |
| 106 | + |
| 107 | +const updaterMap = {} |
0 commit comments