-
Notifications
You must be signed in to change notification settings - Fork 68
/
entity.js
61 lines (51 loc) · 1.31 KB
/
entity.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
import React from 'react';
import createReactClass from 'create-react-class';
import Listener from '../mixins/listener';
import compareProps from '../utils/compare-props';
export default (name, latLngProp, events) => {
return createReactClass({
mixins: [Listener],
entity: null,
componentDidMount() {
const options = this.getOptions(this.props);
this.entity = new google.maps[name](options);
this.addListeners(this.entity, events);
},
componentWillReceiveProps(nextProps) {
if (!compareProps(this.props, nextProps)) {
const options = this.getOptions(nextProps);
this.entity.setOptions(options);
}
},
componentWillUnmount() {
this.entity.setMap(null);
this.removeListeners();
this.entity = null;
},
getEntity() {
return this.entity;
},
getOptions(props) {
return {
...props,
[latLngProp]: this.switchPaths(name, props)
};
},
switchPaths(name, props) {
switch (name) {
case 'Polyline':
return props.path;
break;
case 'Polygon':
return props.paths;
break;
default:
return new google.maps.LatLng(props.lat, props.lng);
break;
}
},
render() {
return null;
}
});
};