-
Notifications
You must be signed in to change notification settings - Fork 3
/
L.Control.Range.js
65 lines (54 loc) · 2.14 KB
/
L.Control.Range.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
L.Control.Range = L.Control.extend({
options: {
position: 'topright',
min: 0,
max: 100,
value: 0,
step: 1,
orient: 'vertical',
iconClass: 'leaflet-range-icon',
icon: true
},
onAdd: function(map) {
var container = L.DomUtil.create('div', 'leaflet-range-control leaflet-bar ' + this.options.orient);
if (this.options.icon) {
L.DomUtil.create('span', this.options.iconClass, container);
};
var slider = L.DomUtil.create('input', '', container);
slider.type = 'range';
slider.setAttribute('orient', this.options.orient);
slider.min = this.options.min;
slider.max = this.options.max;
slider.step = this.options.step;
slider.value = this.options.value;
L.DomEvent.on(slider, 'mousedown mouseup click touchstart', L.DomEvent.stopPropagation);
/* IE11 seems to process events in the wrong order, so the only way to prevent map movement while dragging the
* slider is to disable map dragging when the cursor enters the slider (by the time the mousedown event fires
* it's too late becuase the event seems to go to the map first, which results in any subsequent motion
* resulting in map movement even after map.dragging.disable() is called.
*/
L.DomEvent.on(slider, 'mouseenter', function(e) {
map.dragging.disable()
});
L.DomEvent.on(slider, 'mouseleave', function(e) {
map.dragging.enable();
});
L.DomEvent.on(slider, 'change', function(e) {
this.fire('change', {value: e.target.value});
}.bind(this));
L.DomEvent.on(slider, 'input', function(e) {
this.fire('input', {value: e.target.value});
}.bind(this));
this._slider = slider;
this._container = container;
return this._container;
},
setValue: function(value) {
this.options.value = value;
this._slider.value = value;
},
});
L.Control.Range.include(L.Evented.prototype)
L.control.range = function (options) {
return new L.Control.Range(options);
};