-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathsubtoolbar.html
94 lines (93 loc) · 3.33 KB
/
subtoolbar.html
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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"/>
<link rel="stylesheet" type="text/css" href="../node_modules/leaflet/dist/leaflet.css" />
<link rel="stylesheet" href="../dist/leaflet.toolbar.css"/>
<script src="../node_modules/leaflet/dist/leaflet-src.js"></script>
<script src="../dist/leaflet.toolbar-src.js"></script>
<style>
html, body, #map {
margin: 0;
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map('map').setView([41.7896, -87.5996], 15);
L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution: '<a href="http://openstreetmap.org/copyright">OpenStreetMap Contributors</a>'
}).addTo(map);
/* A sub-action which completes as soon as it is activated.
* Sub-actions receive their parent action as an argument to
* their `initialize` function. We save a reference to this
* parent action so we can disable it as soon as the sub-action
* completes.
*/
var ImmediateSubAction = L.Toolbar2.Action.extend({
initialize: function(map, myAction) {
this.map = map;
this.myAction = myAction;
L.Toolbar2.Action.prototype.initialize.call(this);
},
addHooks: function() {
this.myAction.disable();
}
});
var World = ImmediateSubAction.extend({
options: {
toolbarIcon: {
html: 'World',
tooltip: 'See the whole world'
}
},
addHooks: function () {
this.map.setView([0, 0], 0);
ImmediateSubAction.prototype.addHooks.call(this);
}
});
var Eiffel = ImmediateSubAction.extend({
options: {
toolbarIcon: {
html: 'Eiffel Tower',
tooltip: 'Go to the Eiffel Tower'
}
},
addHooks: function () {
this.map.setView([48.85815, 2.29420], 19);
ImmediateSubAction.prototype.addHooks.call(this);
}
});
var Cancel = ImmediateSubAction.extend({
options: {
toolbarIcon: {
html: '<i class="fa fa-times"></i>',
tooltip: 'Cancel'
}
}
});
var MyCustomAction = L.Toolbar2.Action.extend({
options: {
toolbarIcon: {
className: 'fa fa-eye',
},
/* Use L.Toolbar2 for sub-toolbars. A sub-toolbar is,
* by definition, contained inside another toolbar, so it
* doesn't need the additional styling and behavior of a
* L.Toolbar2.Control or L.Toolbar2.Popup.
*/
subToolbar: new L.Toolbar2({
actions: [World, Eiffel, Cancel]
})
}
});
new L.Toolbar2.Control({
position: 'topleft',
actions: [MyCustomAction]
}).addTo(map);
</script>
</body>
</html>