-
Notifications
You must be signed in to change notification settings - Fork 31
/
Leaflet.Control.Custom.js
65 lines (54 loc) · 2 KB
/
Leaflet.Control.Custom.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
(function (window, document, undefined) {
L.Control.Custom = L.Control.extend({
version: '1.0.1',
options: {
position: 'topright',
id: '',
title: '',
classes: '',
content: '',
style: {},
datas: {},
events: {},
},
container: null,
onAdd: function (map) {
this.container = L.DomUtil.create('div');
this.container.id = this.options.id;
this.container.title = this.options.title;
this.container.className = this.options.classes;
this.container.innerHTML = this.options.content;
for (var option in this.options.style)
{
this.container.style[option] = this.options.style[option];
}
for (var data in this.options.datas)
{
this.container.dataset[data] = this.options.datas[data];
}
/* Prevent click events propagation to map */
L.DomEvent.disableClickPropagation(this.container);
/* Prevent right click event propagation to map */
L.DomEvent.on(this.container, 'contextmenu', function (ev)
{
L.DomEvent.stopPropagation(ev);
});
/* Prevent scroll events propagation to map when cursor on the div */
L.DomEvent.disableScrollPropagation(this.container);
for (var event in this.options.events)
{
L.DomEvent.on(this.container, event, this.options.events[event], this.container);
}
return this.container;
},
onRemove: function (map) {
for (var event in this.options.events)
{
L.DomEvent.off(this.container, event, this.options.events[event], this.container);
}
},
});
L.control.custom = function (options) {
return new L.Control.Custom(options);
};
}(window, document));