-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaflet.control.views.js
108 lines (99 loc) · 3.74 KB
/
leaflet.control.views.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
L.Control.Views = L.Control.extend({
options: {
collapsed: true,
position: 'topleft',
text: '⚓',
title: 'Views navigator',
forceSeparateButton: false,
vcLatLng: [52.03, 19.27],
vcZoom: 6
},
initialize: function (views, options) {
L.setOptions(this, options);
this._views = {};
for (var i in views) {
this._addView(views[i], i);
}
},
onAdd: function (map) {
this._initLayout();
this._update();
this._map = map;
return this._container;
},
removeView: function (view, name) {
delete this._views[L.stamp(view)];
return this._update();
},
addView: function (view, name) {
this._addView(view, name);
return this._update();
},
reset: function (view, name) {
this._views = {};
return this._update();
},
_initLayout: function () {
var className = 'leaflet-control-navigate', container;
container = this._container = L.DomUtil.create('div', className);
/*
var toggler = this._layersLink = L.DomUtil.create('a', className + '-toggle', container);
toggler.href = '#';
toggler.title = 'Layers';
toggler.innerHTML = '⚓';
*/
if (!L.Browser.touch) {
L.DomEvent
.disableClickPropagation(container)
.disableScrollPropagation(container);
} else {
L.DomEvent.on(container, 'click', L.DomEvent.stopPropagation);
}
this._viewsList = L.DomUtil.create('div', className + '-list', this._container);
return container;
},
_update: function () {
if (!this._container) { return; }
this._viewsList.innerHTML = '';
var i, obj;
for (i in this._views) {
obj = this._views[i];
this._createButton(obj);
/*this._addItem(obj);*/
}
return this;
},
_addView: function (view, name) {
var id = L.stamp(view);
this._views[id] = {
view: view,
name: name
};
},
_createButton: function (obj) {
var link = L.DomUtil.create('a', 'leaflet-control-navigate-item', this._viewsList);
link.innerHTML = obj.name;
link.href = '#';
link.viewId = L.stamp(obj.view);
L.DomEvent.on(link, 'click', function(){
view = this._views[link.viewId].view;
if(view.bounds){
this._map.fitBounds(view.bounds);
}else{
this._map.setView(view.center, view.zoom);
}
}, this);
return link;
},
});
/*
L.Map.addInitHook(function () {
if (this.options.viewsControl) {
this.viewsControl = L.control.views(this.options.viewsControlOptions);
this.addControl(this.viewsControl);
}
});
*/
L.control.views = function (options) {
return new L.Control.Views(options);
};