-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapbox-gl-view-control.js
72 lines (65 loc) · 1.89 KB
/
mapbox-gl-view-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
class ViewControl {
constructor(options = {}) {
this.options = {
initialView: {
center: [73.8274, 15.4406],
zoom: 9,
pitch: 28,
bearing: 0
},
iconUrl: 'assets/goa-icon.svg',
...options
};
}
onAdd(map) {
this._map = map;
// Create container with jQuery
this._container = $('<div>', {
class: 'mapboxgl-ctrl mapboxgl-ctrl-group'
})[0];
// Create button with jQuery
const $button = $('<button>', {
class: 'mapboxgl-ctrl-icon',
type: 'button',
'aria-label': 'Reset map view',
css: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '30px',
height: '30px'
}
});
// Create image with jQuery
const $img = $('<img>', {
src: this.options.iconUrl,
width: 20,
height: 20,
css: { display: 'block' }
});
// Add event handlers using jQuery
$button
.append($img)
.on('click', () => {
this._map.flyTo({
...this.options.initialView,
duration: 4000,
essential: true,
curve: 1.42,
speed: 0.6
});
})
.on('mouseenter', function() {
$(this).css('backgroundColor', '#f0f0f0');
})
.on('mouseleave', function() {
$(this).css('backgroundColor', '#ffffff');
})
.appendTo(this._container);
return this._container;
}
onRemove() {
$(this._container).remove();
this._map = undefined;
}
}