-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGoogleMap.jsx
49 lines (38 loc) · 1009 Bytes
/
GoogleMap.jsx
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
import React, { Component } from 'react';
import asyncLoading from '../src/AsyncLoad';
class GoogleMap extends Component {
state = { map: null }
static sampleStaticFunction () {
console.info('Static Function called');
}
initialize (canvas) {
if (this.props.gmap && this.state.map == null) {
const gmap = this.props.gmap;
this.state.map = new gmap.Map(canvas, {
center: new gmap.LatLng(22.25, 114.1667),
zoom: 12
});
}
}
componentDidMount () {
this.initialize(React.findDOMNode(this));
}
componentDidUpdate () {
this.initialize(React.findDOMNode(this));
}
render () {
return (
<div className="mapCanvas" style={{ width: '100%', height: '500px' }}></div>
);
}
}
function mapScriptsToProps (ownProps) {
return {
gmap: {
globalPath: 'google.maps',
url: 'https://maps.googleapis.com/maps/api/js?v=3.exp',
jsonp: true
}
};
}
export default asyncLoading(mapScriptsToProps)(GoogleMap);