-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLeaflet.moduleTest.js
More file actions
205 lines (176 loc) · 6.76 KB
/
Leaflet.moduleTest.js
File metadata and controls
205 lines (176 loc) · 6.76 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//Originally copied from https://github.com/Leaflet/Leaflet.fullscreen/blob/gh-pages/dist/Leaflet.fullscreen.js
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['leaflet'], factory);
} else if (typeof module !== 'undefined') {
// Node/CommonJS
module.exports = factory(require('leaflet'));
} else {
// Browser globals
if (typeof window.L === 'undefined') {
throw new Error('Leaflet must be loaded first');
}
factory(window.L);
}
}(function (L) {
// L.Control.MarkerThumbnail = L.Control.extend({
// onAdd: function(map) {
// var img = L.DomUtil.create('img');
// img.src = './favicon-32x32.png';
// img.style.width = '200px';
// return img;
// },
// onRemove: function(map) {
// // Nothing to do here
// }
// });
// L.control.markerThumbnail = function(opts) {
// return new L.Control.MarkerThumbnail(opts);
// }
// L.control.markerThumbnail({ position: 'bottomright' }).addTo(map);
//Below is the fullscreen implementation.
L.Control.LayerPreview = L.Control.extend({
options: {
position: 'bottomright',
defaultSrc: './favicon.ico',
width: '320px',
height: '180px'
},
onAdd: function (map) {
const container = L.DomUtil.create('div', 'leaflet-control-preview leaflet-bar leaflet-control');
this.image = L.DomUtil.create('img', 'leaflet-control-preview-image leaflet-bar-part', container);
this.image.src = this.options.defaultSrc;
this.image.style.width = this.options.width;
this.image.style.height = this.options.height;
this.image.style.display = "block";
this._map = map;
// this._map.on('fullscreenchange', this._toggleTitle, this);
// this._toggleTitle();
L.DomEvent.on(this.image, 'click', this._click, this);
return container;
},
onRemove: function(map) {
// Nothing to do here
},
_click: function (e) {
L.DomEvent.stopPropagation(e);
L.DomEvent.preventDefault(e);
// this._map.toggleFullscreen(this.options);
},
// _toggleTitle: function() {
// this.link.title = this.options.title[this._map.isFullscreen()];
// }
});
L.Map.include({
setPreviewImage: function (url) {
this.layerPreview.image.src = url;
},
// isFullscreen: function () {
// return this._isFullscreen || false;
// },
// toggleFullscreen: function (options) {
// var container = this.getContainer();
// if (this.isFullscreen()) {
// if (options && options.pseudoFullscreen) {
// this._disablePseudoFullscreen(container);
// } else if (document.exitFullscreen) {
// document.exitFullscreen();
// } else if (document.mozCancelFullScreen) {
// document.mozCancelFullScreen();
// } else if (document.webkitCancelFullScreen) {
// document.webkitCancelFullScreen();
// } else if (document.msExitFullscreen) {
// document.msExitFullscreen();
// } else {
// this._disablePseudoFullscreen(container);
// }
// } else {
// if (options && options.pseudoFullscreen) {
// this._enablePseudoFullscreen(container);
// } else if (container.requestFullscreen) {
// container.requestFullscreen();
// } else if (container.mozRequestFullScreen) {
// container.mozRequestFullScreen();
// } else if (container.webkitRequestFullscreen) {
// container.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
// } else if (container.msRequestFullscreen) {
// container.msRequestFullscreen();
// } else {
// this._enablePseudoFullscreen(container);
// }
// }
// },
// _enablePseudoFullscreen: function (container) {
// L.DomUtil.addClass(container, 'leaflet-pseudo-fullscreen');
// this._setFullscreen(true);
// this.fire('fullscreenchange');
// },
// _disablePseudoFullscreen: function (container) {
// L.DomUtil.removeClass(container, 'leaflet-pseudo-fullscreen');
// this._setFullscreen(false);
// this.fire('fullscreenchange');
// },
// _setFullscreen: function(fullscreen) {
// this._isFullscreen = fullscreen;
// var container = this.getContainer();
// if (fullscreen) {
// L.DomUtil.addClass(container, 'leaflet-fullscreen-on');
// } else {
// L.DomUtil.removeClass(container, 'leaflet-fullscreen-on');
// }
// this.invalidateSize();
// },
// _onFullscreenChange: function (e) {
// var fullscreenElement =
// document.fullscreenElement ||
// document.mozFullScreenElement ||
// document.webkitFullscreenElement ||
// document.msFullscreenElement;
// if (fullscreenElement === this.getContainer() && !this._isFullscreen) {
// this._setFullscreen(true);
// this.fire('fullscreenchange');
// } else if (fullscreenElement !== this.getContainer() && this._isFullscreen) {
// this._setFullscreen(false);
// this.fire('fullscreenchange');
// }
// }
});
L.Map.mergeOptions({
layerPreview: false
});
L.Map.addInitHook(function () {
if (this.options.layerPreview) {
/* When you pass an argument to new L.Control.LayerPreview, it marges the
* arguments with the options object. This means you generally have to
* pass in an object. If you pass in a string, for example, it will
* interpret it as an array, and add a key for each index with the value
* being each letter of that string. */
// this.layerPreview = new L.Control.LayerPreview(this.options.layerPreview); //WRONG
this.layerPreview = new L.Control.LayerPreview(); //Good, unless we want extra parameters
this.addControl(this.layerPreview);
}
// var fullscreenchange;
// if ('onfullscreenchange' in document) {
// fullscreenchange = 'fullscreenchange';
// } else if ('onmozfullscreenchange' in document) {
// fullscreenchange = 'mozfullscreenchange';
// } else if ('onwebkitfullscreenchange' in document) {
// fullscreenchange = 'webkitfullscreenchange';
// } else if ('onmsfullscreenchange' in document) {
// fullscreenchange = 'MSFullscreenChange';
// }
// if (fullscreenchange) {
// var onFullscreenChange = L.bind(this._onFullscreenChange, this);
// this.whenReady(function () {
// L.DomEvent.on(document, fullscreenchange, onFullscreenChange);
// });
// this.on('unload', function () {
// L.DomEvent.off(document, fullscreenchange, onFullscreenChange);
// });
// }
});
L.control.layerPreview = function (options) {
return new L.Control.LayerPreview(options);
};
}));