-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmandelbrot-iterations-control.js
94 lines (78 loc) · 2.86 KB
/
mandelbrot-iterations-control.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import L from './leaflet-shim.js';
const Iterations = L.Control.extend({
options: {
position: 'bottomright',
iterationsTitle: 'The current number of iterations',
decreaseIterationsTitle: 'Decrease the number of iterations',
increaseIterationsTitle: 'Increase the number of iterations',
iterationsHeaderTitle: 'The current number of iterations',
increaseIterationsText: '+',
decreaseIterationsText: '−',
},
onAdd() {
const name = 'mandelbrot-iterations';
const container = L.DomUtil.create('div', name + ' leaflet-bar');
this._iterationsHeader = this._createHeader(
'',
this.options.iterationsTitle,
name + '-header',
container,
);
const buttonsContainer = L.DomUtil.create('div', name + '-controls', container)
this._increaseIterationsButton = this._createButton(
this.options.increaseIterationsText,
this.options.increaseIterationsTitle,
name + '-increase',
buttonsContainer,
this._increaseIterations
);
this._decreaseIterationsButton = this._createButton(
this.options.decreaseIterationsText,
this.options.decreaseIterationsTitle,
name + '-decrease',
buttonsContainer,
this._decreaseIterations
);
this._map.on('iterationschange', this._updateIterationsHeader, this);
return container;
},
_createHeader: function (html, title, className, container, fn) {
var header = L.DomUtil.create('span', className, container);
header.innerHTML = html;
header.title = title;
header.setAttribute('aria-label', title);
L.DomEvent.disableClickPropagation(header);
return header;
},
_createButton: function (html, title, className, container, fn) {
var link = L.DomUtil.create('a', className, container);
link.innerHTML = html;
link.href = '#';
link.title = title;
link.setAttribute('role', 'button');
link.setAttribute('aria-label', title);
L.DomEvent.disableClickPropagation(link);
L.DomEvent.on(link, 'click', L.DomEvent.stop);
L.DomEvent.on(link, 'click', fn, this);
L.DomEvent.on(link, 'click', this._refocusOnMap, this);
return link;
},
_increaseIterations() {
this._map.increaseIterations();
},
_decreaseIterations() {
this._map.decreaseIterations();
},
_updateIterationsHeader(e) {
this._iterationsHeader.textContent = String(e.value);
}
});
L.Map.mergeOptions({
iterationsControl: false,
});
L.Map.addInitHook(function () {
if (this.options.iterationsControl) {
this._iterationsControl = new Iterations();
this.addControl(this._iterationsControl);
}
});