-
Notifications
You must be signed in to change notification settings - Fork 939
/
Polyline.js
71 lines (58 loc) · 1.61 KB
/
Polyline.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
"use strict";
var React = require("react/addons");
var ChildMixin = require("./mixins/ChildMixin");
var EventBindingMixin = require("./mixins/EventBindingMixin");
module.exports = React.createClass({
displayName: "Polyline",
mixins: [ChildMixin, EventBindingMixin],
getInitialState () {
return {
polyline: null
};
},
componentDidMount () {
var polyline = this._init_polyline();
if (!polyline) return;
this.add_listeners(polyline);
},
componentWillUpdate () {
var {polyline} = this.state;
if (!polyline) return;
this.clear_listeners(polyline);
},
componentDidUpdate () {
var polyline = this._init_polyline();
if (!polyline) return;
this.add_listeners(polyline);
polyline.setOptions(this.props);
},
componentWillUnmount () {
var {polyline} = this.state;
if (!polyline) return;
this.clear_listeners(polyline);
polyline.setMap(null);
this.setState({ polyline: null });
},
render () {
return this._render(this.props, this.state);
},
get_event_names () {
return "click dblclick drag dragend dragstart mousedown mousemove mouseout mouseover mouseup rightclick";
},
_init_polyline () {
var {context} = this;
var {polyline} = this.state;
if (polyline || !context.hasMap() || !context.getApi()) {
return polyline;
}
var {Polyline} = context.getApi();
polyline = new Polyline(this.props);
polyline.setMap(context.getMap());
this.expose_getters_from(Polyline.prototype, polyline);
this.setState({ polyline });
return polyline;
},
_render (props, state) {
return null;
}
});