forked from tinuzz/leaflet-messagebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaflet-messagebox.js
42 lines (35 loc) · 1.04 KB
/
leaflet-messagebox.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
L.Control.Messagebox = L.Control.extend({
options: {
position: 'topright',
timeout: 3000
},
onAdd: function (map) {
this._container = L.DomUtil.create('div', 'leaflet-control-messagebox');
//L.DomEvent.disableClickPropagation(this._container);
return this._container;
},
show: function (message, timeout) {
var elem = this._container;
elem.innerHTML = message;
elem.style.display = 'block';
timeout = timeout || this.options.timeout;
if (typeof this.timeoutID == 'number') {
clearTimeout(this.timeoutID);
}
this.timeoutID = setTimeout(function () {
elem.style.display = 'none';
}, timeout);
}
});
L.Map.mergeOptions({
messagebox: false
});
L.Map.addInitHook(function () {
if (this.options.messagebox) {
this.messagebox = new L.Control.Messagebox();
this.addControl(this.messagebox);
}
});
L.control.messagebox = function (options) {
return new L.Control.Messagebox(options);
};