-
Notifications
You must be signed in to change notification settings - Fork 939
/
InfoWindow.js
72 lines (60 loc) · 1.74 KB
/
InfoWindow.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
"use strict";
var React = require("react/addons");
var ChildMixin = require("./mixins/ChildMixin");
var EventBindingMixin = require("./mixins/EventBindingMixin");
module.exports = React.createClass({
displayName: "InfoWindow",
mixins: [ChildMixin, EventBindingMixin],
getInitialState () {
return {
infowindow: null
};
},
componentDidMount () {
var infowindow = this._init_infowindow();
if (!infowindow) return;
this.add_listeners(infowindow);
},
componentWillUpdate () {
var {infowindow} = this.state;
if (!infowindow) return;
this.clear_listeners(infowindow);
},
componentDidUpdate () {
var infowindow = this._init_infowindow();
if (!infowindow) return;
this.add_listeners(infowindow);
infowindow.setOptions(this.props);
},
componentWillUnmount () {
var {infowindow} = this.state;
if(!infowindow) return;
this.clear_listeners(infowindow);
this.setState({ infowindow: 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_infowindow () {
var {context} = this;
var {infowindow} = this.state;
if(infowindow || !context.hasMap() || !context.getApi()) {
return infowindow;
}
var {InfoWindow} = context.getApi();
if (this.props.owner) {
var {marker} = context.getRef(this.props.owner).state;
}
infowindow = new InfoWindow(this.props);
infowindow.open(context.getMap(), marker);
this.expose_getters_from(InfoWindow.prototype, infowindow);
this.setState({ infowindow });
return infowindow;
},
_render (props, state) {
return null;
}
});