-
Notifications
You must be signed in to change notification settings - Fork 936
/
GoogleMap.js
108 lines (89 loc) · 3.54 KB
/
GoogleMap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import {
default as React,
PropTypes,
Component,
findDOMNode,
} from "react";
import {
default as GoogleMapHolder,
mapDefaultPropTypes,
mapControlledPropTypes,
mapEventPropTypes,
} from "./creators/GoogleMapHolder";
export default class GoogleMap extends Component {
static propTypes = {
containerTagName: PropTypes.string.isRequired,
containerProps: PropTypes.object.isRequired,
// Uncontrolled default[props] - used only in componentDidMount
...mapDefaultPropTypes,
// Controlled [props] - used in componentDidMount/componentDidUpdate
...mapControlledPropTypes,
// Event [onEventName]
...mapEventPropTypes,
}
// Public APIs
//
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map
//
// [].map.call($0.querySelectorAll("tr>td>code"), function(it){ return it.textContent; }).filter(function(it){ return it.match(/^get/) && !it.match(/Map$/); })
getBounds () { return this.state.map.getBounds(); }
getCenter () { return this.state.map.getCenter(); }
getDiv () { return this.state.map.getDiv(); }
getHeading () { return this.state.map.getHeading(); }
getMapTypeId () { return this.state.map.getMapTypeId(); }
getProjection () { return this.state.map.getProjection(); }
getStreetView () { return this.state.map.getStreetView(); }
getTilt () { return this.state.map.getTilt(); }
getZoom () { return this.state.map.getZoom(); }
// END - Public APIs
//
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map
//
// Public APIs - Use this carefully
// See discussion in https://github.com/tomchentw/react-google-maps/issues/62
//
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map
//
// [].map.call($0.querySelectorAll("tr>td>code"), function(it){ return it.textContent; }).filter(function(it){ return !it.match(/^get/) && !it.match(/^set/) && !it.match(/Map$/); })
fitBounds (bounds) { return this.state.map.fitBounds(bounds); }
panBy (x, y) { return this.state.map.panBy(x, y); }
panTo (latLng) { return this.state.map.panTo(latLng); }
panToBounds (latLngBounds) { return this.state.map.panToBounds(latLngBounds); }
// END - Public APIs - Use this carefully
//
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map
static defaultProps = {
containerTagName: "div",
containerProps: {},
}
state = {
}
componentDidMount () {
const domEl = findDOMNode(this);
const {containerTagName, containerProps, children, ...mapProps} = this.props;
// TODO: support asynchronous load of google.maps API at this level.
//
// Create google.maps.Map instance so that dom is initialized before
// React's children creators.
//
const map = GoogleMapHolder._createMap(domEl, mapProps);
this.setState({ map });
}
render () {
const {containerTagName, containerProps, children, ...mapProps} = this.props;
const child = this.state.map ? (
// Notice: implementation details
//
// In this state, the DOM of google.maps.Map is already initialized in
// my innerHTML. Adding extra React components will not clean it
// in current (0.13.3) version. It will use prepend to add DOM of
// GoogleMapHolder and become a sibling of the DOM of google.maps.Map
// Not sure this is subject to change
//
<GoogleMapHolder map={this.state.map} {...mapProps}>
{children}
</GoogleMapHolder>
) : undefined;
return React.createElement(containerTagName, containerProps, child);
}
}