Skip to content

Commit d76a455

Browse files
Simektomchentw
authored andcommitted
feat(GroundOverlay): add GroundOverlay component
* Ref #624
1 parent 9f98237 commit d76a455

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

src/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export const INFO_WINDOW = `__SECRET_INFO_WINDOW_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
2626

2727
export const OVERLAY_VIEW = `__SECRET_OVERLAY_VIEW_DO_NOT_USE_OR_YOU_WILL_BE_FIRED`
2828

29+
export const GROUND_LAYER = `__SECRET_GROUND_LAYER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED`
30+
2931
export const DRAWING_MANAGER = `__SECRET_DRAWING_MANAGER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED`
3032

3133
export const SEARCH_BOX = `__SECRET_SEARCH_BOX_DO_NOT_USE_OR_YOU_WILL_BE_FIRED`

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export { default as InfoWindow } from "./components/InfoWindow"
1818

1919
export { default as OverlayView } from "./components/OverlayView"
2020

21+
export { default as GroundOverlay } from "./components/GroundOverlay"
22+
2123
export { default as DirectionsRenderer } from "./components/DirectionsRenderer"
2224

2325
export { default as FusionTablesLayer } from "./components/FusionTablesLayer"

src/macros/GroundOverlay.jsx

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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

Comments
 (0)