|
0 |
/*
|
|
1 |
Leaflet, a JavaScript library for mobile-friendly interactive maps. http://leafletjs.com
|
|
2 |
(c) 2010-2013, Vladimir Agafonkin
|
|
3 |
(c) 2010-2011, CloudMade
|
|
4 |
*/
|
|
5 |
(function (window, document, undefined) {
|
|
6 |
var oldL = window.L,
|
|
7 |
L = {};
|
|
8 |
|
|
9 |
L.version = '0.7.3';
|
|
10 |
|
|
11 |
// define Leaflet for Node module pattern loaders, including Browserify
|
|
12 |
if (typeof module === 'object' && typeof module.exports === 'object') {
|
|
13 |
module.exports = L;
|
|
14 |
|
|
15 |
// define Leaflet as an AMD module
|
|
16 |
} else if (typeof define === 'function' && define.amd) {
|
|
17 |
define(L);
|
|
18 |
}
|
|
19 |
|
|
20 |
// define Leaflet as a global L variable, saving the original L to restore later if needed
|
|
21 |
|
|
22 |
L.noConflict = function () {
|
|
23 |
window.L = oldL;
|
|
24 |
return this;
|
|
25 |
};
|
|
26 |
|
|
27 |
window.L = L;
|
|
28 |
|
|
29 |
|
|
30 |
/*
|
|
31 |
* L.Util contains various utility functions used throughout Leaflet code.
|
|
32 |
*/
|
|
33 |
|
|
34 |
L.Util = {
|
|
35 |
extend: function (dest) { // (Object[, Object, ...]) ->
|
|
36 |
var sources = Array.prototype.slice.call(arguments, 1),
|
|
37 |
i, j, len, src;
|
|
38 |
|
|
39 |
for (j = 0, len = sources.length; j < len; j++) {
|
|
40 |
src = sources[j] || {};
|
|
41 |
for (i in src) {
|
|
42 |
if (src.hasOwnProperty(i)) {
|
|
43 |
dest[i] = src[i];
|
|
44 |
}
|
|
45 |
}
|
|
46 |
}
|
|
47 |
return dest;
|
|
48 |
},
|
|
49 |
|
|
50 |
bind: function (fn, obj) { // (Function, Object) -> Function
|
|
51 |
var args = arguments.length > 2 ? Array.prototype.slice.call(arguments, 2) : null;
|
|
52 |
return function () {
|
|
53 |
return fn.apply(obj, args || arguments);
|
|
54 |
};
|
|
55 |
},
|
|
56 |
|
|
57 |
stamp: (function () {
|
|
58 |
var lastId = 0,
|
|
59 |
key = '_leaflet_id';
|
|
60 |
return function (obj) {
|
|
61 |
obj[key] = obj[key] || ++lastId;
|
|
62 |
return obj[key];
|
|
63 |
};
|
|
64 |
}()),
|
|
65 |
|
|
66 |
invokeEach: function (obj, method, context) {
|
|
67 |
var i, args;
|
|
68 |
|
|
69 |
if (typeof obj === 'object') {
|
|
70 |
args = Array.prototype.slice.call(arguments, 3);
|
|
71 |
|
|
72 |
for (i in obj) {
|
|
73 |
method.apply(context, [i, obj[i]].concat(args));
|
|
74 |
}
|
|
75 |
return true;
|
|
76 |
}
|
|
77 |
|
|
78 |
return false;
|
|
79 |
},
|
|
80 |
|
|
81 |
limitExecByInterval: function (fn, time, context) {
|
|
82 |
var lock, execOnUnlock;
|
|
83 |
|
|
84 |
return function wrapperFn() {
|
|
85 |
var args = arguments;
|
|
86 |
|
|
87 |
if (lock) {
|
|
88 |
execOnUnlock = true;
|
|
89 |
return;
|
|
90 |
}
|
|
91 |
|
|
92 |
lock = true;
|
|
93 |
|
|
94 |
setTimeout(function () {
|
|
95 |
lock = false;
|
|
96 |
|
|
97 |
if (execOnUnlock) {
|
|
98 |
wrapperFn.apply(context, args);
|
|
99 |
execOnUnlock = false;
|
|
100 |
}
|
|
101 |
}, time);
|
|
102 |
|
|
103 |
fn.apply(context, args);
|
|
104 |
};
|
|
105 |
},
|
|
106 |
|
|
107 |
falseFn: function () {
|
|
108 |
return false;
|
|
109 |
},
|
|
110 |
|
|
111 |
formatNum: function (num, digits) {
|
|
112 |
var pow = Math.pow(10, digits || 5);
|
|
113 |
return Math.round(num * pow) / pow;
|
|
114 |
},
|
|
115 |
|
|
116 |
trim: function (str) {
|
|
117 |
return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '');
|
|
118 |
},
|
|
119 |
|
|
120 |
splitWords: function (str) {
|
|
121 |
return L.Util.trim(str).split(/\s+/);
|
|
122 |
},
|
|
123 |
|
|
124 |
setOptions: function (obj, options) {
|
|
125 |
obj.options = L.extend({}, obj.options, options);
|
|
126 |
return obj.options;
|
|
127 |
},
|
|
128 |
|
|
129 |
getParamString: function (obj, existingUrl, uppercase) {
|
|
130 |
var params = [];
|
|
131 |
for (var i in obj) {
|
|
132 |
params.push(encodeURIComponent(uppercase ? i.toUpperCase() : i) + '=' + encodeURIComponent(obj[i]));
|
|
133 |
}
|
|
134 |
return ((!existingUrl || existingUrl.indexOf('?') === -1) ? '?' : '&') + params.join('&');
|
|
135 |
},
|
|
136 |
template: function (str, data) {
|
|
137 |
return str.replace(/\{ *([\w_]+) *\}/g, function (str, key) {
|
|
138 |
var value = data[key];
|
|
139 |
if (value === undefined) {
|
|
140 |
throw new Error('No value provided for variable ' + str);
|
|
141 |
} else if (typeof value === 'function') {
|
|
142 |
value = value(data);
|
|
143 |
}
|
|
144 |
return value;
|
|
145 |
});
|
|
146 |
},
|
|
147 |
|
|
148 |
isArray: Array.isArray || function (obj) {
|
|
149 |
return (Object.prototype.toString.call(obj) === '[object Array]');
|
|
150 |
},
|
|
151 |
|
|
152 |
emptyImageUrl: 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='
|
|
153 |
};
|
|
154 |
|
|
155 |
(function () {
|
|
156 |
|
|
157 |
// inspired by http://paulirish.com/2011/requestanimationframe-for-smart-animating/
|
|
158 |
|
|
159 |
function getPrefixed(name) {
|
|
160 |
var i, fn,
|
|
161 |
prefixes = ['webkit', 'moz', 'o', 'ms'];
|
|
162 |
|
|
163 |
for (i = 0; i < prefixes.length && !fn; i++) {
|
|
164 |
fn = window[prefixes[i] + name];
|
|
165 |
}
|
|
166 |
|
|
167 |
return fn;
|
|
168 |
}
|
|
169 |
|
|
170 |
var lastTime = 0;
|
|
171 |
|
|
172 |
function timeoutDefer(fn) {
|
|
173 |
var time = +new Date(),
|
|
174 |
timeToCall = Math.max(0, 16 - (time - lastTime));
|
|
175 |
|
|
176 |
lastTime = time + timeToCall;
|
|
177 |
return window.setTimeout(fn, timeToCall);
|
|
178 |
}
|
|
179 |
|
|
180 |
var requestFn = window.requestAnimationFrame ||
|
|
181 |
getPrefixed('RequestAnimationFrame') || timeoutDefer;
|
|
182 |
|
|
183 |
var cancelFn = window.cancelAnimationFrame ||
|
|
184 |
getPrefixed('CancelAnimationFrame') ||
|
|
185 |
getPrefixed('CancelRequestAnimationFrame') ||
|
|
186 |
function (id) { window.clearTimeout(id); };
|
|
187 |
|
|
188 |
|
|
189 |
L.Util.requestAnimFrame = function (fn, context, immediate, element) {
|
|
190 |
fn = L.bind(fn, context);
|
|
191 |
|
|
192 |
if (immediate && requestFn === timeoutDefer) {
|
|
193 |
fn();
|
|
194 |
} else {
|
|
195 |
return requestFn.call(window, fn, element);
|
|
196 |
}
|
|
197 |
};
|
|
198 |
|
|
199 |
L.Util.cancelAnimFrame = function (id) {
|
|
200 |
if (id) {
|
|
201 |
cancelFn.call(window, id);
|
|
202 |
}
|
|
203 |
};
|
|
204 |
|
|
205 |
}());
|
|
206 |
|
|
207 |
// shortcuts for most used utility functions
|
|
208 |
L.extend = L.Util.extend;
|
|
209 |
L.bind = L.Util.bind;
|
|
210 |
L.stamp = L.Util.stamp;
|
|
211 |
L.setOptions = L.Util.setOptions;
|
|
212 |
|
|
213 |
|
|
214 |
/*
|
|
215 |
* L.Class powers the OOP facilities of the library.
|
|
216 |
* Thanks to John Resig and Dean Edwards for inspiration!
|
|
217 |
*/
|
|
218 |
|
|
219 |
L.Class = function () {};
|
|
220 |
|
|
221 |
L.Class.extend = function (props) {
|
|
222 |
|
|
223 |
// extended class with the new prototype
|
|
224 |
var NewClass = function () {
|
|
225 |
|
|
226 |
// call the constructor
|
|
227 |
if (this.initialize) {
|
|
228 |
this.initialize.apply(this, arguments);
|
|
229 |
}
|
|
230 |
|
|
231 |
// call all constructor hooks
|
|
232 |
if (this._initHooks) {
|
|
233 |
this.callInitHooks();
|
|
234 |
}
|
|
235 |
};
|
|
236 |
|
|
237 |
// instantiate class without calling constructor
|
|
238 |
var F = function () {};
|
|
239 |
F.prototype = this.prototype;
|
|
240 |
|
|
241 |
var proto = new F();
|
|
242 |
proto.constructor = NewClass;
|
|
243 |
|
|
244 |
NewClass.prototype = proto;
|
|
245 |
|
|
246 |
//inherit parent's statics
|
|
247 |
for (var i in this) {
|
|
248 |
if (this.hasOwnProperty(i) && i !== 'prototype') {
|
|
249 |
NewClass[i] = this[i];
|
|
250 |
}
|
|
251 |
}
|
|
252 |
|
|
253 |
// mix static properties into the class
|
|
254 |
if (props.statics) {
|
|
255 |
L.extend(NewClass, props.statics);
|
|
256 |
delete props.statics;
|
|
257 |
}
|
|
258 |
|
|
259 |
// mix includes into the prototype
|
|
260 |
if (props.includes) {
|
|
261 |
L.Util.extend.apply(null, [proto].concat(props.includes));
|
|
262 |
delete props.includes;
|
|
263 |
}
|
|
264 |
|
|
265 |
// merge options
|
|
266 |
if (props.options && proto.options) {
|
|
267 |
props.options = L.extend({}, proto.options, props.options);
|
|
268 |
}
|
|
269 |
|
|
270 |
// mix given properties into the prototype
|
|
271 |
L.extend(proto, props);
|
|
272 |
|
|
273 |
proto._initHooks = [];
|
|
274 |
|
|
275 |
var parent = this;
|
|
276 |
// jshint camelcase: false
|
|
277 |
NewClass.__super__ = parent.prototype;
|
|
278 |
|
|
279 |
// add method for calling all hooks
|
|
280 |
proto.callInitHooks = function () {
|
|
281 |
|
|
282 |
if (this._initHooksCalled) { return; }
|
|
283 |
|
|
284 |
if (parent.prototype.callInitHooks) {
|
|
285 |
parent.prototype.callInitHooks.call(this);
|
|
286 |
}
|
|
287 |
|
|
288 |
this._initHooksCalled = true;
|
|
289 |
|
|
290 |
for (var i = 0, len = proto._initHooks.length; i < len; i++) {
|
|
291 |
proto._initHooks[i].call(this);
|
|
292 |
}
|
|
293 |
};
|
|
294 |
|
|
295 |
return NewClass;
|
|
296 |
};
|
|
297 |
|
|
298 |
|
|
299 |
// method for adding properties to prototype
|
|
300 |
L.Class.include = function (props) {
|
|
301 |
L.extend(this.prototype, props);
|
|
302 |
};
|
|
303 |
|
|
304 |
// merge new default options to the Class
|
|
305 |
L.Class.mergeOptions = function (options) {
|
|
306 |
L.extend(this.prototype.options, options);
|
|
307 |
};
|
|
308 |
|
|
309 |
// add a constructor hook
|
|
310 |
L.Class.addInitHook = function (fn) { // (Function) || (String, args...)
|
|
311 |
var args = Array.prototype.slice.call(arguments, 1);
|
|
312 |
|
|
313 |
var init = typeof fn === 'function' ? fn : function () {
|
|
314 |
this[fn].apply(this, args);
|
|
315 |
};
|
|
316 |
|
|
317 |
this.prototype._initHooks = this.prototype._initHooks || [];
|
|
318 |
this.prototype._initHooks.push(init);
|
|
319 |
};
|
|
320 |
|
|
321 |
|
|
322 |
/*
|
|
323 |
* L.Mixin.Events is used to add custom events functionality to Leaflet classes.
|
|
324 |
*/
|
|
325 |
|
|
326 |
var eventsKey = '_leaflet_events';
|
|
327 |
|
|
328 |
L.Mixin = {};
|
|
329 |
|
|
330 |
L.Mixin.Events = {
|
|
331 |
|
|
332 |
addEventListener: function (types, fn, context) { // (String, Function[, Object]) or (Object[, Object])
|
|
333 |
|
|
334 |
// types can be a map of types/handlers
|
|
335 |
if (L.Util.invokeEach(types, this.addEventListener, this, fn, context)) { return this; }
|
|
336 |
|
|
337 |
var events = this[eventsKey] = this[eventsKey] || {},
|
|
338 |
contextId = context && context !== this && L.stamp(context),
|
|
339 |
i, len, event, type, indexKey, indexLenKey, typeIndex;
|
|
340 |
|
|
341 |
// types can be a string of space-separated words
|
|
342 |
types = L.Util.splitWords(types);
|
|
343 |
|
|
344 |
for (i = 0, len = types.length; i < len; i++) {
|
|
345 |
event = {
|
|
346 |
action: fn,
|
|
347 |
context: context || this
|
|
348 |
};
|
|
349 |
type = types[i];
|
|
350 |
|
|
351 |
if (contextId) {
|
|
352 |
// store listeners of a particular context in a separate hash (if it has an id)
|
|
353 |
// gives a major performance boost when removing thousands of map layers
|
|
354 |
|
|
355 |
indexKey = type + '_idx';
|
|
356 |
indexLenKey = indexKey + '_len';
|
|
357 |
|
|
358 |
typeIndex = events[indexKey] = events[indexKey] || {};
|
|
359 |
|
|
360 |
if (!typeIndex[contextId]) {
|
|
361 |
typeIndex[contextId] = [];
|
|
362 |
|
|
363 |
// keep track of the number of keys in the index to quickly check if it's empty
|
|
364 |
events[indexLenKey] = (events[indexLenKey] || 0) + 1;
|
|
365 |
}
|
|
366 |
|
|
367 |
typeIndex[contextId].push(event);
|
|
368 |
|
|
369 |
|
|
370 |
} else {
|
|
371 |
events[type] = events[type] || [];
|
|
372 |
events[type].push(event);
|
|
373 |
}
|
|
374 |
}
|
|
375 |
|
|
376 |
return this;
|
|
377 |
},
|
|
378 |
|
|
379 |
hasEventListeners: function (type) { // (String) -> Boolean
|
|
380 |
var events = this[eventsKey];
|
|
381 |
return !!events && ((type in events && events[type].length > 0) ||
|
|
382 |
(type + '_idx' in events && events[type + '_idx_len'] > 0));
|
|
383 |
},
|
|
384 |
|
|
385 |
removeEventListener: function (types, fn, context) { // ([String, Function, Object]) or (Object[, Object])
|
|
386 |
|
|
387 |
if (!this[eventsKey]) {
|
|
388 |
return this;
|
|
389 |
}
|
|
390 |
|
|
391 |
if (!types) {
|
|
392 |
return this.clearAllEventListeners();
|
|
393 |
}
|
|
394 |
|
|
395 |
if (L.Util.invokeEach(types, this.removeEventListener, this, fn, context)) { return this; }
|
|
396 |
|
|
397 |
var events = this[eventsKey],
|
|
398 |
contextId = context && context !== this && L.stamp(context),
|
|
399 |
i, len, type, listeners, j, indexKey, indexLenKey, typeIndex, removed;
|
|
400 |
|
|
401 |
types = L.Util.splitWords(types);
|
|
402 |
|
|
403 |
for (i = 0, len = types.length; i < len; i++) {
|
|
404 |
type = types[i];
|
|
405 |
indexKey = type + '_idx';
|
|
406 |
indexLenKey = indexKey + '_len';
|
|
407 |
|
|
408 |
typeIndex = events[indexKey];
|
|
409 |
|
|
410 |
if (!fn) {
|
|
411 |
// clear all listeners for a type if function isn't specified
|
|
412 |
delete events[type];
|
|
413 |
delete events[indexKey];
|
|
414 |
delete events[indexLenKey];
|
|
415 |
|
|
416 |
} else {
|
|
417 |
listeners = contextId && typeIndex ? typeIndex[contextId] : events[type];
|
|
418 |
|
|
419 |
if (listeners) {
|
|
420 |
for (j = listeners.length - 1; j >= 0; j--) {
|
|
421 |
if ((listeners[j].action === fn) && (!context || (listeners[j].context === context))) {
|
|
422 |
removed = listeners.splice(j, 1);
|
|
423 |
// set the old action to a no-op, because it is possible
|
|
424 |
// that the listener is being iterated over as part of a dispatch
|
|
425 |
removed[0].action = L.Util.falseFn;
|
|
426 |
}
|
|
427 |
}
|
|
428 |
|
|
429 |
if (context && typeIndex && (listeners.length === 0)) {
|
|
430 |
delete typeIndex[contextId];
|
|
431 |
events[indexLenKey]--;
|
|
432 |
}
|
|
433 |
}
|
|
434 |
}
|
|
435 |
}
|
|
436 |
|
|
437 |
return this;
|
|
438 |
},
|
|
439 |
|
|
440 |
clearAllEventListeners: function () {
|
|
441 |
delete this[eventsKey];
|
|
442 |
return this;
|
|
443 |
},
|
|
444 |
|
|
445 |
fireEvent: function (type, data) { // (String[, Object])
|
|
446 |
if (!this.hasEventListeners(type)) {
|
|
447 |
return this;
|
|
448 |
}
|
|
449 |
|
|
450 |
var event = L.Util.extend({}, data, { type: type, target: this });
|
|
451 |
|
|
452 |
var events = this[eventsKey],
|
|
453 |
listeners, i, len, typeIndex, contextId;
|
|
454 |
|
|
455 |
if (events[type]) {
|
|
456 |
// make sure adding/removing listeners inside other listeners won't cause infinite loop
|
|
457 |
listeners = events[type].slice();
|
|
458 |
|
|
459 |
for (i = 0, len = listeners.length; i < len; i++) {
|
|
460 |
listeners[i].action.call(listeners[i].context, event);
|
|
461 |
}
|
|
462 |
}
|
|
463 |
|
|
464 |
// fire event for the context-indexed listeners as well
|
|
465 |
typeIndex = events[type + '_idx'];
|
|
466 |
|
|
467 |
for (contextId in typeIndex) {
|
|
468 |
listeners = typeIndex[contextId].slice();
|
|
469 |
|
|
470 |
if (listeners) {
|
|
471 |
for (i = 0, len = listeners.length; i < len; i++) {
|
|
472 |
listeners[i].action.call(listeners[i].context, event);
|
|
473 |
}
|
|
474 |
}
|
|
475 |
}
|
|
476 |
|
|
477 |
return this;
|
|
478 |
},
|
|
479 |
|
|
480 |
addOneTimeEventListener: function (types, fn, context) {
|
|
481 |
|
|
482 |
if (L.Util.invokeEach(types, this.addOneTimeEventListener, this, fn, context)) { return this; }
|
|
483 |
|
|
484 |
var handler = L.bind(function () {
|
|
485 |
this
|
|
486 |
.removeEventListener(types, fn, context)
|
|
487 |
.removeEventListener(types, handler, context);
|
|
488 |
}, this);
|
|
489 |
|
|
490 |
return this
|
|
491 |
.addEventListener(types, fn, context)
|
|
492 |
.addEventListener(types, handler, context);
|
|
493 |
}
|
|
494 |
};
|
|
495 |
|
|
496 |
L.Mixin.Events.on = L.Mixin.Events.addEventListener;
|
|
497 |
L.Mixin.Events.off = L.Mixin.Events.removeEventListener;
|
|
498 |
L.Mixin.Events.once = L.Mixin.Events.addOneTimeEventListener;
|
|
499 |
L.Mixin.Events.fire = L.Mixin.Events.fireEvent;
|
|
500 |
|
|
501 |
|
|
502 |
/*
|
|
503 |
* L.Browser handles different browser and feature detections for internal Leaflet use.
|
|
504 |
*/
|
|
505 |
|
|
506 |
(function () {
|
|
507 |
|
|
508 |
var ie = 'ActiveXObject' in window,
|
|
509 |
ielt9 = ie && !document.addEventListener,
|
|
510 |
|
|
511 |
// terrible browser detection to work around Safari / iOS / Android browser bugs
|
|
512 |
ua = navigator.userAgent.toLowerCase(),
|
|
513 |
webkit = ua.indexOf('webkit') !== -1,
|
|
514 |
chrome = ua.indexOf('chrome') !== -1,
|
|
515 |
phantomjs = ua.indexOf('phantom') !== -1,
|
|
516 |
android = ua.indexOf('android') !== -1,
|
|
517 |
android23 = ua.search('android [23]') !== -1,
|
|
518 |
gecko = ua.indexOf('gecko') !== -1,
|
|
519 |
|
|
520 |
mobile = typeof orientation !== undefined + '',
|
|
521 |
msPointer = window.navigator && window.navigator.msPointerEnabled &&
|
|
522 |
window.navigator.msMaxTouchPoints && !window.PointerEvent,
|
|
523 |
pointer = (window.PointerEvent && window.navigator.pointerEnabled && window.navigator.maxTouchPoints) ||
|
|
524 |
msPointer,
|
|
525 |
retina = ('devicePixelRatio' in window && window.devicePixelRatio > 1) ||
|
|
526 |
('matchMedia' in window && window.matchMedia('(min-resolution:144dpi)') &&
|
|
527 |
window.matchMedia('(min-resolution:144dpi)').matches),
|
|
528 |
|
|
529 |
doc = document.documentElement,
|
|
530 |
ie3d = ie && ('transition' in doc.style),
|
|
531 |
webkit3d = ('WebKitCSSMatrix' in window) && ('m11' in new window.WebKitCSSMatrix()) && !android23,
|
|
532 |
gecko3d = 'MozPerspective' in doc.style,
|
|
533 |
opera3d = 'OTransition' in doc.style,
|
|
534 |
any3d = !window.L_DISABLE_3D && (ie3d || webkit3d || gecko3d || opera3d) && !phantomjs;
|
|
535 |
|
|
536 |
|
|
537 |
// PhantomJS has 'ontouchstart' in document.documentElement, but doesn't actually support touch.
|
|
538 |
// https://github.com/Leaflet/Leaflet/pull/1434#issuecomment-13843151
|
|
539 |
|
|
540 |
var touch = !window.L_NO_TOUCH && !phantomjs && (function () {
|
|
541 |
|
|
542 |
var startName = 'ontouchstart';
|
|
543 |
|
|
544 |
// IE10+ (We simulate these into touch* events in L.DomEvent and L.DomEvent.Pointer) or WebKit, etc.
|
|
545 |
if (pointer || (startName in doc)) {
|
|
546 |
return true;
|
|
547 |
}
|
|
548 |
|
|
549 |
// Firefox/Gecko
|
|
550 |
var div = document.createElement('div'),
|
|
551 |
supported = false;
|
|
552 |
|
|
553 |
if (!div.setAttribute) {
|
|
554 |
return false;
|
|
555 |
}
|
|
556 |
div.setAttribute(startName, 'return;');
|
|
557 |
|
|
558 |
if (typeof div[startName] === 'function') {
|
|
559 |
supported = true;
|
|
560 |
}
|
|
561 |
|
|
562 |
div.removeAttribute(startName);
|
|
563 |
div = null;
|
|
564 |
|
|
565 |
return supported;
|
|
566 |
}());
|
|
567 |
|
|
568 |
|
|
569 |
L.Browser = {
|
|
570 |
ie: ie,
|
|
571 |
ielt9: ielt9,
|
|
572 |
webkit: webkit,
|
|
573 |
gecko: gecko && !webkit && !window.opera && !ie,
|
|
574 |
|
|
575 |
android: android,
|
|
576 |
android23: android23,
|
|
577 |
|
|
578 |
chrome: chrome,
|
|
579 |
|
|
580 |
ie3d: ie3d,
|
|
581 |
webkit3d: webkit3d,
|
|
582 |
gecko3d: gecko3d,
|
|
583 |
opera3d: opera3d,
|
|
584 |
any3d: any3d,
|
|
585 |
|
|
586 |
mobile: mobile,
|
|
587 |
mobileWebkit: mobile && webkit,
|
|
588 |
mobileWebkit3d: mobile && webkit3d,
|
|
589 |
mobileOpera: mobile && window.opera,
|
|
590 |
|
|
591 |
touch: touch,
|
|
592 |
msPointer: msPointer,
|
|
593 |
pointer: pointer,
|
|
594 |
|
|
595 |
retina: retina
|
|
596 |
};
|
|
597 |
|
|
598 |
}());
|
|
599 |
|
|
600 |
|
|
601 |
/*
|
|
602 |
* L.Point represents a point with x and y coordinates.
|
|
603 |
*/
|
|
604 |
|
|
605 |
L.Point = function (/*Number*/ x, /*Number*/ y, /*Boolean*/ round) {
|
|
606 |
this.x = (round ? Math.round(x) : x);
|
|
607 |
this.y = (round ? Math.round(y) : y);
|
|
608 |
};
|
|
609 |
|
|
610 |
L.Point.prototype = {
|
|
611 |
|
|
612 |
clone: function () {
|
|
613 |
return new L.Point(this.x, this.y);
|
|
614 |
},
|
|
615 |
|
|
616 |
// non-destructive, returns a new point
|
|
617 |
add: function (point) {
|
|
618 |
return this.clone()._add(L.point(point));
|
|
619 |
},
|
|
620 |
|
|
621 |
// destructive, used directly for performance in situations where it's safe to modify existing point
|
|
622 |
_add: function (point) {
|
|
623 |
this.x += point.x;
|
|
624 |
this.y += point.y;
|
|
625 |
return this;
|
|
626 |
},
|
|
627 |
|
|
628 |
subtract: function (point) {
|
|
629 |
return this.clone()._subtract(L.point(point));
|
|
630 |
},
|
|
631 |
|
|
632 |
_subtract: function (point) {
|
|
633 |
this.x -= point.x;
|
|
634 |
this.y -= point.y;
|
|
635 |
return this;
|
|
636 |
},
|
|
637 |
|
|
638 |
divideBy: function (num) {
|
|
639 |
return this.clone()._divideBy(num);
|
|
640 |
},
|
|
641 |
|
|
642 |
_divideBy: function (num) {
|
|
643 |
this.x /= num;
|
|
644 |
this.y /= num;
|
|
645 |
return this;
|
|
646 |
},
|
|
647 |
|
|
648 |
multiplyBy: function (num) {
|
|
649 |
return this.clone()._multiplyBy(num);
|
|
650 |
},
|
|
651 |
|
|
652 |
_multiplyBy: function (num) {
|
|
653 |
this.x *= num;
|
|
654 |
this.y *= num;
|
|
655 |
return this;
|
|
656 |
},
|
|
657 |
|
|
658 |
round: function () {
|
|
659 |
return this.clone()._round();
|
|
660 |
},
|
|
661 |
|
|
662 |
_round: function () {
|
|
663 |
this.x = Math.round(this.x);
|
|
664 |
this.y = Math.round(this.y);
|
|
665 |
return this;
|
|
666 |
},
|
|
667 |
|
|
668 |
floor: function () {
|
|
669 |
return this.clone()._floor();
|
|
670 |
},
|
|
671 |
|
|
672 |
_floor: function () {
|
|
673 |
this.x = Math.floor(this.x);
|
|
674 |
this.y = Math.floor(this.y);
|
|
675 |
return this;
|
|
676 |
},
|
|
677 |
|
|
678 |
distanceTo: function (point) {
|
|
679 |
point = L.point(point);
|
|
680 |
|
|
681 |
var x = point.x - this.x,
|
|
682 |
y = point.y - this.y;
|
|
683 |
|
|
684 |
return Math.sqrt(x * x + y * y);
|
|
685 |
},
|
|
686 |
|
|
687 |
equals: function (point) {
|
|
688 |
point = L.point(point);
|
|
689 |
|
|
690 |
return point.x === this.x &&
|
|
691 |
point.y === this.y;
|
|
692 |
},
|
|
693 |
|
|
694 |
contains: function (point) {
|
|
695 |
point = L.point(point);
|
|
696 |
|
|
697 |
return Math.abs(point.x) <= Math.abs(this.x) &&
|
|
698 |
Math.abs(point.y) <= Math.abs(this.y);
|
|
699 |
},
|
|
700 |
|
|
701 |
toString: function () {
|
|
702 |
return 'Point(' +
|
|
703 |
L.Util.formatNum(this.x) + ', ' +
|
|
704 |
L.Util.formatNum(this.y) + ')';
|
|
705 |
}
|
|
706 |
};
|
|
707 |
|
|
708 |
L.point = function (x, y, round) {
|
|
709 |
if (x instanceof L.Point) {
|
|
710 |
return x;
|
|
711 |
}
|
|
712 |
if (L.Util.isArray(x)) {
|
|
713 |
return new L.Point(x[0], x[1]);
|
|
714 |
}
|
|
715 |
if (x === undefined || x === null) {
|
|
716 |
return x;
|
|
717 |
}
|
|
718 |
return new L.Point(x, y, round);
|
|
719 |
};
|
|
720 |
|
|
721 |
|
|
722 |
/*
|
|
723 |
* L.Bounds represents a rectangular area on the screen in pixel coordinates.
|
|
724 |
*/
|
|
725 |
|
|
726 |
L.Bounds = function (a, b) { //(Point, Point) or Point[]
|
|
727 |
if (!a) { return; }
|
|
728 |
|
|
729 |
var points = b ? [a, b] : a;
|
|
730 |
|
|
731 |
for (var i = 0, len = points.length; i < len; i++) {
|
|
732 |
this.extend(points[i]);
|
|
733 |
}
|
|
734 |
};
|
|
735 |
|
|
736 |
L.Bounds.prototype = {
|
|
737 |
// extend the bounds to contain the given point
|
|
738 |
extend: function (point) { // (Point)
|
|
739 |
point = L.point(point);
|
|
740 |
|
|
741 |
if (!this.min && !this.max) {
|
|
742 |
this.min = point.clone();
|
|
743 |
this.max = point.clone();
|
|
744 |
} else {
|
|
745 |
this.min.x = Math.min(point.x, this.min.x);
|
|
746 |
this.max.x = Math.max(point.x, this.max.x);
|
|
747 |
this.min.y = Math.min(point.y, this.min.y);
|
|
748 |
this.max.y = Math.max(point.y, this.max.y);
|
|
749 |
}
|
|
750 |
return this;
|
|
751 |
},
|
|
752 |
|
|
753 |
getCenter: function (round) { // (Boolean) -> Point
|
|
754 |
return new L.Point(
|
|
755 |
(this.min.x + this.max.x) / 2,
|
|
756 |
(this.min.y + this.max.y) / 2, round);
|
|
757 |
},
|
|
758 |
|
|
759 |
getBottomLeft: function () { // -> Point
|
|
760 |
return new L.Point(this.min.x, this.max.y);
|
|
761 |
},
|
|
762 |
|
|
763 |
getTopRight: function () { // -> Point
|
|
764 |
return new L.Point(this.max.x, this.min.y);
|
|
765 |
},
|
|
766 |
|
|
767 |
getSize: function () {
|
|
768 |
return this.max.subtract(this.min);
|
|
769 |
},
|
|
770 |
|
|
771 |
contains: function (obj) { // (Bounds) or (Point) -> Boolean
|
|
772 |
var min, max;
|
|
773 |
|
|
774 |
if (typeof obj[0] === 'number' || obj instanceof L.Point) {
|
|
775 |
obj = L.point(obj);
|
|
776 |
} else {
|
|
777 |
obj = L.bounds(obj);
|
|
778 |
}
|
|
779 |
|
|
780 |
if (obj instanceof L.Bounds) {
|
|
781 |
min = obj.min;
|
|
782 |
max = obj.max;
|
|
783 |
} else {
|
|
784 |
min = max = obj;
|
|
785 |
}
|
|
786 |
|
|
787 |
return (min.x >= this.min.x) &&
|
|
788 |
(max.x <= this.max.x) &&
|
|
789 |
(min.y >= this.min.y) &&
|
|
790 |
(max.y <= this.max.y);
|
|
791 |
},
|
|
792 |
|
|
793 |
intersects: function (bounds) { // (Bounds) -> Boolean
|
|
794 |
bounds = L.bounds(bounds);
|
|
795 |
|
|
796 |
var min = this.min,
|
|
797 |
max = this.max,
|
|
798 |
min2 = bounds.min,
|
|
799 |
max2 = bounds.max,
|
|
800 |
xIntersects = (max2.x >= min.x) && (min2.x <= max.x),
|
|
801 |
yIntersects = (max2.y >= min.y) && (min2.y <= max.y);
|
|
802 |
|
|
803 |
return xIntersects && yIntersects;
|
|
804 |
},
|
|
805 |
|
|
806 |
isValid: function () {
|
|
807 |
return !!(this.min && this.max);
|
|
808 |
}
|
|
809 |
};
|
|
810 |
|
|
811 |
L.bounds = function (a, b) { // (Bounds) or (Point, Point) or (Point[])
|
|
812 |
if (!a || a instanceof L.Bounds) {
|
|
813 |
return a;
|
|
814 |
}
|
|
815 |
return new L.Bounds(a, b);
|
|
816 |
};
|
|
817 |
|
|
818 |
|
|
819 |
/*
|
|
820 |
* L.Transformation is an utility class to perform simple point transformations through a 2d-matrix.
|
|
821 |
*/
|
|
822 |
|
|
823 |
L.Transformation = function (a, b, c, d) {
|
|
824 |
this._a = a;
|
|
825 |
this._b = b;
|
|
826 |
this._c = c;
|
|
827 |
this._d = d;
|
|
828 |
};
|
|
829 |
|
|
830 |
L.Transformation.prototype = {
|
|
831 |
transform: function (point, scale) { // (Point, Number) -> Point
|
|
832 |
return this._transform(point.clone(), scale);
|
|
833 |
},
|
|
834 |
|
|
835 |
// destructive transform (faster)
|
|
836 |
_transform: function (point, scale) {
|
|
837 |
scale = scale || 1;
|
|
838 |
point.x = scale * (this._a * point.x + this._b);
|
|
839 |
point.y = scale * (this._c * point.y + this._d);
|
|
840 |
return point;
|
|
841 |
},
|
|
842 |
|
|
843 |
untransform: function (point, scale) {
|
|
844 |
scale = scale || 1;
|
|
845 |
return new L.Point(
|
|
846 |
(point.x / scale - this._b) / this._a,
|
|
847 |
(point.y / scale - this._d) / this._c);
|
|
848 |
}
|
|
849 |
};
|
|
850 |
|
|
851 |
|
|
852 |
/*
|
|
853 |
* L.DomUtil contains various utility functions for working with DOM.
|
|
854 |
*/
|
|
855 |
|
|
856 |
L.DomUtil = {
|
|
857 |
get: function (id) {
|
|
858 |
return (typeof id === 'string' ? document.getElementById(id) : id);
|
|
859 |
},
|
|
860 |
|
|
861 |
getStyle: function (el, style) {
|
|
862 |
|
|
863 |
var value = el.style[style];
|
|
864 |
|
|
865 |
if (!value && el.currentStyle) {
|
|
866 |
value = el.currentStyle[style];
|
|
867 |
}
|
|
868 |
|
|
869 |
if ((!value || value === 'auto') && document.defaultView) {
|
|
870 |
var css = document.defaultView.getComputedStyle(el, null);
|
|
871 |
value = css ? css[style] : null;
|
|
872 |
}
|
|
873 |
|
|
874 |
return value === 'auto' ? null : value;
|
|
875 |
},
|
|
876 |
|
|
877 |
getViewportOffset: function (element) {
|
|
878 |
|
|
879 |
var top = 0,
|
|
880 |
left = 0,
|
|
881 |
el = element,
|
|
882 |
docBody = document.body,
|
|
883 |
docEl = document.documentElement,
|
|
884 |
pos;
|
|
885 |
|
|
886 |
do {
|
|
887 |
top += el.offsetTop || 0;
|
|
888 |
left += el.offsetLeft || 0;
|
|
889 |
|
|
890 |
//add borders
|
|
891 |
top += parseInt(L.DomUtil.getStyle(el, 'borderTopWidth'), 10) || 0;
|
|
892 |
left += parseInt(L.DomUtil.getStyle(el, 'borderLeftWidth'), 10) || 0;
|
|
893 |
|
|
894 |
pos = L.DomUtil.getStyle(el, 'position');
|
|
895 |
|
|
896 |
if (el.offsetParent === docBody && pos === 'absolute') { break; }
|
|
897 |
|
|
898 |
if (pos === 'fixed') {
|
|
899 |
top += docBody.scrollTop || docEl.scrollTop || 0;
|
|
900 |
left += docBody.scrollLeft || docEl.scrollLeft || 0;
|
|
901 |
break;
|
|
902 |
}
|
|
903 |
|
|
904 |
if (pos === 'relative' && !el.offsetLeft) {
|
|
905 |
var width = L.DomUtil.getStyle(el, 'width'),
|
|
906 |
maxWidth = L.DomUtil.getStyle(el, 'max-width'),
|
|
907 |
r = el.getBoundingClientRect();
|
|
908 |
|
|
909 |
if (width !== 'none' || maxWidth !== 'none') {
|
|
910 |
left += r.left + el.clientLeft;
|
|
911 |
}
|
|
912 |
|
|
913 |
//calculate full y offset since we're breaking out of the loop
|
|
914 |
top += r.top + (docBody.scrollTop || docEl.scrollTop || 0);
|
|
915 |
|
|
916 |
break;
|
|
917 |
}
|
|
918 |
|
|
919 |
el = el.offsetParent;
|
|
920 |
|
|
921 |
} while (el);
|
|
922 |
|
|
923 |
el = element;
|
|
924 |
|
|
925 |
do {
|
|
926 |
if (el === docBody) { break; }
|
|
927 |
|
|
928 |
top -= el.scrollTop || 0;
|
|
929 |
left -= el.scrollLeft || 0;
|
|
930 |
|
|
931 |
el = el.parentNode;
|
|
932 |
} while (el);
|
|
933 |
|
|
934 |
return new L.Point(left, top);
|
|
935 |
},
|
|
936 |
|
|
937 |
documentIsLtr: function () {
|
|
938 |
if (!L.DomUtil._docIsLtrCached) {
|
|
939 |
L.DomUtil._docIsLtrCached = true;
|
|
940 |
L.DomUtil._docIsLtr = L.DomUtil.getStyle(document.body, 'direction') === 'ltr';
|
|
941 |
}
|
|
942 |
return L.DomUtil._docIsLtr;
|
|
943 |
},
|
|
944 |
|
|
945 |
create: function (tagName, className, container) {
|
|
946 |
|
|
947 |
var el = document.createElement(tagName);
|
|
948 |
el.className = className;
|
|
949 |
|
|
950 |
if (container) {
|
|
951 |
container.appendChild(el);
|
|
952 |
}
|
|
953 |
|
|
954 |
return el;
|
|
955 |
},
|
|
956 |
|
|
957 |
hasClass: function (el, name) {
|
|
958 |
if (el.classList !== undefined) {
|
|
959 |
return el.classList.contains(name);
|
|
960 |
}
|
|
961 |
var className = L.DomUtil._getClass(el);
|
|
962 |
return className.length > 0 && new RegExp('(^|\\s)' + name + '(\\s|$)').test(className);
|
|
963 |
},
|
|
964 |
|
|
965 |
addClass: function (el, name) {
|
|
966 |
if (el.classList !== undefined) {
|
|
967 |
var classes = L.Util.splitWords(name);
|
|
968 |
for (var i = 0, len = classes.length; i < len; i++) {
|
|
969 |
el.classList.add(classes[i]);
|
|
970 |
}
|
|
971 |
} else if (!L.DomUtil.hasClass(el, name)) {
|
|
972 |
var className = L.DomUtil._getClass(el);
|
|
973 |
L.DomUtil._setClass(el, (className ? className + ' ' : '') + name);
|
|
974 |
}
|
|
975 |
},
|
|
976 |
|
|
977 |
removeClass: function (el, name) {
|
|
978 |
if (el.classList !== undefined) {
|
|
979 |
el.classList.remove(name);
|
|
980 |
} else {
|
|
981 |
L.DomUtil._setClass(el, L.Util.trim((' ' + L.DomUtil._getClass(el) + ' ').replace(' ' + name + ' ', ' ')));
|
|
982 |
}
|
|
983 |
},
|
|
984 |
|
|
985 |
_setClass: function (el, name) {
|
|
986 |
if (el.className.baseVal === undefined) {
|
|
987 |
el.className = name;
|
|
988 |
} else {
|
|
989 |
// in case of SVG element
|
|
990 |
el.className.baseVal = name;
|
|
991 |
}
|
|
992 |
},
|
|
993 |
|
|
994 |
_getClass: function (el) {
|
|
995 |
return el.className.baseVal === undefined ? el.className : el.className.baseVal;
|
|
996 |
},
|
|
997 |
|
|
998 |
setOpacity: function (el, value) {
|
|
999 |
|
|
1000 |
if ('opacity' in el.style) {
|
|
1001 |
el.style.opacity = value;
|
|
1002 |
|
|
1003 |
} else if ('filter' in el.style) {
|
|
1004 |
|
|
1005 |
var filter = false,
|
|
1006 |
filterName = 'DXImageTransform.Microsoft.Alpha';
|
|
1007 |
|
|
1008 |
// filters collection throws an error if we try to retrieve a filter that doesn't exist
|
|
1009 |
try {
|
|
1010 |
filter = el.filters.item(filterName);
|
|
1011 |
} catch (e) {
|
|
1012 |
// don't set opacity to 1 if we haven't already set an opacity,
|
|
1013 |
// it isn't needed and breaks transparent pngs.
|
|
1014 |
if (value === 1) { return; }
|
|
1015 |
}
|
|
1016 |
|
|
1017 |
value = Math.round(value * 100);
|
|
1018 |
|
|
1019 |
if (filter) {
|
|
1020 |
filter.Enabled = (value !== 100);
|
|
1021 |
filter.Opacity = value;
|
|
1022 |
} else {
|
|
1023 |
el.style.filter += ' progid:' + filterName + '(opacity=' + value + ')';
|
|
1024 |
}
|
|
1025 |
}
|
|
1026 |
},
|
|
1027 |
|
|
1028 |
testProp: function (props) {
|
|
1029 |
|
|
1030 |
var style = document.documentElement.style;
|
|
1031 |
|
|
1032 |
for (var i = 0; i < props.length; i++) {
|
|
1033 |
if (props[i] in style) {
|
|
1034 |
return props[i];
|
|
1035 |
}
|
|
1036 |
}
|
|
1037 |
return false;
|
|
1038 |
},
|
|
1039 |
|
|
1040 |
getTranslateString: function (point) {
|
|
1041 |
// on WebKit browsers (Chrome/Safari/iOS Safari/Android) using translate3d instead of translate
|
|
1042 |
// makes animation smoother as it ensures HW accel is used. Firefox 13 doesn't care
|
|
1043 |
// (same speed either way), Opera 12 doesn't support translate3d
|
|
1044 |
|
|
1045 |
var is3d = L.Browser.webkit3d,
|
|
1046 |
open = 'translate' + (is3d ? '3d' : '') + '(',
|
|
1047 |
close = (is3d ? ',0' : '') + ')';
|
|
1048 |
|
|
1049 |
return open + point.x + 'px,' + point.y + 'px' + close;
|
|
1050 |
},
|
|
1051 |
|
|
1052 |
getScaleString: function (scale, origin) {
|
|
1053 |
|
|
1054 |
var preTranslateStr = L.DomUtil.getTranslateString(origin.add(origin.multiplyBy(-1 * scale))),
|
|
1055 |
scaleStr = ' scale(' + scale + ') ';
|
|
1056 |
|
|
1057 |
return preTranslateStr + scaleStr;
|
|
1058 |
},
|
|
1059 |
|
|
1060 |
setPosition: function (el, point, disable3D) { // (HTMLElement, Point[, Boolean])
|
|
1061 |
|
|
1062 |
// jshint camelcase: false
|
|
1063 |
el._leaflet_pos = point;
|
|
1064 |
|
|
1065 |
if (!disable3D && L.Browser.any3d) {
|
|
1066 |
el.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString(point);
|
|
1067 |
} else {
|
|
1068 |
el.style.left = point.x + 'px';
|
|
1069 |
el.style.top = point.y + 'px';
|
|
1070 |
}
|
|
1071 |
},
|
|
1072 |
|
|
1073 |
getPosition: function (el) {
|
|
1074 |
// this method is only used for elements previously positioned using setPosition,
|
|
1075 |
// so it's safe to cache the position for performance
|
|
1076 |
|
|
1077 |
// jshint camelcase: false
|
|
1078 |
return el._leaflet_pos;
|
|
1079 |
}
|
|
1080 |
};
|
|
1081 |
|
|
1082 |
|
|
1083 |
// prefix style property names
|
|
1084 |
|
|
1085 |
L.DomUtil.TRANSFORM = L.DomUtil.testProp(
|
|
1086 |
['transform', 'WebkitTransform', 'OTransform', 'MozTransform', 'msTransform']);
|
|
1087 |
|
|
1088 |
// webkitTransition comes first because some browser versions that drop vendor prefix don't do
|
|
1089 |
// the same for the transitionend event, in particular the Android 4.1 stock browser
|
|
1090 |
|
|
1091 |
L.DomUtil.TRANSITION = L.DomUtil.testProp(
|
|
1092 |
['webkitTransition', 'transition', 'OTransition', 'MozTransition', 'msTransition']);
|
|
1093 |
|
|
1094 |
L.DomUtil.TRANSITION_END =
|
|
1095 |
L.DomUtil.TRANSITION === 'webkitTransition' || L.DomUtil.TRANSITION === 'OTransition' ?
|
|
1096 |
L.DomUtil.TRANSITION + 'End' : 'transitionend';
|
|
1097 |
|
|
1098 |
(function () {
|
|
1099 |
if ('onselectstart' in document) {
|
|
1100 |
L.extend(L.DomUtil, {
|
|
1101 |
disableTextSelection: function () {
|
|
1102 |
L.DomEvent.on(window, 'selectstart', L.DomEvent.preventDefault);
|
|
1103 |
},
|
|
1104 |
|
|
1105 |
enableTextSelection: function () {
|
|
1106 |
L.DomEvent.off(window, 'selectstart', L.DomEvent.preventDefault);
|
|
1107 |
}
|
|
1108 |
});
|
|
1109 |
} else {
|
|
1110 |
var userSelectProperty = L.DomUtil.testProp(
|
|
1111 |
['userSelect', 'WebkitUserSelect', 'OUserSelect', 'MozUserSelect', 'msUserSelect']);
|
|
1112 |
|
|
1113 |
L.extend(L.DomUtil, {
|
|
1114 |
disableTextSelection: function () {
|
|
1115 |
if (userSelectProperty) {
|
|
1116 |
var style = document.documentElement.style;
|
|
1117 |
this._userSelect = style[userSelectProperty];
|
|
1118 |
style[userSelectProperty] = 'none';
|
|
1119 |
}
|
|
1120 |
},
|
|
1121 |
|
|
1122 |
enableTextSelection: function () {
|
|
1123 |
if (userSelectProperty) {
|
|
1124 |
document.documentElement.style[userSelectProperty] = this._userSelect;
|
|
1125 |
delete this._userSelect;
|
|
1126 |
}
|
|
1127 |
}
|
|
1128 |
});
|
|
1129 |
}
|
|
1130 |
|
|
1131 |
L.extend(L.DomUtil, {
|
|
1132 |
disableImageDrag: function () {
|
|
1133 |
L.DomEvent.on(window, 'dragstart', L.DomEvent.preventDefault);
|
|
1134 |
},
|
|
1135 |
|
|
1136 |
enableImageDrag: function () {
|
|
1137 |
L.DomEvent.off(window, 'dragstart', L.DomEvent.preventDefault);
|
|
1138 |
}
|
|
1139 |
});
|
|
1140 |
})();
|
|
1141 |
|
|
1142 |
|
|
1143 |
/*
|
|
1144 |
* L.LatLng represents a geographical point with latitude and longitude coordinates.
|
|
1145 |
*/
|
|
1146 |
|
|
1147 |
L.LatLng = function (lat, lng, alt) { // (Number, Number, Number)
|
|
1148 |
lat = parseFloat(lat);
|
|
1149 |
lng = parseFloat(lng);
|
|
1150 |
|
|
1151 |
if (isNaN(lat) || isNaN(lng)) {
|
|
1152 |
throw new Error('Invalid LatLng object: (' + lat + ', ' + lng + ')');
|
|
1153 |
}
|
|
1154 |
|
|
1155 |
this.lat = lat;
|
|
1156 |
this.lng = lng;
|
|
1157 |
|
|
1158 |
if (alt !== undefined) {
|
|
1159 |
this.alt = parseFloat(alt);
|
|
1160 |
}
|
|
1161 |
};
|
|
1162 |
|
|
1163 |
L.extend(L.LatLng, {
|
|
1164 |
DEG_TO_RAD: Math.PI / 180,
|
|
1165 |
RAD_TO_DEG: 180 / Math.PI,
|
|
1166 |
MAX_MARGIN: 1.0E-9 // max margin of error for the "equals" check
|
|
1167 |
});
|
|
1168 |
|
|
1169 |
L.LatLng.prototype = {
|
|
1170 |
equals: function (obj) { // (LatLng) -> Boolean
|
|
1171 |
if (!obj) { return false; }
|
|
1172 |
|
|
1173 |
obj = L.latLng(obj);
|
|
1174 |
|
|
1175 |
var margin = Math.max(
|
|
1176 |
Math.abs(this.lat - obj.lat),
|
|
1177 |
Math.abs(this.lng - obj.lng));
|
|
1178 |
|
|
1179 |
return margin <= L.LatLng.MAX_MARGIN;
|
|
1180 |
},
|
|
1181 |
|
|
1182 |
toString: function (precision) { // (Number) -> String
|
|
1183 |
return 'LatLng(' +
|
|
1184 |
L.Util.formatNum(this.lat, precision) + ', ' +
|
|
1185 |
L.Util.formatNum(this.lng, precision) + ')';
|
|
1186 |
},
|
|
1187 |
|
|
1188 |
// Haversine distance formula, see http://en.wikipedia.org/wiki/Haversine_formula
|
|
1189 |
// TODO move to projection code, LatLng shouldn't know about Earth
|
|
1190 |
distanceTo: function (other) { // (LatLng) -> Number
|
|
1191 |
other = L.latLng(other);
|
|
1192 |
|
|
1193 |
var R = 6378137, // earth radius in meters
|
|
1194 |
d2r = L.LatLng.DEG_TO_RAD,
|
|
1195 |
dLat = (other.lat - this.lat) * d2r,
|
|
1196 |
dLon = (other.lng - this.lng) * d2r,
|
|
1197 |
lat1 = this.lat * d2r,
|
|
1198 |
lat2 = other.lat * d2r,
|
|
1199 |
sin1 = Math.sin(dLat / 2),
|
|
1200 |
sin2 = Math.sin(dLon / 2);
|
|
1201 |
|
|
1202 |
var a = sin1 * sin1 + sin2 * sin2 * Math.cos(lat1) * Math.cos(lat2);
|
|
1203 |
|
|
1204 |
return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
1205 |
},
|
|
1206 |
|
|
1207 |
wrap: function (a, b) { // (Number, Number) -> LatLng
|
|
1208 |
var lng = this.lng;
|
|
1209 |
|
|
1210 |
a = a || -180;
|
|
1211 |
b = b || 180;
|
|
1212 |
|
|
1213 |
lng = (lng + b) % (b - a) + (lng < a || lng === b ? b : a);
|
|
1214 |
|
|
1215 |
return new L.LatLng(this.lat, lng);
|
|
1216 |
}
|
|
1217 |
};
|
|
1218 |
|
|
1219 |
L.latLng = function (a, b) { // (LatLng) or ([Number, Number]) or (Number, Number)
|
|
1220 |
if (a instanceof L.LatLng) {
|
|
1221 |
return a;
|
|
1222 |
}
|
|
1223 |
if (L.Util.isArray(a)) {
|
|
1224 |
if (typeof a[0] === 'number' || typeof a[0] === 'string') {
|
|
1225 |
return new L.LatLng(a[0], a[1], a[2]);
|
|
1226 |
} else {
|
|
1227 |
return null;
|
|
1228 |
}
|
|
1229 |
}
|
|
1230 |
if (a === undefined || a === null) {
|
|
1231 |
return a;
|
|
1232 |
}
|
|
1233 |
if (typeof a === 'object' && 'lat' in a) {
|
|
1234 |
return new L.LatLng(a.lat, 'lng' in a ? a.lng : a.lon);
|
|
1235 |
}
|
|
1236 |
if (b === undefined) {
|
|
1237 |
return null;
|
|
1238 |
}
|
|
1239 |
return new L.LatLng(a, b);
|
|
1240 |
};
|
|
1241 |
|
|
1242 |
|
|
1243 |
|
|
1244 |
/*
|
|
1245 |
* L.LatLngBounds represents a rectangular area on the map in geographical coordinates.
|
|
1246 |
*/
|
|
1247 |
|
|
1248 |
L.LatLngBounds = function (southWest, northEast) { // (LatLng, LatLng) or (LatLng[])
|
|
1249 |
if (!southWest) { return; }
|
|
1250 |
|
|
1251 |
var latlngs = northEast ? [southWest, northEast] : southWest;
|
|
1252 |
|
|
1253 |
for (var i = 0, len = latlngs.length; i < len; i++) {
|
|
1254 |
this.extend(latlngs[i]);
|
|
1255 |
}
|
|
1256 |
};
|
|
1257 |
|
|
1258 |
L.LatLngBounds.prototype = {
|
|
1259 |
// extend the bounds to contain the given point or bounds
|
|
1260 |
extend: function (obj) { // (LatLng) or (LatLngBounds)
|
|
1261 |
if (!obj) { return this; }
|
|
1262 |
|
|
1263 |
var latLng = L.latLng(obj);
|
|
1264 |
if (latLng !== null) {
|
|
1265 |
obj = latLng;
|
|
1266 |
} else {
|
|
1267 |
obj = L.latLngBounds(obj);
|
|
1268 |
}
|
|
1269 |
|
|
1270 |
if (obj instanceof L.LatLng) {
|
|
1271 |
if (!this._southWest && !this._northEast) {
|
|
1272 |
this._southWest = new L.LatLng(obj.lat, obj.lng);
|
|
1273 |
this._northEast = new L.LatLng(obj.lat, obj.lng);
|
|
1274 |
} else {
|
|
1275 |
this._southWest.lat = Math.min(obj.lat, this._southWest.lat);
|
|
1276 |
this._southWest.lng = Math.min(obj.lng, this._southWest.lng);
|
|
1277 |
|
|
1278 |
this._northEast.lat = Math.max(obj.lat, this._northEast.lat);
|
|
1279 |
this._northEast.lng = Math.max(obj.lng, this._northEast.lng);
|
|
1280 |
}
|
|
1281 |
} else if (obj instanceof L.LatLngBounds) {
|
|
1282 |
this.extend(obj._southWest);
|
|
1283 |
this.extend(obj._northEast);
|
|
1284 |
}
|
|
1285 |
return this;
|
|
1286 |
},
|
|
1287 |
|
|
1288 |
// extend the bounds by a percentage
|
|
1289 |
pad: function (bufferRatio) { // (Number) -> LatLngBounds
|
|
1290 |
var sw = this._southWest,
|
|
1291 |
ne = this._northEast,
|
|
1292 |
heightBuffer = Math.abs(sw.lat - ne.lat) * bufferRatio,
|
|
1293 |
widthBuffer = Math.abs(sw.lng - ne.lng) * bufferRatio;
|
|
1294 |
|
|
1295 |
return new L.LatLngBounds(
|
|
1296 |
new L.LatLng(sw.lat - heightBuffer, sw.lng - widthBuffer),
|
|
1297 |
new L.LatLng(ne.lat + heightBuffer, ne.lng + widthBuffer));
|
|
1298 |
},
|
|
1299 |
|
|
1300 |
getCenter: function () { // -> LatLng
|
|
1301 |
return new L.LatLng(
|
|
1302 |
(this._southWest.lat + this._northEast.lat) / 2,
|
|
1303 |
(this._southWest.lng + this._northEast.lng) / 2);
|
|
1304 |
},
|
|
1305 |
|
|
1306 |
getSouthWest: function () {
|
|
1307 |
return this._southWest;
|
|
1308 |
},
|
|
1309 |
|
|
1310 |
getNorthEast: function () {
|
|
1311 |
return this._northEast;
|
|
1312 |
},
|
|
1313 |
|
|
1314 |
getNorthWest: function () {
|
|
1315 |
return new L.LatLng(this.getNorth(), this.getWest());
|
|
1316 |
},
|
|
1317 |
|
|
1318 |
getSouthEast: function () {
|
|
1319 |
return new L.LatLng(this.getSouth(), this.getEast());
|
|
1320 |
},
|
|
1321 |
|
|
1322 |
getWest: function () {
|
|
1323 |
return this._southWest.lng;
|
|
1324 |
},
|
|
1325 |
|
|
1326 |
getSouth: function () {
|
|
1327 |
return this._southWest.lat;
|
|
1328 |
},
|
|
1329 |
|
|
1330 |
getEast: function () {
|
|
1331 |
return this._northEast.lng;
|
|
1332 |
},
|
|
1333 |
|
|
1334 |
getNorth: function () {
|
|
1335 |
return this._northEast.lat;
|
|
1336 |
},
|
|
1337 |
|
|
1338 |
contains: function (obj) { // (LatLngBounds) or (LatLng) -> Boolean
|
|
1339 |
if (typeof obj[0] === 'number' || obj instanceof L.LatLng) {
|
|
1340 |
obj = L.latLng(obj);
|
|
1341 |
} else {
|
|
1342 |
obj = L.latLngBounds(obj);
|
|
1343 |
}
|
|
1344 |
|
|
1345 |
var sw = this._southWest,
|
|
1346 |
ne = this._northEast,
|
|
1347 |
sw2, ne2;
|
|
1348 |
|
|
1349 |
if (obj instanceof L.LatLngBounds) {
|
|
1350 |
sw2 = obj.getSouthWest();
|
|
1351 |
ne2 = obj.getNorthEast();
|
|
1352 |
} else {
|
|
1353 |
sw2 = ne2 = obj;
|
|
1354 |
}
|
|
1355 |
|
|
1356 |
return (sw2.lat >= sw.lat) && (ne2.lat <= ne.lat) &&
|
|
1357 |
(sw2.lng >= sw.lng) && (ne2.lng <= ne.lng);
|
|
1358 |
},
|
|
1359 |
|
|
1360 |
intersects: function (bounds) { // (LatLngBounds)
|
|
1361 |
bounds = L.latLngBounds(bounds);
|
|
1362 |
|
|
1363 |
var sw = this._southWest,
|
|
1364 |
ne = this._northEast,
|
|
1365 |
sw2 = bounds.getSouthWest(),
|
|
1366 |
ne2 = bounds.getNorthEast(),
|
|
1367 |
|
|
1368 |
latIntersects = (ne2.lat >= sw.lat) && (sw2.lat <= ne.lat),
|
|
1369 |
lngIntersects = (ne2.lng >= sw.lng) && (sw2.lng <= ne.lng);
|
|
1370 |
|
|
1371 |
return latIntersects && lngIntersects;
|
|
1372 |
},
|
|
1373 |
|
|
1374 |
toBBoxString: function () {
|
|
1375 |
return [this.getWest(), this.getSouth(), this.getEast(), this.getNorth()].join(',');
|
|
1376 |
},
|
|
1377 |
|
|
1378 |
equals: function (bounds) { // (LatLngBounds)
|
|
1379 |
if (!bounds) { return false; }
|
|
1380 |
|
|
1381 |
bounds = L.latLngBounds(bounds);
|
|
1382 |
|
|
1383 |
return this._southWest.equals(bounds.getSouthWest()) &&
|
|
1384 |
this._northEast.equals(bounds.getNorthEast());
|
|
1385 |
},
|
|
1386 |
|
|
1387 |
isValid: function () {
|
|
1388 |
return !!(this._southWest && this._northEast);
|
|
1389 |
}
|
|
1390 |
};
|
|
1391 |
|
|
1392 |
//TODO International date line?
|
|
1393 |
|
|
1394 |
L.latLngBounds = function (a, b) { // (LatLngBounds) or (LatLng, LatLng)
|
|
1395 |
if (!a || a instanceof L.LatLngBounds) {
|
|
1396 |
return a;
|
|
1397 |
}
|
|
1398 |
return new L.LatLngBounds(a, b);
|
|
1399 |
};
|
|
1400 |
|
|
1401 |
|
|
1402 |
/*
|
|
1403 |
* L.Projection contains various geographical projections used by CRS classes.
|
|
1404 |
*/
|
|
1405 |
|
|
1406 |
L.Projection = {};
|
|
1407 |
|
|
1408 |
|
|
1409 |
/*
|
|
1410 |
* Spherical Mercator is the most popular map projection, used by EPSG:3857 CRS used by default.
|
|
1411 |
*/
|
|
1412 |
|
|
1413 |
L.Projection.SphericalMercator = {
|
|
1414 |
MAX_LATITUDE: 85.0511287798,
|
|
1415 |
|
|
1416 |
project: function (latlng) { // (LatLng) -> Point
|
|
1417 |
var d = L.LatLng.DEG_TO_RAD,
|
|
1418 |
max = this.MAX_LATITUDE,
|
|
1419 |
lat = Math.max(Math.min(max, latlng.lat), -max),
|
|
1420 |
x = latlng.lng * d,
|
|
1421 |
y = lat * d;
|
|
1422 |
|
|
1423 |
y = Math.log(Math.tan((Math.PI / 4) + (y / 2)));
|
|
1424 |
|
|
1425 |
return new L.Point(x, y);
|
|
1426 |
},
|
|
1427 |
|
|
1428 |
unproject: function (point) { // (Point, Boolean) -> LatLng
|
|
1429 |
var d = L.LatLng.RAD_TO_DEG,
|
|
1430 |
lng = point.x * d,
|
|
1431 |
lat = (2 * Math.atan(Math.exp(point.y)) - (Math.PI / 2)) * d;
|
|
1432 |
|
|
1433 |
return new L.LatLng(lat, lng);
|
|
1434 |
}
|
|
1435 |
};
|
|
1436 |
|
|
1437 |
|
|
1438 |
/*
|
|
1439 |
* Simple equirectangular (Plate Carree) projection, used by CRS like EPSG:4326 and Simple.
|
|
1440 |
*/
|
|
1441 |
|
|
1442 |
L.Projection.LonLat = {
|
|
1443 |
project: function (latlng) {
|
|
1444 |
return new L.Point(latlng.lng, latlng.lat);
|
|
1445 |
},
|
|
1446 |
|
|
1447 |
unproject: function (point) {
|
|
1448 |
return new L.LatLng(point.y, point.x);
|
|
1449 |
}
|
|
1450 |
};
|
|
1451 |
|
|
1452 |
|
|
1453 |
/*
|
|
1454 |
* L.CRS is a base object for all defined CRS (Coordinate Reference Systems) in Leaflet.
|
|
1455 |
*/
|
|
1456 |
|
|
1457 |
L.CRS = {
|
|
1458 |
latLngToPoint: function (latlng, zoom) { // (LatLng, Number) -> Point
|
|
1459 |
var projectedPoint = this.projection.project(latlng),
|
|
1460 |
scale = this.scale(zoom);
|
|
1461 |
|
|
1462 |
return this.transformation._transform(projectedPoint, scale);
|
|
1463 |
},
|
|
1464 |
|
|
1465 |
pointToLatLng: function (point, zoom) { // (Point, Number[, Boolean]) -> LatLng
|
|
1466 |
var scale = this.scale(zoom),
|
|
1467 |
untransformedPoint = this.transformation.untransform(point, scale);
|
|
1468 |
|
|
1469 |
return this.projection.unproject(untransformedPoint);
|
|
1470 |
},
|
|
1471 |
|
|
1472 |
project: function (latlng) {
|
|
1473 |
return this.projection.project(latlng);
|
|
1474 |
},
|
|
1475 |
|
|
1476 |
scale: function (zoom) {
|
|
1477 |
return 256 * Math.pow(2, zoom);
|
|
1478 |
},
|
|
1479 |
|
|
1480 |
getSize: function (zoom) {
|
|
1481 |
var s = this.scale(zoom);
|
|
1482 |
return L.point(s, s);
|
|
1483 |
}
|
|
1484 |
};
|
|
1485 |
|
|
1486 |
|
|
1487 |
/*
|
|
1488 |
* A simple CRS that can be used for flat non-Earth maps like panoramas or game maps.
|
|
1489 |
*/
|
|
1490 |
|
|
1491 |
L.CRS.Simple = L.extend({}, L.CRS, {
|
|
1492 |
projection: L.Projection.LonLat,
|
|
1493 |
transformation: new L.Transformation(1, 0, -1, 0),
|
|
1494 |
|
|
1495 |
scale: function (zoom) {
|
|
1496 |
return Math.pow(2, zoom);
|
|
1497 |
}
|
|
1498 |
});
|
|
1499 |
|
|
1500 |
|
|
1501 |
/*
|
|
1502 |
* L.CRS.EPSG3857 (Spherical Mercator) is the most common CRS for web mapping
|
|
1503 |
* and is used by Leaflet by default.
|
|
1504 |
*/
|
|
1505 |
|
|
1506 |
L.CRS.EPSG3857 = L.extend({}, L.CRS, {
|
|
1507 |
code: 'EPSG:3857',
|
|
1508 |
|
|
1509 |
projection: L.Projection.SphericalMercator,
|
|
1510 |
transformation: new L.Transformation(0.5 / Math.PI, 0.5, -0.5 / Math.PI, 0.5),
|
|
1511 |
|
|
1512 |
project: function (latlng) { // (LatLng) -> Point
|
|
1513 |
var projectedPoint = this.projection.project(latlng),
|
|
1514 |
earthRadius = 6378137;
|
|
1515 |
return projectedPoint.multiplyBy(earthRadius);
|
|
1516 |
}
|
|
1517 |
});
|
|
1518 |
|
|
1519 |
L.CRS.EPSG900913 = L.extend({}, L.CRS.EPSG3857, {
|
|
1520 |
code: 'EPSG:900913'
|
|
1521 |
});
|
|
1522 |
|
|
1523 |
|
|
1524 |
/*
|
|
1525 |
* L.CRS.EPSG4326 is a CRS popular among advanced GIS specialists.
|
|
1526 |
*/
|
|
1527 |
|
|
1528 |
L.CRS.EPSG4326 = L.extend({}, L.CRS, {
|
|
1529 |
code: 'EPSG:4326',
|
|
1530 |
|
|
1531 |
projection: L.Projection.LonLat,
|
|
1532 |
transformation: new L.Transformation(1 / 360, 0.5, -1 / 360, 0.5)
|
|
1533 |
});
|
|
1534 |
|
|
1535 |
|
|
1536 |
/*
|
|
1537 |
* L.Map is the central class of the API - it is used to create a map.
|
|
1538 |
*/
|
|
1539 |
|
|
1540 |
L.Map = L.Class.extend({
|
|
1541 |
|
|
1542 |
includes: L.Mixin.Events,
|
|
1543 |
|
|
1544 |
options: {
|
|
1545 |
crs: L.CRS.EPSG3857,
|
|
1546 |
|
|
1547 |
/*
|
|
1548 |
center: LatLng,
|
|
1549 |
zoom: Number,
|
|
1550 |
layers: Array,
|
|
1551 |
*/
|
|
1552 |
|
|
1553 |
fadeAnimation: L.DomUtil.TRANSITION && !L.Browser.android23,
|
|
1554 |
trackResize: true,
|
|
1555 |
markerZoomAnimation: L.DomUtil.TRANSITION && L.Browser.any3d
|
|
1556 |
},
|
|
1557 |
|
|
1558 |
initialize: function (id, options) { // (HTMLElement or String, Object)
|
|
1559 |
options = L.setOptions(this, options);
|
|
1560 |
|
|
1561 |
|
|
1562 |
this._initContainer(id);
|
|
1563 |
this._initLayout();
|
|
1564 |
|
|
1565 |
// hack for https://github.com/Leaflet/Leaflet/issues/1980
|
|
1566 |
this._onResize = L.bind(this._onResize, this);
|
|
1567 |
|
|
1568 |
this._initEvents();
|
|
1569 |
|
|
1570 |
if (options.maxBounds) {
|
|
1571 |
this.setMaxBounds(options.maxBounds);
|
|
1572 |
}
|
|
1573 |
|
|
1574 |
if (options.center && options.zoom !== undefined) {
|
|
1575 |
this.setView(L.latLng(options.center), options.zoom, {reset: true});
|
|
1576 |
}
|
|
1577 |
|
|
1578 |
this._handlers = [];
|
|
1579 |
|
|
1580 |
this._layers = {};
|
|
1581 |
this._zoomBoundLayers = {};
|
|
1582 |
this._tileLayersNum = 0;
|
|
1583 |
|
|
1584 |
this.callInitHooks();
|
|
1585 |
|
|
1586 |
this._addLayers(options.layers);
|
|
1587 |
},
|
|
1588 |
|
|
1589 |
|
|
1590 |
// public methods that modify map state
|
|
1591 |
|
|
1592 |
// replaced by animation-powered implementation in Map.PanAnimation.js
|
|
1593 |
setView: function (center, zoom) {
|
|
1594 |
zoom = zoom === undefined ? this.getZoom() : zoom;
|
|
1595 |
this._resetView(L.latLng(center), this._limitZoom(zoom));
|
|
1596 |
return this;
|
|
1597 |
},
|
|
1598 |
|
|
1599 |
setZoom: function (zoom, options) {
|
|
1600 |
if (!this._loaded) {
|
|
1601 |
this._zoom = this._limitZoom(zoom);
|
|
1602 |
return this;
|
|
1603 |
}
|
|
1604 |
return this.setView(this.getCenter(), zoom, {zoom: options});
|
|
1605 |
},
|
|
1606 |
|
|
1607 |
zoomIn: function (delta, options) {
|
|
1608 |
return this.setZoom(this._zoom + (delta || 1), options);
|
|
1609 |
},
|
|
1610 |
|
|
1611 |
zoomOut: function (delta, options) {
|
|
1612 |
return this.setZoom(this._zoom - (delta || 1), options);
|
|
1613 |
},
|
|
1614 |
|
|
1615 |
setZoomAround: function (latlng, zoom, options) {
|
|
1616 |
var scale = this.getZoomScale(zoom),
|
|
1617 |
viewHalf = this.getSize().divideBy(2),
|
|
1618 |
containerPoint = latlng instanceof L.Point ? latlng : this.latLngToContainerPoint(latlng),
|
|
1619 |
|
|
1620 |
centerOffset = containerPoint.subtract(viewHalf).multiplyBy(1 - 1 / scale),
|
|
1621 |
newCenter = this.containerPointToLatLng(viewHalf.add(centerOffset));
|
|
1622 |
|
|
1623 |
return this.setView(newCenter, zoom, {zoom: options});
|
|
1624 |
},
|
|
1625 |
|
|
1626 |
fitBounds: function (bounds, options) {
|
|
1627 |
|
|
1628 |
options = options || {};
|
|
1629 |
bounds = bounds.getBounds ? bounds.getBounds() : L.latLngBounds(bounds);
|
|
1630 |
|
|
1631 |
var paddingTL = L.point(options.paddingTopLeft || options.padding || [0, 0]),
|
|
1632 |
paddingBR = L.point(options.paddingBottomRight || options.padding || [0, 0]),
|
|
1633 |
|
|
1634 |
zoom = this.getBoundsZoom(bounds, false, paddingTL.add(paddingBR)),
|
|
1635 |
paddingOffset = paddingBR.subtract(paddingTL).divideBy(2),
|
|
1636 |
|
|
1637 |
swPoint = this.project(bounds.getSouthWest(), zoom),
|
|
1638 |
nePoint = this.project(bounds.getNorthEast(), zoom),
|
|
1639 |
center = this.unproject(swPoint.add(nePoint).divideBy(2).add(paddingOffset), zoom);
|
|
1640 |
|
|
1641 |
zoom = options && options.maxZoom ? Math.min(options.maxZoom, zoom) : zoom;
|
|
1642 |
|
|
1643 |
return this.setView(center, zoom, options);
|
|
1644 |
},
|
|
1645 |
|
|
1646 |
fitWorld: function (options) {
|
|
1647 |
return this.fitBounds([[-90, -180], [90, 180]], options);
|
|
1648 |
},
|
|
1649 |
|
|
1650 |
panTo: function (center, options) { // (LatLng)
|
|
1651 |
return this.setView(center, this._zoom, {pan: options});
|
|
1652 |
},
|
|
1653 |
|
|
1654 |
panBy: function (offset) { // (Point)
|
|
1655 |
// replaced with animated panBy in Map.PanAnimation.js
|
|
1656 |
this.fire('movestart');
|
|
1657 |
|
|
1658 |
this._rawPanBy(L.point(offset));
|
|
1659 |
|
|
1660 |
this.fire('move');
|
|
1661 |
return this.fire('moveend');
|
|
1662 |
},
|
|
1663 |
|
|
1664 |
setMaxBounds: function (bounds) {
|
|
1665 |
bounds = L.latLngBounds(bounds);
|
|
1666 |
|
|
1667 |
this.options.maxBounds = bounds;
|
|
1668 |
|
|
1669 |
if (!bounds) {
|
|
1670 |
return this.off('moveend', this._panInsideMaxBounds, this);
|
|
1671 |
}
|
|
1672 |
|
|
1673 |
if (this._loaded) {
|
|
1674 |
this._panInsideMaxBounds();
|
|
1675 |
}
|
|
1676 |
|
|
1677 |
return this.on('moveend', this._panInsideMaxBounds, this);
|
|
1678 |
},
|
|
1679 |
|
|
1680 |
panInsideBounds: function (bounds, options) {
|
|
1681 |
var center = this.getCenter(),
|
|
1682 |
newCenter = this._limitCenter(center, this._zoom, bounds);
|
|
1683 |
|
|
1684 |
if (center.equals(newCenter)) { return this; }
|
|
1685 |
|
|
1686 |
return this.panTo(newCenter, options);
|
|
1687 |
},
|
|
1688 |
|
|
1689 |
addLayer: function (layer) {
|
|
1690 |
// TODO method is too big, refactor
|
|
1691 |
|
|
1692 |
var id = L.stamp(layer);
|
|
1693 |
|
|
1694 |
if (this._layers[id]) { return this; }
|
|
1695 |
|
|
1696 |
this._layers[id] = layer;
|
|
1697 |
|
|
1698 |
// TODO getMaxZoom, getMinZoom in ILayer (instead of options)
|
|
1699 |
if (layer.options && (!isNaN(layer.options.maxZoom) || !isNaN(layer.options.minZoom))) {
|
|
1700 |
this._zoomBoundLayers[id] = layer;
|
|
1701 |
this._updateZoomLevels();
|
|
1702 |
}
|
|
1703 |
|
|
1704 |
// TODO looks ugly, refactor!!!
|
|
1705 |
if (this.options.zoomAnimation && L.TileLayer && (layer instanceof L.TileLayer)) {
|
|
1706 |
this._tileLayersNum++;
|
|
1707 |
this._tileLayersToLoad++;
|
|
1708 |
layer.on('load', this._onTileLayerLoad, this);
|
|
1709 |
}
|
|
1710 |
|
|
1711 |
if (this._loaded) {
|
|
1712 |
this._layerAdd(layer);
|
|
1713 |
}
|
|
1714 |
|
|
1715 |
return this;
|
|
1716 |
},
|
|
1717 |
|
|
1718 |
removeLayer: function (layer) {
|
|
1719 |
var id = L.stamp(layer);
|
|
1720 |
|
|
1721 |
if (!this._layers[id]) { return this; }
|
|
1722 |
|
|
1723 |
if (this._loaded) {
|
|
1724 |
layer.onRemove(this);
|
|
1725 |
}
|
|
1726 |
|
|
1727 |
delete this._layers[id];
|
|
1728 |
|
|
1729 |
if (this._loaded) {
|
|
1730 |
this.fire('layerremove', {layer: layer});
|
|
1731 |
}
|
|
1732 |
|
|
1733 |
if (this._zoomBoundLayers[id]) {
|
|
1734 |
delete this._zoomBoundLayers[id];
|
|
1735 |
this._updateZoomLevels();
|
|
1736 |
}
|
|
1737 |
|
|
1738 |
// TODO looks ugly, refactor
|
|
1739 |
if (this.options.zoomAnimation && L.TileLayer && (layer instanceof L.TileLayer)) {
|
|
1740 |
this._tileLayersNum--;
|
|
1741 |
this._tileLayersToLoad--;
|
|
1742 |
layer.off('load', this._onTileLayerLoad, this);
|
|
1743 |
}
|
|
1744 |
|
|
1745 |
return this;
|
|
1746 |
},
|
|
1747 |
|
|
1748 |
hasLayer: function (layer) {
|
|
1749 |
if (!layer) { return false; }
|
|
1750 |
|
|
1751 |
return (L.stamp(layer) in this._layers);
|
|
1752 |
},
|
|
1753 |
|
|
1754 |
eachLayer: function (method, context) {
|
|
1755 |
for (var i in this._layers) {
|
|
1756 |
method.call(context, this._layers[i]);
|
|
1757 |
}
|
|
1758 |
return this;
|
|
1759 |
},
|
|
1760 |
|
|
1761 |
invalidateSize: function (options) {
|
|
1762 |
if (!this._loaded) { return this; }
|
|
1763 |
|
|
1764 |
options = L.extend({
|
|
1765 |
animate: false,
|
|
1766 |
pan: true
|
|
1767 |
}, options === true ? {animate: true} : options);
|
|
1768 |
|
|
1769 |
var oldSize = this.getSize();
|
|
1770 |
this._sizeChanged = true;
|
|
1771 |
this._initialCenter = null;
|
|
1772 |
|
|
1773 |
var newSize = this.getSize(),
|
|
1774 |
oldCenter = oldSize.divideBy(2).round(),
|
|
1775 |
newCenter = newSize.divideBy(2).round(),
|
|
1776 |
offset = oldCenter.subtract(newCenter);
|
|
1777 |
|
|
1778 |
if (!offset.x && !offset.y) { return this; }
|
|
1779 |
|
|
1780 |
if (options.animate && options.pan) {
|
|
1781 |
this.panBy(offset);
|
|
1782 |
|
|
1783 |
} else {
|
|
1784 |
if (options.pan) {
|
|
1785 |
this._rawPanBy(offset);
|
|
1786 |
}
|
|
1787 |
|
|
1788 |
this.fire('move');
|
|
1789 |
|
|
1790 |
if (options.debounceMoveend) {
|
|
1791 |
clearTimeout(this._sizeTimer);
|
|
1792 |
this._sizeTimer = setTimeout(L.bind(this.fire, this, 'moveend'), 200);
|
|
1793 |
} else {
|
|
1794 |
this.fire('moveend');
|
|
1795 |
}
|
|
1796 |
}
|
|
1797 |
|
|
1798 |
return this.fire('resize', {
|
|
1799 |
oldSize: oldSize,
|
|
1800 |
newSize: newSize
|
|
1801 |
});
|
|
1802 |
},
|
|
1803 |
|
|
1804 |
// TODO handler.addTo
|
|
1805 |
addHandler: function (name, HandlerClass) {
|
|
1806 |
if (!HandlerClass) { return this; }
|
|
1807 |
|
|
1808 |
var handler = this[name] = new HandlerClass(this);
|
|
1809 |
|
|
1810 |
this._handlers.push(handler);
|
|
1811 |
|
|
1812 |
if (this.options[name]) {
|
|
1813 |
handler.enable();
|
|
1814 |
}
|
|
1815 |
|
|
1816 |
return this;
|
|
1817 |
},
|
|
1818 |
|
|
1819 |
remove: function () {
|
|
1820 |
if (this._loaded) {
|
|
1821 |
this.fire('unload');
|
|
1822 |
}
|
|
1823 |
|
|
1824 |
this._initEvents('off');
|
|
1825 |
|
|
1826 |
try {
|
|
1827 |
// throws error in IE6-8
|
|
1828 |
delete this._container._leaflet;
|
|
1829 |
} catch (e) {
|
|
1830 |
this._container._leaflet = undefined;
|
|
1831 |
}
|
|
1832 |
|
|
1833 |
this._clearPanes();
|
|
1834 |
if (this._clearControlPos) {
|
|
1835 |
this._clearControlPos();
|
|
1836 |
}
|
|
1837 |
|
|
1838 |
this._clearHandlers();
|
|
1839 |
|
|
1840 |
return this;
|
|
1841 |
},
|
|
1842 |
|
|
1843 |
|
|
1844 |
// public methods for getting map state
|
|
1845 |
|
|
1846 |
getCenter: function () { // (Boolean) -> LatLng
|
|
1847 |
this._checkIfLoaded();
|
|
1848 |
|
|
1849 |
if (this._initialCenter && !this._moved()) {
|
|
1850 |
return this._initialCenter;
|
|
1851 |
}
|
|
1852 |
return this.layerPointToLatLng(this._getCenterLayerPoint());
|
|
1853 |
},
|
|
1854 |
|
|
1855 |
getZoom: function () {
|
|
1856 |
return this._zoom;
|
|
1857 |
},
|
|
1858 |
|
|
1859 |
getBounds: function () {
|
|
1860 |
var bounds = this.getPixelBounds(),
|
|
1861 |
sw = this.unproject(bounds.getBottomLeft()),
|
|
1862 |
ne = this.unproject(bounds.getTopRight());
|
|
1863 |
|
|
1864 |
return new L.LatLngBounds(sw, ne);
|
|
1865 |
},
|
|
1866 |
|
|
1867 |
getMinZoom: function () {
|
|
1868 |
return this.options.minZoom === undefined ?
|
|
1869 |
(this._layersMinZoom === undefined ? 0 : this._layersMinZoom) :
|
|
1870 |
this.options.minZoom;
|
|
1871 |
},
|
|
1872 |
|
|
1873 |
getMaxZoom: function () {
|
|
1874 |
return this.options.maxZoom === undefined ?
|
|
1875 |
(this._layersMaxZoom === undefined ? Infinity : this._layersMaxZoom) :
|
|
1876 |
this.options.maxZoom;
|
|
1877 |
},
|
|
1878 |
|
|
1879 |
getBoundsZoom: function (bounds, inside, padding) { // (LatLngBounds[, Boolean, Point]) -> Number
|
|
1880 |
bounds = L.latLngBounds(bounds);
|
|
1881 |
|
|
1882 |
var zoom = this.getMinZoom() - (inside ? 1 : 0),
|
|
1883 |
maxZoom = this.getMaxZoom(),
|
|
1884 |
size = this.getSize(),
|
|
1885 |
|
|
1886 |
nw = bounds.getNorthWest(),
|
|
1887 |
se = bounds.getSouthEast(),
|
|
1888 |
|
|
1889 |
zoomNotFound = true,
|
|
1890 |
boundsSize;
|
|
1891 |
|
|
1892 |
padding = L.point(padding || [0, 0]);
|
|
1893 |
|
|
1894 |
do {
|
|
1895 |
zoom++;
|
|
1896 |
boundsSize = this.project(se, zoom).subtract(this.project(nw, zoom)).add(padding);
|
|
1897 |
zoomNotFound = !inside ? size.contains(boundsSize) : boundsSize.x < size.x || boundsSize.y < size.y;
|
|
1898 |
|
|
1899 |
} while (zoomNotFound && zoom <= maxZoom);
|
|
1900 |
|
|
1901 |
if (zoomNotFound && inside) {
|
|
1902 |
return null;
|
|
1903 |
}
|
|
1904 |
|
|
1905 |
return inside ? zoom : zoom - 1;
|
|
1906 |
},
|
|
1907 |
|
|
1908 |
getSize: function () {
|
|
1909 |
if (!this._size || this._sizeChanged) {
|
|
1910 |
this._size = new L.Point(
|
|
1911 |
this._container.clientWidth,
|
|
1912 |
this._container.clientHeight);
|
|
1913 |
|
|
1914 |
this._sizeChanged = false;
|
|
1915 |
}
|
|
1916 |
return this._size.clone();
|
|
1917 |
},
|
|
1918 |
|
|
1919 |
getPixelBounds: function () {
|
|
1920 |
var topLeftPoint = this._getTopLeftPoint();
|
|
1921 |
return new L.Bounds(topLeftPoint, topLeftPoint.add(this.getSize()));
|
|
1922 |
},
|
|
1923 |
|
|
1924 |
getPixelOrigin: function () {
|
|
1925 |
this._checkIfLoaded();
|
|
1926 |
return this._initialTopLeftPoint;
|
|
1927 |
},
|
|
1928 |
|
|
1929 |
getPanes: function () {
|
|
1930 |
return this._panes;
|
|
1931 |
},
|
|
1932 |
|
|
1933 |
getContainer: function () {
|
|
1934 |
return this._container;
|
|
1935 |
},
|
|
1936 |
|
|
1937 |
|
|
1938 |
// TODO replace with universal implementation after refactoring projections
|
|
1939 |
|
|
1940 |
getZoomScale: function (toZoom) {
|
|
1941 |
var crs = this.options.crs;
|
|
1942 |
return crs.scale(toZoom) / crs.scale(this._zoom);
|
|
1943 |
},
|
|
1944 |
|
|
1945 |
getScaleZoom: function (scale) {
|
|
1946 |
return this._zoom + (Math.log(scale) / Math.LN2);
|
|
1947 |
},
|
|
1948 |
|
|
1949 |
|
|
1950 |
// conversion methods
|
|
1951 |
|
|
1952 |
project: function (latlng, zoom) { // (LatLng[, Number]) -> Point
|
|
1953 |
zoom = zoom === undefined ? this._zoom : zoom;
|
|
1954 |
return this.options.crs.latLngToPoint(L.latLng(latlng), zoom);
|
|
1955 |
},
|
|
1956 |
|
|
1957 |
unproject: function (point, zoom) { // (Point[, Number]) -> LatLng
|
|
1958 |
zoom = zoom === undefined ? this._zoom : zoom;
|
|
1959 |
return this.options.crs.pointToLatLng(L.point(point), zoom);
|
|
1960 |
},
|
|
1961 |
|
|
1962 |
layerPointToLatLng: function (point) { // (Point)
|
|
1963 |
var projectedPoint = L.point(point).add(this.getPixelOrigin());
|
|
1964 |
return this.unproject(projectedPoint);
|
|
1965 |
},
|
|
1966 |
|
|
1967 |
latLngToLayerPoint: function (latlng) { // (LatLng)
|
|
1968 |
var projectedPoint = this.project(L.latLng(latlng))._round();
|
|
1969 |
return projectedPoint._subtract(this.getPixelOrigin());
|
|
1970 |
},
|
|
1971 |
|
|
1972 |
containerPointToLayerPoint: function (point) { // (Point)
|
|
1973 |
return L.point(point).subtract(this._getMapPanePos());
|
|
1974 |
},
|
|
1975 |
|
|
1976 |
layerPointToContainerPoint: function (point) { // (Point)
|
|
1977 |
return L.point(point).add(this._getMapPanePos());
|
|
1978 |
},
|
|
1979 |
|
|
1980 |
containerPointToLatLng: function (point) {
|
|
1981 |
var layerPoint = this.containerPointToLayerPoint(L.point(point));
|
|
1982 |
return this.layerPointToLatLng(layerPoint);
|
|
1983 |
},
|
|
1984 |
|
|
1985 |
latLngToContainerPoint: function (latlng) {
|
|
1986 |
return this.layerPointToContainerPoint(this.latLngToLayerPoint(L.latLng(latlng)));
|
|
1987 |
},
|
|
1988 |
|
|
1989 |
mouseEventToContainerPoint: function (e) { // (MouseEvent)
|
|
1990 |
return L.DomEvent.getMousePosition(e, this._container);
|
|
1991 |
},
|
|
1992 |
|
|
1993 |
mouseEventToLayerPoint: function (e) { // (MouseEvent)
|
|
1994 |
return this.containerPointToLayerPoint(this.mouseEventToContainerPoint(e));
|
|
1995 |
},
|
|
1996 |
|
|
1997 |
mouseEventToLatLng: function (e) { // (MouseEvent)
|
|
1998 |
return this.layerPointToLatLng(this.mouseEventToLayerPoint(e));
|
|
1999 |
},
|
|
2000 |
|
|
2001 |
|
|
2002 |
// map initialization methods
|
|
2003 |
|
|
2004 |
_initContainer: function (id) {
|
|
2005 |
var container = this._container = L.DomUtil.get(id);
|
|
2006 |
|
|
2007 |
if (!container) {
|
|
2008 |
throw new Error('Map container not found.');
|
|
2009 |
} else if (container._leaflet) {
|
|
2010 |
throw new Error('Map container is already initialized.');
|
|
2011 |
}
|
|
2012 |
|
|
2013 |
container._leaflet = true;
|
|
2014 |
},
|
|
2015 |
|
|
2016 |
_initLayout: function () {
|
|
2017 |
var container = this._container;
|
|
2018 |
|
|
2019 |
L.DomUtil.addClass(container, 'leaflet-container' +
|
|
2020 |
(L.Browser.touch ? ' leaflet-touch' : '') +
|
|
2021 |
(L.Browser.retina ? ' leaflet-retina' : '') +
|
|
2022 |
(L.Browser.ielt9 ? ' leaflet-oldie' : '') +
|
|
2023 |
(this.options.fadeAnimation ? ' leaflet-fade-anim' : ''));
|
|
2024 |
|
|
2025 |
var position = L.DomUtil.getStyle(container, 'position');
|
|
2026 |
|
|
2027 |
if (position !== 'absolute' && position !== 'relative' && position !== 'fixed') {
|
|
2028 |
container.style.position = 'relative';
|
|
2029 |
}
|
|
2030 |
|
|
2031 |
this._initPanes();
|
|
2032 |
|
|
2033 |
if (this._initControlPos) {
|
|
2034 |
this._initControlPos();
|
|
2035 |
}
|
|
2036 |
},
|
|
2037 |
|
|
2038 |
_initPanes: function () {
|
|
2039 |
var panes = this._panes = {};
|
|
2040 |
|
|
2041 |
this._mapPane = panes.mapPane = this._createPane('leaflet-map-pane', this._container);
|
|
2042 |
|
|
2043 |
this._tilePane = panes.tilePane = this._createPane('leaflet-tile-pane', this._mapPane);
|
|
2044 |
panes.objectsPane = this._createPane('leaflet-objects-pane', this._mapPane);
|
|
2045 |
panes.shadowPane = this._createPane('leaflet-shadow-pane');
|
|
2046 |
panes.overlayPane = this._createPane('leaflet-overlay-pane');
|
|
2047 |
panes.markerPane = this._createPane('leaflet-marker-pane');
|
|
2048 |
panes.popupPane = this._createPane('leaflet-popup-pane');
|
|
2049 |
|
|
2050 |
var zoomHide = ' leaflet-zoom-hide';
|
|
2051 |
|
|
2052 |
if (!this.options.markerZoomAnimation) {
|
|
2053 |
L.DomUtil.addClass(panes.markerPane, zoomHide);
|
|
2054 |
L.DomUtil.addClass(panes.shadowPane, zoomHide);
|
|
2055 |
L.DomUtil.addClass(panes.popupPane, zoomHide);
|
|
2056 |
}
|
|
2057 |
},
|
|
2058 |
|
|
2059 |
_createPane: function (className, container) {
|
|
2060 |
return L.DomUtil.create('div', className, container || this._panes.objectsPane);
|
|
2061 |
},
|
|
2062 |
|
|
2063 |
_clearPanes: function () {
|
|
2064 |
this._container.removeChild(this._mapPane);
|
|
2065 |
},
|
|
2066 |
|
|
2067 |
_addLayers: function (layers) {
|
|
2068 |
layers = layers ? (L.Util.isArray(layers) ? layers : [layers]) : [];
|
|
2069 |
|
|
2070 |
for (var i = 0, len = layers.length; i < len; i++) {
|
|
2071 |
this.addLayer(layers[i]);
|
|
2072 |
}
|
|
2073 |
},
|
|
2074 |
|
|
2075 |
|
|
2076 |
// private methods that modify map state
|
|
2077 |
|
|
2078 |
_resetView: function (center, zoom, preserveMapOffset, afterZoomAnim) {
|
|
2079 |
|
|
2080 |
var zoomChanged = (this._zoom !== zoom);
|
|
2081 |
|
|
2082 |
if (!afterZoomAnim) {
|
|
2083 |
this.fire('movestart');
|
|
2084 |
|
|
2085 |
if (zoomChanged) {
|
|
2086 |
this.fire('zoomstart');
|
|
2087 |
}
|
|
2088 |
}
|
|
2089 |
|
|
2090 |
this._zoom = zoom;
|
|
2091 |
this._initialCenter = center;
|
|
2092 |
|
|
2093 |
this._initialTopLeftPoint = this._getNewTopLeftPoint(center);
|
|
2094 |
|
|
2095 |
if (!preserveMapOffset) {
|
|
2096 |
L.DomUtil.setPosition(this._mapPane, new L.Point(0, 0));
|
|
2097 |
} else {
|
|
2098 |
this._initialTopLeftPoint._add(this._getMapPanePos());
|
|
2099 |
}
|
|
2100 |
|
|
2101 |
this._tileLayersToLoad = this._tileLayersNum;
|
|
2102 |
|
|
2103 |
var loading = !this._loaded;
|
|
2104 |
this._loaded = true;
|
|
2105 |
|
|
2106 |
this.fire('viewreset', {hard: !preserveMapOffset});
|
|
2107 |
|
|
2108 |
if (loading) {
|
|
2109 |
this.fire('load');
|
|
2110 |
this.eachLayer(this._layerAdd, this);
|
|
2111 |
}
|
|
2112 |
|
|
2113 |
this.fire('move');
|
|
2114 |
|
|
2115 |
if (zoomChanged || afterZoomAnim) {
|
|
2116 |
this.fire('zoomend');
|
|
2117 |
}
|
|
2118 |
|
|
2119 |
this.fire('moveend', {hard: !preserveMapOffset});
|
|
2120 |
},
|
|
2121 |
|
|
2122 |
_rawPanBy: function (offset) {
|
|
2123 |
L.DomUtil.setPosition(this._mapPane, this._getMapPanePos().subtract(offset));
|
|
2124 |
},
|
|
2125 |
|
|
2126 |
_getZoomSpan: function () {
|
|
2127 |
return this.getMaxZoom() - this.getMinZoom();
|
|
2128 |
},
|
|
2129 |
|
|
2130 |
_updateZoomLevels: function () {
|
|
2131 |
var i,
|
|
2132 |
minZoom = Infinity,
|
|
2133 |
maxZoom = -Infinity,
|
|
2134 |
oldZoomSpan = this._getZoomSpan();
|
|
2135 |
|
|
2136 |
for (i in this._zoomBoundLayers) {
|
|
2137 |
var layer = this._zoomBoundLayers[i];
|
|
2138 |
if (!isNaN(layer.options.minZoom)) {
|
|
2139 |
minZoom = Math.min(minZoom, layer.options.minZoom);
|
|
2140 |
}
|
|
2141 |
if (!isNaN(layer.options.maxZoom)) {
|
|
2142 |
maxZoom = Math.max(maxZoom, layer.options.maxZoom);
|
|
2143 |
}
|
|
2144 |
}
|
|
2145 |
|
|
2146 |
if (i === undefined) { // we have no tilelayers
|
|
2147 |
this._layersMaxZoom = this._layersMinZoom = undefined;
|
|
2148 |
} else {
|
|
2149 |
this._layersMaxZoom = maxZoom;
|
|
2150 |
this._layersMinZoom = minZoom;
|
|
2151 |
}
|
|
2152 |
|
|
2153 |
if (oldZoomSpan !== this._getZoomSpan()) {
|
|
2154 |
this.fire('zoomlevelschange');
|
|
2155 |
}
|
|
2156 |
},
|
|
2157 |
|
|
2158 |
_panInsideMaxBounds: function () {
|
|
2159 |
this.panInsideBounds(this.options.maxBounds);
|
|
2160 |
},
|
|
2161 |
|
|
2162 |
_checkIfLoaded: function () {
|
|
2163 |
if (!this._loaded) {
|
|
2164 |
throw new Error('Set map center and zoom first.');
|
|
2165 |
}
|
|
2166 |
},
|
|
2167 |
|
|
2168 |
// map events
|
|
2169 |
|
|
2170 |
_initEvents: function (onOff) {
|
|
2171 |
if (!L.DomEvent) { return; }
|
|
2172 |
|
|
2173 |
onOff = onOff || 'on';
|
|
2174 |
|
|
2175 |
L.DomEvent[onOff](this._container, 'click', this._onMouseClick, this);
|
|
2176 |
|
|
2177 |
var events = ['dblclick', 'mousedown', 'mouseup', 'mouseenter',
|
|
2178 |
'mouseleave', 'mousemove', 'contextmenu'],
|
|
2179 |
i, len;
|
|
2180 |
|
|
2181 |
for (i = 0, len = events.length; i < len; i++) {
|
|
2182 |
L.DomEvent[onOff](this._container, events[i], this._fireMouseEvent, this);
|
|
2183 |
}
|
|
2184 |
|
|
2185 |
if (this.options.trackResize) {
|
|
2186 |
L.DomEvent[onOff](window, 'resize', this._onResize, this);
|
|
2187 |
}
|
|
2188 |
},
|
|
2189 |
|
|
2190 |
_onResize: function () {
|
|
2191 |
L.Util.cancelAnimFrame(this._resizeRequest);
|
|
2192 |
this._resizeRequest = L.Util.requestAnimFrame(
|
|
2193 |
function () { this.invalidateSize({debounceMoveend: true}); }, this, false, this._container);
|
|
2194 |
},
|
|
2195 |
|
|
2196 |
_onMouseClick: function (e) {
|
|
2197 |
if (!this._loaded || (!e._simulated &&
|
|
2198 |
((this.dragging && this.dragging.moved()) ||
|
|
2199 |
(this.boxZoom && this.boxZoom.moved()))) ||
|
|
2200 |
L.DomEvent._skipped(e)) { return; }
|
|
2201 |
|
|
2202 |
this.fire('preclick');
|
|
2203 |
this._fireMouseEvent(e);
|
|
2204 |
},
|
|
2205 |
|
|
2206 |
_fireMouseEvent: function (e) {
|
|
2207 |
if (!this._loaded || L.DomEvent._skipped(e)) { return; }
|
|
2208 |
|
|
2209 |
var type = e.type;
|
|
2210 |
|
|
2211 |
type = (type === 'mouseenter' ? 'mouseover' : (type === 'mouseleave' ? 'mouseout' : type));
|
|
2212 |
|
|
2213 |
if (!this.hasEventListeners(type)) { return; }
|
|
2214 |
|
|
2215 |
if (type === 'contextmenu') {
|
|
2216 |
L.DomEvent.preventDefault(e);
|
|
2217 |
}
|
|
2218 |
|
|
2219 |
var containerPoint = this.mouseEventToContainerPoint(e),
|
|
2220 |
layerPoint = this.containerPointToLayerPoint(containerPoint),
|
|
2221 |
latlng = this.layerPointToLatLng(layerPoint);
|
|
2222 |
|
|
2223 |
this.fire(type, {
|
|
2224 |
latlng: latlng,
|
|
2225 |
layerPoint: layerPoint,
|
|
2226 |
containerPoint: containerPoint,
|
|
2227 |
originalEvent: e
|
|
2228 |
});
|
|
2229 |
},
|
|
2230 |
|
|
2231 |
_onTileLayerLoad: function () {
|
|
2232 |
this._tileLayersToLoad--;
|
|
2233 |
if (this._tileLayersNum && !this._tileLayersToLoad) {
|
|
2234 |
this.fire('tilelayersload');
|
|
2235 |
}
|
|
2236 |
},
|
|
2237 |
|
|
2238 |
_clearHandlers: function () {
|
|
2239 |
for (var i = 0, len = this._handlers.length; i < len; i++) {
|
|
2240 |
this._handlers[i].disable();
|
|
2241 |
}
|
|
2242 |
},
|
|
2243 |
|
|
2244 |
whenReady: function (callback, context) {
|
|
2245 |
if (this._loaded) {
|
|
2246 |
callback.call(context || this, this);
|
|
2247 |
} else {
|
|
2248 |
this.on('load', callback, context);
|
|
2249 |
}
|
|
2250 |
return this;
|
|
2251 |
},
|
|
2252 |
|
|
2253 |
_layerAdd: function (layer) {
|
|
2254 |
layer.onAdd(this);
|
|
2255 |
this.fire('layeradd', {layer: layer});
|
|
2256 |
},
|
|
2257 |
|
|
2258 |
|
|
2259 |
// private methods for getting map state
|
|
2260 |
|
|
2261 |
_getMapPanePos: function () {
|
|
2262 |
return L.DomUtil.getPosition(this._mapPane);
|
|
2263 |
},
|
|
2264 |
|
|
2265 |
_moved: function () {
|
|
2266 |
var pos = this._getMapPanePos();
|
|
2267 |
return pos && !pos.equals([0, 0]);
|
|
2268 |
},
|
|
2269 |
|
|
2270 |
_getTopLeftPoint: function () {
|
|
2271 |
return this.getPixelOrigin().subtract(this._getMapPanePos());
|
|
2272 |
},
|
|
2273 |
|
|
2274 |
_getNewTopLeftPoint: function (center, zoom) {
|
|
2275 |
var viewHalf = this.getSize()._divideBy(2);
|
|
2276 |
// TODO round on display, not calculation to increase precision?
|
|
2277 |
return this.project(center, zoom)._subtract(viewHalf)._round();
|
|
2278 |
},
|
|
2279 |
|
|
2280 |
_latLngToNewLayerPoint: function (latlng, newZoom, newCenter) {
|
|
2281 |
var topLeft = this._getNewTopLeftPoint(newCenter, newZoom).add(this._getMapPanePos());
|
|
2282 |
return this.project(latlng, newZoom)._subtract(topLeft);
|
|
2283 |
},
|
|
2284 |
|
|
2285 |
// layer point of the current center
|
|
2286 |
_getCenterLayerPoint: function () {
|
|
2287 |
return this.containerPointToLayerPoint(this.getSize()._divideBy(2));
|
|
2288 |
},
|
|
2289 |
|
|
2290 |
// offset of the specified place to the current center in pixels
|
|
2291 |
_getCenterOffset: function (latlng) {
|
|
2292 |
return this.latLngToLayerPoint(latlng).subtract(this._getCenterLayerPoint());
|
|
2293 |
},
|
|
2294 |
|
|
2295 |
// adjust center for view to get inside bounds
|
|
2296 |
_limitCenter: function (center, zoom, bounds) {
|
|
2297 |
|
|
2298 |
if (!bounds) { return center; }
|
|
2299 |
|
|
2300 |
var centerPoint = this.project(center, zoom),
|
|
2301 |
viewHalf = this.getSize().divideBy(2),
|
|
2302 |
viewBounds = new L.Bounds(centerPoint.subtract(viewHalf), centerPoint.add(viewHalf)),
|
|
2303 |
offset = this._getBoundsOffset(viewBounds, bounds, zoom);
|
|
2304 |
|
|
2305 |
return this.unproject(centerPoint.add(offset), zoom);
|
|
2306 |
},
|
|
2307 |
|
|
2308 |
// adjust offset for view to get inside bounds
|
|
2309 |
_limitOffset: function (offset, bounds) {
|
|
2310 |
if (!bounds) { return offset; }
|
|
2311 |
|
|
2312 |
var viewBounds = this.getPixelBounds(),
|
|
2313 |
newBounds = new L.Bounds(viewBounds.min.add(offset), viewBounds.max.add(offset));
|
|
2314 |
|
|
2315 |
return offset.add(this._getBoundsOffset(newBounds, bounds));
|
|
2316 |
},
|
|
2317 |
|
|
2318 |
// returns offset needed for pxBounds to get inside maxBounds at a specified zoom
|
|
2319 |
_getBoundsOffset: function (pxBounds, maxBounds, zoom) {
|
|
2320 |
var nwOffset = this.project(maxBounds.getNorthWest(), zoom).subtract(pxBounds.min),
|
|
2321 |
seOffset = this.project(maxBounds.getSouthEast(), zoom).subtract(pxBounds.max),
|
|
2322 |
|
|
2323 |
dx = this._rebound(nwOffset.x, -seOffset.x),
|
|
2324 |
dy = this._rebound(nwOffset.y, -seOffset.y);
|
|
2325 |
|
|
2326 |
return new L.Point(dx, dy);
|
|
2327 |
},
|
|
2328 |
|
|
2329 |
_rebound: function (left, right) {
|
|
2330 |
return left + right > 0 ?
|
|
2331 |
Math.round(left - right) / 2 :
|
|
2332 |
Math.max(0, Math.ceil(left)) - Math.max(0, Math.floor(right));
|
|
2333 |
},
|
|
2334 |
|
|
2335 |
_limitZoom: function (zoom) {
|
|
2336 |
var min = this.getMinZoom(),
|
|
2337 |
max = this.getMaxZoom();
|
|
2338 |
|
|
2339 |
return Math.max(min, Math.min(max, zoom));
|
|
2340 |
}
|
|
2341 |
});
|
|
2342 |
|
|
2343 |
L.map = function (id, options) {
|
|
2344 |
return new L.Map(id, options);
|
|
2345 |
};
|
|
2346 |
|
|
2347 |
|
|
2348 |
/*
|
|
2349 |
* Mercator projection that takes into account that the Earth is not a perfect sphere.
|
|
2350 |
* Less popular than spherical mercator; used by projections like EPSG:3395.
|
|
2351 |
*/
|
|
2352 |
|
|
2353 |
L.Projection.Mercator = {
|
|
2354 |
MAX_LATITUDE: 85.0840591556,
|
|
2355 |
|
|
2356 |
R_MINOR: 6356752.314245179,
|
|
2357 |
R_MAJOR: 6378137,
|
|
2358 |
|
|
2359 |
project: function (latlng) { // (LatLng) -> Point
|
|
2360 |
var d = L.LatLng.DEG_TO_RAD,
|
|
2361 |
max = this.MAX_LATITUDE,
|
|
2362 |
lat = Math.max(Math.min(max, latlng.lat), -max),
|
|
2363 |
r = this.R_MAJOR,
|
|
2364 |
r2 = this.R_MINOR,
|
|
2365 |
x = latlng.lng * d * r,
|
|
2366 |
y = lat * d,
|
|
2367 |
tmp = r2 / r,
|
|
2368 |
eccent = Math.sqrt(1.0 - tmp * tmp),
|
|
2369 |
con = eccent * Math.sin(y);
|
|
2370 |
|
|
2371 |
con = Math.pow((1 - con) / (1 + con), eccent * 0.5);
|
|
2372 |
|
|
2373 |
var ts = Math.tan(0.5 * ((Math.PI * 0.5) - y)) / con;
|
|
2374 |
y = -r * Math.log(ts);
|
|
2375 |
|
|
2376 |
return new L.Point(x, y);
|
|
2377 |
},
|
|
2378 |
|
|
2379 |
unproject: function (point) { // (Point, Boolean) -> LatLng
|
|
2380 |
var d = L.LatLng.RAD_TO_DEG,
|
|
2381 |
r = this.R_MAJOR,
|
|
2382 |
r2 = this.R_MINOR,
|
|
2383 |
lng = point.x * d / r,
|
|
2384 |
tmp = r2 / r,
|
|
2385 |
eccent = Math.sqrt(1 - (tmp * tmp)),
|
|
2386 |
ts = Math.exp(- point.y / r),
|
|
2387 |
phi = (Math.PI / 2) - 2 * Math.atan(ts),
|
|
2388 |
numIter = 15,
|
|
2389 |
tol = 1e-7,
|
|
2390 |
i = numIter,
|
|
2391 |
dphi = 0.1,
|
|
2392 |
con;
|
|
2393 |
|
|
2394 |
while ((Math.abs(dphi) > tol) && (--i > 0)) {
|
|
2395 |
con = eccent * Math.sin(phi);
|
|
2396 |
dphi = (Math.PI / 2) - 2 * Math.atan(ts *
|
|
2397 |
Math.pow((1.0 - con) / (1.0 + con), 0.5 * eccent)) - phi;
|
|
2398 |
phi += dphi;
|
|
2399 |
}
|
|
2400 |
|
|
2401 |
return new L.LatLng(phi * d, lng);
|
|
2402 |
}
|
|
2403 |
};
|
|
2404 |
|
|
2405 |
|
|
2406 |
|
|
2407 |
L.CRS.EPSG3395 = L.extend({}, L.CRS, {
|
|
2408 |
code: 'EPSG:3395',
|
|
2409 |
|
|
2410 |
projection: L.Projection.Mercator,
|
|
2411 |
|
|
2412 |
transformation: (function () {
|
|
2413 |
var m = L.Projection.Mercator,
|
|
2414 |
r = m.R_MAJOR,
|
|
2415 |
scale = 0.5 / (Math.PI * r);
|
|
2416 |
|
|
2417 |
return new L.Transformation(scale, 0.5, -scale, 0.5);
|
|
2418 |
}())
|
|
2419 |
});
|
|
2420 |
|
|
2421 |
|
|
2422 |
/*
|
|
2423 |
* L.TileLayer is used for standard xyz-numbered tile layers.
|
|
2424 |
*/
|
|
2425 |
|
|
2426 |
L.TileLayer = L.Class.extend({
|
|
2427 |
includes: L.Mixin.Events,
|
|
2428 |
|
|
2429 |
options: {
|
|
2430 |
minZoom: 0,
|
|
2431 |
maxZoom: 18,
|
|
2432 |
tileSize: 256,
|
|
2433 |
subdomains: 'abc',
|
|
2434 |
errorTileUrl: '',
|
|
2435 |
attribution: '',
|
|
2436 |
zoomOffset: 0,
|
|
2437 |
opacity: 1,
|
|
2438 |
/*
|
|
2439 |
maxNativeZoom: null,
|
|
2440 |
zIndex: null,
|
|
2441 |
tms: false,
|
|
2442 |
continuousWorld: false,
|
|
2443 |
noWrap: false,
|
|
2444 |
zoomReverse: false,
|
|
2445 |
detectRetina: false,
|
|
2446 |
reuseTiles: false,
|
|
2447 |
bounds: false,
|
|
2448 |
*/
|
|
2449 |
unloadInvisibleTiles: L.Browser.mobile,
|
|
2450 |
updateWhenIdle: L.Browser.mobile
|
|
2451 |
},
|
|
2452 |
|
|
2453 |
initialize: function (url, options) {
|
|
2454 |
options = L.setOptions(this, options);
|
|
2455 |
|
|
2456 |
// detecting retina displays, adjusting tileSize and zoom levels
|
|
2457 |
if (options.detectRetina && L.Browser.retina && options.maxZoom > 0) {
|
|
2458 |
|
|
2459 |
options.tileSize = Math.floor(options.tileSize / 2);
|
|
2460 |
options.zoomOffset++;
|
|
2461 |
|
|
2462 |
if (options.minZoom > 0) {
|
|
2463 |
options.minZoom--;
|
|
2464 |
}
|
|
2465 |
this.options.maxZoom--;
|
|
2466 |
}
|
|
2467 |
|
|
2468 |
if (options.bounds) {
|
|
2469 |
options.bounds = L.latLngBounds(options.bounds);
|
|
2470 |
}
|
|
2471 |
|
|
2472 |
this._url = url;
|
|
2473 |
|
|
2474 |
var subdomains = this.options.subdomains;
|
|
2475 |
|
|
2476 |
if (typeof subdomains === 'string') {
|
|
2477 |
this.options.subdomains = subdomains.split('');
|
|
2478 |
}
|
|
2479 |
},
|
|
2480 |
|
|
2481 |
onAdd: function (map) {
|
|
2482 |
this._map = map;
|
|
2483 |
this._animated = map._zoomAnimated;
|
|
2484 |
|
|
2485 |
// create a container div for tiles
|
|
2486 |
this._initContainer();
|
|
2487 |
|
|
2488 |
// set up events
|
|
2489 |
map.on({
|
|
2490 |
'viewreset': this._reset,
|
|
2491 |
'moveend': this._update
|
|
2492 |
}, this);
|
|
2493 |
|
|
2494 |
if (this._animated) {
|
|
2495 |
map.on({
|
|
2496 |
'zoomanim': this._animateZoom,
|
|
2497 |
'zoomend': this._endZoomAnim
|
|
2498 |
}, this);
|
|
2499 |
}
|
|
2500 |
|
|
2501 |
if (!this.options.updateWhenIdle) {
|
|
2502 |
this._limitedUpdate = L.Util.limitExecByInterval(this._update, 150, this);
|
|
2503 |
map.on('move', this._limitedUpdate, this);
|
|
2504 |
}
|
|
2505 |
|
|
2506 |
this._reset();
|
|
2507 |
this._update();
|
|
2508 |
},
|
|
2509 |
|
|
2510 |
addTo: function (map) {
|
|
2511 |
map.addLayer(this);
|
|
2512 |
return this;
|
|
2513 |
},
|
|
2514 |
|
|
2515 |
onRemove: function (map) {
|
|
2516 |
this._container.parentNode.removeChild(this._container);
|
|
2517 |
|
|
2518 |
map.off({
|
|
2519 |
'viewreset': this._reset,
|
|
2520 |
'moveend': this._update
|
|
2521 |
}, this);
|
|
2522 |
|
|
2523 |
if (this._animated) {
|
|
2524 |
map.off({
|
|
2525 |
'zoomanim': this._animateZoom,
|
|
2526 |
'zoomend': this._endZoomAnim
|
|
2527 |
}, this);
|
|
2528 |
}
|
|
2529 |
|
|
2530 |
if (!this.options.updateWhenIdle) {
|
|
2531 |
map.off('move', this._limitedUpdate, this);
|
|
2532 |
}
|
|
2533 |
|
|
2534 |
this._container = null;
|
|
2535 |
this._map = null;
|
|
2536 |
},
|
|
2537 |
|
|
2538 |
bringToFront: function () {
|
|
2539 |
var pane = this._map._panes.tilePane;
|
|
2540 |
|
|
2541 |
if (this._container) {
|
|
2542 |
pane.appendChild(this._container);
|
|
2543 |
this._setAutoZIndex(pane, Math.max);
|
|
2544 |
}
|
|
2545 |
|
|
2546 |
return this;
|
|
2547 |
},
|
|
2548 |
|
|
2549 |
bringToBack: function () {
|
|
2550 |
var pane = this._map._panes.tilePane;
|
|
2551 |
|
|
2552 |
if (this._container) {
|
|
2553 |
pane.insertBefore(this._container, pane.firstChild);
|
|
2554 |
this._setAutoZIndex(pane, Math.min);
|
|
2555 |
}
|
|
2556 |
|
|
2557 |
return this;
|
|
2558 |
},
|
|
2559 |
|
|
2560 |
getAttribution: function () {
|
|
2561 |
return this.options.attribution;
|
|
2562 |
},
|
|
2563 |
|
|
2564 |
getContainer: function () {
|
|
2565 |
return this._container;
|
|
2566 |
},
|
|
2567 |
|
|
2568 |
setOpacity: function (opacity) {
|
|
2569 |
this.options.opacity = opacity;
|
|
2570 |
|
|
2571 |
if (this._map) {
|
|
2572 |
this._updateOpacity();
|
|
2573 |
}
|
|
2574 |
|
|
2575 |
return this;
|
|
2576 |
},
|
|
2577 |
|
|
2578 |
setZIndex: function (zIndex) {
|
|
2579 |
this.options.zIndex = zIndex;
|
|
2580 |
this._updateZIndex();
|
|
2581 |
|
|
2582 |
return this;
|
|
2583 |
},
|
|
2584 |
|
|
2585 |
setUrl: function (url, noRedraw) {
|
|
2586 |
this._url = url;
|
|
2587 |
|
|
2588 |
if (!noRedraw) {
|
|
2589 |
this.redraw();
|
|
2590 |
}
|
|
2591 |
|
|
2592 |
return this;
|
|
2593 |
},
|
|
2594 |
|
|
2595 |
redraw: function () {
|
|
2596 |
if (this._map) {
|
|
2597 |
this._reset({hard: true});
|
|
2598 |
this._update();
|
|
2599 |
}
|
|
2600 |
return this;
|
|
2601 |
},
|
|
2602 |
|
|
2603 |
_updateZIndex: function () {
|
|
2604 |
if (this._container && this.options.zIndex !== undefined) {
|
|
2605 |
this._container.style.zIndex = this.options.zIndex;
|
|
2606 |
}
|
|
2607 |
},
|
|
2608 |
|
|
2609 |
_setAutoZIndex: function (pane, compare) {
|
|
2610 |
|
|
2611 |
var layers = pane.children,
|
|
2612 |
edgeZIndex = -compare(Infinity, -Infinity), // -Infinity for max, Infinity for min
|
|
2613 |
zIndex, i, len;
|
|
2614 |
|
|
2615 |
for (i = 0, len = layers.length; i < len; i++) {
|
|
2616 |
|
|
2617 |
if (layers[i] !== this._container) {
|
|
2618 |
zIndex = parseInt(layers[i].style.zIndex, 10);
|
|
2619 |
|
|
2620 |
if (!isNaN(zIndex)) {
|
|
2621 |
edgeZIndex = compare(edgeZIndex, zIndex);
|
|
2622 |
}
|
|
2623 |
}
|
|
2624 |
}
|
|
2625 |
|
|
2626 |
this.options.zIndex = this._container.style.zIndex =
|
|
2627 |
(isFinite(edgeZIndex) ? edgeZIndex : 0) + compare(1, -1);
|
|
2628 |
},
|
|
2629 |
|
|
2630 |
_updateOpacity: function () {
|
|
2631 |
var i,
|
|
2632 |
tiles = this._tiles;
|
|
2633 |
|
|
2634 |
if (L.Browser.ielt9) {
|
|
2635 |
for (i in tiles) {
|
|
2636 |
L.DomUtil.setOpacity(tiles[i], this.options.opacity);
|
|
2637 |
}
|
|
2638 |
} else {
|
|
2639 |
L.DomUtil.setOpacity(this._container, this.options.opacity);
|
|
2640 |
}
|
|
2641 |
},
|
|
2642 |
|
|
2643 |
_initContainer: function () {
|
|
2644 |
var tilePane = this._map._panes.tilePane;
|
|
2645 |
|
|
2646 |
if (!this._container) {
|
|
2647 |
this._container = L.DomUtil.create('div', 'leaflet-layer');
|
|
2648 |
|
|
2649 |
this._updateZIndex();
|
|
2650 |
|
|
2651 |
if (this._animated) {
|
|
2652 |
var className = 'leaflet-tile-container';
|
|
2653 |
|
|
2654 |
this._bgBuffer = L.DomUtil.create('div', className, this._container);
|
|
2655 |
this._tileContainer = L.DomUtil.create('div', className, this._container);
|
|
2656 |
|
|
2657 |
} else {
|
|
2658 |
this._tileContainer = this._container;
|
|
2659 |
}
|
|
2660 |
|
|
2661 |
tilePane.appendChild(this._container);
|
|
2662 |
|
|
2663 |
if (this.options.opacity < 1) {
|
|
2664 |
this._updateOpacity();
|
|
2665 |
}
|
|
2666 |
}
|
|
2667 |
},
|
|
2668 |
|
|
2669 |
_reset: function (e) {
|
|
2670 |
for (var key in this._tiles) {
|
|
2671 |
this.fire('tileunload', {tile: this._tiles[key]});
|
|
2672 |
}
|
|
2673 |
|
|
2674 |
this._tiles = {};
|
|
2675 |
this._tilesToLoad = 0;
|
|
2676 |
|
|
2677 |
if (this.options.reuseTiles) {
|
|
2678 |
this._unusedTiles = [];
|
|
2679 |
}
|
|
2680 |
|
|
2681 |
this._tileContainer.innerHTML = '';
|
|
2682 |
|
|
2683 |
if (this._animated && e && e.hard) {
|
|
2684 |
this._clearBgBuffer();
|
|
2685 |
}
|
|
2686 |
|
|
2687 |
this._initContainer();
|
|
2688 |
},
|
|
2689 |
|
|
2690 |
_getTileSize: function () {
|
|
2691 |
var map = this._map,
|
|
2692 |
zoom = map.getZoom() + this.options.zoomOffset,
|
|
2693 |
zoomN = this.options.maxNativeZoom,
|
|
2694 |
tileSize = this.options.tileSize;
|
|
2695 |
|
|
2696 |
if (zoomN && zoom > zoomN) {
|
|
2697 |
tileSize = Math.round(map.getZoomScale(zoom) / map.getZoomScale(zoomN) * tileSize);
|
|
2698 |
}
|
|
2699 |
|
|
2700 |
return tileSize;
|
|
2701 |
},
|
|
2702 |
|
|
2703 |
_update: function () {
|
|
2704 |
|
|
2705 |
if (!this._map) { return; }
|
|
2706 |
|
|
2707 |
var map = this._map,
|
|
2708 |
bounds = map.getPixelBounds(),
|
|
2709 |
zoom = map.getZoom(),
|
|
2710 |
tileSize = this._getTileSize();
|
|
2711 |
|
|
2712 |
if (zoom > this.options.maxZoom || zoom < this.options.minZoom) {
|
|
2713 |
return;
|
|
2714 |
}
|
|
2715 |
|
|
2716 |
var tileBounds = L.bounds(
|
|
2717 |
bounds.min.divideBy(tileSize)._floor(),
|
|
2718 |
bounds.max.divideBy(tileSize)._floor());
|
|
2719 |
|
|
2720 |
this._addTilesFromCenterOut(tileBounds);
|
|
2721 |
|
|
2722 |
if (this.options.unloadInvisibleTiles || this.options.reuseTiles) {
|
|
2723 |
this._removeOtherTiles(tileBounds);
|
|
2724 |
}
|
|
2725 |
},
|
|
2726 |
|
|
2727 |
_addTilesFromCenterOut: function (bounds) {
|
|
2728 |
var queue = [],
|
|
2729 |
center = bounds.getCenter();
|
|
2730 |
|
|
2731 |
var j, i, point;
|
|
2732 |
|
|
2733 |
for (j = bounds.min.y; j <= bounds.max.y; j++) {
|
|
2734 |
for (i = bounds.min.x; i <= bounds.max.x; i++) {
|
|
2735 |
point = new L.Point(i, j);
|
|
2736 |
|
|
2737 |
if (this._tileShouldBeLoaded(point)) {
|
|
2738 |
queue.push(point);
|
|
2739 |
}
|
|
2740 |
}
|
|
2741 |
}
|
|
2742 |
|
|
2743 |
var tilesToLoad = queue.length;
|
|
2744 |
|
|
2745 |
if (tilesToLoad === 0) { return; }
|
|
2746 |
|
|
2747 |
// load tiles in order of their distance to center
|
|
2748 |
queue.sort(function (a, b) {
|
|
2749 |
return a.distanceTo(center) - b.distanceTo(center);
|
|
2750 |
});
|
|
2751 |
|
|
2752 |
var fragment = document.createDocumentFragment();
|
|
2753 |
|
|
2754 |
// if its the first batch of tiles to load
|
|
2755 |
if (!this._tilesToLoad) {
|
|
2756 |
this.fire('loading');
|
|
2757 |
}
|
|
2758 |
|
|
2759 |
this._tilesToLoad += tilesToLoad;
|
|
2760 |
|
|
2761 |
for (i = 0; i < tilesToLoad; i++) {
|
|
2762 |
this._addTile(queue[i], fragment);
|
|
2763 |
}
|
|
2764 |
|
|
2765 |
this._tileContainer.appendChild(fragment);
|
|
2766 |
},
|
|
2767 |
|
|
2768 |
_tileShouldBeLoaded: function (tilePoint) {
|
|
2769 |
if ((tilePoint.x + ':' + tilePoint.y) in this._tiles) {
|
|
2770 |
return false; // already loaded
|
|
2771 |
}
|
|
2772 |
|
|
2773 |
var options = this.options;
|
|
2774 |
|
|
2775 |
if (!options.continuousWorld) {
|
|
2776 |
var limit = this._getWrapTileNum();
|
|
2777 |
|
|
2778 |
// don't load if exceeds world bounds
|
|
2779 |
if ((options.noWrap && (tilePoint.x < 0 || tilePoint.x >= limit.x)) ||
|
|
2780 |
tilePoint.y < 0 || tilePoint.y >= limit.y) { return false; }
|
|
2781 |
}
|
|
2782 |
|
|
2783 |
if (options.bounds) {
|
|
2784 |
var tileSize = options.tileSize,
|
|
2785 |
nwPoint = tilePoint.multiplyBy(tileSize),
|
|
2786 |
sePoint = nwPoint.add([tileSize, tileSize]),
|
|
2787 |
nw = this._map.unproject(nwPoint),
|
|
2788 |
se = this._map.unproject(sePoint);
|
|
2789 |
|
|
2790 |
// TODO temporary hack, will be removed after refactoring projections
|
|
2791 |
// https://github.com/Leaflet/Leaflet/issues/1618
|
|
2792 |
if (!options.continuousWorld && !options.noWrap) {
|
|
2793 |
nw = nw.wrap();
|
|
2794 |
se = se.wrap();
|
|
2795 |
}
|
|
2796 |
|
|
2797 |
if (!options.bounds.intersects([nw, se])) { return false; }
|
|
2798 |
}
|
|
2799 |
|
|
2800 |
return true;
|
|
2801 |
},
|
|
2802 |
|
|
2803 |
_removeOtherTiles: function (bounds) {
|
|
2804 |
var kArr, x, y, key;
|
|
2805 |
|
|
2806 |
for (key in this._tiles) {
|
|
2807 |
kArr = key.split(':');
|
|
2808 |
x = parseInt(kArr[0], 10);
|
|
2809 |
y = parseInt(kArr[1], 10);
|
|
2810 |
|
|
2811 |
// remove tile if it's out of bounds
|
|
2812 |
if (x < bounds.min.x || x > bounds.max.x || y < bounds.min.y || y > bounds.max.y) {
|
|
2813 |
this._removeTile(key);
|
|
2814 |
}
|
|
2815 |
}
|
|
2816 |
},
|
|
2817 |
|
|
2818 |
_removeTile: function (key) {
|
|
2819 |
var tile = this._tiles[key];
|
|
2820 |
|
|
2821 |
this.fire('tileunload', {tile: tile, url: tile.src});
|
|
2822 |
|
|
2823 |
if (this.options.reuseTiles) {
|
|
2824 |
L.DomUtil.removeClass(tile, 'leaflet-tile-loaded');
|
|
2825 |
this._unusedTiles.push(tile);
|
|
2826 |
|
|
2827 |
} else if (tile.parentNode === this._tileContainer) {
|
|
2828 |
this._tileContainer.removeChild(tile);
|
|
2829 |
}
|
|
2830 |
|
|
2831 |
// for https://github.com/CloudMade/Leaflet/issues/137
|
|
2832 |
if (!L.Browser.android) {
|
|
2833 |
tile.onload = null;
|
|
2834 |
tile.src = L.Util.emptyImageUrl;
|
|
2835 |
}
|
|
2836 |
|
|
2837 |
delete this._tiles[key];
|
|
2838 |
},
|
|
2839 |
|
|
2840 |
_addTile: function (tilePoint, container) {
|
|
2841 |
var tilePos = this._getTilePos(tilePoint);
|
|
2842 |
|
|
2843 |
// get unused tile - or create a new tile
|
|
2844 |
var tile = this._getTile();
|
|
2845 |
|
|
2846 |
/*
|
|
2847 |
Chrome 20 layouts much faster with top/left (verify with timeline, frames)
|
|
2848 |
Android 4 browser has display issues with top/left and requires transform instead
|
|
2849 |
(other browsers don't currently care) - see debug/hacks/jitter.html for an example
|
|
2850 |
*/
|
|
2851 |
L.DomUtil.setPosition(tile, tilePos, L.Browser.chrome);
|
|
2852 |
|
|
2853 |
this._tiles[tilePoint.x + ':' + tilePoint.y] = tile;
|
|
2854 |
|
|
2855 |
this._loadTile(tile, tilePoint);
|
|
2856 |
|
|
2857 |
if (tile.parentNode !== this._tileContainer) {
|
|
2858 |
container.appendChild(tile);
|
|
2859 |
}
|
|
2860 |
},
|
|
2861 |
|
|
2862 |
_getZoomForUrl: function () {
|
|
2863 |
|
|
2864 |
var options = this.options,
|
|
2865 |
zoom = this._map.getZoom();
|
|
2866 |
|
|
2867 |
if (options.zoomReverse) {
|
|
2868 |
zoom = options.maxZoom - zoom;
|
|
2869 |
}
|
|
2870 |
|
|
2871 |
zoom += options.zoomOffset;
|
|
2872 |
|
|
2873 |
return options.maxNativeZoom ? Math.min(zoom, options.maxNativeZoom) : zoom;
|
|
2874 |
},
|
|
2875 |
|
|
2876 |
_getTilePos: function (tilePoint) {
|
|
2877 |
var origin = this._map.getPixelOrigin(),
|
|
2878 |
tileSize = this._getTileSize();
|
|
2879 |
|
|
2880 |
return tilePoint.multiplyBy(tileSize).subtract(origin);
|
|
2881 |
},
|
|
2882 |
|
|
2883 |
// image-specific code (override to implement e.g. Canvas or SVG tile layer)
|
|
2884 |
|
|
2885 |
getTileUrl: function (tilePoint) {
|
|
2886 |
return L.Util.template(this._url, L.extend({
|
|
2887 |
s: this._getSubdomain(tilePoint),
|
|
2888 |
z: tilePoint.z,
|
|
2889 |
x: tilePoint.x,
|
|
2890 |
y: tilePoint.y
|
|
2891 |
}, this.options));
|
|
2892 |
},
|
|
2893 |
|
|
2894 |
_getWrapTileNum: function () {
|
|
2895 |
var crs = this._map.options.crs,
|
|
2896 |
size = crs.getSize(this._map.getZoom());
|
|
2897 |
return size.divideBy(this._getTileSize())._floor();
|
|
2898 |
},
|
|
2899 |
|
|
2900 |
_adjustTilePoint: function (tilePoint) {
|
|
2901 |
|
|
2902 |
var limit = this._getWrapTileNum();
|
|
2903 |
|
|
2904 |
// wrap tile coordinates
|
|
2905 |
if (!this.options.continuousWorld && !this.options.noWrap) {
|
|
2906 |
tilePoint.x = ((tilePoint.x % limit.x) + limit.x) % limit.x;
|
|
2907 |
}
|
|
2908 |
|
|
2909 |
if (this.options.tms) {
|
|
2910 |
tilePoint.y = limit.y - tilePoint.y - 1;
|
|
2911 |
}
|
|
2912 |
|
|
2913 |
tilePoint.z = this._getZoomForUrl();
|
|
2914 |
},
|
|
2915 |
|
|
2916 |
_getSubdomain: function (tilePoint) {
|
|
2917 |
var index = Math.abs(tilePoint.x + tilePoint.y) % this.options.subdomains.length;
|
|
2918 |
return this.options.subdomains[index];
|
|
2919 |
},
|
|
2920 |
|
|
2921 |
_getTile: function () {
|
|
2922 |
if (this.options.reuseTiles && this._unusedTiles.length > 0) {
|
|
2923 |
var tile = this._unusedTiles.pop();
|
|
2924 |
this._resetTile(tile);
|
|
2925 |
return tile;
|
|
2926 |
}
|
|
2927 |
return this._createTile();
|
|
2928 |
},
|
|
2929 |
|
|
2930 |
// Override if data stored on a tile needs to be cleaned up before reuse
|
|
2931 |
_resetTile: function (/*tile*/) {},
|
|
2932 |
|
|
2933 |
_createTile: function () {
|
|
2934 |
var tile = L.DomUtil.create('img', 'leaflet-tile');
|
|
2935 |
tile.style.width = tile.style.height = this._getTileSize() + 'px';
|
|
2936 |
tile.galleryimg = 'no';
|
|
2937 |
|
|
2938 |
tile.onselectstart = tile.onmousemove = L.Util.falseFn;
|
|
2939 |
|
|
2940 |
if (L.Browser.ielt9 && this.options.opacity !== undefined) {
|
|
2941 |
L.DomUtil.setOpacity(tile, this.options.opacity);
|
|
2942 |
}
|
|
2943 |
// without this hack, tiles disappear after zoom on Chrome for Android
|
|
2944 |
// https://github.com/Leaflet/Leaflet/issues/2078
|
|
2945 |
if (L.Browser.mobileWebkit3d) {
|
|
2946 |
tile.style.WebkitBackfaceVisibility = 'hidden';
|
|
2947 |
}
|
|
2948 |
return tile;
|
|
2949 |
},
|
|
2950 |
|
|
2951 |
_loadTile: function (tile, tilePoint) {
|
|
2952 |
tile._layer = this;
|
|
2953 |
tile.onload = this._tileOnLoad;
|
|
2954 |
tile.onerror = this._tileOnError;
|
|
2955 |
|
|
2956 |
this._adjustTilePoint(tilePoint);
|
|
2957 |
tile.src = this.getTileUrl(tilePoint);
|
|
2958 |
|
|
2959 |
this.fire('tileloadstart', {
|
|
2960 |
tile: tile,
|
|
2961 |
url: tile.src
|
|
2962 |
});
|
|
2963 |
},
|
|
2964 |
|
|
2965 |
_tileLoaded: function () {
|
|
2966 |
this._tilesToLoad--;
|
|
2967 |
|
|
2968 |
if (this._animated) {
|
|
2969 |
L.DomUtil.addClass(this._tileContainer, 'leaflet-zoom-animated');
|
|
2970 |
}
|
|
2971 |
|
|
2972 |
if (!this._tilesToLoad) {
|
|
2973 |
this.fire('load');
|
|
2974 |
|
|
2975 |
if (this._animated) {
|
|
2976 |
// clear scaled tiles after all new tiles are loaded (for performance)
|
|
2977 |
clearTimeout(this._clearBgBufferTimer);
|
|
2978 |
this._clearBgBufferTimer = setTimeout(L.bind(this._clearBgBuffer, this), 500);
|
|
2979 |
}
|
|
2980 |
}
|
|
2981 |
},
|
|
2982 |
|
|
2983 |
_tileOnLoad: function () {
|
|
2984 |
var layer = this._layer;
|
|
2985 |
|
|
2986 |
//Only if we are loading an actual image
|
|
2987 |
if (this.src !== L.Util.emptyImageUrl) {
|
|
2988 |
L.DomUtil.addClass(this, 'leaflet-tile-loaded');
|
|
2989 |
|
|
2990 |
layer.fire('tileload', {
|
|
2991 |
tile: this,
|
|
2992 |
url: this.src
|
|
2993 |
});
|
|
2994 |
}
|
|
2995 |
|
|
2996 |
layer._tileLoaded();
|
|
2997 |
},
|
|
2998 |
|
|
2999 |
_tileOnError: function () {
|
|
3000 |
var layer = this._layer;
|
|
3001 |
|
|
3002 |
layer.fire('tileerror', {
|
|
3003 |
tile: this,
|
|
3004 |
url: this.src
|
|
3005 |
});
|
|
3006 |
|
|
3007 |
var newUrl = layer.options.errorTileUrl;
|
|
3008 |
if (newUrl) {
|
|
3009 |
this.src = newUrl;
|
|
3010 |
}
|
|
3011 |
|
|
3012 |
layer._tileLoaded();
|
|
3013 |
}
|
|
3014 |
});
|
|
3015 |
|
|
3016 |
L.tileLayer = function (url, options) {
|
|
3017 |
return new L.TileLayer(url, options);
|
|
3018 |
};
|
|
3019 |
|
|
3020 |
|
|
3021 |
/*
|
|
3022 |
* L.TileLayer.WMS is used for putting WMS tile layers on the map.
|
|
3023 |
*/
|
|
3024 |
|
|
3025 |
L.TileLayer.WMS = L.TileLayer.extend({
|
|
3026 |
|
|
3027 |
defaultWmsParams: {
|
|
3028 |
service: 'WMS',
|
|
3029 |
request: 'GetMap',
|
|
3030 |
version: '1.1.1',
|
|
3031 |
layers: '',
|
|
3032 |
styles: '',
|
|
3033 |
format: 'image/jpeg',
|
|
3034 |
transparent: false
|
|
3035 |
},
|
|
3036 |
|
|
3037 |
initialize: function (url, options) { // (String, Object)
|
|
3038 |
|
|
3039 |
this._url = url;
|
|
3040 |
|
|
3041 |
var wmsParams = L.extend({}, this.defaultWmsParams),
|
|
3042 |
tileSize = options.tileSize || this.options.tileSize;
|
|
3043 |
|
|
3044 |
if (options.detectRetina && L.Browser.retina) {
|
|
3045 |
wmsParams.width = wmsParams.height = tileSize * 2;
|
|
3046 |
} else {
|
|
3047 |
wmsParams.width = wmsParams.height = tileSize;
|
|
3048 |
}
|
|
3049 |
|
|
3050 |
for (var i in options) {
|
|
3051 |
// all keys that are not TileLayer options go to WMS params
|
|
3052 |
if (!this.options.hasOwnProperty(i) && i !== 'crs') {
|
|
3053 |
wmsParams[i] = options[i];
|
|
3054 |
}
|
|
3055 |
}
|
|
3056 |
|
|
3057 |
this.wmsParams = wmsParams;
|
|
3058 |
|
|
3059 |
L.setOptions(this, options);
|
|
3060 |
},
|
|
3061 |
|
|
3062 |
onAdd: function (map) {
|
|
3063 |
|
|
3064 |
this._crs = this.options.crs || map.options.crs;
|
|
3065 |
|
|
3066 |
this._wmsVersion = parseFloat(this.wmsParams.version);
|
|
3067 |
|
|
3068 |
var projectionKey = this._wmsVersion >= 1.3 ? 'crs' : 'srs';
|
|
3069 |
this.wmsParams[projectionKey] = this._crs.code;
|
|
3070 |
|
|
3071 |
L.TileLayer.prototype.onAdd.call(this, map);
|
|
3072 |
},
|
|
3073 |
|
|
3074 |
getTileUrl: function (tilePoint) { // (Point, Number) -> String
|
|
3075 |
|
|
3076 |
var map = this._map,
|
|
3077 |
tileSize = this.options.tileSize,
|
|
3078 |
|
|
3079 |
nwPoint = tilePoint.multiplyBy(tileSize),
|
|
3080 |
sePoint = nwPoint.add([tileSize, tileSize]),
|
|
3081 |
|
|
3082 |
nw = this._crs.project(map.unproject(nwPoint, tilePoint.z)),
|
|
3083 |
se = this._crs.project(map.unproject(sePoint, tilePoint.z)),
|
|
3084 |
bbox = this._wmsVersion >= 1.3 && this._crs === L.CRS.EPSG4326 ?
|
|
3085 |
[se.y, nw.x, nw.y, se.x].join(',') :
|
|
3086 |
[nw.x, se.y, se.x, nw.y].join(','),
|
|
3087 |
|
|
3088 |
url = L.Util.template(this._url, {s: this._getSubdomain(tilePoint)});
|
|
3089 |
|
|
3090 |
return url + L.Util.getParamString(this.wmsParams, url, true) + '&BBOX=' + bbox;
|
|
3091 |
},
|
|
3092 |
|
|
3093 |
setParams: function (params, noRedraw) {
|
|
3094 |
|
|
3095 |
L.extend(this.wmsParams, params);
|
|
3096 |
|
|
3097 |
if (!noRedraw) {
|
|
3098 |
this.redraw();
|
|
3099 |
}
|
|
3100 |
|
|
3101 |
return this;
|
|
3102 |
}
|
|
3103 |
});
|
|
3104 |
|
|
3105 |
L.tileLayer.wms = function (url, options) {
|
|
3106 |
return new L.TileLayer.WMS(url, options);
|
|
3107 |
};
|
|
3108 |
|
|
3109 |
|
|
3110 |
/*
|
|
3111 |
* L.TileLayer.Canvas is a class that you can use as a base for creating
|
|
3112 |
* dynamically drawn Canvas-based tile layers.
|
|
3113 |
*/
|
|
3114 |
|
|
3115 |
L.TileLayer.Canvas = L.TileLayer.extend({
|
|
3116 |
options: {
|
|
3117 |
async: false
|
|
3118 |
},
|
|
3119 |
|
|
3120 |
initialize: function (options) {
|
|
3121 |
L.setOptions(this, options);
|
|
3122 |
},
|
|
3123 |
|
|
3124 |
redraw: function () {
|
|
3125 |
if (this._map) {
|
|
3126 |
this._reset({hard: true});
|
|
3127 |
this._update();
|
|
3128 |
}
|
|
3129 |
|
|
3130 |
for (var i in this._tiles) {
|
|
3131 |
this._redrawTile(this._tiles[i]);
|
|
3132 |
}
|
|
3133 |
return this;
|
|
3134 |
},
|
|
3135 |
|
|
3136 |
_redrawTile: function (tile) {
|
|
3137 |
this.drawTile(tile, tile._tilePoint, this._map._zoom);
|
|
3138 |
},
|
|
3139 |
|
|
3140 |
_createTile: function () {
|
|
3141 |
var tile = L.DomUtil.create('canvas', 'leaflet-tile');
|
|
3142 |
tile.width = tile.height = this.options.tileSize;
|
|
3143 |
tile.onselectstart = tile.onmousemove = L.Util.falseFn;
|
|
3144 |
return tile;
|
|
3145 |
},
|
|
3146 |
|
|
3147 |
_loadTile: function (tile, tilePoint) {
|
|
3148 |
tile._layer = this;
|
|
3149 |
tile._tilePoint = tilePoint;
|
|
3150 |
|
|
3151 |
this._redrawTile(tile);
|
|
3152 |
|
|
3153 |
if (!this.options.async) {
|
|
3154 |
this.tileDrawn(tile);
|
|
3155 |
}
|
|
3156 |
},
|
|
3157 |
|
|
3158 |
drawTile: function (/*tile, tilePoint*/) {
|
|
3159 |
// override with rendering code
|
|
3160 |
},
|
|
3161 |
|
|
3162 |
tileDrawn: function (tile) {
|
|
3163 |
this._tileOnLoad.call(tile);
|
|
3164 |
}
|
|
3165 |
});
|
|
3166 |
|
|
3167 |
|
|
3168 |
L.tileLayer.canvas = function (options) {
|
|
3169 |
return new L.TileLayer.Canvas(options);
|
|
3170 |
};
|
|
3171 |
|
|
3172 |
|
|
3173 |
/*
|
|
3174 |
* L.ImageOverlay is used to overlay images over the map (to specific geographical bounds).
|
|
3175 |
*/
|
|
3176 |
|
|
3177 |
L.ImageOverlay = L.Class.extend({
|
|
3178 |
includes: L.Mixin.Events,
|
|
3179 |
|
|
3180 |
options: {
|
|
3181 |
opacity: 1
|
|
3182 |
},
|
|
3183 |
|
|
3184 |
initialize: function (url, bounds, options) { // (String, LatLngBounds, Object)
|
|
3185 |
this._url = url;
|
|
3186 |
this._bounds = L.latLngBounds(bounds);
|
|
3187 |
|
|
3188 |
L.setOptions(this, options);
|
|
3189 |
},
|
|
3190 |
|
|
3191 |
onAdd: function (map) {
|
|
3192 |
this._map = map;
|
|
3193 |
|
|
3194 |
if (!this._image) {
|
|
3195 |
this._initImage();
|
|
3196 |
}
|
|
3197 |
|
|
3198 |
map._panes.overlayPane.appendChild(this._image);
|
|
3199 |
|
|
3200 |
map.on('viewreset', this._reset, this);
|
|
3201 |
|
|
3202 |
if (map.options.zoomAnimation && L.Browser.any3d) {
|
|
3203 |
map.on('zoomanim', this._animateZoom, this);
|
|
3204 |
}
|
|
3205 |
|
|
3206 |
this._reset();
|
|
3207 |
},
|
|
3208 |
|
|
3209 |
onRemove: function (map) {
|
|
3210 |
map.getPanes().overlayPane.removeChild(this._image);
|
|
3211 |
|
|
3212 |
map.off('viewreset', this._reset, this);
|
|
3213 |
|
|
3214 |
if (map.options.zoomAnimation) {
|
|
3215 |
map.off('zoomanim', this._animateZoom, this);
|
|
3216 |
}
|
|
3217 |
},
|
|
3218 |
|
|
3219 |
addTo: function (map) {
|
|
3220 |
map.addLayer(this);
|
|
3221 |
return this;
|
|
3222 |
},
|
|
3223 |
|
|
3224 |
setOpacity: function (opacity) {
|
|
3225 |
this.options.opacity = opacity;
|
|
3226 |
this._updateOpacity();
|
|
3227 |
return this;
|
|
3228 |
},
|
|
3229 |
|
|
3230 |
// TODO remove bringToFront/bringToBack duplication from TileLayer/Path
|
|
3231 |
bringToFront: function () {
|
|
3232 |
if (this._image) {
|
|
3233 |
this._map._panes.overlayPane.appendChild(this._image);
|
|
3234 |
}
|
|
3235 |
return this;
|
|
3236 |
},
|
|
3237 |
|
|
3238 |
bringToBack: function () {
|
|
3239 |
var pane = this._map._panes.overlayPane;
|
|
3240 |
if (this._image) {
|
|
3241 |
pane.insertBefore(this._image, pane.firstChild);
|
|
3242 |
}
|
|
3243 |
return this;
|
|
3244 |
},
|
|
3245 |
|
|
3246 |
setUrl: function (url) {
|
|
3247 |
this._url = url;
|
|
3248 |
this._image.src = this._url;
|
|
3249 |
},
|
|
3250 |
|
|
3251 |
getAttribution: function () {
|
|
3252 |
return this.options.attribution;
|
|
3253 |
},
|
|
3254 |
|
|
3255 |
_initImage: function () {
|
|
3256 |
this._image = L.DomUtil.create('img', 'leaflet-image-layer');
|
|
3257 |
|
|
3258 |
if (this._map.options.zoomAnimation && L.Browser.any3d) {
|
|
3259 |
L.DomUtil.addClass(this._image, 'leaflet-zoom-animated');
|
|
3260 |
} else {
|
|
3261 |
L.DomUtil.addClass(this._image, 'leaflet-zoom-hide');
|
|
3262 |
}
|
|
3263 |
|
|
3264 |
this._updateOpacity();
|
|
3265 |
|
|
3266 |
//TODO createImage util method to remove duplication
|
|
3267 |
L.extend(this._image, {
|
|
3268 |
galleryimg: 'no',
|
|
3269 |
onselectstart: L.Util.falseFn,
|
|
3270 |
onmousemove: L.Util.falseFn,
|
|
3271 |
onload: L.bind(this._onImageLoad, this),
|
|
3272 |
src: this._url
|
|
3273 |
});
|
|
3274 |
},
|
|
3275 |
|
|
3276 |
_animateZoom: function (e) {
|
|
3277 |
var map = this._map,
|
|
3278 |
image = this._image,
|
|
3279 |
scale = map.getZoomScale(e.zoom),
|
|
3280 |
nw = this._bounds.getNorthWest(),
|
|
3281 |
se = this._bounds.getSouthEast(),
|
|
3282 |
|
|
3283 |
topLeft = map._latLngToNewLayerPoint(nw, e.zoom, e.center),
|
|
3284 |
size = map._latLngToNewLayerPoint(se, e.zoom, e.center)._subtract(topLeft),
|
|
3285 |
origin = topLeft._add(size._multiplyBy((1 / 2) * (1 - 1 / scale)));
|
|
3286 |
|
|
3287 |
image.style[L.DomUtil.TRANSFORM] =
|
|
3288 |
L.DomUtil.getTranslateString(origin) + ' scale(' + scale + ') ';
|
|
3289 |
},
|
|
3290 |
|
|
3291 |
_reset: function () {
|
|
3292 |
var image = this._image,
|
|
3293 |
topLeft = this._map.latLngToLayerPoint(this._bounds.getNorthWest()),
|
|
3294 |
size = this._map.latLngToLayerPoint(this._bounds.getSouthEast())._subtract(topLeft);
|
|
3295 |
|
|
3296 |
L.DomUtil.setPosition(image, topLeft);
|
|
3297 |
|
|
3298 |
image.style.width = size.x + 'px';
|
|
3299 |
image.style.height = size.y + 'px';
|
|
3300 |
},
|
|
3301 |
|
|
3302 |
_onImageLoad: function () {
|
|
3303 |
this.fire('load');
|
|
3304 |
},
|
|
3305 |
|
|
3306 |
_updateOpacity: function () {
|
|
3307 |
L.DomUtil.setOpacity(this._image, this.options.opacity);
|
|
3308 |
}
|
|
3309 |
});
|
|
3310 |
|
|
3311 |
L.imageOverlay = function (url, bounds, options) {
|
|
3312 |
return new L.ImageOverlay(url, bounds, options);
|
|
3313 |
};
|
|
3314 |
|
|
3315 |
|
|
3316 |
/*
|
|
3317 |
* L.Icon is an image-based icon class that you can use with L.Marker for custom markers.
|
|
3318 |
*/
|
|
3319 |
|
|
3320 |
L.Icon = L.Class.extend({
|
|
3321 |
options: {
|
|
3322 |
/*
|
|
3323 |
iconUrl: (String) (required)
|
|
3324 |
iconRetinaUrl: (String) (optional, used for retina devices if detected)
|
|
3325 |
iconSize: (Point) (can be set through CSS)
|
|
3326 |
iconAnchor: (Point) (centered by default, can be set in CSS with negative margins)
|
|
3327 |
popupAnchor: (Point) (if not specified, popup opens in the anchor point)
|
|
3328 |
shadowUrl: (String) (no shadow by default)
|
|
3329 |
shadowRetinaUrl: (String) (optional, used for retina devices if detected)
|
|
3330 |
shadowSize: (Point)
|
|
3331 |
shadowAnchor: (Point)
|
|
3332 |
*/
|
|
3333 |
className: ''
|
|
3334 |
},
|
|
3335 |
|
|
3336 |
initialize: function (options) {
|
|
3337 |
L.setOptions(this, options);
|
|
3338 |
},
|
|
3339 |
|
|
3340 |
createIcon: function (oldIcon) {
|
|
3341 |
return this._createIcon('icon', oldIcon);
|
|
3342 |
},
|
|
3343 |
|
|
3344 |
createShadow: function (oldIcon) {
|
|
3345 |
return this._createIcon('shadow', oldIcon);
|
|
3346 |
},
|
|
3347 |
|
|
3348 |
_createIcon: function (name, oldIcon) {
|
|
3349 |
var src = this._getIconUrl(name);
|
|
3350 |
|
|
3351 |
if (!src) {
|
|
3352 |
if (name === 'icon') {
|
|
3353 |
throw new Error('iconUrl not set in Icon options (see the docs).');
|
|
3354 |
}
|
|
3355 |
return null;
|
|
3356 |
}
|
|
3357 |
|
|
3358 |
var img;
|
|
3359 |
if (!oldIcon || oldIcon.tagName !== 'IMG') {
|
|
3360 |
img = this._createImg(src);
|
|
3361 |
} else {
|
|
3362 |
img = this._createImg(src, oldIcon);
|
|
3363 |
}
|
|
3364 |
this._setIconStyles(img, name);
|
|
3365 |
|
|
3366 |
return img;
|
|
3367 |
},
|
|
3368 |
|
|
3369 |
_setIconStyles: function (img, name) {
|
|
3370 |
var options = this.options,
|
|
3371 |
size = L.point(options[name + 'Size']),
|
|
3372 |
anchor;
|
|
3373 |
|
|
3374 |
if (name === 'shadow') {
|
|
3375 |
anchor = L.point(options.shadowAnchor || options.iconAnchor);
|
|
3376 |
} else {
|
|
3377 |
anchor = L.point(options.iconAnchor);
|
|
3378 |
}
|
|
3379 |
|
|
3380 |
if (!anchor && size) {
|
|
3381 |
anchor = size.divideBy(2, true);
|
|
3382 |
}
|
|
3383 |
|
|
3384 |
img.className = 'leaflet-marker-' + name + ' ' + options.className;
|
|
3385 |
|
|
3386 |
if (anchor) {
|
|
3387 |
img.style.marginLeft = (-anchor.x) + 'px';
|
|
3388 |
img.style.marginTop = (-anchor.y) + 'px';
|
|
3389 |
}
|
|
3390 |
|
|
3391 |
if (size) {
|
|
3392 |
img.style.width = size.x + 'px';
|
|
3393 |
img.style.height = size.y + 'px';
|
|
3394 |
}
|
|
3395 |
},
|
|
3396 |
|
|
3397 |
_createImg: function (src, el) {
|
|
3398 |
el = el || document.createElement('img');
|
|
3399 |
el.src = src;
|
|
3400 |
return el;
|
|
3401 |
},
|
|
3402 |
|
|
3403 |
_getIconUrl: function (name) {
|
|
3404 |
if (L.Browser.retina && this.options[name + 'RetinaUrl']) {
|
|
3405 |
return this.options[name + 'RetinaUrl'];
|
|
3406 |
}
|
|
3407 |
return this.options[name + 'Url'];
|
|
3408 |
}
|
|
3409 |
});
|
|
3410 |
|
|
3411 |
L.icon = function (options) {
|
|
3412 |
return new L.Icon(options);
|
|
3413 |
};
|
|
3414 |
|
|
3415 |
|
|
3416 |
/*
|
|
3417 |
* L.Icon.Default is the blue marker icon used by default in Leaflet.
|
|
3418 |
*/
|
|
3419 |
|
|
3420 |
L.Icon.Default = L.Icon.extend({
|
|
3421 |
|
|
3422 |
options: {
|
|
3423 |
iconSize: [25, 41],
|
|
3424 |
iconAnchor: [12, 41],
|
|
3425 |
popupAnchor: [1, -34],
|
|
3426 |
|
|
3427 |
shadowSize: [41, 41]
|
|
3428 |
},
|
|
3429 |
|
|
3430 |
_getIconUrl: function (name) {
|
|
3431 |
var key = name + 'Url';
|
|
3432 |
|
|
3433 |
if (this.options[key]) {
|
|
3434 |
return this.options[key];
|
|
3435 |
}
|
|
3436 |
|
|
3437 |
if (L.Browser.retina && name === 'icon') {
|
|
3438 |
name += '-2x';
|
|
3439 |
}
|
|
3440 |
|
|
3441 |
var path = L.Icon.Default.imagePath;
|
|
3442 |
|
|
3443 |
if (!path) {
|
|
3444 |
throw new Error('Couldn\'t autodetect L.Icon.Default.imagePath, set it manually.');
|
|
3445 |
}
|
|
3446 |
|
|
3447 |
return path + '/marker-' + name + '.png';
|
|
3448 |
}
|
|
3449 |
});
|
|
3450 |
|
|
3451 |
L.Icon.Default.imagePath = (function () {
|
|
3452 |
var scripts = document.getElementsByTagName('script'),
|
|
3453 |
leafletRe = /[\/^]leaflet[\-\._]?([\w\-\._]*)\.js\??/;
|
|
3454 |
|
|
3455 |
var i, len, src, matches, path;
|
|
3456 |
|
|
3457 |
for (i = 0, len = scripts.length; i < len; i++) {
|
|
3458 |
src = scripts[i].src;
|
|
3459 |
matches = src.match(leafletRe);
|
|
3460 |
|
|
3461 |
if (matches) {
|
|
3462 |
path = src.split(leafletRe)[0];
|
|
3463 |
return (path ? path + '/' : '') + 'images';
|
|
3464 |
}
|
|
3465 |
}
|
|
3466 |
}());
|
|
3467 |
|
|
3468 |
|
|
3469 |
/*
|
|
3470 |
* L.Marker is used to display clickable/draggable icons on the map.
|
|
3471 |
*/
|
|
3472 |
|
|
3473 |
L.Marker = L.Class.extend({
|
|
3474 |
|
|
3475 |
includes: L.Mixin.Events,
|
|
3476 |
|
|
3477 |
options: {
|
|
3478 |
icon: new L.Icon.Default(),
|
|
3479 |
title: '',
|
|
3480 |
alt: '',
|
|
3481 |
clickable: true,
|
|
3482 |
draggable: false,
|
|
3483 |
keyboard: true,
|
|
3484 |
zIndexOffset: 0,
|
|
3485 |
opacity: 1,
|
|
3486 |
riseOnHover: false,
|
|
3487 |
riseOffset: 250
|
|
3488 |
},
|
|
3489 |
|
|
3490 |
initialize: function (latlng, options) {
|
|
3491 |
L.setOptions(this, options);
|
|
3492 |
this._latlng = L.latLng(latlng);
|
|
3493 |
},
|
|
3494 |
|
|
3495 |
onAdd: function (map) {
|
|
3496 |
this._map = map;
|
|
3497 |
|
|
3498 |
map.on('viewreset', this.update, this);
|
|
3499 |
|
|
3500 |
this._initIcon();
|
|
3501 |
this.update();
|
|
3502 |
this.fire('add');
|
|
3503 |
|
|
3504 |
if (map.options.zoomAnimation && map.options.markerZoomAnimation) {
|
|
3505 |
map.on('zoomanim', this._animateZoom, this);
|
|
3506 |
}
|
|
3507 |
},
|
|
3508 |
|
|
3509 |
addTo: function (map) {
|
|
3510 |
map.addLayer(this);
|
|
3511 |
return this;
|
|
3512 |
},
|
|
3513 |
|
|
3514 |
onRemove: function (map) {
|
|
3515 |
if (this.dragging) {
|
|
3516 |
this.dragging.disable();
|
|
3517 |
}
|
|
3518 |
|
|
3519 |
this._removeIcon();
|
|
3520 |
this._removeShadow();
|
|
3521 |
|
|
3522 |
this.fire('remove');
|
|
3523 |
|
|
3524 |
map.off({
|
|
3525 |
'viewreset': this.update,
|
|
3526 |
'zoomanim': this._animateZoom
|
|
3527 |
}, this);
|
|
3528 |
|
|
3529 |
this._map = null;
|
|
3530 |
},
|
|
3531 |
|
|
3532 |
getLatLng: function () {
|
|
3533 |
return this._latlng;
|
|
3534 |
},
|
|
3535 |
|
|
3536 |
setLatLng: function (latlng) {
|
|
3537 |
this._latlng = L.latLng(latlng);
|
|
3538 |
|
|
3539 |
this.update();
|
|
3540 |
|
|
3541 |
return this.fire('move', { latlng: this._latlng });
|
|
3542 |
},
|
|
3543 |
|
|
3544 |
setZIndexOffset: function (offset) {
|
|
3545 |
this.options.zIndexOffset = offset;
|
|
3546 |
this.update();
|
|
3547 |
|
|
3548 |
return this;
|
|
3549 |
},
|
|
3550 |
|
|
3551 |
setIcon: function (icon) {
|
|
3552 |
|
|
3553 |
this.options.icon = icon;
|
|
3554 |
|
|
3555 |
if (this._map) {
|
|
3556 |
this._initIcon();
|
|
3557 |
this.update();
|
|
3558 |
}
|
|
3559 |
|
|
3560 |
if (this._popup) {
|
|
3561 |
this.bindPopup(this._popup);
|
|
3562 |
}
|
|
3563 |
|
|
3564 |
return this;
|
|
3565 |
},
|
|
3566 |
|
|
3567 |
update: function () {
|
|
3568 |
if (this._icon) {
|
|
3569 |
var pos = this._map.latLngToLayerPoint(this._latlng).round();
|
|
3570 |
this._setPos(pos);
|
|
3571 |
}
|
|
3572 |
|
|
3573 |
return this;
|
|
3574 |
},
|
|
3575 |
|
|
3576 |
_initIcon: function () {
|
|
3577 |
var options = this.options,
|
|
3578 |
map = this._map,
|
|
3579 |
animation = (map.options.zoomAnimation && map.options.markerZoomAnimation),
|
|
3580 |
classToAdd = animation ? 'leaflet-zoom-animated' : 'leaflet-zoom-hide';
|
|
3581 |
|
|
3582 |
var icon = options.icon.createIcon(this._icon),
|
|
3583 |
addIcon = false;
|
|
3584 |
|
|
3585 |
// if we're not reusing the icon, remove the old one and init new one
|
|
3586 |
if (icon !== this._icon) {
|
|
3587 |
if (this._icon) {
|
|
3588 |
this._removeIcon();
|
|
3589 |
}
|
|
3590 |
addIcon = true;
|
|
3591 |
|
|
3592 |
if (options.title) {
|
|
3593 |
icon.title = options.title;
|
|
3594 |
}
|
|
3595 |
|
|
3596 |
if (options.alt) {
|
|
3597 |
icon.alt = options.alt;
|
|
3598 |
}
|
|
3599 |
}
|
|
3600 |
|
|
3601 |
L.DomUtil.addClass(icon, classToAdd);
|
|
3602 |
|
|
3603 |
if (options.keyboard) {
|
|
3604 |
icon.tabIndex = '0';
|
|
3605 |
}
|
|
3606 |
|
|
3607 |
this._icon = icon;
|
|
3608 |
|
|
3609 |
this._initInteraction();
|
|
3610 |
|
|
3611 |
if (options.riseOnHover) {
|
|
3612 |
L.DomEvent
|
|
3613 |
.on(icon, 'mouseover', this._bringToFront, this)
|
|
3614 |
.on(icon, 'mouseout', this._resetZIndex, this);
|
|
3615 |
}
|
|
3616 |
|
|
3617 |
var newShadow = options.icon.createShadow(this._shadow),
|
|
3618 |
addShadow = false;
|
|
3619 |
|
|
3620 |
if (newShadow !== this._shadow) {
|
|
3621 |
this._removeShadow();
|
|
3622 |
addShadow = true;
|
|
3623 |
}
|
|
3624 |
|
|
3625 |
if (newShadow) {
|
|
3626 |
L.DomUtil.addClass(newShadow, classToAdd);
|
|
3627 |
}
|
|
3628 |
this._shadow = newShadow;
|
|
3629 |
|
|
3630 |
|
|
3631 |
if (options.opacity < 1) {
|
|
3632 |
this._updateOpacity();
|
|
3633 |
}
|
|
3634 |
|
|
3635 |
|
|
3636 |
var panes = this._map._panes;
|
|
3637 |
|
|
3638 |
if (addIcon) {
|
|
3639 |
panes.markerPane.appendChild(this._icon);
|
|
3640 |
}
|
|
3641 |
|
|
3642 |
if (newShadow && addShadow) {
|
|
3643 |
panes.shadowPane.appendChild(this._shadow);
|
|
3644 |
}
|
|
3645 |
},
|
|
3646 |
|
|
3647 |
_removeIcon: function () {
|
|
3648 |
if (this.options.riseOnHover) {
|
|
3649 |
L.DomEvent
|
|
3650 |
.off(this._icon, 'mouseover', this._bringToFront)
|
|
3651 |
.off(this._icon, 'mouseout', this._resetZIndex);
|
|
3652 |
}
|
|
3653 |
|
|
3654 |
this._map._panes.markerPane.removeChild(this._icon);
|
|
3655 |
|
|
3656 |
this._icon = null;
|
|
3657 |
},
|
|
3658 |
|
|
3659 |
_removeShadow: function () {
|
|
3660 |
if (this._shadow) {
|
|
3661 |
this._map._panes.shadowPane.removeChild(this._shadow);
|
|
3662 |
}
|
|
3663 |
this._shadow = null;
|
|
3664 |
},
|
|
3665 |
|
|
3666 |
_setPos: function (pos) {
|
|
3667 |
L.DomUtil.setPosition(this._icon, pos);
|
|
3668 |
|
|
3669 |
if (this._shadow) {
|
|
3670 |
L.DomUtil.setPosition(this._shadow, pos);
|
|
3671 |
}
|
|
3672 |
|
|
3673 |
this._zIndex = pos.y + this.options.zIndexOffset;
|
|
3674 |
|
|
3675 |
this._resetZIndex();
|
|
3676 |
},
|
|
3677 |
|
|
3678 |
_updateZIndex: function (offset) {
|
|
3679 |
this._icon.style.zIndex = this._zIndex + offset;
|
|
3680 |
},
|
|
3681 |
|
|
3682 |
_animateZoom: function (opt) {
|
|
3683 |
var pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center).round();
|
|
3684 |
|
|
3685 |
this._setPos(pos);
|
|
3686 |
},
|
|
3687 |
|
|
3688 |
_initInteraction: function () {
|
|
3689 |
|
|
3690 |
if (!this.options.clickable) { return; }
|
|
3691 |
|
|
3692 |
// TODO refactor into something shared with Map/Path/etc. to DRY it up
|
|
3693 |
|
|
3694 |
var icon = this._icon,
|
|
3695 |
events = ['dblclick', 'mousedown', 'mouseover', 'mouseout', 'contextmenu'];
|
|
3696 |
|
|
3697 |
L.DomUtil.addClass(icon, 'leaflet-clickable');
|
|
3698 |
L.DomEvent.on(icon, 'click', this._onMouseClick, this);
|
|
3699 |
L.DomEvent.on(icon, 'keypress', this._onKeyPress, this);
|
|
3700 |
|
|
3701 |
for (var i = 0; i < events.length; i++) {
|
|
3702 |
L.DomEvent.on(icon, events[i], this._fireMouseEvent, this);
|
|
3703 |
}
|
|
3704 |
|
|
3705 |
if (L.Handler.MarkerDrag) {
|
|
3706 |
this.dragging = new L.Handler.MarkerDrag(this);
|
|
3707 |
|
|
3708 |
if (this.options.draggable) {
|
|
3709 |
this.dragging.enable();
|
|
3710 |
}
|
|
3711 |
}
|
|
3712 |
},
|
|
3713 |
|
|
3714 |
_onMouseClick: function (e) {
|
|
3715 |
var wasDragged = this.dragging && this.dragging.moved();
|
|
3716 |
|
|
3717 |
if (this.hasEventListeners(e.type) || wasDragged) {
|
|
3718 |
L.DomEvent.stopPropagation(e);
|
|
3719 |
}
|
|
3720 |
|
|
3721 |
if (wasDragged) { return; }
|
|
3722 |
|
|
3723 |
if ((!this.dragging || !this.dragging._enabled) && this._map.dragging && this._map.dragging.moved()) { return; }
|
|
3724 |
|
|
3725 |
this.fire(e.type, {
|
|
3726 |
originalEvent: e,
|
|
3727 |
latlng: this._latlng
|
|
3728 |
});
|
|
3729 |
},
|
|
3730 |
|
|
3731 |
_onKeyPress: function (e) {
|
|
3732 |
if (e.keyCode === 13) {
|
|
3733 |
this.fire('click', {
|
|
3734 |
originalEvent: e,
|
|
3735 |
latlng: this._latlng
|
|
3736 |
});
|
|
3737 |
}
|
|
3738 |
},
|
|
3739 |
|
|
3740 |
_fireMouseEvent: function (e) {
|
|
3741 |
|
|
3742 |
this.fire(e.type, {
|
|
3743 |
originalEvent: e,
|
|
3744 |
latlng: this._latlng
|
|
3745 |
});
|
|
3746 |
|
|
3747 |
// TODO proper custom event propagation
|
|
3748 |
// this line will always be called if marker is in a FeatureGroup
|
|
3749 |
if (e.type === 'contextmenu' && this.hasEventListeners(e.type)) {
|
|
3750 |
L.DomEvent.preventDefault(e);
|
|
3751 |
}
|
|
3752 |
if (e.type !== 'mousedown') {
|
|
3753 |
L.DomEvent.stopPropagation(e);
|
|
3754 |
} else {
|
|
3755 |
L.DomEvent.preventDefault(e);
|
|
3756 |
}
|
|
3757 |
},
|
|
3758 |
|
|
3759 |
setOpacity: function (opacity) {
|
|
3760 |
this.options.opacity = opacity;
|
|
3761 |
if (this._map) {
|
|
3762 |
this._updateOpacity();
|
|
3763 |
}
|
|
3764 |
|
|
3765 |
return this;
|
|
3766 |
},
|
|
3767 |
|
|
3768 |
_updateOpacity: function () {
|
|
3769 |
L.DomUtil.setOpacity(this._icon, this.options.opacity);
|
|
3770 |
if (this._shadow) {
|
|
3771 |
L.DomUtil.setOpacity(this._shadow, this.options.opacity);
|
|
3772 |
}
|
|
3773 |
},
|
|
3774 |
|
|
3775 |
_bringToFront: function () {
|
|
3776 |
this._updateZIndex(this.options.riseOffset);
|
|
3777 |
},
|
|
3778 |
|
|
3779 |
_resetZIndex: function () {
|
|
3780 |
this._updateZIndex(0);
|
|
3781 |
}
|
|
3782 |
});
|
|
3783 |
|
|
3784 |
L.marker = function (latlng, options) {
|
|
3785 |
return new L.Marker(latlng, options);
|
|
3786 |
};
|
|
3787 |
|
|
3788 |
|
|
3789 |
/*
|
|
3790 |
* L.DivIcon is a lightweight HTML-based icon class (as opposed to the image-based L.Icon)
|
|
3791 |
* to use with L.Marker.
|
|
3792 |
*/
|
|
3793 |
|
|
3794 |
L.DivIcon = L.Icon.extend({
|
|
3795 |
options: {
|
|
3796 |
iconSize: [12, 12], // also can be set through CSS
|
|
3797 |
/*
|
|
3798 |
iconAnchor: (Point)
|
|
3799 |
popupAnchor: (Point)
|
|
3800 |
html: (String)
|
|
3801 |
bgPos: (Point)
|
|
3802 |
*/
|
|
3803 |
className: 'leaflet-div-icon',
|
|
3804 |
html: false
|
|
3805 |
},
|
|
3806 |
|
|
3807 |
createIcon: function (oldIcon) {
|
|
3808 |
var div = (oldIcon && oldIcon.tagName === 'DIV') ? oldIcon : document.createElement('div'),
|
|
3809 |
options = this.options;
|
|
3810 |
|
|
3811 |
if (options.html !== false) {
|
|
3812 |
div.innerHTML = options.html;
|
|
3813 |
} else {
|
|
3814 |
div.innerHTML = '';
|
|
3815 |
}
|
|
3816 |
|
|
3817 |
if (options.bgPos) {
|
|
3818 |
div.style.backgroundPosition =
|
|
3819 |
(-options.bgPos.x) + 'px ' + (-options.bgPos.y) + 'px';
|
|
3820 |
}
|
|
3821 |
|
|
3822 |
this._setIconStyles(div, 'icon');
|
|
3823 |
return div;
|
|
3824 |
},
|
|
3825 |
|
|
3826 |
createShadow: function () {
|
|
3827 |
return null;
|
|
3828 |
}
|
|
3829 |
});
|
|
3830 |
|
|
3831 |
L.divIcon = function (options) {
|
|
3832 |
return new L.DivIcon(options);
|
|
3833 |
};
|
|
3834 |
|
|
3835 |
|
|
3836 |
/*
|
|
3837 |
* L.Popup is used for displaying popups on the map.
|
|
3838 |
*/
|
|
3839 |
|
|
3840 |
L.Map.mergeOptions({
|
|
3841 |
closePopupOnClick: true
|
|
3842 |
});
|
|
3843 |
|
|
3844 |
L.Popup = L.Class.extend({
|
|
3845 |
includes: L.Mixin.Events,
|
|
3846 |
|
|
3847 |
options: {
|
|
3848 |
minWidth: 50,
|
|
3849 |
maxWidth: 300,
|
|
3850 |
// maxHeight: null,
|
|
3851 |
autoPan: true,
|
|
3852 |
closeButton: true,
|
|
3853 |
offset: [0, 7],
|
|
3854 |
autoPanPadding: [5, 5],
|
|
3855 |
// autoPanPaddingTopLeft: null,
|
|
3856 |
// autoPanPaddingBottomRight: null,
|
|
3857 |
keepInView: false,
|
|
3858 |
className: '',
|
|
3859 |
zoomAnimation: true
|
|
3860 |
},
|
|
3861 |
|
|
3862 |
initialize: function (options, source) {
|
|
3863 |
L.setOptions(this, options);
|
|
3864 |
|
|
3865 |
this._source = source;
|
|
3866 |
this._animated = L.Browser.any3d && this.options.zoomAnimation;
|
|
3867 |
this._isOpen = false;
|
|
3868 |
},
|
|
3869 |
|
|
3870 |
onAdd: function (map) {
|
|
3871 |
this._map = map;
|
|
3872 |
|
|
3873 |
if (!this._container) {
|
|
3874 |
this._initLayout();
|
|
3875 |
}
|
|
3876 |
|
|
3877 |
var animFade = map.options.fadeAnimation;
|
|
3878 |
|
|
3879 |
if (animFade) {
|
|
3880 |
L.DomUtil.setOpacity(this._container, 0);
|
|
3881 |
}
|
|
3882 |
map._panes.popupPane.appendChild(this._container);
|
|
3883 |
|
|
3884 |
map.on(this._getEvents(), this);
|
|
3885 |
|
|
3886 |
this.update();
|
|
3887 |
|
|
3888 |
if (animFade) {
|
|
3889 |
L.DomUtil.setOpacity(this._container, 1);
|
|
3890 |
}
|
|
3891 |
|
|
3892 |
this.fire('open');
|
|
3893 |
|
|
3894 |
map.fire('popupopen', {popup: this});
|
|
3895 |
|
|
3896 |
if (this._source) {
|
|
3897 |
this._source.fire('popupopen', {popup: this});
|
|
3898 |
}
|
|
3899 |
},
|
|
3900 |
|
|
3901 |
addTo: function (map) {
|
|
3902 |
map.addLayer(this);
|
|
3903 |
return this;
|
|
3904 |
},
|
|
3905 |
|
|
3906 |
openOn: function (map) {
|
|
3907 |
map.openPopup(this);
|
|
3908 |
return this;
|
|
3909 |
},
|
|
3910 |
|
|
3911 |
onRemove: function (map) {
|
|
3912 |
map._panes.popupPane.removeChild(this._container);
|
|
3913 |
|
|
3914 |
L.Util.falseFn(this._container.offsetWidth); // force reflow
|
|
3915 |
|
|
3916 |
map.off(this._getEvents(), this);
|
|
3917 |
|
|
3918 |
if (map.options.fadeAnimation) {
|
|
3919 |
L.DomUtil.setOpacity(this._container, 0);
|
|
3920 |
}
|
|
3921 |
|
|
3922 |
this._map = null;
|
|
3923 |
|
|
3924 |
this.fire('close');
|
|
3925 |
|
|
3926 |
map.fire('popupclose', {popup: this});
|
|
3927 |
|
|
3928 |
if (this._source) {
|
|
3929 |
this._source.fire('popupclose', {popup: this});
|
|
3930 |
}
|
|
3931 |
},
|
|
3932 |
|
|
3933 |
getLatLng: function () {
|
|
3934 |
return this._latlng;
|
|
3935 |
},
|
|
3936 |
|
|
3937 |
setLatLng: function (latlng) {
|
|
3938 |
this._latlng = L.latLng(latlng);
|
|
3939 |
if (this._map) {
|
|
3940 |
this._updatePosition();
|
|
3941 |
this._adjustPan();
|
|
3942 |
}
|
|
3943 |
return this;
|
|
3944 |
},
|
|
3945 |
|
|
3946 |
getContent: function () {
|
|
3947 |
return this._content;
|
|
3948 |
},
|
|
3949 |
|
|
3950 |
setContent: function (content) {
|
|
3951 |
this._content = content;
|
|
3952 |
this.update();
|
|
3953 |
return this;
|
|
3954 |
},
|
|
3955 |
|
|
3956 |
update: function () {
|
|
3957 |
if (!this._map) { return; }
|
|
3958 |
|
|
3959 |
this._container.style.visibility = 'hidden';
|
|
3960 |
|
|
3961 |
this._updateContent();
|
|
3962 |
this._updateLayout();
|
|
3963 |
this._updatePosition();
|
|
3964 |
|
|
3965 |
this._container.style.visibility = '';
|
|
3966 |
|
|
3967 |
this._adjustPan();
|
|
3968 |
},
|
|
3969 |
|
|
3970 |
_getEvents: function () {
|
|
3971 |
var events = {
|
|
3972 |
viewreset: this._updatePosition
|
|
3973 |
};
|
|
3974 |
|
|
3975 |
if (this._animated) {
|
|
3976 |
events.zoomanim = this._zoomAnimation;
|
|
3977 |
}
|
|
3978 |
if ('closeOnClick' in this.options ? this.options.closeOnClick : this._map.options.closePopupOnClick) {
|
|
3979 |
events.preclick = this._close;
|
|
3980 |
}
|
|
3981 |
if (this.options.keepInView) {
|
|
3982 |
events.moveend = this._adjustPan;
|
|
3983 |
}
|
|
3984 |
|
|
3985 |
return events;
|
|
3986 |
},
|
|
3987 |
|
|
3988 |
_close: function () {
|
|
3989 |
if (this._map) {
|
|
3990 |
this._map.closePopup(this);
|
|
3991 |
}
|
|
3992 |
},
|
|
3993 |
|
|
3994 |
_initLayout: function () {
|
|
3995 |
var prefix = 'leaflet-popup',
|
|
3996 |
containerClass = prefix + ' ' + this.options.className + ' leaflet-zoom-' +
|
|
3997 |
(this._animated ? 'animated' : 'hide'),
|
|
3998 |
container = this._container = L.DomUtil.create('div', containerClass),
|
|
3999 |
closeButton;
|
|
4000 |
|
|
4001 |
if (this.options.closeButton) {
|
|
4002 |
closeButton = this._closeButton =
|
|
4003 |
L.DomUtil.create('a', prefix + '-close-button', container);
|
|
4004 |
closeButton.href = '#close';
|
|
4005 |
closeButton.innerHTML = '×';
|
|
4006 |
L.DomEvent.disableClickPropagation(closeButton);
|
|
4007 |
|
|
4008 |
L.DomEvent.on(closeButton, 'click', this._onCloseButtonClick, this);
|
|
4009 |
}
|
|
4010 |
|
|
4011 |
var wrapper = this._wrapper =
|
|
4012 |
L.DomUtil.create('div', prefix + '-content-wrapper', container);
|
|
4013 |
L.DomEvent.disableClickPropagation(wrapper);
|
|
4014 |
|
|
4015 |
this._contentNode = L.DomUtil.create('div', prefix + '-content', wrapper);
|
|
4016 |
|
|
4017 |
L.DomEvent.disableScrollPropagation(this._contentNode);
|
|
4018 |
L.DomEvent.on(wrapper, 'contextmenu', L.DomEvent.stopPropagation);
|
|
4019 |
|
|
4020 |
this._tipContainer = L.DomUtil.create('div', prefix + '-tip-container', container);
|
|
4021 |
this._tip = L.DomUtil.create('div', prefix + '-tip', this._tipContainer);
|
|
4022 |
},
|
|
4023 |
|
|
4024 |
_updateContent: function () {
|
|
4025 |
if (!this._content) { return; }
|
|
4026 |
|
|
4027 |
if (typeof this._content === 'string') {
|
|
4028 |
this._contentNode.innerHTML = this._content;
|
|
4029 |
} else {
|
|
4030 |
while (this._contentNode.hasChildNodes()) {
|
|
4031 |
this._contentNode.removeChild(this._contentNode.firstChild);
|
|
4032 |
}
|
|
4033 |
this._contentNode.appendChild(this._content);
|
|
4034 |
}
|
|
4035 |
this.fire('contentupdate');
|
|
4036 |
},
|
|
4037 |
|
|
4038 |
_updateLayout: function () {
|
|
4039 |
var container = this._contentNode,
|
|
4040 |
style = container.style;
|
|
4041 |
|
|
4042 |
style.width = '';
|
|
4043 |
style.whiteSpace = 'nowrap';
|
|
4044 |
|
|
4045 |
var width = container.offsetWidth;
|
|
4046 |
width = Math.min(width, this.options.maxWidth);
|
|
4047 |
width = Math.max(width, this.options.minWidth);
|
|
4048 |
|
|
4049 |
style.width = (width + 1) + 'px';
|
|
4050 |
style.whiteSpace = '';
|
|
4051 |
|
|
4052 |
style.height = '';
|
|
4053 |
|
|
4054 |
var height = container.offsetHeight,
|
|
4055 |
maxHeight = this.options.maxHeight,
|
|
4056 |
scrolledClass = 'leaflet-popup-scrolled';
|
|
4057 |
|
|
4058 |
if (maxHeight && height > maxHeight) {
|
|
4059 |
style.height = maxHeight + 'px';
|
|
4060 |
L.DomUtil.addClass(container, scrolledClass);
|
|
4061 |
} else {
|
|
4062 |
L.DomUtil.removeClass(container, scrolledClass);
|
|
4063 |
}
|
|
4064 |
|
|
4065 |
this._containerWidth = this._container.offsetWidth;
|
|
4066 |
},
|
|
4067 |
|
|
4068 |
_updatePosition: function () {
|
|
4069 |
if (!this._map) { return; }
|
|
4070 |
|
|
4071 |
var pos = this._map.latLngToLayerPoint(this._latlng),
|
|
4072 |
animated = this._animated,
|
|
4073 |
offset = L.point(this.options.offset);
|
|
4074 |
|
|
4075 |
if (animated) {
|
|
4076 |
L.DomUtil.setPosition(this._container, pos);
|
|
4077 |
}
|
|
4078 |
|
|
4079 |
this._containerBottom = -offset.y - (animated ? 0 : pos.y);
|
|
4080 |
this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x + (animated ? 0 : pos.x);
|
|
4081 |
|
|
4082 |
// bottom position the popup in case the height of the popup changes (images loading etc)
|
|
4083 |
this._container.style.bottom = this._containerBottom + 'px';
|
|
4084 |
this._container.style.left = this._containerLeft + 'px';
|
|
4085 |
},
|
|
4086 |
|
|
4087 |
_zoomAnimation: function (opt) {
|
|
4088 |
var pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center);
|
|
4089 |
|
|
4090 |
L.DomUtil.setPosition(this._container, pos);
|
|
4091 |
},
|
|
4092 |
|
|
4093 |
_adjustPan: function () {
|
|
4094 |
if (!this.options.autoPan) { return; }
|
|
4095 |
|
|
4096 |
var map = this._map,
|
|
4097 |
containerHeight = this._container.offsetHeight,
|
|
4098 |
containerWidth = this._containerWidth,
|
|
4099 |
|
|
4100 |
layerPos = new L.Point(this._containerLeft, -containerHeight - this._containerBottom);
|
|
4101 |
|
|
4102 |
if (this._animated) {
|
|
4103 |
layerPos._add(L.DomUtil.getPosition(this._container));
|
|
4104 |
}
|
|
4105 |
|
|
4106 |
var containerPos = map.layerPointToContainerPoint(layerPos),
|
|
4107 |
padding = L.point(this.options.autoPanPadding),
|
|
4108 |
paddingTL = L.point(this.options.autoPanPaddingTopLeft || padding),
|
|
4109 |
paddingBR = L.point(this.options.autoPanPaddingBottomRight || padding),
|
|
4110 |
size = map.getSize(),
|
|
4111 |
dx = 0,
|
|
4112 |
dy = 0;
|
|
4113 |
|
|
4114 |
if (containerPos.x + containerWidth + paddingBR.x > size.x) { // right
|
|
4115 |
dx = containerPos.x + containerWidth - size.x + paddingBR.x;
|
|
4116 |
}
|
|
4117 |
if (containerPos.x - dx - paddingTL.x < 0) { // left
|
|
4118 |
dx = containerPos.x - paddingTL.x;
|
|
4119 |
}
|
|
4120 |
if (containerPos.y + containerHeight + paddingBR.y > size.y) { // bottom
|
|
4121 |
dy = containerPos.y + containerHeight - size.y + paddingBR.y;
|
|
4122 |
}
|
|
4123 |
if (containerPos.y - dy - paddingTL.y < 0) { // top
|
|
4124 |
dy = containerPos.y - paddingTL.y;
|
|
4125 |
}
|
|
4126 |
|
|
4127 |
if (dx || dy) {
|
|
4128 |
map
|
|
4129 |
.fire('autopanstart')
|
|
4130 |
.panBy([dx, dy]);
|
|
4131 |
}
|
|
4132 |
},
|
|
4133 |
|
|
4134 |
_onCloseButtonClick: function (e) {
|
|
4135 |
this._close();
|
|
4136 |
L.DomEvent.stop(e);
|
|
4137 |
}
|
|
4138 |
});
|
|
4139 |
|
|
4140 |
L.popup = function (options, source) {
|
|
4141 |
return new L.Popup(options, source);
|
|
4142 |
};
|
|
4143 |
|
|
4144 |
|
|
4145 |
L.Map.include({
|
|
4146 |
openPopup: function (popup, latlng, options) { // (Popup) or (String || HTMLElement, LatLng[, Object])
|
|
4147 |
this.closePopup();
|
|
4148 |
|
|
4149 |
if (!(popup instanceof L.Popup)) {
|
|
4150 |
var content = popup;
|
|
4151 |
|
|
4152 |
popup = new L.Popup(options)
|
|
4153 |
.setLatLng(latlng)
|
|
4154 |
.setContent(content);
|
|
4155 |
}
|
|
4156 |
popup._isOpen = true;
|
|
4157 |
|
|
4158 |
this._popup = popup;
|
|
4159 |
return this.addLayer(popup);
|
|
4160 |
},
|
|
4161 |
|
|
4162 |
closePopup: function (popup) {
|
|
4163 |
if (!popup || popup === this._popup) {
|
|
4164 |
popup = this._popup;
|
|
4165 |
this._popup = null;
|
|
4166 |
}
|
|
4167 |
if (popup) {
|
|
4168 |
this.removeLayer(popup);
|
|
4169 |
popup._isOpen = false;
|
|
4170 |
}
|
|
4171 |
return this;
|
|
4172 |
}
|
|
4173 |
});
|
|
4174 |
|
|
4175 |
|
|
4176 |
/*
|
|
4177 |
* Popup extension to L.Marker, adding popup-related methods.
|
|
4178 |
*/
|
|
4179 |
|
|
4180 |
L.Marker.include({
|
|
4181 |
openPopup: function () {
|
|
4182 |
if (this._popup && this._map && !this._map.hasLayer(this._popup)) {
|
|
4183 |
this._popup.setLatLng(this._latlng);
|
|
4184 |
this._map.openPopup(this._popup);
|
|
4185 |
}
|
|
4186 |
|
|
4187 |
return this;
|
|
4188 |
},
|
|
4189 |
|
|
4190 |
closePopup: function () {
|
|
4191 |
if (this._popup) {
|
|
4192 |
this._popup._close();
|
|
4193 |
}
|
|
4194 |
return this;
|
|
4195 |
},
|
|
4196 |
|
|
4197 |
togglePopup: function () {
|
|
4198 |
if (this._popup) {
|
|
4199 |
if (this._popup._isOpen) {
|
|
4200 |
this.closePopup();
|
|
4201 |
} else {
|
|
4202 |
this.openPopup();
|
|
4203 |
}
|
|
4204 |
}
|
|
4205 |
return this;
|
|
4206 |
},
|
|
4207 |
|
|
4208 |
bindPopup: function (content, options) {
|
|
4209 |
var anchor = L.point(this.options.icon.options.popupAnchor || [0, 0]);
|
|
4210 |
|
|
4211 |
anchor = anchor.add(L.Popup.prototype.options.offset);
|
|
4212 |
|
|
4213 |
if (options && options.offset) {
|
|
4214 |
anchor = anchor.add(options.offset);
|
|
4215 |
}
|
|
4216 |
|
|
4217 |
options = L.extend({offset: anchor}, options);
|
|
4218 |
|
|
4219 |
if (!this._popupHandlersAdded) {
|
|
4220 |
this
|
|
4221 |
.on('click', this.togglePopup, this)
|
|
4222 |
.on('remove', this.closePopup, this)
|
|
4223 |
.on('move', this._movePopup, this);
|
|
4224 |
this._popupHandlersAdded = true;
|
|
4225 |
}
|
|
4226 |
|
|
4227 |
if (content instanceof L.Popup) {
|
|
4228 |
L.setOptions(content, options);
|
|
4229 |
this._popup = content;
|
|
4230 |
} else {
|
|
4231 |
this._popup = new L.Popup(options, this)
|
|
4232 |
.setContent(content);
|
|
4233 |
}
|
|
4234 |
|
|
4235 |
return this;
|
|
4236 |
},
|
|
4237 |
|
|
4238 |
setPopupContent: function (content) {
|
|
4239 |
if (this._popup) {
|
|
4240 |
this._popup.setContent(content);
|
|
4241 |
}
|
|
4242 |
return this;
|
|
4243 |
},
|
|
4244 |
|
|
4245 |
unbindPopup: function () {
|
|
4246 |
if (this._popup) {
|
|
4247 |
this._popup = null;
|
|
4248 |
this
|
|
4249 |
.off('click', this.togglePopup, this)
|
|
4250 |
.off('remove', this.closePopup, this)
|
|
4251 |
.off('move', this._movePopup, this);
|
|
4252 |
this._popupHandlersAdded = false;
|
|
4253 |
}
|
|
4254 |
return this;
|
|
4255 |
},
|
|
4256 |
|
|
4257 |
getPopup: function () {
|
|
4258 |
return this._popup;
|
|
4259 |
},
|
|
4260 |
|
|
4261 |
_movePopup: function (e) {
|
|
4262 |
this._popup.setLatLng(e.latlng);
|
|
4263 |
}
|
|
4264 |
});
|
|
4265 |
|
|
4266 |
|
|
4267 |
/*
|
|
4268 |
* L.LayerGroup is a class to combine several layers into one so that
|
|
4269 |
* you can manipulate the group (e.g. add/remove it) as one layer.
|
|
4270 |
*/
|
|
4271 |
|
|
4272 |
L.LayerGroup = L.Class.extend({
|
|
4273 |
initialize: function (layers) {
|
|
4274 |
this._layers = {};
|
|
4275 |
|
|
4276 |
var i, len;
|
|
4277 |
|
|
4278 |
if (layers) {
|
|
4279 |
for (i = 0, len = layers.length; i < len; i++) {
|
|
4280 |
this.addLayer(layers[i]);
|
|
4281 |
}
|
|
4282 |
}
|
|
4283 |
},
|
|
4284 |
|
|
4285 |
addLayer: function (layer) {
|
|
4286 |
var id = this.getLayerId(layer);
|
|
4287 |
|
|
4288 |
this._layers[id] = layer;
|
|
4289 |
|
|
4290 |
if (this._map) {
|
|
4291 |
this._map.addLayer(layer);
|
|
4292 |
}
|
|
4293 |
|
|
4294 |
return this;
|
|
4295 |
},
|
|
4296 |
|
|
4297 |
removeLayer: function (layer) {
|
|
4298 |
var id = layer in this._layers ? layer : this.getLayerId(layer);
|
|
4299 |
|
|
4300 |
if (this._map && this._layers[id]) {
|
|
4301 |
this._map.removeLayer(this._layers[id]);
|
|
4302 |
}
|
|
4303 |
|
|
4304 |
delete this._layers[id];
|
|
4305 |
|
|
4306 |
return this;
|
|
4307 |
},
|
|
4308 |
|
|
4309 |
hasLayer: function (layer) {
|
|
4310 |
if (!layer) { return false; }
|
|
4311 |
|
|
4312 |
return (layer in this._layers || this.getLayerId(layer) in this._layers);
|
|
4313 |
},
|
|
4314 |
|
|
4315 |
clearLayers: function () {
|
|
4316 |
this.eachLayer(this.removeLayer, this);
|
|
4317 |
return this;
|
|
4318 |
},
|
|
4319 |
|
|
4320 |
invoke: function (methodName) {
|
|
4321 |
var args = Array.prototype.slice.call(arguments, 1),
|
|
4322 |
i, layer;
|
|
4323 |
|
|
4324 |
for (i in this._layers) {
|
|
4325 |
layer = this._layers[i];
|
|
4326 |
|
|
4327 |
if (layer[methodName]) {
|
|
4328 |
layer[methodName].apply(layer, args);
|
|
4329 |
}
|
|
4330 |
}
|
|
4331 |
|
|
4332 |
return this;
|
|
4333 |
},
|
|
4334 |
|
|
4335 |
onAdd: function (map) {
|
|
4336 |
this._map = map;
|
|
4337 |
this.eachLayer(map.addLayer, map);
|
|
4338 |
},
|
|
4339 |
|
|
4340 |
onRemove: function (map) {
|
|
4341 |
this.eachLayer(map.removeLayer, map);
|
|
4342 |
this._map = null;
|
|
4343 |
},
|
|
4344 |
|
|
4345 |
addTo: function (map) {
|
|
4346 |
map.addLayer(this);
|
|
4347 |
return this;
|
|
4348 |
},
|
|
4349 |
|
|
4350 |
eachLayer: function (method, context) {
|
|
4351 |
for (var i in this._layers) {
|
|
4352 |
method.call(context, this._layers[i]);
|
|
4353 |
}
|
|
4354 |
return this;
|
|
4355 |
},
|
|
4356 |
|
|
4357 |
getLayer: function (id) {
|
|
4358 |
return this._layers[id];
|
|
4359 |
},
|
|
4360 |
|
|
4361 |
getLayers: function () {
|
|
4362 |
var layers = [];
|
|
4363 |
|
|
4364 |
for (var i in this._layers) {
|
|
4365 |
layers.push(this._layers[i]);
|
|
4366 |
}
|
|
4367 |
return layers;
|
|
4368 |
},
|
|
4369 |
|
|
4370 |
setZIndex: function (zIndex) {
|
|
4371 |
return this.invoke('setZIndex', zIndex);
|
|
4372 |
},
|
|
4373 |
|
|
4374 |
getLayerId: function (layer) {
|
|
4375 |
return L.stamp(layer);
|
|
4376 |
}
|
|
4377 |
});
|
|
4378 |
|
|
4379 |
L.layerGroup = function (layers) {
|
|
4380 |
return new L.LayerGroup(layers);
|
|
4381 |
};
|
|
4382 |
|
|
4383 |
|
|
4384 |
/*
|
|
4385 |
* L.FeatureGroup extends L.LayerGroup by introducing mouse events and additional methods
|
|
4386 |
* shared between a group of interactive layers (like vectors or markers).
|
|
4387 |
*/
|
|
4388 |
|
|
4389 |
L.FeatureGroup = L.LayerGroup.extend({
|
|
4390 |
includes: L.Mixin.Events,
|
|
4391 |
|
|
4392 |
statics: {
|
|
4393 |
EVENTS: 'click dblclick mouseover mouseout mousemove contextmenu popupopen popupclose'
|
|
4394 |
},
|
|
4395 |
|
|
4396 |
addLayer: function (layer) {
|
|
4397 |
if (this.hasLayer(layer)) {
|
|
4398 |
return this;
|
|
4399 |
}
|
|
4400 |
|
|
4401 |
if ('on' in layer) {
|
|
4402 |
layer.on(L.FeatureGroup.EVENTS, this._propagateEvent, this);
|
|
4403 |
}
|
|
4404 |
|
|
4405 |
L.LayerGroup.prototype.addLayer.call(this, layer);
|
|
4406 |
|
|
4407 |
if (this._popupContent && layer.bindPopup) {
|
|
4408 |
layer.bindPopup(this._popupContent, this._popupOptions);
|
|
4409 |
}
|
|
4410 |
|
|
4411 |
return this.fire('layeradd', {layer: layer});
|
|
4412 |
},
|
|
4413 |
|
|
4414 |
removeLayer: function (layer) {
|
|
4415 |
if (!this.hasLayer(layer)) {
|
|
4416 |
return this;
|
|
4417 |
}
|
|
4418 |
if (layer in this._layers) {
|
|
4419 |
layer = this._layers[layer];
|
|
4420 |
}
|
|
4421 |
|
|
4422 |
layer.off(L.FeatureGroup.EVENTS, this._propagateEvent, this);
|
|
4423 |
|
|
4424 |
L.LayerGroup.prototype.removeLayer.call(this, layer);
|
|
4425 |
|
|
4426 |
if (this._popupContent) {
|
|
4427 |
this.invoke('unbindPopup');
|
|
4428 |
}
|
|
4429 |
|
|
4430 |
return this.fire('layerremove', {layer: layer});
|
|
4431 |
},
|
|
4432 |
|
|
4433 |
bindPopup: function (content, options) {
|
|
4434 |
this._popupContent = content;
|
|
4435 |
this._popupOptions = options;
|
|
4436 |
return this.invoke('bindPopup', content, options);
|
|
4437 |
},
|
|
4438 |
|
|
4439 |
openPopup: function (latlng) {
|
|
4440 |
// open popup on the first layer
|
|
4441 |
for (var id in this._layers) {
|
|
4442 |
this._layers[id].openPopup(latlng);
|
|
4443 |
break;
|
|
4444 |
}
|
|
4445 |
return this;
|
|
4446 |
},
|
|
4447 |
|
|
4448 |
setStyle: function (style) {
|
|
4449 |
return this.invoke('setStyle', style);
|
|
4450 |
},
|
|
4451 |
|
|
4452 |
bringToFront: function () {
|
|
4453 |
return this.invoke('bringToFront');
|
|
4454 |
},
|
|
4455 |
|
|
4456 |
bringToBack: function () {
|
|
4457 |
return this.invoke('bringToBack');
|
|
4458 |
},
|
|
4459 |
|
|
4460 |
getBounds: function () {
|
|
4461 |
var bounds = new L.LatLngBounds();
|
|
4462 |
|
|
4463 |
this.eachLayer(function (layer) {
|
|
4464 |
bounds.extend(layer instanceof L.Marker ? layer.getLatLng() : layer.getBounds());
|
|
4465 |
});
|
|
4466 |
|
|
4467 |
return bounds;
|
|
4468 |
},
|
|
4469 |
|
|
4470 |
_propagateEvent: function (e) {
|
|
4471 |
e = L.extend({
|
|
4472 |
layer: e.target,
|
|
4473 |
target: this
|
|
4474 |
}, e);
|
|
4475 |
this.fire(e.type, e);
|
|
4476 |
}
|
|
4477 |
});
|
|
4478 |
|
|
4479 |
L.featureGroup = function (layers) {
|
|
4480 |
return new L.FeatureGroup(layers);
|
|
4481 |
};
|
|
4482 |
|
|
4483 |
|
|
4484 |
/*
|
|
4485 |
* L.Path is a base class for rendering vector paths on a map. Inherited by Polyline, Circle, etc.
|
|
4486 |
*/
|
|
4487 |
|
|
4488 |
L.Path = L.Class.extend({
|
|
4489 |
includes: [L.Mixin.Events],
|
|
4490 |
|
|
4491 |
statics: {
|
|
4492 |
// how much to extend the clip area around the map view
|
|
4493 |
// (relative to its size, e.g. 0.5 is half the screen in each direction)
|
|
4494 |
// set it so that SVG element doesn't exceed 1280px (vectors flicker on dragend if it is)
|
|
4495 |
CLIP_PADDING: (function () {
|
|
4496 |
var max = L.Browser.mobile ? 1280 : 2000,
|
|
4497 |
target = (max / Math.max(window.outerWidth, window.outerHeight) - 1) / 2;
|
|
4498 |
return Math.max(0, Math.min(0.5, target));
|
|
4499 |
})()
|
|
4500 |
},
|
|
4501 |
|
|
4502 |
options: {
|
|
4503 |
stroke: true,
|
|
4504 |
color: '#0033ff',
|
|
4505 |
dashArray: null,
|
|
4506 |
lineCap: null,
|
|
4507 |
lineJoin: null,
|
|
4508 |
weight: 5,
|
|
4509 |
opacity: 0.5,
|
|
4510 |
|
|
4511 |
fill: false,
|
|
4512 |
fillColor: null, //same as color by default
|
|
4513 |
fillOpacity: 0.2,
|
|
4514 |
|
|
4515 |
clickable: true
|
|
4516 |
},
|
|
4517 |
|
|
4518 |
initialize: function (options) {
|
|
4519 |
L.setOptions(this, options);
|
|
4520 |
},
|
|
4521 |
|
|
4522 |
onAdd: function (map) {
|
|
4523 |
this._map = map;
|
|
4524 |
|
|
4525 |
if (!this._container) {
|
|
4526 |
this._initElements();
|
|
4527 |
this._initEvents();
|
|
4528 |
}
|
|
4529 |
|
|
4530 |
this.projectLatlngs();
|
|
4531 |
this._updatePath();
|
|
4532 |
|
|
4533 |
if (this._container) {
|
|
4534 |
this._map._pathRoot.appendChild(this._container);
|
|
4535 |
}
|
|
4536 |
|
|
4537 |
this.fire('add');
|
|
4538 |
|
|
4539 |
map.on({
|
|
4540 |
'viewreset': this.projectLatlngs,
|
|
4541 |
'moveend': this._updatePath
|
|
4542 |
}, this);
|
|
4543 |
},
|
|
4544 |
|
|
4545 |
addTo: function (map) {
|
|
4546 |
map.addLayer(this);
|
|
4547 |
return this;
|
|
4548 |
},
|
|
4549 |
|
|
4550 |
onRemove: function (map) {
|
|
4551 |
map._pathRoot.removeChild(this._container);
|
|
4552 |
|
|
4553 |
// Need to fire remove event before we set _map to null as the event hooks might need the object
|
|
4554 |
this.fire('remove');
|
|
4555 |
this._map = null;
|
|
4556 |
|
|
4557 |
if (L.Browser.vml) {
|
|
4558 |
this._container = null;
|
|
4559 |
this._stroke = null;
|
|
4560 |
this._fill = null;
|
|
4561 |
}
|
|
4562 |
|
|
4563 |
map.off({
|
|
4564 |
'viewreset': this.projectLatlngs,
|
|
4565 |
'moveend': this._updatePath
|
|
4566 |
}, this);
|
|
4567 |
},
|
|
4568 |
|
|
4569 |
projectLatlngs: function () {
|
|
4570 |
// do all projection stuff here
|
|
4571 |
},
|
|
4572 |
|
|
4573 |
setStyle: function (style) {
|
|
4574 |
L.setOptions(this, style);
|
|
4575 |
|
|
4576 |
if (this._container) {
|
|
4577 |
this._updateStyle();
|
|
4578 |
}
|
|
4579 |
|
|
4580 |
return this;
|
|
4581 |
},
|
|
4582 |
|
|
4583 |
redraw: function () {
|
|
4584 |
if (this._map) {
|
|
4585 |
this.projectLatlngs();
|
|
4586 |
this._updatePath();
|
|
4587 |
}
|
|
4588 |
return this;
|
|
4589 |
}
|
|
4590 |
});
|
|
4591 |
|
|
4592 |
L.Map.include({
|
|
4593 |
_updatePathViewport: function () {
|
|
4594 |
var p = L.Path.CLIP_PADDING,
|
|
4595 |
size = this.getSize(),
|
|
4596 |
panePos = L.DomUtil.getPosition(this._mapPane),
|
|
4597 |
min = panePos.multiplyBy(-1)._subtract(size.multiplyBy(p)._round()),
|
|
4598 |
max = min.add(size.multiplyBy(1 + p * 2)._round());
|
|
4599 |
|
|
4600 |
this._pathViewport = new L.Bounds(min, max);
|
|
4601 |
}
|
|
4602 |
});
|
|
4603 |
|
|
4604 |
|
|
4605 |
/*
|
|
4606 |
* Extends L.Path with SVG-specific rendering code.
|
|
4607 |
*/
|
|
4608 |
|
|
4609 |
L.Path.SVG_NS = 'http://www.w3.org/2000/svg';
|
|
4610 |
|
|
4611 |
L.Browser.svg = !!(document.createElementNS && document.createElementNS(L.Path.SVG_NS, 'svg').createSVGRect);
|
|
4612 |
|
|
4613 |
L.Path = L.Path.extend({
|
|
4614 |
statics: {
|
|
4615 |
SVG: L.Browser.svg
|
|
4616 |
},
|
|
4617 |
|
|
4618 |
bringToFront: function () {
|
|
4619 |
var root = this._map._pathRoot,
|
|
4620 |
path = this._container;
|
|
4621 |
|
|
4622 |
if (path && root.lastChild !== path) {
|
|
4623 |
root.appendChild(path);
|
|
4624 |
}
|
|
4625 |
return this;
|
|
4626 |
},
|
|
4627 |
|
|
4628 |
bringToBack: function () {
|
|
4629 |
var root = this._map._pathRoot,
|
|
4630 |
path = this._container,
|
|
4631 |
first = root.firstChild;
|
|
4632 |
|
|
4633 |
if (path && first !== path) {
|
|
4634 |
root.insertBefore(path, first);
|
|
4635 |
}
|
|
4636 |
return this;
|
|
4637 |
},
|
|
4638 |
|
|
4639 |
getPathString: function () {
|
|
4640 |
// form path string here
|
|
4641 |
},
|
|
4642 |
|
|
4643 |
_createElement: function (name) {
|
|
4644 |
return document.createElementNS(L.Path.SVG_NS, name);
|
|
4645 |
},
|
|
4646 |
|
|
4647 |
_initElements: function () {
|
|
4648 |
this._map._initPathRoot();
|
|
4649 |
this._initPath();
|
|
4650 |
this._initStyle();
|
|
4651 |
},
|
|
4652 |
|
|
4653 |
_initPath: function () {
|
|
4654 |
this._container = this._createElement('g');
|
|
4655 |
|
|
4656 |
this._path = this._createElement('path');
|
|
4657 |
|
|
4658 |
if (this.options.className) {
|
|
4659 |
L.DomUtil.addClass(this._path, this.options.className);
|
|
4660 |
}
|
|
4661 |
|
|
4662 |
this._container.appendChild(this._path);
|
|
4663 |
},
|
|
4664 |
|
|
4665 |
_initStyle: function () {
|
|
4666 |
if (this.options.stroke) {
|
|
4667 |
this._path.setAttribute('stroke-linejoin', 'round');
|
|
4668 |
this._path.setAttribute('stroke-linecap', 'round');
|
|
4669 |
}
|
|
4670 |
if (this.options.fill) {
|
|
4671 |
this._path.setAttribute('fill-rule', 'evenodd');
|
|
4672 |
}
|
|
4673 |
if (this.options.pointerEvents) {
|
|
4674 |
this._path.setAttribute('pointer-events', this.options.pointerEvents);
|
|
4675 |
}
|
|
4676 |
if (!this.options.clickable && !this.options.pointerEvents) {
|
|
4677 |
this._path.setAttribute('pointer-events', 'none');
|
|
4678 |
}
|
|
4679 |
this._updateStyle();
|
|
4680 |
},
|
|
4681 |
|
|
4682 |
_updateStyle: function () {
|
|
4683 |
if (this.options.stroke) {
|
|
4684 |
this._path.setAttribute('stroke', this.options.color);
|
|
4685 |
this._path.setAttribute('stroke-opacity', this.options.opacity);
|
|
4686 |
this._path.setAttribute('stroke-width', this.options.weight);
|
|
4687 |
if (this.options.dashArray) {
|
|
4688 |
this._path.setAttribute('stroke-dasharray', this.options.dashArray);
|
|
4689 |
} else {
|
|
4690 |
this._path.removeAttribute('stroke-dasharray');
|
|
4691 |
}
|
|
4692 |
if (this.options.lineCap) {
|
|
4693 |
this._path.setAttribute('stroke-linecap', this.options.lineCap);
|
|
4694 |
}
|
|
4695 |
if (this.options.lineJoin) {
|
|
4696 |
this._path.setAttribute('stroke-linejoin', this.options.lineJoin);
|
|
4697 |
}
|
|
4698 |
} else {
|
|
4699 |
this._path.setAttribute('stroke', 'none');
|
|
4700 |
}
|
|
4701 |
if (this.options.fill) {
|
|
4702 |
this._path.setAttribute('fill', this.options.fillColor || this.options.color);
|
|
4703 |
this._path.setAttribute('fill-opacity', this.options.fillOpacity);
|
|
4704 |
} else {
|
|
4705 |
this._path.setAttribute('fill', 'none');
|
|
4706 |
}
|
|
4707 |
},
|
|
4708 |
|
|
4709 |
_updatePath: function () {
|
|
4710 |
var str = this.getPathString();
|
|
4711 |
if (!str) {
|
|
4712 |
// fix webkit empty string parsing bug
|
|
4713 |
str = 'M0 0';
|
|
4714 |
}
|
|
4715 |
this._path.setAttribute('d', str);
|
|
4716 |
},
|
|
4717 |
|
|
4718 |
// TODO remove duplication with L.Map
|
|
4719 |
_initEvents: function () {
|
|
4720 |
if (this.options.clickable) {
|
|
4721 |
if (L.Browser.svg || !L.Browser.vml) {
|
|
4722 |
L.DomUtil.addClass(this._path, 'leaflet-clickable');
|
|
4723 |
}
|
|
4724 |
|
|
4725 |
L.DomEvent.on(this._container, 'click', this._onMouseClick, this);
|
|
4726 |
|
|
4727 |
var events = ['dblclick', 'mousedown', 'mouseover',
|
|
4728 |
'mouseout', 'mousemove', 'contextmenu'];
|
|
4729 |
for (var i = 0; i < events.length; i++) {
|
|
4730 |
L.DomEvent.on(this._container, events[i], this._fireMouseEvent, this);
|
|
4731 |
}
|
|
4732 |
}
|
|
4733 |
},
|
|
4734 |
|
|
4735 |
_onMouseClick: function (e) {
|
|
4736 |
if (this._map.dragging && this._map.dragging.moved()) { return; }
|
|
4737 |
|
|
4738 |
this._fireMouseEvent(e);
|
|
4739 |
},
|
|
4740 |
|
|
4741 |
_fireMouseEvent: function (e) {
|
|
4742 |
if (!this.hasEventListeners(e.type)) { return; }
|
|
4743 |
|
|
4744 |
var map = this._map,
|
|
4745 |
containerPoint = map.mouseEventToContainerPoint(e),
|
|
4746 |
layerPoint = map.containerPointToLayerPoint(containerPoint),
|
|
4747 |
latlng = map.layerPointToLatLng(layerPoint);
|
|
4748 |
|
|
4749 |
this.fire(e.type, {
|
|
4750 |
latlng: latlng,
|
|
4751 |
layerPoint: layerPoint,
|
|
4752 |
containerPoint: containerPoint,
|
|
4753 |
originalEvent: e
|
|
4754 |
});
|
|
4755 |
|
|
4756 |
if (e.type === 'contextmenu') {
|
|
4757 |
L.DomEvent.preventDefault(e);
|
|
4758 |
}
|
|
4759 |
if (e.type !== 'mousemove') {
|
|
4760 |
L.DomEvent.stopPropagation(e);
|
|
4761 |
}
|
|
4762 |
}
|
|
4763 |
});
|
|
4764 |
|
|
4765 |
L.Map.include({
|
|
4766 |
_initPathRoot: function () {
|
|
4767 |
if (!this._pathRoot) {
|
|
4768 |
this._pathRoot = L.Path.prototype._createElement('svg');
|
|
4769 |
this._panes.overlayPane.appendChild(this._pathRoot);
|
|
4770 |
|
|
4771 |
if (this.options.zoomAnimation && L.Browser.any3d) {
|
|
4772 |
L.DomUtil.addClass(this._pathRoot, 'leaflet-zoom-animated');
|
|
4773 |
|
|
4774 |
this.on({
|
|
4775 |
'zoomanim': this._animatePathZoom,
|
|
4776 |
'zoomend': this._endPathZoom
|
|
4777 |
});
|
|
4778 |
} else {
|
|
4779 |
L.DomUtil.addClass(this._pathRoot, 'leaflet-zoom-hide');
|
|
4780 |
}
|
|
4781 |
|
|
4782 |
this.on('moveend', this._updateSvgViewport);
|
|
4783 |
this._updateSvgViewport();
|
|
4784 |
}
|
|
4785 |
},
|
|
4786 |
|
|
4787 |
_animatePathZoom: function (e) {
|
|
4788 |
var scale = this.getZoomScale(e.zoom),
|
|
4789 |
offset = this._getCenterOffset(e.center)._multiplyBy(-scale)._add(this._pathViewport.min);
|
|
4790 |
|
|
4791 |
this._pathRoot.style[L.DomUtil.TRANSFORM] =
|
|
4792 |
L.DomUtil.getTranslateString(offset) + ' scale(' + scale + ') ';
|
|
4793 |
|
|
4794 |
this._pathZooming = true;
|
|
4795 |
},
|
|
4796 |
|
|
4797 |
_endPathZoom: function () {
|
|
4798 |
this._pathZooming = false;
|
|
4799 |
},
|
|
4800 |
|
|
4801 |
_updateSvgViewport: function () {
|
|
4802 |
|
|
4803 |
if (this._pathZooming) {
|
|
4804 |
// Do not update SVGs while a zoom animation is going on otherwise the animation will break.
|
|
4805 |
// When the zoom animation ends we will be updated again anyway
|
|
4806 |
// This fixes the case where you do a momentum move and zoom while the move is still ongoing.
|
|
4807 |
return;
|
|
4808 |
}
|
|
4809 |
|
|
4810 |
this._updatePathViewport();
|
|
4811 |
|
|
4812 |
var vp = this._pathViewport,
|
|
4813 |
min = vp.min,
|
|
4814 |
max = vp.max,
|
|
4815 |
width = max.x - min.x,
|
|
4816 |
height = max.y - min.y,
|
|
4817 |
root = this._pathRoot,
|
|
4818 |
pane = this._panes.overlayPane;
|
|
4819 |
|
|
4820 |
// Hack to make flicker on drag end on mobile webkit less irritating
|
|
4821 |
if (L.Browser.mobileWebkit) {
|
|
4822 |
pane.removeChild(root);
|
|
4823 |
}
|
|
4824 |
|
|
4825 |
L.DomUtil.setPosition(root, min);
|
|
4826 |
root.setAttribute('width', width);
|
|
4827 |
root.setAttribute('height', height);
|
|
4828 |
root.setAttribute('viewBox', [min.x, min.y, width, height].join(' '));
|
|
4829 |
|
|
4830 |
if (L.Browser.mobileWebkit) {
|
|
4831 |
pane.appendChild(root);
|
|
4832 |
}
|
|
4833 |
}
|
|
4834 |
});
|
|
4835 |
|
|
4836 |
|
|
4837 |
/*
|
|
4838 |
* Popup extension to L.Path (polylines, polygons, circles), adding popup-related methods.
|
|
4839 |
*/
|
|
4840 |
|
|
4841 |
L.Path.include({
|
|
4842 |
|
|
4843 |
bindPopup: function (content, options) {
|
|
4844 |
|
|
4845 |
if (content instanceof L.Popup) {
|
|
4846 |
this._popup = content;
|
|
4847 |
} else {
|
|
4848 |
if (!this._popup || options) {
|
|
4849 |
this._popup = new L.Popup(options, this);
|
|
4850 |
}
|
|
4851 |
this._popup.setContent(content);
|
|
4852 |
}
|
|
4853 |
|
|
4854 |
if (!this._popupHandlersAdded) {
|
|
4855 |
this
|
|
4856 |
.on('click', this._openPopup, this)
|
|
4857 |
.on('remove', this.closePopup, this);
|
|
4858 |
|
|
4859 |
this._popupHandlersAdded = true;
|
|
4860 |
}
|
|
4861 |
|
|
4862 |
return this;
|
|
4863 |
},
|
|
4864 |
|
|
4865 |
unbindPopup: function () {
|
|
4866 |
if (this._popup) {
|
|
4867 |
this._popup = null;
|
|
4868 |
this
|
|
4869 |
.off('click', this._openPopup)
|
|
4870 |
.off('remove', this.closePopup);
|
|
4871 |
|
|
4872 |
this._popupHandlersAdded = false;
|
|
4873 |
}
|
|
4874 |
return this;
|
|
4875 |
},
|
|
4876 |
|
|
4877 |
openPopup: function (latlng) {
|
|
4878 |
|
|
4879 |
if (this._popup) {
|
|
4880 |
// open the popup from one of the path's points if not specified
|
|
4881 |
latlng = latlng || this._latlng ||
|
|
4882 |
this._latlngs[Math.floor(this._latlngs.length / 2)];
|
|
4883 |
|
|
4884 |
this._openPopup({latlng: latlng});
|
|
4885 |
}
|
|
4886 |
|
|
4887 |
return this;
|
|
4888 |
},
|
|
4889 |
|
|
4890 |
closePopup: function () {
|
|
4891 |
if (this._popup) {
|
|
4892 |
this._popup._close();
|
|
4893 |
}
|
|
4894 |
return this;
|
|
4895 |
},
|
|
4896 |
|
|
4897 |
_openPopup: function (e) {
|
|
4898 |
this._popup.setLatLng(e.latlng);
|
|
4899 |
this._map.openPopup(this._popup);
|
|
4900 |
}
|
|
4901 |
});
|
|
4902 |
|
|
4903 |
|
|
4904 |
/*
|
|
4905 |
* Vector rendering for IE6-8 through VML.
|
|
4906 |
* Thanks to Dmitry Baranovsky and his Raphael library for inspiration!
|
|
4907 |
*/
|
|
4908 |
|
|
4909 |
L.Browser.vml = !L.Browser.svg && (function () {
|
|
4910 |
try {
|
|
4911 |
var div = document.createElement('div');
|
|
4912 |
div.innerHTML = '<v:shape adj="1"/>';
|
|
4913 |
|
|
4914 |
var shape = div.firstChild;
|
|
4915 |
shape.style.behavior = 'url(#default#VML)';
|
|
4916 |
|
|
4917 |
return shape && (typeof shape.adj === 'object');
|
|
4918 |
|
|
4919 |
} catch (e) {
|
|
4920 |
return false;
|
|
4921 |
}
|
|
4922 |
}());
|
|
4923 |
|
|
4924 |
L.Path = L.Browser.svg || !L.Browser.vml ? L.Path : L.Path.extend({
|
|
4925 |
statics: {
|
|
4926 |
VML: true,
|
|
4927 |
CLIP_PADDING: 0.02
|
|
4928 |
},
|
|
4929 |
|
|
4930 |
_createElement: (function () {
|
|
4931 |
try {
|
|
4932 |
document.namespaces.add('lvml', 'urn:schemas-microsoft-com:vml');
|
|
4933 |
return function (name) {
|
|
4934 |
return document.createElement('<lvml:' + name + ' class="lvml">');
|
|
4935 |
};
|
|
4936 |
} catch (e) {
|
|
4937 |
return function (name) {
|
|
4938 |
return document.createElement(
|
|
4939 |
'<' + name + ' xmlns="urn:schemas-microsoft.com:vml" class="lvml">');
|
|
4940 |
};
|
|
4941 |
}
|
|
4942 |
}()),
|
|
4943 |
|
|
4944 |
_initPath: function () {
|
|
4945 |
var container = this._container = this._createElement('shape');
|
|
4946 |
|
|
4947 |
L.DomUtil.addClass(container, 'leaflet-vml-shape' +
|
|
4948 |
(this.options.className ? ' ' + this.options.className : ''));
|
|
4949 |
|
|
4950 |
if (this.options.clickable) {
|
|
4951 |
L.DomUtil.addClass(container, 'leaflet-clickable');
|
|
4952 |
}
|
|
4953 |
|
|
4954 |
container.coordsize = '1 1';
|
|
4955 |
|
|
4956 |
this._path = this._createElement('path');
|
|
4957 |
container.appendChild(this._path);
|
|
4958 |
|
|
4959 |
this._map._pathRoot.appendChild(container);
|
|
4960 |
},
|
|
4961 |
|
|
4962 |
_initStyle: function () {
|
|
4963 |
this._updateStyle();
|
|
4964 |
},
|
|
4965 |
|
|
4966 |
_updateStyle: function () {
|
|
4967 |
var stroke = this._stroke,
|
|
4968 |
fill = this._fill,
|
|
4969 |
options = this.options,
|
|
4970 |
container = this._container;
|
|
4971 |
|
|
4972 |
container.stroked = options.stroke;
|
|
4973 |
container.filled = options.fill;
|
|
4974 |
|
|
4975 |
if (options.stroke) {
|
|
4976 |
if (!stroke) {
|
|
4977 |
stroke = this._stroke = this._createElement('stroke');
|
|
4978 |
stroke.endcap = 'round';
|
|
4979 |
container.appendChild(stroke);
|
|
4980 |
}
|
|
4981 |
stroke.weight = options.weight + 'px';
|
|
4982 |
stroke.color = options.color;
|
|
4983 |
stroke.opacity = options.opacity;
|
|
4984 |
|
|
4985 |
if (options.dashArray) {
|
|
4986 |
stroke.dashStyle = L.Util.isArray(options.dashArray) ?
|
|
4987 |
options.dashArray.join(' ') :
|
|
4988 |
options.dashArray.replace(/( *, *)/g, ' ');
|
|
4989 |
} else {
|
|
4990 |
stroke.dashStyle = '';
|
|
4991 |
}
|
|
4992 |
if (options.lineCap) {
|
|
4993 |
stroke.endcap = options.lineCap.replace('butt', 'flat');
|
|
4994 |
}
|
|
4995 |
if (options.lineJoin) {
|
|
4996 |
stroke.joinstyle = options.lineJoin;
|
|
4997 |
}
|
|
4998 |
|
|
4999 |
} else if (stroke) {
|
|
5000 |
container.removeChild(stroke);
|
|
5001 |
this._stroke = null;
|
|
5002 |
}
|
|
5003 |
|
|
5004 |
if (options.fill) {
|
|
5005 |
if (!fill) {
|
|
5006 |
fill = this._fill = this._createElement('fill');
|
|
5007 |
container.appendChild(fill);
|
|
5008 |
}
|
|
5009 |
fill.color = options.fillColor || options.color;
|
|
5010 |
fill.opacity = options.fillOpacity;
|
|
5011 |
|
|
5012 |
} else if (fill) {
|
|
5013 |
container.removeChild(fill);
|
|
5014 |
this._fill = null;
|
|
5015 |
}
|
|
5016 |
},
|
|
5017 |
|
|
5018 |
_updatePath: function () {
|
|
5019 |
var style = this._container.style;
|
|
5020 |
|
|
5021 |
style.display = 'none';
|
|
5022 |
this._path.v = this.getPathString() + ' '; // the space fixes IE empty path string bug
|
|
5023 |
style.display = '';
|
|
5024 |
}
|
|
5025 |
});
|
|
5026 |
|
|
5027 |
L.Map.include(L.Browser.svg || !L.Browser.vml ? {} : {
|
|
5028 |
_initPathRoot: function () {
|
|
5029 |
if (this._pathRoot) { return; }
|
|
5030 |
|
|
5031 |
var root = this._pathRoot = document.createElement('div');
|
|
5032 |
root.className = 'leaflet-vml-container';
|
|
5033 |
this._panes.overlayPane.appendChild(root);
|
|
5034 |
|
|
5035 |
this.on('moveend', this._updatePathViewport);
|
|
5036 |
this._updatePathViewport();
|
|
5037 |
}
|
|
5038 |
});
|
|
5039 |
|
|
5040 |
|
|
5041 |
/*
|
|
5042 |
* Vector rendering for all browsers that support canvas.
|
|
5043 |
*/
|
|
5044 |
|
|
5045 |
L.Browser.canvas = (function () {
|
|
5046 |
return !!document.createElement('canvas').getContext;
|
|
5047 |
}());
|
|
5048 |
|
|
5049 |
L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path : L.Path.extend({
|
|
5050 |
statics: {
|
|
5051 |
//CLIP_PADDING: 0.02, // not sure if there's a need to set it to a small value
|
|
5052 |
CANVAS: true,
|
|
5053 |
SVG: false
|
|
5054 |
},
|
|
5055 |
|
|
5056 |
redraw: function () {
|
|
5057 |
if (this._map) {
|
|
5058 |
this.projectLatlngs();
|
|
5059 |
this._requestUpdate();
|
|
5060 |
}
|
|
5061 |
return this;
|
|
5062 |
},
|
|
5063 |
|
|
5064 |
setStyle: function (style) {
|
|
5065 |
L.setOptions(this, style);
|
|
5066 |
|
|
5067 |
if (this._map) {
|
|
5068 |
this._updateStyle();
|
|
5069 |
this._requestUpdate();
|
|
5070 |
}
|
|
5071 |
return this;
|
|
5072 |
},
|
|
5073 |
|
|
5074 |
onRemove: function (map) {
|
|
5075 |
map
|
|
5076 |
.off('viewreset', this.projectLatlngs, this)
|
|
5077 |
.off('moveend', this._updatePath, this);
|
|
5078 |
|
|
5079 |
if (this.options.clickable) {
|
|
5080 |
this._map.off('click', this._onClick, this);
|
|
5081 |
this._map.off('mousemove', this._onMouseMove, this);
|
|
5082 |
}
|
|
5083 |
|
|
5084 |
this._requestUpdate();
|
|
5085 |
|
|
5086 |
this.fire('remove');
|
|
5087 |
this._map = null;
|
|
5088 |
},
|
|
5089 |
|
|
5090 |
_requestUpdate: function () {
|
|
5091 |
if (this._map && !L.Path._updateRequest) {
|
|
5092 |
L.Path._updateRequest = L.Util.requestAnimFrame(this._fireMapMoveEnd, this._map);
|
|
5093 |
}
|
|
5094 |
},
|
|
5095 |
|
|
5096 |
_fireMapMoveEnd: function () {
|
|
5097 |
L.Path._updateRequest = null;
|
|
5098 |
this.fire('moveend');
|
|
5099 |
},
|
|
5100 |
|
|
5101 |
_initElements: function () {
|
|
5102 |
this._map._initPathRoot();
|
|
5103 |
this._ctx = this._map._canvasCtx;
|
|
5104 |
},
|
|
5105 |
|
|
5106 |
_updateStyle: function () {
|
|
5107 |
var options = this.options;
|
|
5108 |
|
|
5109 |
if (options.stroke) {
|
|
5110 |
this._ctx.lineWidth = options.weight;
|
|
5111 |
this._ctx.strokeStyle = options.color;
|
|
5112 |
}
|
|
5113 |
if (options.fill) {
|
|
5114 |
this._ctx.fillStyle = options.fillColor || options.color;
|
|
5115 |
}
|
|
5116 |
},
|
|
5117 |
|
|
5118 |
_drawPath: function () {
|
|
5119 |
var i, j, len, len2, point, drawMethod;
|
|
5120 |
|
|
5121 |
this._ctx.beginPath();
|
|
5122 |
|
|
5123 |
for (i = 0, len = this._parts.length; i < len; i++) {
|
|
5124 |
for (j = 0, len2 = this._parts[i].length; j < len2; j++) {
|
|
5125 |
point = this._parts[i][j];
|
|
5126 |
drawMethod = (j === 0 ? 'move' : 'line') + 'To';
|
|
5127 |
|
|
5128 |
this._ctx[drawMethod](point.x, point.y);
|
|
5129 |
}
|
|
5130 |
// TODO refactor ugly hack
|
|
5131 |
if (this instanceof L.Polygon) {
|
|
5132 |
this._ctx.closePath();
|
|
5133 |
}
|
|
5134 |
}
|
|
5135 |
},
|
|
5136 |
|
|
5137 |
_checkIfEmpty: function () {
|
|
5138 |
return !this._parts.length;
|
|
5139 |
},
|
|
5140 |
|
|
5141 |
_updatePath: function () {
|
|
5142 |
if (this._checkIfEmpty()) { return; }
|
|
5143 |
|
|
5144 |
var ctx = this._ctx,
|
|
5145 |
options = this.options;
|
|
5146 |
|
|
5147 |
this._drawPath();
|
|
5148 |
ctx.save();
|
|
5149 |
this._updateStyle();
|
|
5150 |
|
|
5151 |
if (options.fill) {
|
|
5152 |
ctx.globalAlpha = options.fillOpacity;
|
|
5153 |
ctx.fill();
|
|
5154 |
}
|
|
5155 |
|
|
5156 |
if (options.stroke) {
|
|
5157 |
ctx.globalAlpha = options.opacity;
|
|
5158 |
ctx.stroke();
|
|
5159 |
}
|
|
5160 |
|
|
5161 |
ctx.restore();
|
|
5162 |
|
|
5163 |
// TODO optimization: 1 fill/stroke for all features with equal style instead of 1 for each feature
|
|
5164 |
},
|
|
5165 |
|
|
5166 |
_initEvents: function () {
|
|
5167 |
if (this.options.clickable) {
|
|
5168 |
// TODO dblclick
|
|
5169 |
this._map.on('mousemove', this._onMouseMove, this);
|
|
5170 |
this._map.on('click', this._onClick, this);
|
|
5171 |
}
|
|
5172 |
},
|
|
5173 |
|
|
5174 |
_onClick: function (e) {
|
|
5175 |
if (this._containsPoint(e.layerPoint)) {
|
|
5176 |
this.fire('click', e);
|
|
5177 |
}
|
|
5178 |
},
|
|
5179 |
|
|
5180 |
_onMouseMove: function (e) {
|
|
5181 |
if (!this._map || this._map._animatingZoom) { return; }
|
|
5182 |
|
|
5183 |
// TODO don't do on each move
|
|
5184 |
if (this._containsPoint(e.layerPoint)) {
|
|
5185 |
this._ctx.canvas.style.cursor = 'pointer';
|
|
5186 |
this._mouseInside = true;
|
|
5187 |
this.fire('mouseover', e);
|
|
5188 |
|
|
5189 |
} else if (this._mouseInside) {
|
|
5190 |
this._ctx.canvas.style.cursor = '';
|
|
5191 |
this._mouseInside = false;
|
|
5192 |
this.fire('mouseout', e);
|
|
5193 |
}
|
|
5194 |
}
|
|
5195 |
});
|
|
5196 |
|
|
5197 |
L.Map.include((L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? {} : {
|
|
5198 |
_initPathRoot: function () {
|
|
5199 |
var root = this._pathRoot,
|
|
5200 |
ctx;
|
|
5201 |
|
|
5202 |
if (!root) {
|
|
5203 |
root = this._pathRoot = document.createElement('canvas');
|
|
5204 |
root.style.position = 'absolute';
|
|
5205 |
ctx = this._canvasCtx = root.getContext('2d');
|
|
5206 |
|
|
5207 |
ctx.lineCap = 'round';
|
|
5208 |
ctx.lineJoin = 'round';
|
|
5209 |
|
|
5210 |
this._panes.overlayPane.appendChild(root);
|
|
5211 |
|
|
5212 |
if (this.options.zoomAnimation) {
|
|
5213 |
this._pathRoot.className = 'leaflet-zoom-animated';
|
|
5214 |
this.on('zoomanim', this._animatePathZoom);
|
|
5215 |
this.on('zoomend', this._endPathZoom);
|
|
5216 |
}
|
|
5217 |
this.on('moveend', this._updateCanvasViewport);
|
|
5218 |
this._updateCanvasViewport();
|
|
5219 |
}
|
|
5220 |
},
|
|
5221 |
|
|
5222 |
_updateCanvasViewport: function () {
|
|
5223 |
// don't redraw while zooming. See _updateSvgViewport for more details
|
|
5224 |
if (this._pathZooming) { return; }
|
|
5225 |
this._updatePathViewport();
|
|
5226 |
|
|
5227 |
var vp = this._pathViewport,
|
|
5228 |
min = vp.min,
|
|
5229 |
size = vp.max.subtract(min),
|
|
5230 |
root = this._pathRoot;
|
|
5231 |
|
|
5232 |
//TODO check if this works properly on mobile webkit
|
|
5233 |
L.DomUtil.setPosition(root, min);
|
|
5234 |
root.width = size.x;
|
|
5235 |
root.height = size.y;
|
|
5236 |
root.getContext('2d').translate(-min.x, -min.y);
|
|
5237 |
}
|
|
5238 |
});
|
|
5239 |
|
|
5240 |
|
|
5241 |
/*
|
|
5242 |
* L.LineUtil contains different utility functions for line segments
|
|
5243 |
* and polylines (clipping, simplification, distances, etc.)
|
|
5244 |
*/
|
|
5245 |
|
|
5246 |
/*jshint bitwise:false */ // allow bitwise operations for this file
|
|
5247 |
|
|
5248 |
L.LineUtil = {
|
|
5249 |
|
|
5250 |
// Simplify polyline with vertex reduction and Douglas-Peucker simplification.
|
|
5251 |
// Improves rendering performance dramatically by lessening the number of points to draw.
|
|
5252 |
|
|
5253 |
simplify: function (/*Point[]*/ points, /*Number*/ tolerance) {
|
|
5254 |
if (!tolerance || !points.length) {
|
|
5255 |
return points.slice();
|
|
5256 |
}
|
|
5257 |
|
|
5258 |
var sqTolerance = tolerance * tolerance;
|
|
5259 |
|
|
5260 |
// stage 1: vertex reduction
|
|
5261 |
points = this._reducePoints(points, sqTolerance);
|
|
5262 |
|
|
5263 |
// stage 2: Douglas-Peucker simplification
|
|
5264 |
points = this._simplifyDP(points, sqTolerance);
|
|
5265 |
|
|
5266 |
return points;
|
|
5267 |
},
|
|
5268 |
|
|
5269 |
// distance from a point to a segment between two points
|
|
5270 |
pointToSegmentDistance: function (/*Point*/ p, /*Point*/ p1, /*Point*/ p2) {
|
|
5271 |
return Math.sqrt(this._sqClosestPointOnSegment(p, p1, p2, true));
|
|
5272 |
},
|
|
5273 |
|
|
5274 |
closestPointOnSegment: function (/*Point*/ p, /*Point*/ p1, /*Point*/ p2) {
|
|
5275 |
return this._sqClosestPointOnSegment(p, p1, p2);
|
|
5276 |
},
|
|
5277 |
|
|
5278 |
// Douglas-Peucker simplification, see http://en.wikipedia.org/wiki/Douglas-Peucker_algorithm
|
|
5279 |
_simplifyDP: function (points, sqTolerance) {
|
|
5280 |
|
|
5281 |
var len = points.length,
|
|
5282 |
ArrayConstructor = typeof Uint8Array !== undefined + '' ? Uint8Array : Array,
|
|
5283 |
markers = new ArrayConstructor(len);
|
|
5284 |
|
|
5285 |
markers[0] = markers[len - 1] = 1;
|
|
5286 |
|
|
5287 |
this._simplifyDPStep(points, markers, sqTolerance, 0, len - 1);
|
|
5288 |
|
|
5289 |
var i,
|
|
5290 |
newPoints = [];
|
|
5291 |
|
|
5292 |
for (i = 0; i < len; i++) {
|
|
5293 |
if (markers[i]) {
|
|
5294 |
newPoints.push(points[i]);
|
|
5295 |
}
|
|
5296 |
}
|
|
5297 |
|
|
5298 |
return newPoints;
|
|
5299 |
},
|
|
5300 |
|
|
5301 |
_simplifyDPStep: function (points, markers, sqTolerance, first, last) {
|
|
5302 |
|
|
5303 |
var maxSqDist = 0,
|
|
5304 |
index, i, sqDist;
|
|
5305 |
|
|
5306 |
for (i = first + 1; i <= last - 1; i++) {
|
|
5307 |
sqDist = this._sqClosestPointOnSegment(points[i], points[first], points[last], true);
|
|
5308 |
|
|
5309 |
if (sqDist > maxSqDist) {
|
|
5310 |
index = i;
|
|
5311 |
maxSqDist = sqDist;
|
|
5312 |
}
|
|
5313 |
}
|
|
5314 |
|
|
5315 |
if (maxSqDist > sqTolerance) {
|
|
5316 |
markers[index] = 1;
|
|
5317 |
|
|
5318 |
this._simplifyDPStep(points, markers, sqTolerance, first, index);
|
|
5319 |
this._simplifyDPStep(points, markers, sqTolerance, index, last);
|
|
5320 |
}
|
|
5321 |
},
|
|
5322 |
|
|
5323 |
// reduce points that are too close to each other to a single point
|
|
5324 |
_reducePoints: function (points, sqTolerance) {
|
|
5325 |
var reducedPoints = [points[0]];
|
|
5326 |
|
|
5327 |
for (var i = 1, prev = 0, len = points.length; i < len; i++) {
|
|
5328 |
if (this._sqDist(points[i], points[prev]) > sqTolerance) {
|
|
5329 |
reducedPoints.push(points[i]);
|
|
5330 |
prev = i;
|
|
5331 |
}
|
|
5332 |
}
|
|
5333 |
if (prev < len - 1) {
|
|
5334 |
reducedPoints.push(points[len - 1]);
|
|
5335 |
}
|
|
5336 |
return reducedPoints;
|
|
5337 |
},
|
|
5338 |
|
|
5339 |
// Cohen-Sutherland line clipping algorithm.
|
|
5340 |
// Used to avoid rendering parts of a polyline that are not currently visible.
|
|
5341 |
|
|
5342 |
clipSegment: function (a, b, bounds, useLastCode) {
|
|
5343 |
var codeA = useLastCode ? this._lastCode : this._getBitCode(a, bounds),
|
|
5344 |
codeB = this._getBitCode(b, bounds),
|
|
5345 |
|
|
5346 |
codeOut, p, newCode;
|
|
5347 |
|
|
5348 |
// save 2nd code to avoid calculating it on the next segment
|
|
5349 |
this._lastCode = codeB;
|
|
5350 |
|
|
5351 |
while (true) {
|
|
5352 |
// if a,b is inside the clip window (trivial accept)
|
|
5353 |
if (!(codeA | codeB)) {
|
|
5354 |
return [a, b];
|
|
5355 |
// if a,b is outside the clip window (trivial reject)
|
|
5356 |
} else if (codeA & codeB) {
|
|
5357 |
return false;
|
|
5358 |
// other cases
|
|
5359 |
} else {
|
|
5360 |
codeOut = codeA || codeB;
|
|
5361 |
p = this._getEdgeIntersection(a, b, codeOut, bounds);
|
|
5362 |
newCode = this._getBitCode(p, bounds);
|
|
5363 |
|
|
5364 |
if (codeOut === codeA) {
|
|
5365 |
a = p;
|
|
5366 |
codeA = newCode;
|
|
5367 |
} else {
|
|
5368 |
b = p;
|
|
5369 |
codeB = newCode;
|
|
5370 |
}
|
|
5371 |
}
|
|
5372 |
}
|
|
5373 |
},
|
|
5374 |
|
|
5375 |
_getEdgeIntersection: function (a, b, code, bounds) {
|
|
5376 |
var dx = b.x - a.x,
|
|
5377 |
dy = b.y - a.y,
|
|
5378 |
min = bounds.min,
|
|
5379 |
max = bounds.max;
|
|
5380 |
|
|
5381 |
if (code & 8) { // top
|
|
5382 |
return new L.Point(a.x + dx * (max.y - a.y) / dy, max.y);
|
|
5383 |
} else if (code & 4) { // bottom
|
|
5384 |
return new L.Point(a.x + dx * (min.y - a.y) / dy, min.y);
|
|
5385 |
} else if (code & 2) { // right
|
|
5386 |
return new L.Point(max.x, a.y + dy * (max.x - a.x) / dx);
|
|
5387 |
} else if (code & 1) { // left
|
|
5388 |
return new L.Point(min.x, a.y + dy * (min.x - a.x) / dx);
|
|
5389 |
}
|
|
5390 |
},
|
|
5391 |
|
|
5392 |
_getBitCode: function (/*Point*/ p, bounds) {
|
|
5393 |
var code = 0;
|
|
5394 |
|
|
5395 |
if (p.x < bounds.min.x) { // left
|
|
5396 |
code |= 1;
|
|
5397 |
} else if (p.x > bounds.max.x) { // right
|
|
5398 |
code |= 2;
|
|
5399 |
}
|
|
5400 |
if (p.y < bounds.min.y) { // bottom
|
|
5401 |
code |= 4;
|
|
5402 |
} else if (p.y > bounds.max.y) { // top
|
|
5403 |
code |= 8;
|
|
5404 |
}
|
|
5405 |
|
|
5406 |
return code;
|
|
5407 |
},
|
|
5408 |
|
|
5409 |
// square distance (to avoid unnecessary Math.sqrt calls)
|
|
5410 |
_sqDist: function (p1, p2) {
|
|
5411 |
var dx = p2.x - p1.x,
|
|
5412 |
dy = p2.y - p1.y;
|
|
5413 |
return dx * dx + dy * dy;
|
|
5414 |
},
|
|
5415 |
|
|
5416 |
// return closest point on segment or distance to that point
|
|
5417 |
_sqClosestPointOnSegment: function (p, p1, p2, sqDist) {
|
|
5418 |
var x = p1.x,
|
|
5419 |
y = p1.y,
|
|
5420 |
dx = p2.x - x,
|
|
5421 |
dy = p2.y - y,
|
|
5422 |
dot = dx * dx + dy * dy,
|
|
5423 |
t;
|
|
5424 |
|
|
5425 |
if (dot > 0) {
|
|
5426 |
t = ((p.x - x) * dx + (p.y - y) * dy) / dot;
|
|
5427 |
|
|
5428 |
if (t > 1) {
|
|
5429 |
x = p2.x;
|
|
5430 |
y = p2.y;
|
|
5431 |
} else if (t > 0) {
|
|
5432 |
x += dx * t;
|
|
5433 |
y += dy * t;
|
|
5434 |
}
|
|
5435 |
}
|
|
5436 |
|
|
5437 |
dx = p.x - x;
|
|
5438 |
dy = p.y - y;
|
|
5439 |
|
|
5440 |
return sqDist ? dx * dx + dy * dy : new L.Point(x, y);
|
|
5441 |
}
|
|
5442 |
};
|
|
5443 |
|
|
5444 |
|
|
5445 |
/*
|
|
5446 |
* L.Polyline is used to display polylines on a map.
|
|
5447 |
*/
|
|
5448 |
|
|
5449 |
L.Polyline = L.Path.extend({
|
|
5450 |
initialize: function (latlngs, options) {
|
|
5451 |
L.Path.prototype.initialize.call(this, options);
|
|
5452 |
|
|
5453 |
this._latlngs = this._convertLatLngs(latlngs);
|
|
5454 |
},
|
|
5455 |
|
|
5456 |
options: {
|
|
5457 |
// how much to simplify the polyline on each zoom level
|
|
5458 |
// more = better performance and smoother look, less = more accurate
|
|
5459 |
smoothFactor: 1.0,
|
|
5460 |
noClip: false
|
|
5461 |
},
|
|
5462 |
|
|
5463 |
projectLatlngs: function () {
|
|
5464 |
this._originalPoints = [];
|
|
5465 |
|
|
5466 |
for (var i = 0, len = this._latlngs.length; i < len; i++) {
|
|
5467 |
this._originalPoints[i] = this._map.latLngToLayerPoint(this._latlngs[i]);
|
|
5468 |
}
|
|
5469 |
},
|
|
5470 |
|
|
5471 |
getPathString: function () {
|
|
5472 |
for (var i = 0, len = this._parts.length, str = ''; i < len; i++) {
|
|
5473 |
str += this._getPathPartStr(this._parts[i]);
|
|
5474 |
}
|
|
5475 |
return str;
|
|
5476 |
},
|
|
5477 |
|
|
5478 |
getLatLngs: function () {
|
|
5479 |
return this._latlngs;
|
|
5480 |
},
|
|
5481 |
|
|
5482 |
setLatLngs: function (latlngs) {
|
|
5483 |
this._latlngs = this._convertLatLngs(latlngs);
|
|
5484 |
return this.redraw();
|
|
5485 |
},
|
|
5486 |
|
|
5487 |
addLatLng: function (latlng) {
|
|
5488 |
this._latlngs.push(L.latLng(latlng));
|
|
5489 |
return this.redraw();
|
|
5490 |
},
|
|
5491 |
|
|
5492 |
spliceLatLngs: function () { // (Number index, Number howMany)
|
|
5493 |
var removed = [].splice.apply(this._latlngs, arguments);
|
|
5494 |
this._convertLatLngs(this._latlngs, true);
|
|
5495 |
this.redraw();
|
|
5496 |
return removed;
|
|
5497 |
},
|
|
5498 |
|
|
5499 |
closestLayerPoint: function (p) {
|
|
5500 |
var minDistance = Infinity, parts = this._parts, p1, p2, minPoint = null;
|
|
5501 |
|
|
5502 |
for (var j = 0, jLen = parts.length; j < jLen; j++) {
|
|
5503 |
var points = parts[j];
|
|
5504 |
for (var i = 1, len = points.length; i < len; i++) {
|
|
5505 |
p1 = points[i - 1];
|
|
5506 |
p2 = points[i];
|
|
5507 |
var sqDist = L.LineUtil._sqClosestPointOnSegment(p, p1, p2, true);
|
|
5508 |
if (sqDist < minDistance) {
|
|
5509 |
minDistance = sqDist;
|
|
5510 |
minPoint = L.LineUtil._sqClosestPointOnSegment(p, p1, p2);
|
|
5511 |
}
|
|
5512 |
}
|
|
5513 |
}
|
|
5514 |
if (minPoint) {
|
|
5515 |
minPoint.distance = Math.sqrt(minDistance);
|
|
5516 |
}
|
|
5517 |
return minPoint;
|
|
5518 |
},
|
|
5519 |
|
|
5520 |
getBounds: function () {
|
|
5521 |
return new L.LatLngBounds(this.getLatLngs());
|
|
5522 |
},
|
|
5523 |
|
|
5524 |
_convertLatLngs: function (latlngs, overwrite) {
|
|
5525 |
var i, len, target = overwrite ? latlngs : [];
|
|
5526 |
|
|
5527 |
for (i = 0, len = latlngs.length; i < len; i++) {
|
|
5528 |
if (L.Util.isArray(latlngs[i]) && typeof latlngs[i][0] !== 'number') {
|
|
5529 |
return;
|
|
5530 |
}
|
|
5531 |
target[i] = L.latLng(latlngs[i]);
|
|
5532 |
}
|
|
5533 |
return target;
|
|
5534 |
},
|
|
5535 |
|
|
5536 |
_initEvents: function () {
|
|
5537 |
L.Path.prototype._initEvents.call(this);
|
|
5538 |
},
|
|
5539 |
|
|
5540 |
_getPathPartStr: function (points) {
|
|
5541 |
var round = L.Path.VML;
|
|
5542 |
|
|
5543 |
for (var j = 0, len2 = points.length, str = '', p; j < len2; j++) {
|
|
5544 |
p = points[j];
|
|
5545 |
if (round) {
|
|
5546 |
p._round();
|
|
5547 |
}
|
|
5548 |
str += (j ? 'L' : 'M') + p.x + ' ' + p.y;
|
|
5549 |
}
|
|
5550 |
return str;
|
|
5551 |
},
|
|
5552 |
|
|
5553 |
_clipPoints: function () {
|
|
5554 |
var points = this._originalPoints,
|
|
5555 |
len = points.length,
|
|
5556 |
i, k, segment;
|
|
5557 |
|
|
5558 |
if (this.options.noClip) {
|
|
5559 |
this._parts = [points];
|
|
5560 |
return;
|
|
5561 |
}
|
|
5562 |
|
|
5563 |
this._parts = [];
|
|
5564 |
|
|
5565 |
var parts = this._parts,
|
|
5566 |
vp = this._map._pathViewport,
|
|
5567 |
lu = L.LineUtil;
|
|
5568 |
|
|
5569 |
for (i = 0, k = 0; i < len - 1; i++) {
|
|
5570 |
segment = lu.clipSegment(points[i], points[i + 1], vp, i);
|
|
5571 |
if (!segment) {
|
|
5572 |
continue;
|
|
5573 |
}
|
|
5574 |
|
|
5575 |
parts[k] = parts[k] || [];
|
|
5576 |
parts[k].push(segment[0]);
|
|
5577 |
|
|
5578 |
// if segment goes out of screen, or it's the last one, it's the end of the line part
|
|
5579 |
if ((segment[1] !== points[i + 1]) || (i === len - 2)) {
|
|
5580 |
parts[k].push(segment[1]);
|
|
5581 |
k++;
|
|
5582 |
}
|
|
5583 |
}
|
|
5584 |
},
|
|
5585 |
|
|
5586 |
// simplify each clipped part of the polyline
|
|
5587 |
_simplifyPoints: function () {
|
|
5588 |
var parts = this._parts,
|
|
5589 |
lu = L.LineUtil;
|
|
5590 |
|
|
5591 |
for (var i = 0, len = parts.length; i < len; i++) {
|
|
5592 |
parts[i] = lu.simplify(parts[i], this.options.smoothFactor);
|
|
5593 |
}
|
|
5594 |
},
|
|
5595 |
|
|
5596 |
_updatePath: function () {
|
|
5597 |
if (!this._map) { return; }
|
|
5598 |
|
|
5599 |
this._clipPoints();
|
|
5600 |
this._simplifyPoints();
|
|
5601 |
|
|
5602 |
L.Path.prototype._updatePath.call(this);
|
|
5603 |
}
|
|
5604 |
});
|
|
5605 |
|
|
5606 |
L.polyline = function (latlngs, options) {
|
|
5607 |
return new L.Polyline(latlngs, options);
|
|
5608 |
};
|
|
5609 |
|
|
5610 |
|
|
5611 |
/*
|
|
5612 |
* L.PolyUtil contains utility functions for polygons (clipping, etc.).
|
|
5613 |
*/
|
|
5614 |
|
|
5615 |
/*jshint bitwise:false */ // allow bitwise operations here
|
|
5616 |
|
|
5617 |
L.PolyUtil = {};
|
|
5618 |
|
|
5619 |
/*
|
|
5620 |
* Sutherland-Hodgeman polygon clipping algorithm.
|
|
5621 |
* Used to avoid rendering parts of a polygon that are not currently visible.
|
|
5622 |
*/
|
|
5623 |
L.PolyUtil.clipPolygon = function (points, bounds) {
|
|
5624 |
var clippedPoints,
|
|
5625 |
edges = [1, 4, 2, 8],
|
|
5626 |
i, j, k,
|
|
5627 |
a, b,
|
|
5628 |
len, edge, p,
|
|
5629 |
lu = L.LineUtil;
|
|
5630 |
|
|
5631 |
for (i = 0, len = points.length; i < len; i++) {
|
|
5632 |
points[i]._code = lu._getBitCode(points[i], bounds);
|
|
5633 |
}
|
|
5634 |
|
|
5635 |
// for each edge (left, bottom, right, top)
|
|
5636 |
for (k = 0; k < 4; k++) {
|
|
5637 |
edge = edges[k];
|
|
5638 |
clippedPoints = [];
|
|
5639 |
|
|
5640 |
for (i = 0, len = points.length, j = len - 1; i < len; j = i++) {
|
|
5641 |
a = points[i];
|
|
5642 |
b = points[j];
|
|
5643 |
|
|
5644 |
// if a is inside the clip window
|
|
5645 |
if (!(a._code & edge)) {
|
|
5646 |
// if b is outside the clip window (a->b goes out of screen)
|
|
5647 |
if (b._code & edge) {
|
|
5648 |
p = lu._getEdgeIntersection(b, a, edge, bounds);
|
|
5649 |
p._code = lu._getBitCode(p, bounds);
|
|
5650 |
clippedPoints.push(p);
|
|
5651 |
}
|
|
5652 |
clippedPoints.push(a);
|
|
5653 |
|
|
5654 |
// else if b is inside the clip window (a->b enters the screen)
|
|
5655 |
} else if (!(b._code & edge)) {
|
|
5656 |
p = lu._getEdgeIntersection(b, a, edge, bounds);
|
|
5657 |
p._code = lu._getBitCode(p, bounds);
|
|
5658 |
clippedPoints.push(p);
|
|
5659 |
}
|
|
5660 |
}
|
|
5661 |
points = clippedPoints;
|
|
5662 |
}
|
|
5663 |
|
|
5664 |
return points;
|
|
5665 |
};
|
|
5666 |
|
|
5667 |
|
|
5668 |
/*
|
|
5669 |
* L.Polygon is used to display polygons on a map.
|
|
5670 |
*/
|
|
5671 |
|
|
5672 |
L.Polygon = L.Polyline.extend({
|
|
5673 |
options: {
|
|
5674 |
fill: true
|
|
5675 |
},
|
|
5676 |
|
|
5677 |
initialize: function (latlngs, options) {
|
|
5678 |
L.Polyline.prototype.initialize.call(this, latlngs, options);
|
|
5679 |
this._initWithHoles(latlngs);
|
|
5680 |
},
|
|
5681 |
|
|
5682 |
_initWithHoles: function (latlngs) {
|
|
5683 |
var i, len, hole;
|
|
5684 |
if (latlngs && L.Util.isArray(latlngs[0]) && (typeof latlngs[0][0] !== 'number')) {
|
|
5685 |
this._latlngs = this._convertLatLngs(latlngs[0]);
|
|
5686 |
this._holes = latlngs.slice(1);
|
|
5687 |
|
|
5688 |
for (i = 0, len = this._holes.length; i < len; i++) {
|
|
5689 |
hole = this._holes[i] = this._convertLatLngs(this._holes[i]);
|
|
5690 |
if (hole[0].equals(hole[hole.length - 1])) {
|
|
5691 |
hole.pop();
|
|
5692 |
}
|
|
5693 |
}
|
|
5694 |
}
|
|
5695 |
|
|
5696 |
// filter out last point if its equal to the first one
|
|
5697 |
latlngs = this._latlngs;
|
|
5698 |
|
|
5699 |
if (latlngs.length >= 2 && latlngs[0].equals(latlngs[latlngs.length - 1])) {
|
|
5700 |
latlngs.pop();
|
|
5701 |
}
|
|
5702 |
},
|
|
5703 |
|
|
5704 |
projectLatlngs: function () {
|
|
5705 |
L.Polyline.prototype.projectLatlngs.call(this);
|
|
5706 |
|
|
5707 |
// project polygon holes points
|
|
5708 |
// TODO move this logic to Polyline to get rid of duplication
|
|
5709 |
this._holePoints = [];
|
|
5710 |
|
|
5711 |
if (!this._holes) { return; }
|
|
5712 |
|
|
5713 |
var i, j, len, len2;
|
|
5714 |
|
|
5715 |
for (i = 0, len = this._holes.length; i < len; i++) {
|
|
5716 |
this._holePoints[i] = [];
|
|
5717 |
|
|
5718 |
for (j = 0, len2 = this._holes[i].length; j < len2; j++) {
|
|
5719 |
this._holePoints[i][j] = this._map.latLngToLayerPoint(this._holes[i][j]);
|
|
5720 |
}
|
|
5721 |
}
|
|
5722 |
},
|
|
5723 |
|
|
5724 |
setLatLngs: function (latlngs) {
|
|
5725 |
if (latlngs && L.Util.isArray(latlngs[0]) && (typeof latlngs[0][0] !== 'number')) {
|
|
5726 |
this._initWithHoles(latlngs);
|
|
5727 |
return this.redraw();
|
|
5728 |
} else {
|
|
5729 |
return L.Polyline.prototype.setLatLngs.call(this, latlngs);
|
|
5730 |
}
|
|
5731 |
},
|
|
5732 |
|
|
5733 |
_clipPoints: function () {
|
|
5734 |
var points = this._originalPoints,
|
|
5735 |
newParts = [];
|
|
5736 |
|
|
5737 |
this._parts = [points].concat(this._holePoints);
|
|
5738 |
|
|
5739 |
if (this.options.noClip) { return; }
|
|
5740 |
|
|
5741 |
for (var i = 0, len = this._parts.length; i < len; i++) {
|
|
5742 |
var clipped = L.PolyUtil.clipPolygon(this._parts[i], this._map._pathViewport);
|
|
5743 |
if (clipped.length) {
|
|
5744 |
newParts.push(clipped);
|
|
5745 |
}
|
|
5746 |
}
|
|
5747 |
|
|
5748 |
this._parts = newParts;
|
|
5749 |
},
|
|
5750 |
|
|
5751 |
_getPathPartStr: function (points) {
|
|
5752 |
var str = L.Polyline.prototype._getPathPartStr.call(this, points);
|
|
5753 |
return str + (L.Browser.svg ? 'z' : 'x');
|
|
5754 |
}
|
|
5755 |
});
|
|
5756 |
|
|
5757 |
L.polygon = function (latlngs, options) {
|
|
5758 |
return new L.Polygon(latlngs, options);
|
|
5759 |
};
|
|
5760 |
|
|
5761 |
|
|
5762 |
/*
|
|
5763 |
* Contains L.MultiPolyline and L.MultiPolygon layers.
|
|
5764 |
*/
|
|
5765 |
|
|
5766 |
(function () {
|
|
5767 |
function createMulti(Klass) {
|
|
5768 |
|
|
5769 |
return L.FeatureGroup.extend({
|
|
5770 |
|
|
5771 |
initialize: function (latlngs, options) {
|
|
5772 |
this._layers = {};
|
|
5773 |
this._options = options;
|
|
5774 |
this.setLatLngs(latlngs);
|
|
5775 |
},
|
|
5776 |
|
|
5777 |
setLatLngs: function (latlngs) {
|
|
5778 |
var i = 0,
|
|
5779 |
len = latlngs.length;
|
|
5780 |
|
|
5781 |
this.eachLayer(function (layer) {
|
|
5782 |
if (i < len) {
|
|
5783 |
layer.setLatLngs(latlngs[i++]);
|
|
5784 |
} else {
|
|
5785 |
this.removeLayer(layer);
|
|
5786 |
}
|
|
5787 |
}, this);
|
|
5788 |
|
|
5789 |
while (i < len) {
|
|
5790 |
this.addLayer(new Klass(latlngs[i++], this._options));
|
|
5791 |
}
|
|
5792 |
|
|
5793 |
return this;
|
|
5794 |
},
|
|
5795 |
|
|
5796 |
getLatLngs: function () {
|
|
5797 |
var latlngs = [];
|
|
5798 |
|
|
5799 |
this.eachLayer(function (layer) {
|
|
5800 |
latlngs.push(layer.getLatLngs());
|
|
5801 |
});
|
|
5802 |
|
|
5803 |
return latlngs;
|
|
5804 |
}
|
|
5805 |
});
|
|
5806 |
}
|
|
5807 |
|
|
5808 |
L.MultiPolyline = createMulti(L.Polyline);
|
|
5809 |
L.MultiPolygon = createMulti(L.Polygon);
|
|
5810 |
|
|
5811 |
L.multiPolyline = function (latlngs, options) {
|
|
5812 |
return new L.MultiPolyline(latlngs, options);
|
|
5813 |
};
|
|
5814 |
|
|
5815 |
L.multiPolygon = function (latlngs, options) {
|
|
5816 |
return new L.MultiPolygon(latlngs, options);
|
|
5817 |
};
|
|
5818 |
}());
|
|
5819 |
|
|
5820 |
|
|
5821 |
/*
|
|
5822 |
* L.Rectangle extends Polygon and creates a rectangle when passed a LatLngBounds object.
|
|
5823 |
*/
|
|
5824 |
|
|
5825 |
L.Rectangle = L.Polygon.extend({
|
|
5826 |
initialize: function (latLngBounds, options) {
|
|
5827 |
L.Polygon.prototype.initialize.call(this, this._boundsToLatLngs(latLngBounds), options);
|
|
5828 |
},
|
|
5829 |
|
|
5830 |
setBounds: function (latLngBounds) {
|
|
5831 |
this.setLatLngs(this._boundsToLatLngs(latLngBounds));
|
|
5832 |
},
|
|
5833 |
|
|
5834 |
_boundsToLatLngs: function (latLngBounds) {
|
|
5835 |
latLngBounds = L.latLngBounds(latLngBounds);
|
|
5836 |
return [
|
|
5837 |
latLngBounds.getSouthWest(),
|
|
5838 |
latLngBounds.getNorthWest(),
|
|
5839 |
latLngBounds.getNorthEast(),
|
|
5840 |
latLngBounds.getSouthEast()
|
|
5841 |
];
|
|
5842 |
}
|
|
5843 |
});
|
|
5844 |
|
|
5845 |
L.rectangle = function (latLngBounds, options) {
|
|
5846 |
return new L.Rectangle(latLngBounds, options);
|
|
5847 |
};
|
|
5848 |
|
|
5849 |
|
|
5850 |
/*
|
|
5851 |
* L.Circle is a circle overlay (with a certain radius in meters).
|
|
5852 |
*/
|
|
5853 |
|
|
5854 |
L.Circle = L.Path.extend({
|
|
5855 |
initialize: function (latlng, radius, options) {
|
|
5856 |
L.Path.prototype.initialize.call(this, options);
|
|
5857 |
|
|
5858 |
this._latlng = L.latLng(latlng);
|
|
5859 |
this._mRadius = radius;
|
|
5860 |
},
|
|
5861 |
|
|
5862 |
options: {
|
|
5863 |
fill: true
|
|
5864 |
},
|
|
5865 |
|
|
5866 |
setLatLng: function (latlng) {
|
|
5867 |
this._latlng = L.latLng(latlng);
|
|
5868 |
return this.redraw();
|
|
5869 |
},
|
|
5870 |
|
|
5871 |
setRadius: function (radius) {
|
|
5872 |
this._mRadius = radius;
|
|
5873 |
return this.redraw();
|
|
5874 |
},
|
|
5875 |
|
|
5876 |
projectLatlngs: function () {
|
|
5877 |
var lngRadius = this._getLngRadius(),
|
|
5878 |
latlng = this._latlng,
|
|
5879 |
pointLeft = this._map.latLngToLayerPoint([latlng.lat, latlng.lng - lngRadius]);
|
|
5880 |
|
|
5881 |
this._point = this._map.latLngToLayerPoint(latlng);
|
|
5882 |
this._radius = Math.max(this._point.x - pointLeft.x, 1);
|
|
5883 |
},
|
|
5884 |
|
|
5885 |
getBounds: function () {
|
|
5886 |
var lngRadius = this._getLngRadius(),
|
|
5887 |
latRadius = (this._mRadius / 40075017) * 360,
|
|
5888 |
latlng = this._latlng;
|
|
5889 |
|
|
5890 |
return new L.LatLngBounds(
|
|
5891 |
[latlng.lat - latRadius, latlng.lng - lngRadius],
|
|
5892 |
[latlng.lat + latRadius, latlng.lng + lngRadius]);
|
|
5893 |
},
|
|
5894 |
|
|
5895 |
getLatLng: function () {
|
|
5896 |
return this._latlng;
|
|
5897 |
},
|
|
5898 |
|
|
5899 |
getPathString: function () {
|
|
5900 |
var p = this._point,
|
|
5901 |
r = this._radius;
|
|
5902 |
|
|
5903 |
if (this._checkIfEmpty()) {
|
|
5904 |
return '';
|
|
5905 |
}
|
|
5906 |
|
|
5907 |
if (L.Browser.svg) {
|
|
5908 |
return 'M' + p.x + ',' + (p.y - r) +
|
|
5909 |
'A' + r + ',' + r + ',0,1,1,' +
|
|
5910 |
(p.x - 0.1) + ',' + (p.y - r) + ' z';
|
|
5911 |
} else {
|
|
5912 |
p._round();
|
|
5913 |
r = Math.round(r);
|
|
5914 |
return 'AL ' + p.x + ',' + p.y + ' ' + r + ',' + r + ' 0,' + (65535 * 360);
|
|
5915 |
}
|
|
5916 |
},
|
|
5917 |
|
|
5918 |
getRadius: function () {
|
|
5919 |
return this._mRadius;
|
|
5920 |
},
|
|
5921 |
|
|
5922 |
// TODO Earth hardcoded, move into projection code!
|
|
5923 |
|
|
5924 |
_getLatRadius: function () {
|
|
5925 |
return (this._mRadius / 40075017) * 360;
|
|
5926 |
},
|
|
5927 |
|
|
5928 |
_getLngRadius: function () {
|
|
5929 |
return this._getLatRadius() / Math.cos(L.LatLng.DEG_TO_RAD * this._latlng.lat);
|
|
5930 |
},
|
|
5931 |
|
|
5932 |
_checkIfEmpty: function () {
|
|
5933 |
if (!this._map) {
|
|
5934 |
return false;
|
|
5935 |
}
|
|
5936 |
var vp = this._map._pathViewport,
|
|
5937 |
r = this._radius,
|
|
5938 |
p = this._point;
|
|
5939 |
|
|
5940 |
return p.x - r > vp.max.x || p.y - r > vp.max.y ||
|
|
5941 |
p.x + r < vp.min.x || p.y + r < vp.min.y;
|
|
5942 |
}
|
|
5943 |
});
|
|
5944 |
|
|
5945 |
L.circle = function (latlng, radius, options) {
|
|
5946 |
return new L.Circle(latlng, radius, options);
|
|
5947 |
};
|
|
5948 |
|
|
5949 |
|
|
5950 |
/*
|
|
5951 |
* L.CircleMarker is a circle overlay with a permanent pixel radius.
|
|
5952 |
*/
|
|
5953 |
|
|
5954 |
L.CircleMarker = L.Circle.extend({
|
|
5955 |
options: {
|
|
5956 |
radius: 10,
|
|
5957 |
weight: 2
|
|
5958 |
},
|
|
5959 |
|
|
5960 |
initialize: function (latlng, options) {
|
|
5961 |
L.Circle.prototype.initialize.call(this, latlng, null, options);
|
|
5962 |
this._radius = this.options.radius;
|
|
5963 |
},
|
|
5964 |
|
|
5965 |
projectLatlngs: function () {
|
|
5966 |
this._point = this._map.latLngToLayerPoint(this._latlng);
|
|
5967 |
},
|
|
5968 |
|
|
5969 |
_updateStyle : function () {
|
|
5970 |
L.Circle.prototype._updateStyle.call(this);
|
|
5971 |
this.setRadius(this.options.radius);
|
|
5972 |
},
|
|
5973 |
|
|
5974 |
setLatLng: function (latlng) {
|
|
5975 |
L.Circle.prototype.setLatLng.call(this, latlng);
|
|
5976 |
if (this._popup && this._popup._isOpen) {
|
|
5977 |
this._popup.setLatLng(latlng);
|
|
5978 |
}
|
|
5979 |
return this;
|
|
5980 |
},
|
|
5981 |
|
|
5982 |
setRadius: function (radius) {
|
|
5983 |
this.options.radius = this._radius = radius;
|
|
5984 |
return this.redraw();
|
|
5985 |
},
|
|
5986 |
|
|
5987 |
getRadius: function () {
|
|
5988 |
return this._radius;
|
|
5989 |
}
|
|
5990 |
});
|
|
5991 |
|
|
5992 |
L.circleMarker = function (latlng, options) {
|
|
5993 |
return new L.CircleMarker(latlng, options);
|
|
5994 |
};
|
|
5995 |
|
|
5996 |
|
|
5997 |
/*
|
|
5998 |
* Extends L.Polyline to be able to manually detect clicks on Canvas-rendered polylines.
|
|
5999 |
*/
|
|
6000 |
|
|
6001 |
L.Polyline.include(!L.Path.CANVAS ? {} : {
|
|
6002 |
_containsPoint: function (p, closed) {
|
|
6003 |
var i, j, k, len, len2, dist, part,
|
|
6004 |
w = this.options.weight / 2;
|
|
6005 |
|
|
6006 |
if (L.Browser.touch) {
|
|
6007 |
w += 10; // polyline click tolerance on touch devices
|
|
6008 |
}
|
|
6009 |
|
|
6010 |
for (i = 0, len = this._parts.length; i < len; i++) {
|
|
6011 |
part = this._parts[i];
|
|
6012 |
for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
|
|
6013 |
if (!closed && (j === 0)) {
|
|
6014 |
continue;
|
|
6015 |
}
|
|
6016 |
|
|
6017 |
dist = L.LineUtil.pointToSegmentDistance(p, part[k], part[j]);
|
|
6018 |
|
|
6019 |
if (dist <= w) {
|
|
6020 |
return true;
|
|
6021 |
}
|
|
6022 |
}
|
|
6023 |
}
|
|
6024 |
return false;
|
|
6025 |
}
|
|
6026 |
});
|
|
6027 |
|
|
6028 |
|
|
6029 |
/*
|
|
6030 |
* Extends L.Polygon to be able to manually detect clicks on Canvas-rendered polygons.
|
|
6031 |
*/
|
|
6032 |
|
|
6033 |
L.Polygon.include(!L.Path.CANVAS ? {} : {
|
|
6034 |
_containsPoint: function (p) {
|
|
6035 |
var inside = false,
|
|
6036 |
part, p1, p2,
|
|
6037 |
i, j, k,
|
|
6038 |
len, len2;
|
|
6039 |
|
|
6040 |
// TODO optimization: check if within bounds first
|
|
6041 |
|
|
6042 |
if (L.Polyline.prototype._containsPoint.call(this, p, true)) {
|
|
6043 |
// click on polygon border
|
|
6044 |
return true;
|
|
6045 |
}
|
|
6046 |
|
|
6047 |
// ray casting algorithm for detecting if point is in polygon
|
|
6048 |
|
|
6049 |
for (i = 0, len = this._parts.length; i < len; i++) {
|
|
6050 |
part = this._parts[i];
|
|
6051 |
|
|
6052 |
for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
|
|
6053 |
p1 = part[j];
|
|
6054 |
p2 = part[k];
|
|
6055 |
|
|
6056 |
if (((p1.y > p.y) !== (p2.y > p.y)) &&
|
|
6057 |
(p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x)) {
|
|
6058 |
inside = !inside;
|
|
6059 |
}
|
|
6060 |
}
|
|
6061 |
}
|
|
6062 |
|
|
6063 |
return inside;
|
|
6064 |
}
|
|
6065 |
});
|
|
6066 |
|
|
6067 |
|
|
6068 |
/*
|
|
6069 |
* Extends L.Circle with Canvas-specific code.
|
|
6070 |
*/
|
|
6071 |
|
|
6072 |
L.Circle.include(!L.Path.CANVAS ? {} : {
|
|
6073 |
_drawPath: function () {
|
|
6074 |
var p = this._point;
|
|
6075 |
this._ctx.beginPath();
|
|
6076 |
this._ctx.arc(p.x, p.y, this._radius, 0, Math.PI * 2, false);
|
|
6077 |
},
|
|
6078 |
|
|
6079 |
_containsPoint: function (p) {
|
|
6080 |
var center = this._point,
|
|
6081 |
w2 = this.options.stroke ? this.options.weight / 2 : 0;
|
|
6082 |
|
|
6083 |
return (p.distanceTo(center) <= this._radius + w2);
|
|
6084 |
}
|
|
6085 |
});
|
|
6086 |
|
|
6087 |
|
|
6088 |
/*
|
|
6089 |
* CircleMarker canvas specific drawing parts.
|
|
6090 |
*/
|
|
6091 |
|
|
6092 |
L.CircleMarker.include(!L.Path.CANVAS ? {} : {
|
|
6093 |
_updateStyle: function () {
|
|
6094 |
L.Path.prototype._updateStyle.call(this);
|
|
6095 |
}
|
|
6096 |
});
|
|
6097 |
|
|
6098 |
|
|
6099 |
/*
|
|
6100 |
* L.GeoJSON turns any GeoJSON data into a Leaflet layer.
|
|
6101 |
*/
|
|
6102 |
|
|
6103 |
L.GeoJSON = L.FeatureGroup.extend({
|
|
6104 |
|
|
6105 |
initialize: function (geojson, options) {
|
|
6106 |
L.setOptions(this, options);
|
|
6107 |
|
|
6108 |
this._layers = {};
|
|
6109 |
|
|
6110 |
if (geojson) {
|
|
6111 |
this.addData(geojson);
|
|
6112 |
}
|
|
6113 |
},
|
|
6114 |
|
|
6115 |
addData: function (geojson) {
|
|
6116 |
var features = L.Util.isArray(geojson) ? geojson : geojson.features,
|
|
6117 |
i, len, feature;
|
|
6118 |
|
|
6119 |
if (features) {
|
|
6120 |
for (i = 0, len = features.length; i < len; i++) {
|
|
6121 |
// Only add this if geometry or geometries are set and not null
|
|
6122 |
feature = features[i];
|
|
6123 |
if (feature.geometries || feature.geometry || feature.features || feature.coordinates) {
|
|
6124 |
this.addData(features[i]);
|
|
6125 |
}
|
|
6126 |
}
|
|
6127 |
return this;
|
|
6128 |
}
|
|
6129 |
|
|
6130 |
var options = this.options;
|
|
6131 |
|
|
6132 |
if (options.filter && !options.filter(geojson)) { return; }
|
|
6133 |
|
|
6134 |
var layer = L.GeoJSON.geometryToLayer(geojson, options.pointToLayer, options.coordsToLatLng, options);
|
|
6135 |
layer.feature = L.GeoJSON.asFeature(geojson);
|
|
6136 |
|
|
6137 |
layer.defaultOptions = layer.options;
|
|
6138 |
this.resetStyle(layer);
|
|
6139 |
|
|
6140 |
if (options.onEachFeature) {
|
|
6141 |
options.onEachFeature(geojson, layer);
|
|
6142 |
}
|
|
6143 |
|
|
6144 |
return this.addLayer(layer);
|
|
6145 |
},
|
|
6146 |
|
|
6147 |
resetStyle: function (layer) {
|
|
6148 |
var style = this.options.style;
|
|
6149 |
if (style) {
|
|
6150 |
// reset any custom styles
|
|
6151 |
L.Util.extend(layer.options, layer.defaultOptions);
|
|
6152 |
|
|
6153 |
this._setLayerStyle(layer, style);
|
|
6154 |
}
|
|
6155 |
},
|
|
6156 |
|
|
6157 |
setStyle: function (style) {
|
|
6158 |
this.eachLayer(function (layer) {
|
|
6159 |
this._setLayerStyle(layer, style);
|
|
6160 |
}, this);
|
|
6161 |
},
|
|
6162 |
|
|
6163 |
_setLayerStyle: function (layer, style) {
|
|
6164 |
if (typeof style === 'function') {
|
|
6165 |
style = style(layer.feature);
|
|
6166 |
}
|
|
6167 |
if (layer.setStyle) {
|
|
6168 |
layer.setStyle(style);
|
|
6169 |
}
|
|
6170 |
}
|
|
6171 |
});
|
|
6172 |
|
|
6173 |
L.extend(L.GeoJSON, {
|
|
6174 |
geometryToLayer: function (geojson, pointToLayer, coordsToLatLng, vectorOptions) {
|
|
6175 |
var geometry = geojson.type === 'Feature' ? geojson.geometry : geojson,
|
|
6176 |
coords = geometry.coordinates,
|
|
6177 |
layers = [],
|
|
6178 |
latlng, latlngs, i, len;
|
|
6179 |
|
|
6180 |
coordsToLatLng = coordsToLatLng || this.coordsToLatLng;
|
|
6181 |
|
|
6182 |
switch (geometry.type) {
|
|
6183 |
case 'Point':
|
|
6184 |
latlng = coordsToLatLng(coords);
|
|
6185 |
return pointToLayer ? pointToLayer(geojson, latlng) : new L.Marker(latlng);
|
|
6186 |
|
|
6187 |
case 'MultiPoint':
|
|
6188 |
for (i = 0, len = coords.length; i < len; i++) {
|
|
6189 |
latlng = coordsToLatLng(coords[i]);
|
|
6190 |
layers.push(pointToLayer ? pointToLayer(geojson, latlng) : new L.Marker(latlng));
|
|
6191 |
}
|
|
6192 |
return new L.FeatureGroup(layers);
|
|
6193 |
|
|
6194 |
case 'LineString':
|
|
6195 |
latlngs = this.coordsToLatLngs(coords, 0, coordsToLatLng);
|
|
6196 |
return new L.Polyline(latlngs, vectorOptions);
|
|
6197 |
|
|
6198 |
case 'Polygon':
|
|
6199 |
if (coords.length === 2 && !coords[1].length) {
|
|
6200 |
throw new Error('Invalid GeoJSON object.');
|
|
6201 |
}
|
|
6202 |
latlngs = this.coordsToLatLngs(coords, 1, coordsToLatLng);
|
|
6203 |
return new L.Polygon(latlngs, vectorOptions);
|
|
6204 |
|
|
6205 |
case 'MultiLineString':
|
|
6206 |
latlngs = this.coordsToLatLngs(coords, 1, coordsToLatLng);
|
|
6207 |
return new L.MultiPolyline(latlngs, vectorOptions);
|
|
6208 |
|
|
6209 |
case 'MultiPolygon':
|
|
6210 |
latlngs = this.coordsToLatLngs(coords, 2, coordsToLatLng);
|
|
6211 |
return new L.MultiPolygon(latlngs, vectorOptions);
|
|
6212 |
|
|
6213 |
case 'GeometryCollection':
|
|
6214 |
for (i = 0, len = geometry.geometries.length; i < len; i++) {
|
|
6215 |
|
|
6216 |
layers.push(this.geometryToLayer({
|
|
6217 |
geometry: geometry.geometries[i],
|
|
6218 |
type: 'Feature',
|
|
6219 |
properties: geojson.properties
|
|
6220 |
}, pointToLayer, coordsToLatLng, vectorOptions));
|
|
6221 |
}
|
|
6222 |
return new L.FeatureGroup(layers);
|
|
6223 |
|
|
6224 |
default:
|
|
6225 |
throw new Error('Invalid GeoJSON object.');
|
|
6226 |
}
|
|
6227 |
},
|
|
6228 |
|
|
6229 |
coordsToLatLng: function (coords) { // (Array[, Boolean]) -> LatLng
|
|
6230 |
return new L.LatLng(coords[1], coords[0], coords[2]);
|
|
6231 |
},
|
|
6232 |
|
|
6233 |
coordsToLatLngs: function (coords, levelsDeep, coordsToLatLng) { // (Array[, Number, Function]) -> Array
|
|
6234 |
var latlng, i, len,
|
|
6235 |
latlngs = [];
|
|
6236 |
|
|
6237 |
for (i = 0, len = coords.length; i < len; i++) {
|
|
6238 |
latlng = levelsDeep ?
|
|
6239 |
this.coordsToLatLngs(coords[i], levelsDeep - 1, coordsToLatLng) :
|
|
6240 |
(coordsToLatLng || this.coordsToLatLng)(coords[i]);
|
|
6241 |
|
|
6242 |
latlngs.push(latlng);
|
|
6243 |
}
|
|
6244 |
|
|
6245 |
return latlngs;
|
|
6246 |
},
|
|
6247 |
|
|
6248 |
latLngToCoords: function (latlng) {
|
|
6249 |
var coords = [latlng.lng, latlng.lat];
|
|
6250 |
|
|
6251 |
if (latlng.alt !== undefined) {
|
|
6252 |
coords.push(latlng.alt);
|
|
6253 |
}
|
|
6254 |
return coords;
|
|
6255 |
},
|
|
6256 |
|
|
6257 |
latLngsToCoords: function (latLngs) {
|
|
6258 |
var coords = [];
|
|
6259 |
|
|
6260 |
for (var i = 0, len = latLngs.length; i < len; i++) {
|
|
6261 |
coords.push(L.GeoJSON.latLngToCoords(latLngs[i]));
|
|
6262 |
}
|
|
6263 |
|
|
6264 |
return coords;
|
|
6265 |
},
|
|
6266 |
|
|
6267 |
getFeature: function (layer, newGeometry) {
|
|
6268 |
return layer.feature ? L.extend({}, layer.feature, {geometry: newGeometry}) : L.GeoJSON.asFeature(newGeometry);
|
|
6269 |
},
|
|
6270 |
|
|
6271 |
asFeature: function (geoJSON) {
|
|
6272 |
if (geoJSON.type === 'Feature') {
|
|
6273 |
return geoJSON;
|
|
6274 |
}
|
|
6275 |
|
|
6276 |
return {
|
|
6277 |
type: 'Feature',
|
|
6278 |
properties: {},
|
|
6279 |
geometry: geoJSON
|
|
6280 |
};
|
|
6281 |
}
|
|
6282 |
});
|
|
6283 |
|
|
6284 |
var PointToGeoJSON = {
|
|
6285 |
toGeoJSON: function () {
|
|
6286 |
return L.GeoJSON.getFeature(this, {
|
|
6287 |
type: 'Point',
|
|
6288 |
coordinates: L.GeoJSON.latLngToCoords(this.getLatLng())
|
|
6289 |
});
|
|
6290 |
}
|
|
6291 |
};
|
|
6292 |
|
|
6293 |
L.Marker.include(PointToGeoJSON);
|
|
6294 |
L.Circle.include(PointToGeoJSON);
|
|
6295 |
L.CircleMarker.include(PointToGeoJSON);
|
|
6296 |
|
|
6297 |
L.Polyline.include({
|
|
6298 |
toGeoJSON: function () {
|
|
6299 |
return L.GeoJSON.getFeature(this, {
|
|
6300 |
type: 'LineString',
|
|
6301 |
coordinates: L.GeoJSON.latLngsToCoords(this.getLatLngs())
|
|
6302 |
});
|
|
6303 |
}
|
|
6304 |
});
|
|
6305 |
|
|
6306 |
L.Polygon.include({
|
|
6307 |
toGeoJSON: function () {
|
|
6308 |
var coords = [L.GeoJSON.latLngsToCoords(this.getLatLngs())],
|
|
6309 |
i, len, hole;
|
|
6310 |
|
|
6311 |
coords[0].push(coords[0][0]);
|
|
6312 |
|
|
6313 |
if (this._holes) {
|
|
6314 |
for (i = 0, len = this._holes.length; i < len; i++) {
|
|
6315 |
hole = L.GeoJSON.latLngsToCoords(this._holes[i]);
|
|
6316 |
hole.push(hole[0]);
|
|
6317 |
coords.push(hole);
|
|
6318 |
}
|
|
6319 |
}
|
|
6320 |
|
|
6321 |
return L.GeoJSON.getFeature(this, {
|
|
6322 |
type: 'Polygon',
|
|
6323 |
coordinates: coords
|
|
6324 |
});
|
|
6325 |
}
|
|
6326 |
});
|
|
6327 |
|
|
6328 |
(function () {
|
|
6329 |
function multiToGeoJSON(type) {
|
|
6330 |
return function () {
|
|
6331 |
var coords = [];
|
|
6332 |
|
|
6333 |
this.eachLayer(function (layer) {
|
|
6334 |
coords.push(layer.toGeoJSON().geometry.coordinates);
|
|
6335 |
});
|
|
6336 |
|
|
6337 |
return L.GeoJSON.getFeature(this, {
|
|
6338 |
type: type,
|
|
6339 |
coordinates: coords
|
|
6340 |
});
|
|
6341 |
};
|
|
6342 |
}
|
|
6343 |
|
|
6344 |
L.MultiPolyline.include({toGeoJSON: multiToGeoJSON('MultiLineString')});
|
|
6345 |
L.MultiPolygon.include({toGeoJSON: multiToGeoJSON('MultiPolygon')});
|
|
6346 |
|
|
6347 |
L.LayerGroup.include({
|
|
6348 |
toGeoJSON: function () {
|
|
6349 |
|
|
6350 |
var geometry = this.feature && this.feature.geometry,
|
|
6351 |
jsons = [],
|
|
6352 |
json;
|
|
6353 |
|
|
6354 |
if (geometry && geometry.type === 'MultiPoint') {
|
|
6355 |
return multiToGeoJSON('MultiPoint').call(this);
|
|
6356 |
}
|
|
6357 |
|
|
6358 |
var isGeometryCollection = geometry && geometry.type === 'GeometryCollection';
|
|
6359 |
|
|
6360 |
this.eachLayer(function (layer) {
|
|
6361 |
if (layer.toGeoJSON) {
|
|
6362 |
json = layer.toGeoJSON();
|
|
6363 |
jsons.push(isGeometryCollection ? json.geometry : L.GeoJSON.asFeature(json));
|
|
6364 |
}
|
|
6365 |
});
|
|
6366 |
|
|
6367 |
if (isGeometryCollection) {
|
|
6368 |
return L.GeoJSON.getFeature(this, {
|
|
6369 |
geometries: jsons,
|
|
6370 |
type: 'GeometryCollection'
|
|
6371 |
});
|
|
6372 |
}
|
|
6373 |
|
|
6374 |
return {
|
|
6375 |
type: 'FeatureCollection',
|
|
6376 |
features: jsons
|
|
6377 |
};
|
|
6378 |
}
|
|
6379 |
});
|
|
6380 |
}());
|
|
6381 |
|
|
6382 |
L.geoJson = function (geojson, options) {
|
|
6383 |
return new L.GeoJSON(geojson, options);
|
|
6384 |
};
|
|
6385 |
|
|
6386 |
|
|
6387 |
/*
|
|
6388 |
* L.DomEvent contains functions for working with DOM events.
|
|
6389 |
*/
|
|
6390 |
|
|
6391 |
L.DomEvent = {
|
|
6392 |
/* inspired by John Resig, Dean Edwards and YUI addEvent implementations */
|
|
6393 |
addListener: function (obj, type, fn, context) { // (HTMLElement, String, Function[, Object])
|
|
6394 |
|
|
6395 |
var id = L.stamp(fn),
|
|
6396 |
key = '_leaflet_' + type + id,
|
|
6397 |
handler, originalHandler, newType;
|
|
6398 |
|
|
6399 |
if (obj[key]) { return this; }
|
|
6400 |
|
|
6401 |
handler = function (e) {
|
|
6402 |
return fn.call(context || obj, e || L.DomEvent._getEvent());
|
|
6403 |
};
|
|
6404 |
|
|
6405 |
if (L.Browser.pointer && type.indexOf('touch') === 0) {
|
|
6406 |
return this.addPointerListener(obj, type, handler, id);
|
|
6407 |
}
|
|
6408 |
if (L.Browser.touch && (type === 'dblclick') && this.addDoubleTapListener) {
|
|
6409 |
this.addDoubleTapListener(obj, handler, id);
|
|
6410 |
}
|
|
6411 |
|
|
6412 |
if ('addEventListener' in obj) {
|
|
6413 |
|
|
6414 |
if (type === 'mousewheel') {
|
|
6415 |
obj.addEventListener('DOMMouseScroll', handler, false);
|
|
6416 |
obj.addEventListener(type, handler, false);
|
|
6417 |
|
|
6418 |
} else if ((type === 'mouseenter') || (type === 'mouseleave')) {
|
|
6419 |
|
|
6420 |
originalHandler = handler;
|
|
6421 |
newType = (type === 'mouseenter' ? 'mouseover' : 'mouseout');
|
|
6422 |
|
|
6423 |
handler = function (e) {
|
|
6424 |
if (!L.DomEvent._checkMouse(obj, e)) { return; }
|
|
6425 |
return originalHandler(e);
|
|
6426 |
};
|
|
6427 |
|
|
6428 |
obj.addEventListener(newType, handler, false);
|
|
6429 |
|
|
6430 |
} else if (type === 'click' && L.Browser.android) {
|
|
6431 |
originalHandler = handler;
|
|
6432 |
handler = function (e) {
|
|
6433 |
return L.DomEvent._filterClick(e, originalHandler);
|
|
6434 |
};
|
|
6435 |
|
|
6436 |
obj.addEventListener(type, handler, false);
|
|
6437 |
} else {
|
|
6438 |
obj.addEventListener(type, handler, false);
|
|
6439 |
}
|
|
6440 |
|
|
6441 |
} else if ('attachEvent' in obj) {
|
|
6442 |
obj.attachEvent('on' + type, handler);
|
|
6443 |
}
|
|
6444 |
|
|
6445 |
obj[key] = handler;
|
|
6446 |
|
|
6447 |
return this;
|
|
6448 |
},
|
|
6449 |
|
|
6450 |
removeListener: function (obj, type, fn) { // (HTMLElement, String, Function)
|
|
6451 |
|
|
6452 |
var id = L.stamp(fn),
|
|
6453 |
key = '_leaflet_' + type + id,
|
|
6454 |
handler = obj[key];
|
|
6455 |
|
|
6456 |
if (!handler) { return this; }
|
|
6457 |
|
|
6458 |
if (L.Browser.pointer && type.indexOf('touch') === 0) {
|
|
6459 |
this.removePointerListener(obj, type, id);
|
|
6460 |
} else if (L.Browser.touch && (type === 'dblclick') && this.removeDoubleTapListener) {
|
|
6461 |
this.removeDoubleTapListener(obj, id);
|
|
6462 |
|
|
6463 |
} else if ('removeEventListener' in obj) {
|
|
6464 |
|
|
6465 |
if (type === 'mousewheel') {
|
|
6466 |
obj.removeEventListener('DOMMouseScroll', handler, false);
|
|
6467 |
obj.removeEventListener(type, handler, false);
|
|
6468 |
|
|
6469 |
} else if ((type === 'mouseenter') || (type === 'mouseleave')) {
|
|
6470 |
obj.removeEventListener((type === 'mouseenter' ? 'mouseover' : 'mouseout'), handler, false);
|
|
6471 |
} else {
|
|
6472 |
obj.removeEventListener(type, handler, false);
|
|
6473 |
}
|
|
6474 |
} else if ('detachEvent' in obj) {
|
|
6475 |
obj.detachEvent('on' + type, handler);
|
|
6476 |
}
|
|
6477 |
|
|
6478 |
obj[key] = null;
|
|
6479 |
|
|
6480 |
return this;
|
|
6481 |
},
|
|
6482 |
|
|
6483 |
stopPropagation: function (e) {
|
|
6484 |
|
|
6485 |
if (e.stopPropagation) {
|
|
6486 |
e.stopPropagation();
|
|
6487 |
} else {
|
|
6488 |
e.cancelBubble = true;
|
|
6489 |
}
|
|
6490 |
L.DomEvent._skipped(e);
|
|
6491 |
|
|
6492 |
return this;
|
|
6493 |
},
|
|
6494 |
|
|
6495 |
disableScrollPropagation: function (el) {
|
|
6496 |
var stop = L.DomEvent.stopPropagation;
|
|
6497 |
|
|
6498 |
return L.DomEvent
|
|
6499 |
.on(el, 'mousewheel', stop)
|
|
6500 |
.on(el, 'MozMousePixelScroll', stop);
|
|
6501 |
},
|
|
6502 |
|
|
6503 |
disableClickPropagation: function (el) {
|
|
6504 |
var stop = L.DomEvent.stopPropagation;
|
|
6505 |
|
|
6506 |
for (var i = L.Draggable.START.length - 1; i >= 0; i--) {
|
|
6507 |
L.DomEvent.on(el, L.Draggable.START[i], stop);
|
|
6508 |
}
|
|
6509 |
|
|
6510 |
return L.DomEvent
|
|
6511 |
.on(el, 'click', L.DomEvent._fakeStop)
|
|
6512 |
.on(el, 'dblclick', stop);
|
|
6513 |
},
|
|
6514 |
|
|
6515 |
preventDefault: function (e) {
|
|
6516 |
|
|
6517 |
if (e.preventDefault) {
|
|
6518 |
e.preventDefault();
|
|
6519 |
} else {
|
|
6520 |
e.returnValue = false;
|
|
6521 |
}
|
|
6522 |
return this;
|
|
6523 |
},
|
|
6524 |
|
|
6525 |
stop: function (e) {
|
|
6526 |
return L.DomEvent
|
|
6527 |
.preventDefault(e)
|
|
6528 |
.stopPropagation(e);
|
|
6529 |
},
|
|
6530 |
|
|
6531 |
getMousePosition: function (e, container) {
|
|
6532 |
if (!container) {
|
|
6533 |
return new L.Point(e.clientX, e.clientY);
|
|
6534 |
}
|
|
6535 |
|
|
6536 |
var rect = container.getBoundingClientRect();
|
|
6537 |
|
|
6538 |
return new L.Point(
|
|
6539 |
e.clientX - rect.left - container.clientLeft,
|
|
6540 |
e.clientY - rect.top - container.clientTop);
|
|
6541 |
},
|
|
6542 |
|
|
6543 |
getWheelDelta: function (e) {
|
|
6544 |
|
|
6545 |
var delta = 0;
|
|
6546 |
|
|
6547 |
if (e.wheelDelta) {
|
|
6548 |
delta = e.wheelDelta / 120;
|
|
6549 |
}
|
|
6550 |
if (e.detail) {
|
|
6551 |
delta = -e.detail / 3;
|
|
6552 |
}
|
|
6553 |
return delta;
|
|
6554 |
},
|
|
6555 |
|
|
6556 |
_skipEvents: {},
|
|
6557 |
|
|
6558 |
_fakeStop: function (e) {
|
|
6559 |
// fakes stopPropagation by setting a special event flag, checked/reset with L.DomEvent._skipped(e)
|
|
6560 |
L.DomEvent._skipEvents[e.type] = true;
|
|
6561 |
},
|
|
6562 |
|
|
6563 |
_skipped: function (e) {
|
|
6564 |
var skipped = this._skipEvents[e.type];
|
|
6565 |
// reset when checking, as it's only used in map container and propagates outside of the map
|
|
6566 |
this._skipEvents[e.type] = false;
|
|
6567 |
return skipped;
|
|
6568 |
},
|
|
6569 |
|
|
6570 |
// check if element really left/entered the event target (for mouseenter/mouseleave)
|
|
6571 |
_checkMouse: function (el, e) {
|
|
6572 |
|
|
6573 |
var related = e.relatedTarget;
|
|
6574 |
|
|
6575 |
if (!related) { return true; }
|
|
6576 |
|
|
6577 |
try {
|
|
6578 |
while (related && (related !== el)) {
|
|
6579 |
related = related.parentNode;
|
|
6580 |
}
|
|
6581 |
} catch (err) {
|
|
6582 |
return false;
|
|
6583 |
}
|
|
6584 |
return (related !== el);
|
|
6585 |
},
|
|
6586 |
|
|
6587 |
_getEvent: function () { // evil magic for IE
|
|
6588 |
/*jshint noarg:false */
|
|
6589 |
var e = window.event;
|
|
6590 |
if (!e) {
|
|
6591 |
var caller = arguments.callee.caller;
|
|
6592 |
while (caller) {
|
|
6593 |
e = caller['arguments'][0];
|
|
6594 |
if (e && window.Event === e.constructor) {
|
|
6595 |
break;
|
|
6596 |
}
|
|
6597 |
caller = caller.caller;
|
|
6598 |
}
|
|
6599 |
}
|
|
6600 |
return e;
|
|
6601 |
},
|
|
6602 |
|
|
6603 |
// this is a horrible workaround for a bug in Android where a single touch triggers two click events
|
|
6604 |
_filterClick: function (e, handler) {
|
|
6605 |
var timeStamp = (e.timeStamp || e.originalEvent.timeStamp),
|
|
6606 |
elapsed = L.DomEvent._lastClick && (timeStamp - L.DomEvent._lastClick);
|
|
6607 |
|
|
6608 |
// are they closer together than 500ms yet more than 100ms?
|
|
6609 |
// Android typically triggers them ~300ms apart while multiple listeners
|
|
6610 |
// on the same event should be triggered far faster;
|
|
6611 |
// or check if click is simulated on the element, and if it is, reject any non-simulated events
|
|
6612 |
|
|
6613 |
if ((elapsed && elapsed > 100 && elapsed < 500) || (e.target._simulatedClick && !e._simulated)) {
|
|
6614 |
L.DomEvent.stop(e);
|
|
6615 |
return;
|
|
6616 |
}
|
|
6617 |
L.DomEvent._lastClick = timeStamp;
|
|
6618 |
|
|
6619 |
return handler(e);
|
|
6620 |
}
|
|
6621 |
};
|
|
6622 |
|
|
6623 |
L.DomEvent.on = L.DomEvent.addListener;
|
|
6624 |
L.DomEvent.off = L.DomEvent.removeListener;
|
|
6625 |
|
|
6626 |
|
|
6627 |
/*
|
|
6628 |
* L.Draggable allows you to add dragging capabilities to any element. Supports mobile devices too.
|
|
6629 |
*/
|
|
6630 |
|
|
6631 |
L.Draggable = L.Class.extend({
|
|
6632 |
includes: L.Mixin.Events,
|
|
6633 |
|
|
6634 |
statics: {
|
|
6635 |
START: L.Browser.touch ? ['touchstart', 'mousedown'] : ['mousedown'],
|
|
6636 |
END: {
|
|
6637 |
mousedown: 'mouseup',
|
|
6638 |
touchstart: 'touchend',
|
|
6639 |
pointerdown: 'touchend',
|
|
6640 |
MSPointerDown: 'touchend'
|
|
6641 |
},
|
|
6642 |
MOVE: {
|
|
6643 |
mousedown: 'mousemove',
|
|
6644 |
touchstart: 'touchmove',
|
|
6645 |
pointerdown: 'touchmove',
|
|
6646 |
MSPointerDown: 'touchmove'
|
|
6647 |
}
|
|
6648 |
},
|
|
6649 |
|
|
6650 |
initialize: function (element, dragStartTarget) {
|
|
6651 |
this._element = element;
|
|
6652 |
this._dragStartTarget = dragStartTarget || element;
|
|
6653 |
},
|
|
6654 |
|
|
6655 |
enable: function () {
|
|
6656 |
if (this._enabled) { return; }
|
|
6657 |
|
|
6658 |
for (var i = L.Draggable.START.length - 1; i >= 0; i--) {
|
|
6659 |
L.DomEvent.on(this._dragStartTarget, L.Draggable.START[i], this._onDown, this);
|
|
6660 |
}
|
|
6661 |
|
|
6662 |
this._enabled = true;
|
|
6663 |
},
|
|
6664 |
|
|
6665 |
disable: function () {
|
|
6666 |
if (!this._enabled) { return; }
|
|
6667 |
|
|
6668 |
for (var i = L.Draggable.START.length - 1; i >= 0; i--) {
|
|
6669 |
L.DomEvent.off(this._dragStartTarget, L.Draggable.START[i], this._onDown, this);
|
|
6670 |
}
|
|
6671 |
|
|
6672 |
this._enabled = false;
|
|
6673 |
this._moved = false;
|
|
6674 |
},
|
|
6675 |
|
|
6676 |
_onDown: function (e) {
|
|
6677 |
this._moved = false;
|
|
6678 |
|
|
6679 |
if (e.shiftKey || ((e.which !== 1) && (e.button !== 1) && !e.touches)) { return; }
|
|
6680 |
|
|
6681 |
L.DomEvent.stopPropagation(e);
|
|
6682 |
|
|
6683 |
if (L.Draggable._disabled) { return; }
|
|
6684 |
|
|
6685 |
L.DomUtil.disableImageDrag();
|
|
6686 |
L.DomUtil.disableTextSelection();
|
|
6687 |
|
|
6688 |
if (this._moving) { return; }
|
|
6689 |
|
|
6690 |
var first = e.touches ? e.touches[0] : e;
|
|
6691 |
|
|
6692 |
this._startPoint = new L.Point(first.clientX, first.clientY);
|
|
6693 |
this._startPos = this._newPos = L.DomUtil.getPosition(this._element);
|
|
6694 |
|
|
6695 |
L.DomEvent
|
|
6696 |
.on(document, L.Draggable.MOVE[e.type], this._onMove, this)
|
|
6697 |
.on(document, L.Draggable.END[e.type], this._onUp, this);
|
|
6698 |
},
|
|
6699 |
|
|
6700 |
_onMove: function (e) {
|
|
6701 |
if (e.touches && e.touches.length > 1) {
|
|
6702 |
this._moved = true;
|
|
6703 |
return;
|
|
6704 |
}
|
|
6705 |
|
|
6706 |
var first = (e.touches && e.touches.length === 1 ? e.touches[0] : e),
|
|
6707 |
newPoint = new L.Point(first.clientX, first.clientY),
|
|
6708 |
offset = newPoint.subtract(this._startPoint);
|
|
6709 |
|
|
6710 |
if (!offset.x && !offset.y) { return; }
|
|
6711 |
if (L.Browser.touch && Math.abs(offset.x) + Math.abs(offset.y) < 3) { return; }
|
|
6712 |
|
|
6713 |
L.DomEvent.preventDefault(e);
|
|
6714 |
|
|
6715 |
if (!this._moved) {
|
|
6716 |
this.fire('dragstart');
|
|
6717 |
|
|
6718 |
this._moved = true;
|
|
6719 |
this._startPos = L.DomUtil.getPosition(this._element).subtract(offset);
|
|
6720 |
|
|
6721 |
L.DomUtil.addClass(document.body, 'leaflet-dragging');
|
|
6722 |
this._lastTarget = e.target || e.srcElement;
|
|
6723 |
L.DomUtil.addClass(this._lastTarget, 'leaflet-drag-target');
|
|
6724 |
}
|
|
6725 |
|
|
6726 |
this._newPos = this._startPos.add(offset);
|
|
6727 |
this._moving = true;
|
|
6728 |
|
|
6729 |
L.Util.cancelAnimFrame(this._animRequest);
|
|
6730 |
this._animRequest = L.Util.requestAnimFrame(this._updatePosition, this, true, this._dragStartTarget);
|
|
6731 |
},
|
|
6732 |
|
|
6733 |
_updatePosition: function () {
|
|
6734 |
this.fire('predrag');
|
|
6735 |
L.DomUtil.setPosition(this._element, this._newPos);
|
|
6736 |
this.fire('drag');
|
|
6737 |
},
|
|
6738 |
|
|
6739 |
_onUp: function () {
|
|
6740 |
L.DomUtil.removeClass(document.body, 'leaflet-dragging');
|
|
6741 |
|
|
6742 |
if (this._lastTarget) {
|
|
6743 |
L.DomUtil.removeClass(this._lastTarget, 'leaflet-drag-target');
|
|
6744 |
this._lastTarget = null;
|
|
6745 |
}
|
|
6746 |
|
|
6747 |
for (var i in L.Draggable.MOVE) {
|
|
6748 |
L.DomEvent
|
|
6749 |
.off(document, L.Draggable.MOVE[i], this._onMove)
|
|
6750 |
.off(document, L.Draggable.END[i], this._onUp);
|
|
6751 |
}
|
|
6752 |
|
|
6753 |
L.DomUtil.enableImageDrag();
|
|
6754 |
L.DomUtil.enableTextSelection();
|
|
6755 |
|
|
6756 |
if (this._moved && this._moving) {
|
|
6757 |
// ensure drag is not fired after dragend
|
|
6758 |
L.Util.cancelAnimFrame(this._animRequest);
|
|
6759 |
|
|
6760 |
this.fire('dragend', {
|
|
6761 |
distance: this._newPos.distanceTo(this._startPos)
|
|
6762 |
});
|
|
6763 |
}
|
|
6764 |
|
|
6765 |
this._moving = false;
|
|
6766 |
}
|
|
6767 |
});
|
|
6768 |
|
|
6769 |
|
|
6770 |
/*
|
|
6771 |
L.Handler is a base class for handler classes that are used internally to inject
|
|
6772 |
interaction features like dragging to classes like Map and Marker.
|
|
6773 |
*/
|
|
6774 |
|
|
6775 |
L.Handler = L.Class.extend({
|
|
6776 |
initialize: function (map) {
|
|
6777 |
this._map = map;
|
|
6778 |
},
|
|
6779 |
|
|
6780 |
enable: function () {
|
|
6781 |
if (this._enabled) { return; }
|
|
6782 |
|
|
6783 |
this._enabled = true;
|
|
6784 |
this.addHooks();
|
|
6785 |
},
|
|
6786 |
|
|
6787 |
disable: function () {
|
|
6788 |
if (!this._enabled) { return; }
|
|
6789 |
|
|
6790 |
this._enabled = false;
|
|
6791 |
this.removeHooks();
|
|
6792 |
},
|
|
6793 |
|
|
6794 |
enabled: function () {
|
|
6795 |
return !!this._enabled;
|
|
6796 |
}
|
|
6797 |
});
|
|
6798 |
|
|
6799 |
|
|
6800 |
/*
|
|
6801 |
* L.Handler.MapDrag is used to make the map draggable (with panning inertia), enabled by default.
|
|
6802 |
*/
|
|
6803 |
|
|
6804 |
L.Map.mergeOptions({
|
|
6805 |
dragging: true,
|
|
6806 |
|
|
6807 |
inertia: !L.Browser.android23,
|
|
6808 |
inertiaDeceleration: 3400, // px/s^2
|
|
6809 |
inertiaMaxSpeed: Infinity, // px/s
|
|
6810 |
inertiaThreshold: L.Browser.touch ? 32 : 18, // ms
|
|
6811 |
easeLinearity: 0.25,
|
|
6812 |
|
|
6813 |
// TODO refactor, move to CRS
|
|
6814 |
worldCopyJump: false
|
|
6815 |
});
|
|
6816 |
|
|
6817 |
L.Map.Drag = L.Handler.extend({
|
|
6818 |
addHooks: function () {
|
|
6819 |
if (!this._draggable) {
|
|
6820 |
var map = this._map;
|
|
6821 |
|
|
6822 |
this._draggable = new L.Draggable(map._mapPane, map._container);
|
|
6823 |
|
|
6824 |
this._draggable.on({
|
|
6825 |
'dragstart': this._onDragStart,
|
|
6826 |
'drag': this._onDrag,
|
|
6827 |
'dragend': this._onDragEnd
|
|
6828 |
}, this);
|
|
6829 |
|
|
6830 |
if (map.options.worldCopyJump) {
|
|
6831 |
this._draggable.on('predrag', this._onPreDrag, this);
|
|
6832 |
map.on('viewreset', this._onViewReset, this);
|
|
6833 |
|
|
6834 |
map.whenReady(this._onViewReset, this);
|
|
6835 |
}
|
|
6836 |
}
|
|
6837 |
this._draggable.enable();
|
|
6838 |
},
|
|
6839 |
|
|
6840 |
removeHooks: function () {
|
|
6841 |
this._draggable.disable();
|
|
6842 |
},
|
|
6843 |
|
|
6844 |
moved: function () {
|
|
6845 |
return this._draggable && this._draggable._moved;
|
|
6846 |
},
|
|
6847 |
|
|
6848 |
_onDragStart: function () {
|
|
6849 |
var map = this._map;
|
|
6850 |
|
|
6851 |
if (map._panAnim) {
|
|
6852 |
map._panAnim.stop();
|
|
6853 |
}
|
|
6854 |
|
|
6855 |
map
|
|
6856 |
.fire('movestart')
|
|
6857 |
.fire('dragstart');
|
|
6858 |
|
|
6859 |
if (map.options.inertia) {
|
|
6860 |
this._positions = [];
|
|
6861 |
this._times = [];
|
|
6862 |
}
|
|
6863 |
},
|
|
6864 |
|
|
6865 |
_onDrag: function () {
|
|
6866 |
if (this._map.options.inertia) {
|
|
6867 |
var time = this._lastTime = +new Date(),
|
|
6868 |
pos = this._lastPos = this._draggable._newPos;
|
|
6869 |
|
|
6870 |
this._positions.push(pos);
|
|
6871 |
this._times.push(time);
|
|
6872 |
|
|
6873 |
if (time - this._times[0] > 200) {
|
|
6874 |
this._positions.shift();
|
|
6875 |
this._times.shift();
|
|
6876 |
}
|
|
6877 |
}
|
|
6878 |
|
|
6879 |
this._map
|
|
6880 |
.fire('move')
|
|
6881 |
.fire('drag');
|
|
6882 |
},
|
|
6883 |
|
|
6884 |
_onViewReset: function () {
|
|
6885 |
// TODO fix hardcoded Earth values
|
|
6886 |
var pxCenter = this._map.getSize()._divideBy(2),
|
|
6887 |
pxWorldCenter = this._map.latLngToLayerPoint([0, 0]);
|
|
6888 |
|
|
6889 |
this._initialWorldOffset = pxWorldCenter.subtract(pxCenter).x;
|
|
6890 |
this._worldWidth = this._map.project([0, 180]).x;
|
|
6891 |
},
|
|
6892 |
|
|
6893 |
_onPreDrag: function () {
|
|
6894 |
// TODO refactor to be able to adjust map pane position after zoom
|
|
6895 |
var worldWidth = this._worldWidth,
|
|
6896 |
halfWidth = Math.round(worldWidth / 2),
|
|
6897 |
dx = this._initialWorldOffset,
|
|
6898 |
x = this._draggable._newPos.x,
|
|
6899 |
newX1 = (x - halfWidth + dx) % worldWidth + halfWidth - dx,
|
|
6900 |
newX2 = (x + halfWidth + dx) % worldWidth - halfWidth - dx,
|
|
6901 |
newX = Math.abs(newX1 + dx) < Math.abs(newX2 + dx) ? newX1 : newX2;
|
|
6902 |
|
|
6903 |
this._draggable._newPos.x = newX;
|
|
6904 |
},
|
|
6905 |
|
|
6906 |
_onDragEnd: function (e) {
|
|
6907 |
var map = this._map,
|
|
6908 |
options = map.options,
|
|
6909 |
delay = +new Date() - this._lastTime,
|
|
6910 |
|
|
6911 |
noInertia = !options.inertia || delay > options.inertiaThreshold || !this._positions[0];
|
|
6912 |
|
|
6913 |
map.fire('dragend', e);
|
|
6914 |
|
|
6915 |
if (noInertia) {
|
|
6916 |
map.fire('moveend');
|
|
6917 |
|
|
6918 |
} else {
|
|
6919 |
|
|
6920 |
var direction = this._lastPos.subtract(this._positions[0]),
|
|
6921 |
duration = (this._lastTime + delay - this._times[0]) / 1000,
|
|
6922 |
ease = options.easeLinearity,
|
|
6923 |
|
|
6924 |
speedVector = direction.multiplyBy(ease / duration),
|
|
6925 |
speed = speedVector.distanceTo([0, 0]),
|
|
6926 |
|
|
6927 |
limitedSpeed = Math.min(options.inertiaMaxSpeed, speed),
|
|
6928 |
limitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed),
|
|
6929 |
|
|
6930 |
decelerationDuration = limitedSpeed / (options.inertiaDeceleration * ease),
|
|
6931 |
offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();
|
|
6932 |
|
|
6933 |
if (!offset.x || !offset.y) {
|
|
6934 |
map.fire('moveend');
|
|
6935 |
|
|
6936 |
} else {
|
|
6937 |
offset = map._limitOffset(offset, map.options.maxBounds);
|
|
6938 |
|
|
6939 |
L.Util.requestAnimFrame(function () {
|
|
6940 |
map.panBy(offset, {
|
|
6941 |
duration: decelerationDuration,
|
|
6942 |
easeLinearity: ease,
|
|
6943 |
noMoveStart: true
|
|
6944 |
});
|
|
6945 |
});
|
|
6946 |
}
|
|
6947 |
}
|
|
6948 |
}
|
|
6949 |
});
|
|
6950 |
|
|
6951 |
L.Map.addInitHook('addHandler', 'dragging', L.Map.Drag);
|
|
6952 |
|
|
6953 |
|
|
6954 |
/*
|
|
6955 |
* L.Handler.DoubleClickZoom is used to handle double-click zoom on the map, enabled by default.
|
|
6956 |
*/
|
|
6957 |
|
|
6958 |
L.Map.mergeOptions({
|
|
6959 |
doubleClickZoom: true
|
|
6960 |
});
|
|
6961 |
|
|
6962 |
L.Map.DoubleClickZoom = L.Handler.extend({
|
|
6963 |
addHooks: function () {
|
|
6964 |
this._map.on('dblclick', this._onDoubleClick, this);
|
|
6965 |
},
|
|
6966 |
|
|
6967 |
removeHooks: function () {
|
|
6968 |
this._map.off('dblclick', this._onDoubleClick, this);
|
|
6969 |
},
|
|
6970 |
|
|
6971 |
_onDoubleClick: function (e) {
|
|
6972 |
var map = this._map,
|
|
6973 |
zoom = map.getZoom() + (e.originalEvent.shiftKey ? -1 : 1);
|
|
6974 |
|
|
6975 |
if (map.options.doubleClickZoom === 'center') {
|
|
6976 |
map.setZoom(zoom);
|
|
6977 |
} else {
|
|
6978 |
map.setZoomAround(e.containerPoint, zoom);
|
|
6979 |
}
|
|
6980 |
}
|
|
6981 |
});
|
|
6982 |
|
|
6983 |
L.Map.addInitHook('addHandler', 'doubleClickZoom', L.Map.DoubleClickZoom);
|
|
6984 |
|
|
6985 |
|
|
6986 |
/*
|
|
6987 |
* L.Handler.ScrollWheelZoom is used by L.Map to enable mouse scroll wheel zoom on the map.
|
|
6988 |
*/
|
|
6989 |
|
|
6990 |
L.Map.mergeOptions({
|
|
6991 |
scrollWheelZoom: true
|
|
6992 |
});
|
|
6993 |
|
|
6994 |
L.Map.ScrollWheelZoom = L.Handler.extend({
|
|
6995 |
addHooks: function () {
|
|
6996 |
L.DomEvent.on(this._map._container, 'mousewheel', this._onWheelScroll, this);
|
|
6997 |
L.DomEvent.on(this._map._container, 'MozMousePixelScroll', L.DomEvent.preventDefault);
|
|
6998 |
this._delta = 0;
|
|
6999 |
},
|
|
7000 |
|
|
7001 |
removeHooks: function () {
|
|
7002 |
L.DomEvent.off(this._map._container, 'mousewheel', this._onWheelScroll);
|
|
7003 |
L.DomEvent.off(this._map._container, 'MozMousePixelScroll', L.DomEvent.preventDefault);
|
|
7004 |
},
|
|
7005 |
|
|
7006 |
_onWheelScroll: function (e) {
|
|
7007 |
var delta = L.DomEvent.getWheelDelta(e);
|
|
7008 |
|
|
7009 |
this._delta += delta;
|
|
7010 |
this._lastMousePos = this._map.mouseEventToContainerPoint(e);
|
|
7011 |
|
|
7012 |
if (!this._startTime) {
|
|
7013 |
this._startTime = +new Date();
|
|
7014 |
}
|
|
7015 |
|
|
7016 |
var left = Math.max(40 - (+new Date() - this._startTime), 0);
|
|
7017 |
|
|
7018 |
clearTimeout(this._timer);
|
|
7019 |
this._timer = setTimeout(L.bind(this._performZoom, this), left);
|
|
7020 |
|
|
7021 |
L.DomEvent.preventDefault(e);
|
|
7022 |
L.DomEvent.stopPropagation(e);
|
|
7023 |
},
|
|
7024 |
|
|
7025 |
_performZoom: function () {
|
|
7026 |
var map = this._map,
|
|
7027 |
delta = this._delta,
|
|
7028 |
zoom = map.getZoom();
|
|
7029 |
|
|
7030 |
delta = delta > 0 ? Math.ceil(delta) : Math.floor(delta);
|
|
7031 |
delta = Math.max(Math.min(delta, 4), -4);
|
|
7032 |
delta = map._limitZoom(zoom + delta) - zoom;
|
|
7033 |
|
|
7034 |
this._delta = 0;
|
|
7035 |
this._startTime = null;
|
|
7036 |
|
|
7037 |
if (!delta) { return; }
|
|
7038 |
|
|
7039 |
if (map.options.scrollWheelZoom === 'center') {
|
|
7040 |
map.setZoom(zoom + delta);
|
|
7041 |
} else {
|
|
7042 |
map.setZoomAround(this._lastMousePos, zoom + delta);
|
|
7043 |
}
|
|
7044 |
}
|
|
7045 |
});
|
|
7046 |
|
|
7047 |
L.Map.addInitHook('addHandler', 'scrollWheelZoom', L.Map.ScrollWheelZoom);
|
|
7048 |
|
|
7049 |
|
|
7050 |
/*
|
|
7051 |
* Extends the event handling code with double tap support for mobile browsers.
|
|
7052 |
*/
|
|
7053 |
|
|
7054 |
L.extend(L.DomEvent, {
|
|
7055 |
|
|
7056 |
_touchstart: L.Browser.msPointer ? 'MSPointerDown' : L.Browser.pointer ? 'pointerdown' : 'touchstart',
|
|
7057 |
_touchend: L.Browser.msPointer ? 'MSPointerUp' : L.Browser.pointer ? 'pointerup' : 'touchend',
|
|
7058 |
|
|
7059 |
// inspired by Zepto touch code by Thomas Fuchs
|
|
7060 |
addDoubleTapListener: function (obj, handler, id) {
|
|
7061 |
var last,
|
|
7062 |
doubleTap = false,
|
|
7063 |
delay = 250,
|
|
7064 |
touch,
|
|
7065 |
pre = '_leaflet_',
|
|
7066 |
touchstart = this._touchstart,
|
|
7067 |
touchend = this._touchend,
|
|
7068 |
trackedTouches = [];
|
|
7069 |
|
|
7070 |
function onTouchStart(e) {
|
|
7071 |
var count;
|
|
7072 |
|
|
7073 |
if (L.Browser.pointer) {
|
|
7074 |
trackedTouches.push(e.pointerId);
|
|
7075 |
count = trackedTouches.length;
|
|
7076 |
} else {
|
|
7077 |
count = e.touches.length;
|
|
7078 |
}
|
|
7079 |
if (count > 1) {
|
|
7080 |
return;
|
|
7081 |
}
|
|
7082 |
|
|
7083 |
var now = Date.now(),
|
|
7084 |
delta = now - (last || now);
|
|
7085 |
|
|
7086 |
touch = e.touches ? e.touches[0] : e;
|
|
7087 |
doubleTap = (delta > 0 && delta <= delay);
|
|
7088 |
last = now;
|
|
7089 |
}
|
|
7090 |
|
|
7091 |
function onTouchEnd(e) {
|
|
7092 |
if (L.Browser.pointer) {
|
|
7093 |
var idx = trackedTouches.indexOf(e.pointerId);
|
|
7094 |
if (idx === -1) {
|
|
7095 |
return;
|
|
7096 |
}
|
|
7097 |
trackedTouches.splice(idx, 1);
|
|
7098 |
}
|
|
7099 |
|
|
7100 |
if (doubleTap) {
|
|
7101 |
if (L.Browser.pointer) {
|
|
7102 |
// work around .type being readonly with MSPointer* events
|
|
7103 |
var newTouch = { },
|
|
7104 |
prop;
|
|
7105 |
|
|
7106 |
// jshint forin:false
|
|
7107 |
for (var i in touch) {
|
|
7108 |
prop = touch[i];
|
|
7109 |
if (typeof prop === 'function') {
|
|
7110 |
newTouch[i] = prop.bind(touch);
|
|
7111 |
} else {
|
|
7112 |
newTouch[i] = prop;
|
|
7113 |
}
|
|
7114 |
}
|
|
7115 |
touch = newTouch;
|
|
7116 |
}
|
|
7117 |
touch.type = 'dblclick';
|
|
7118 |
handler(touch);
|
|
7119 |
last = null;
|
|
7120 |
}
|
|
7121 |
}
|
|
7122 |
obj[pre + touchstart + id] = onTouchStart;
|
|
7123 |
obj[pre + touchend + id] = onTouchEnd;
|
|
7124 |
|
|
7125 |
// on pointer we need to listen on the document, otherwise a drag starting on the map and moving off screen
|
|
7126 |
// will not come through to us, so we will lose track of how many touches are ongoing
|
|
7127 |
var endElement = L.Browser.pointer ? document.documentElement : obj;
|
|
7128 |
|
|
7129 |
obj.addEventListener(touchstart, onTouchStart, false);
|
|
7130 |
endElement.addEventListener(touchend, onTouchEnd, false);
|
|
7131 |
|
|
7132 |
if (L.Browser.pointer) {
|
|
7133 |
endElement.addEventListener(L.DomEvent.POINTER_CANCEL, onTouchEnd, false);
|
|
7134 |
}
|
|
7135 |
|
|
7136 |
return this;
|
|
7137 |
},
|
|
7138 |
|
|
7139 |
removeDoubleTapListener: function (obj, id) {
|
|
7140 |
var pre = '_leaflet_';
|
|
7141 |
|
|
7142 |
obj.removeEventListener(this._touchstart, obj[pre + this._touchstart + id], false);
|
|
7143 |
(L.Browser.pointer ? document.documentElement : obj).removeEventListener(
|
|
7144 |
this._touchend, obj[pre + this._touchend + id], false);
|
|
7145 |
|
|
7146 |
if (L.Browser.pointer) {
|
|
7147 |
document.documentElement.removeEventListener(L.DomEvent.POINTER_CANCEL, obj[pre + this._touchend + id],
|
|
7148 |
false);
|
|
7149 |
}
|
|
7150 |
|
|
7151 |
return this;
|
|
7152 |
}
|
|
7153 |
});
|
|
7154 |
|
|
7155 |
|
|
7156 |
/*
|
|
7157 |
* Extends L.DomEvent to provide touch support for Internet Explorer and Windows-based devices.
|
|
7158 |
*/
|
|
7159 |
|
|
7160 |
L.extend(L.DomEvent, {
|
|
7161 |
|
|
7162 |
//static
|
|
7163 |
POINTER_DOWN: L.Browser.msPointer ? 'MSPointerDown' : 'pointerdown',
|
|
7164 |
POINTER_MOVE: L.Browser.msPointer ? 'MSPointerMove' : 'pointermove',
|
|
7165 |
POINTER_UP: L.Browser.msPointer ? 'MSPointerUp' : 'pointerup',
|
|
7166 |
POINTER_CANCEL: L.Browser.msPointer ? 'MSPointerCancel' : 'pointercancel',
|
|
7167 |
|
|
7168 |
_pointers: [],
|
|
7169 |
_pointerDocumentListener: false,
|
|
7170 |
|
|
7171 |
// Provides a touch events wrapper for (ms)pointer events.
|
|
7172 |
// Based on changes by veproza https://github.com/CloudMade/Leaflet/pull/1019
|
|
7173 |
//ref http://www.w3.org/TR/pointerevents/ https://www.w3.org/Bugs/Public/show_bug.cgi?id=22890
|
|
7174 |
|
|
7175 |
addPointerListener: function (obj, type, handler, id) {
|
|
7176 |
|
|
7177 |
switch (type) {
|
|
7178 |
case 'touchstart':
|
|
7179 |
return this.addPointerListenerStart(obj, type, handler, id);
|
|
7180 |
case 'touchend':
|
|
7181 |
return this.addPointerListenerEnd(obj, type, handler, id);
|
|
7182 |
case 'touchmove':
|
|
7183 |
return this.addPointerListenerMove(obj, type, handler, id);
|
|
7184 |
default:
|
|
7185 |
throw 'Unknown touch event type';
|
|
7186 |
}
|
|
7187 |
},
|
|
7188 |
|
|
7189 |
addPointerListenerStart: function (obj, type, handler, id) {
|
|
7190 |
var pre = '_leaflet_',
|
|
7191 |
pointers = this._pointers;
|
|
7192 |
|
|
7193 |
var cb = function (e) {
|
|
7194 |
|
|
7195 |
L.DomEvent.preventDefault(e);
|
|
7196 |
|
|
7197 |
var alreadyInArray = false;
|
|
7198 |
for (var i = 0; i < pointers.length; i++) {
|
|
7199 |
if (pointers[i].pointerId === e.pointerId) {
|
|
7200 |
alreadyInArray = true;
|
|
7201 |
break;
|
|
7202 |
}
|
|
7203 |
}
|
|
7204 |
if (!alreadyInArray) {
|
|
7205 |
pointers.push(e);
|
|
7206 |
}
|
|
7207 |
|
|
7208 |
e.touches = pointers.slice();
|
|
7209 |
e.changedTouches = [e];
|
|
7210 |
|
|
7211 |
handler(e);
|
|
7212 |
};
|
|
7213 |
|
|
7214 |
obj[pre + 'touchstart' + id] = cb;
|
|
7215 |
obj.addEventListener(this.POINTER_DOWN, cb, false);
|
|
7216 |
|
|
7217 |
// need to also listen for end events to keep the _pointers list accurate
|
|
7218 |
// this needs to be on the body and never go away
|
|
7219 |
if (!this._pointerDocumentListener) {
|
|
7220 |
var internalCb = function (e) {
|
|
7221 |
for (var i = 0; i < pointers.length; i++) {
|
|
7222 |
if (pointers[i].pointerId === e.pointerId) {
|
|
7223 |
pointers.splice(i, 1);
|
|
7224 |
break;
|
|
7225 |
}
|
|
7226 |
}
|
|
7227 |
};
|
|
7228 |
//We listen on the documentElement as any drags that end by moving the touch off the screen get fired there
|
|
7229 |
document.documentElement.addEventListener(this.POINTER_UP, internalCb, false);
|
|
7230 |
document.documentElement.addEventListener(this.POINTER_CANCEL, internalCb, false);
|
|
7231 |
|
|
7232 |
this._pointerDocumentListener = true;
|
|
7233 |
}
|
|
7234 |
|
|
7235 |
return this;
|
|
7236 |
},
|
|
7237 |
|
|
7238 |
addPointerListenerMove: function (obj, type, handler, id) {
|
|
7239 |
var pre = '_leaflet_',
|
|
7240 |
touches = this._pointers;
|
|
7241 |
|
|
7242 |
function cb(e) {
|
|
7243 |
|
|
7244 |
// don't fire touch moves when mouse isn't down
|
|
7245 |
if ((e.pointerType === e.MSPOINTER_TYPE_MOUSE || e.pointerType === 'mouse') && e.buttons === 0) { return; }
|
|
7246 |
|
|
7247 |
for (var i = 0; i < touches.length; i++) {
|
|
7248 |
if (touches[i].pointerId === e.pointerId) {
|
|
7249 |
touches[i] = e;
|
|
7250 |
break;
|
|
7251 |
}
|
|
7252 |
}
|
|
7253 |
|
|
7254 |
e.touches = touches.slice();
|
|
7255 |
e.changedTouches = [e];
|
|
7256 |
|
|
7257 |
handler(e);
|
|
7258 |
}
|
|
7259 |
|
|
7260 |
obj[pre + 'touchmove' + id] = cb;
|
|
7261 |
obj.addEventListener(this.POINTER_MOVE, cb, false);
|
|
7262 |
|
|
7263 |
return this;
|
|
7264 |
},
|
|
7265 |
|
|
7266 |
addPointerListenerEnd: function (obj, type, handler, id) {
|
|
7267 |
var pre = '_leaflet_',
|
|
7268 |
touches = this._pointers;
|
|
7269 |
|
|
7270 |
var cb = function (e) {
|
|
7271 |
for (var i = 0; i < touches.length; i++) {
|
|
7272 |
if (touches[i].pointerId === e.pointerId) {
|
|
7273 |
touches.splice(i, 1);
|
|
7274 |
break;
|
|
7275 |
}
|
|
7276 |
}
|
|
7277 |
|
|
7278 |
e.touches = touches.slice();
|
|
7279 |
e.changedTouches = [e];
|
|
7280 |
|
|
7281 |
handler(e);
|
|
7282 |
};
|
|
7283 |
|
|
7284 |
obj[pre + 'touchend' + id] = cb;
|
|
7285 |
obj.addEventListener(this.POINTER_UP, cb, false);
|
|
7286 |
obj.addEventListener(this.POINTER_CANCEL, cb, false);
|
|
7287 |
|
|
7288 |
return this;
|
|
7289 |
},
|
|
7290 |
|
|
7291 |
removePointerListener: function (obj, type, id) {
|
|
7292 |
var pre = '_leaflet_',
|
|
7293 |
cb = obj[pre + type + id];
|
|
7294 |
|
|
7295 |
switch (type) {
|
|
7296 |
case 'touchstart':
|
|
7297 |
obj.removeEventListener(this.POINTER_DOWN, cb, false);
|
|
7298 |
break;
|
|
7299 |
case 'touchmove':
|
|
7300 |
obj.removeEventListener(this.POINTER_MOVE, cb, false);
|
|
7301 |
break;
|
|
7302 |
case 'touchend':
|
|
7303 |
obj.removeEventListener(this.POINTER_UP, cb, false);
|
|
7304 |
obj.removeEventListener(this.POINTER_CANCEL, cb, false);
|
|
7305 |
break;
|
|
7306 |
}
|
|
7307 |
|
|
7308 |
return this;
|
|
7309 |
}
|
|
7310 |
});
|
|
7311 |
|
|
7312 |
|
|
7313 |
/*
|
|
7314 |
* L.Handler.TouchZoom is used by L.Map to add pinch zoom on supported mobile browsers.
|
|
7315 |
*/
|
|
7316 |
|
|
7317 |
L.Map.mergeOptions({
|
|
7318 |
touchZoom: L.Browser.touch && !L.Browser.android23,
|
|
7319 |
bounceAtZoomLimits: true
|
|
7320 |
});
|
|
7321 |
|
|
7322 |
L.Map.TouchZoom = L.Handler.extend({
|
|
7323 |
addHooks: function () {
|
|
7324 |
L.DomEvent.on(this._map._container, 'touchstart', this._onTouchStart, this);
|
|
7325 |
},
|
|
7326 |
|
|
7327 |
removeHooks: function () {
|
|
7328 |
L.DomEvent.off(this._map._container, 'touchstart', this._onTouchStart, this);
|
|
7329 |
},
|
|
7330 |
|
|
7331 |
_onTouchStart: function (e) {
|
|
7332 |
var map = this._map;
|
|
7333 |
|
|
7334 |
if (!e.touches || e.touches.length !== 2 || map._animatingZoom || this._zooming) { return; }
|
|
7335 |
|
|
7336 |
var p1 = map.mouseEventToLayerPoint(e.touches[0]),
|
|
7337 |
p2 = map.mouseEventToLayerPoint(e.touches[1]),
|
|
7338 |
viewCenter = map._getCenterLayerPoint();
|
|
7339 |
|
|
7340 |
this._startCenter = p1.add(p2)._divideBy(2);
|
|
7341 |
this._startDist = p1.distanceTo(p2);
|
|
7342 |
|
|
7343 |
this._moved = false;
|
|
7344 |
this._zooming = true;
|
|
7345 |
|
|
7346 |
this._centerOffset = viewCenter.subtract(this._startCenter);
|
|
7347 |
|
|
7348 |
if (map._panAnim) {
|
|
7349 |
map._panAnim.stop();
|
|
7350 |
}
|
|
7351 |
|
|
7352 |
L.DomEvent
|
|
7353 |
.on(document, 'touchmove', this._onTouchMove, this)
|
|
7354 |
.on(document, 'touchend', this._onTouchEnd, this);
|
|
7355 |
|
|
7356 |
L.DomEvent.preventDefault(e);
|
|
7357 |
},
|
|
7358 |
|
|
7359 |
_onTouchMove: function (e) {
|
|
7360 |
var map = this._map;
|
|
7361 |
|
|
7362 |
if (!e.touches || e.touches.length !== 2 || !this._zooming) { return; }
|
|
7363 |
|
|
7364 |
var p1 = map.mouseEventToLayerPoint(e.touches[0]),
|
|
7365 |
p2 = map.mouseEventToLayerPoint(e.touches[1]);
|
|
7366 |
|
|
7367 |
this._scale = p1.distanceTo(p2) / this._startDist;
|
|
7368 |
this._delta = p1._add(p2)._divideBy(2)._subtract(this._startCenter);
|
|
7369 |
|
|
7370 |
if (this._scale === 1) { return; }
|
|
7371 |
|
|
7372 |
if (!map.options.bounceAtZoomLimits) {
|
|
7373 |
if ((map.getZoom() === map.getMinZoom() && this._scale < 1) ||
|
|
7374 |
(map.getZoom() === map.getMaxZoom() && this._scale > 1)) { return; }
|
|
7375 |
}
|
|
7376 |
|
|
7377 |
if (!this._moved) {
|
|
7378 |
L.DomUtil.addClass(map._mapPane, 'leaflet-touching');
|
|
7379 |
|
|
7380 |
map
|
|
7381 |
.fire('movestart')
|
|
7382 |
.fire('zoomstart');
|
|
7383 |
|
|
7384 |
this._moved = true;
|
|
7385 |
}
|
|
7386 |
|
|
7387 |
L.Util.cancelAnimFrame(this._animRequest);
|
|
7388 |
this._animRequest = L.Util.requestAnimFrame(
|
|
7389 |
this._updateOnMove, this, true, this._map._container);
|
|
7390 |
|
|
7391 |
L.DomEvent.preventDefault(e);
|
|
7392 |
},
|
|
7393 |
|
|
7394 |
_updateOnMove: function () {
|
|
7395 |
var map = this._map,
|
|
7396 |
origin = this._getScaleOrigin(),
|
|
7397 |
center = map.layerPointToLatLng(origin),
|
|
7398 |
zoom = map.getScaleZoom(this._scale);
|
|
7399 |
|
|
7400 |
map._animateZoom(center, zoom, this._startCenter, this._scale, this._delta, false, true);
|
|
7401 |
},
|
|
7402 |
|
|
7403 |
_onTouchEnd: function () {
|
|
7404 |
if (!this._moved || !this._zooming) {
|
|
7405 |
this._zooming = false;
|
|
7406 |
return;
|
|
7407 |
}
|
|
7408 |
|
|
7409 |
var map = this._map;
|
|
7410 |
|
|
7411 |
this._zooming = false;
|
|
7412 |
L.DomUtil.removeClass(map._mapPane, 'leaflet-touching');
|
|
7413 |
L.Util.cancelAnimFrame(this._animRequest);
|
|
7414 |
|
|
7415 |
L.DomEvent
|
|
7416 |
.off(document, 'touchmove', this._onTouchMove)
|
|
7417 |
.off(document, 'touchend', this._onTouchEnd);
|
|
7418 |
|
|
7419 |
var origin = this._getScaleOrigin(),
|
|
7420 |
center = map.layerPointToLatLng(origin),
|
|
7421 |
|
|
7422 |
oldZoom = map.getZoom(),
|
|
7423 |
floatZoomDelta = map.getScaleZoom(this._scale) - oldZoom,
|
|
7424 |
roundZoomDelta = (floatZoomDelta > 0 ?
|
|
7425 |
Math.ceil(floatZoomDelta) : Math.floor(floatZoomDelta)),
|
|
7426 |
|
|
7427 |
zoom = map._limitZoom(oldZoom + roundZoomDelta),
|
|
7428 |
scale = map.getZoomScale(zoom) / this._scale;
|
|
7429 |
|
|
7430 |
map._animateZoom(center, zoom, origin, scale);
|
|
7431 |
},
|
|
7432 |
|
|
7433 |
_getScaleOrigin: function () {
|
|
7434 |
var centerOffset = this._centerOffset.subtract(this._delta).divideBy(this._scale);
|
|
7435 |
return this._startCenter.add(centerOffset);
|
|
7436 |
}
|
|
7437 |
});
|
|
7438 |
|
|
7439 |
L.Map.addInitHook('addHandler', 'touchZoom', L.Map.TouchZoom);
|
|
7440 |
|
|
7441 |
|
|
7442 |
/*
|
|
7443 |
* L.Map.Tap is used to enable mobile hacks like quick taps and long hold.
|
|
7444 |
*/
|
|
7445 |
|
|
7446 |
L.Map.mergeOptions({
|
|
7447 |
tap: true,
|
|
7448 |
tapTolerance: 15
|
|
7449 |
});
|
|
7450 |
|
|
7451 |
L.Map.Tap = L.Handler.extend({
|
|
7452 |
addHooks: function () {
|
|
7453 |
L.DomEvent.on(this._map._container, 'touchstart', this._onDown, this);
|
|
7454 |
},
|
|
7455 |
|
|
7456 |
removeHooks: function () {
|
|
7457 |
L.DomEvent.off(this._map._container, 'touchstart', this._onDown, this);
|
|
7458 |
},
|
|
7459 |
|
|
7460 |
_onDown: function (e) {
|
|
7461 |
if (!e.touches) { return; }
|
|
7462 |
|
|
7463 |
L.DomEvent.preventDefault(e);
|
|
7464 |
|
|
7465 |
this._fireClick = true;
|
|
7466 |
|
|
7467 |
// don't simulate click or track longpress if more than 1 touch
|
|
7468 |
if (e.touches.length > 1) {
|
|
7469 |
this._fireClick = false;
|
|
7470 |
clearTimeout(this._holdTimeout);
|
|
7471 |
return;
|
|
7472 |
}
|
|
7473 |
|
|
7474 |
var first = e.touches[0],
|
|
7475 |
el = first.target;
|
|
7476 |
|
|
7477 |
this._startPos = this._newPos = new L.Point(first.clientX, first.clientY);
|
|
7478 |
|
|
7479 |
// if touching a link, highlight it
|
|
7480 |
if (el.tagName && el.tagName.toLowerCase() === 'a') {
|
|
7481 |
L.DomUtil.addClass(el, 'leaflet-active');
|
|
7482 |
}
|
|
7483 |
|
|
7484 |
// simulate long hold but setting a timeout
|
|
7485 |
this._holdTimeout = setTimeout(L.bind(function () {
|
|
7486 |
if (this._isTapValid()) {
|
|
7487 |
this._fireClick = false;
|
|
7488 |
this._onUp();
|
|
7489 |
this._simulateEvent('contextmenu', first);
|
|
7490 |
}
|
|
7491 |
}, this), 1000);
|
|
7492 |
|
|
7493 |
L.DomEvent
|
|
7494 |
.on(document, 'touchmove', this._onMove, this)
|
|
7495 |
.on(document, 'touchend', this._onUp, this);
|
|
7496 |
},
|
|
7497 |
|
|
7498 |
_onUp: function (e) {
|
|
7499 |
clearTimeout(this._holdTimeout);
|
|
7500 |
|
|
7501 |
L.DomEvent
|
|
7502 |
.off(document, 'touchmove', this._onMove, this)
|
|
7503 |
.off(document, 'touchend', this._onUp, this);
|
|
7504 |
|
|
7505 |
if (this._fireClick && e && e.changedTouches) {
|
|
7506 |
|
|
7507 |
var first = e.changedTouches[0],
|
|
7508 |
el = first.target;
|
|
7509 |
|
|
7510 |
if (el && el.tagName && el.tagName.toLowerCase() === 'a') {
|
|
7511 |
L.DomUtil.removeClass(el, 'leaflet-active');
|
|
7512 |
}
|
|
7513 |
|
|
7514 |
// simulate click if the touch didn't move too much
|
|
7515 |
if (this._isTapValid()) {
|
|
7516 |
this._simulateEvent('click', first);
|
|
7517 |
}
|
|
7518 |
}
|
|
7519 |
},
|
|
7520 |
|
|
7521 |
_isTapValid: function () {
|
|
7522 |
return this._newPos.distanceTo(this._startPos) <= this._map.options.tapTolerance;
|
|
7523 |
},
|
|
7524 |
|
|
7525 |
_onMove: function (e) {
|
|
7526 |
var first = e.touches[0];
|
|
7527 |
this._newPos = new L.Point(first.clientX, first.clientY);
|
|
7528 |
},
|
|
7529 |
|
|
7530 |
_simulateEvent: function (type, e) {
|
|
7531 |
var simulatedEvent = document.createEvent('MouseEvents');
|
|
7532 |
|
|
7533 |
simulatedEvent._simulated = true;
|
|
7534 |
e.target._simulatedClick = true;
|
|
7535 |
|
|
7536 |
simulatedEvent.initMouseEvent(
|
|
7537 |
type, true, true, window, 1,
|
|
7538 |
e.screenX, e.screenY,
|
|
7539 |
e.clientX, e.clientY,
|
|
7540 |
false, false, false, false, 0, null);
|
|
7541 |
|
|
7542 |
e.target.dispatchEvent(simulatedEvent);
|
|
7543 |
}
|
|
7544 |
});
|
|
7545 |
|
|
7546 |
if (L.Browser.touch && !L.Browser.pointer) {
|
|
7547 |
L.Map.addInitHook('addHandler', 'tap', L.Map.Tap);
|
|
7548 |
}
|
|
7549 |
|
|
7550 |
|
|
7551 |
/*
|
|
7552 |
* L.Handler.ShiftDragZoom is used to add shift-drag zoom interaction to the map
|
|
7553 |
* (zoom to a selected bounding box), enabled by default.
|
|
7554 |
*/
|
|
7555 |
|
|
7556 |
L.Map.mergeOptions({
|
|
7557 |
boxZoom: true
|
|
7558 |
});
|
|
7559 |
|
|
7560 |
L.Map.BoxZoom = L.Handler.extend({
|
|
7561 |
initialize: function (map) {
|
|
7562 |
this._map = map;
|
|
7563 |
this._container = map._container;
|
|
7564 |
this._pane = map._panes.overlayPane;
|
|
7565 |
this._moved = false;
|
|
7566 |
},
|
|
7567 |
|
|
7568 |
addHooks: function () {
|
|
7569 |
L.DomEvent.on(this._container, 'mousedown', this._onMouseDown, this);
|
|
7570 |
},
|
|
7571 |
|
|
7572 |
removeHooks: function () {
|
|
7573 |
L.DomEvent.off(this._container, 'mousedown', this._onMouseDown);
|
|
7574 |
this._moved = false;
|
|
7575 |
},
|
|
7576 |
|
|
7577 |
moved: function () {
|
|
7578 |
return this._moved;
|
|
7579 |
},
|
|
7580 |
|
|
7581 |
_onMouseDown: function (e) {
|
|
7582 |
this._moved = false;
|
|
7583 |
|
|
7584 |
if (!e.shiftKey || ((e.which !== 1) && (e.button !== 1))) { return false; }
|
|
7585 |
|
|
7586 |
L.DomUtil.disableTextSelection();
|
|
7587 |
L.DomUtil.disableImageDrag();
|
|
7588 |
|
|
7589 |
this._startLayerPoint = this._map.mouseEventToLayerPoint(e);
|
|
7590 |
|
|
7591 |
L.DomEvent
|
|
7592 |
.on(document, 'mousemove', this._onMouseMove, this)
|
|
7593 |
.on(document, 'mouseup', this._onMouseUp, this)
|
|
7594 |
.on(document, 'keydown', this._onKeyDown, this);
|
|
7595 |
},
|
|
7596 |
|
|
7597 |
_onMouseMove: function (e) {
|
|
7598 |
if (!this._moved) {
|
|
7599 |
this._box = L.DomUtil.create('div', 'leaflet-zoom-box', this._pane);
|
|
7600 |
L.DomUtil.setPosition(this._box, this._startLayerPoint);
|
|
7601 |
|
|
7602 |
//TODO refactor: move cursor to styles
|
|
7603 |
this._container.style.cursor = 'crosshair';
|
|
7604 |
this._map.fire('boxzoomstart');
|
|
7605 |
}
|
|
7606 |
|
|
7607 |
var startPoint = this._startLayerPoint,
|
|
7608 |
box = this._box,
|
|
7609 |
|
|
7610 |
layerPoint = this._map.mouseEventToLayerPoint(e),
|
|
7611 |
offset = layerPoint.subtract(startPoint),
|
|
7612 |
|
|
7613 |
newPos = new L.Point(
|
|
7614 |
Math.min(layerPoint.x, startPoint.x),
|
|
7615 |
Math.min(layerPoint.y, startPoint.y));
|
|
7616 |
|
|
7617 |
L.DomUtil.setPosition(box, newPos);
|
|
7618 |
|
|
7619 |
this._moved = true;
|
|
7620 |
|
|
7621 |
// TODO refactor: remove hardcoded 4 pixels
|
|
7622 |
box.style.width = (Math.max(0, Math.abs(offset.x) - 4)) + 'px';
|
|
7623 |
box.style.height = (Math.max(0, Math.abs(offset.y) - 4)) + 'px';
|
|
7624 |
},
|
|
7625 |
|
|
7626 |
_finish: function () {
|
|
7627 |
if (this._moved) {
|
|
7628 |
this._pane.removeChild(this._box);
|
|
7629 |
this._container.style.cursor = '';
|
|
7630 |
}
|
|
7631 |
|
|
7632 |
L.DomUtil.enableTextSelection();
|
|
7633 |
L.DomUtil.enableImageDrag();
|
|
7634 |
|
|
7635 |
L.DomEvent
|
|
7636 |
.off(document, 'mousemove', this._onMouseMove)
|
|
7637 |
.off(document, 'mouseup', this._onMouseUp)
|
|
7638 |
.off(document, 'keydown', this._onKeyDown);
|
|
7639 |
},
|
|
7640 |
|
|
7641 |
_onMouseUp: function (e) {
|
|
7642 |
|
|
7643 |
this._finish();
|
|
7644 |
|
|
7645 |
var map = this._map,
|
|
7646 |
layerPoint = map.mouseEventToLayerPoint(e);
|
|
7647 |
|
|
7648 |
if (this._startLayerPoint.equals(layerPoint)) { return; }
|
|
7649 |
|
|
7650 |
var bounds = new L.LatLngBounds(
|
|
7651 |
map.layerPointToLatLng(this._startLayerPoint),
|
|
7652 |
map.layerPointToLatLng(layerPoint));
|
|
7653 |
|
|
7654 |
map.fitBounds(bounds);
|
|
7655 |
|
|
7656 |
map.fire('boxzoomend', {
|
|
7657 |
boxZoomBounds: bounds
|
|
7658 |
});
|
|
7659 |
},
|
|
7660 |
|
|
7661 |
_onKeyDown: function (e) {
|
|
7662 |
if (e.keyCode === 27) {
|
|
7663 |
this._finish();
|
|
7664 |
}
|
|
7665 |
}
|
|
7666 |
});
|
|
7667 |
|
|
7668 |
L.Map.addInitHook('addHandler', 'boxZoom', L.Map.BoxZoom);
|
|
7669 |
|
|
7670 |
|
|
7671 |
/*
|
|
7672 |
* L.Map.Keyboard is handling keyboard interaction with the map, enabled by default.
|
|
7673 |
*/
|
|
7674 |
|
|
7675 |
L.Map.mergeOptions({
|
|
7676 |
keyboard: true,
|
|
7677 |
keyboardPanOffset: 80,
|
|
7678 |
keyboardZoomOffset: 1
|
|
7679 |
});
|
|
7680 |
|
|
7681 |
L.Map.Keyboard = L.Handler.extend({
|
|
7682 |
|
|
7683 |
keyCodes: {
|
|
7684 |
left: [37],
|
|
7685 |
right: [39],
|
|
7686 |
down: [40],
|
|
7687 |
up: [38],
|
|
7688 |
zoomIn: [187, 107, 61, 171],
|
|
7689 |
zoomOut: [189, 109, 173]
|
|
7690 |
},
|
|
7691 |
|
|
7692 |
initialize: function (map) {
|
|
7693 |
this._map = map;
|
|
7694 |
|
|
7695 |
this._setPanOffset(map.options.keyboardPanOffset);
|
|
7696 |
this._setZoomOffset(map.options.keyboardZoomOffset);
|
|
7697 |
},
|
|
7698 |
|
|
7699 |
addHooks: function () {
|
|
7700 |
var container = this._map._container;
|
|
7701 |
|
|
7702 |
// make the container focusable by tabbing
|
|
7703 |
if (container.tabIndex === -1) {
|
|
7704 |
container.tabIndex = '0';
|
|
7705 |
}
|
|
7706 |
|
|
7707 |
L.DomEvent
|
|
7708 |
.on(container, 'focus', this._onFocus, this)
|
|
7709 |
.on(container, 'blur', this._onBlur, this)
|
|
7710 |
.on(container, 'mousedown', this._onMouseDown, this);
|
|
7711 |
|
|
7712 |
this._map
|
|
7713 |
.on('focus', this._addHooks, this)
|
|
7714 |
.on('blur', this._removeHooks, this);
|
|
7715 |
},
|
|
7716 |
|
|
7717 |
removeHooks: function () {
|
|
7718 |
this._removeHooks();
|
|
7719 |
|
|
7720 |
var container = this._map._container;
|
|
7721 |
|
|
7722 |
L.DomEvent
|
|
7723 |
.off(container, 'focus', this._onFocus, this)
|
|
7724 |
.off(container, 'blur', this._onBlur, this)
|
|
7725 |
.off(container, 'mousedown', this._onMouseDown, this);
|
|
7726 |
|
|
7727 |
this._map
|
|
7728 |
.off('focus', this._addHooks, this)
|
|
7729 |
.off('blur', this._removeHooks, this);
|
|
7730 |
},
|
|
7731 |
|
|
7732 |
_onMouseDown: function () {
|
|
7733 |
if (this._focused) { return; }
|
|
7734 |
|
|
7735 |
var body = document.body,
|
|
7736 |
docEl = document.documentElement,
|
|
7737 |
top = body.scrollTop || docEl.scrollTop,
|
|
7738 |
left = body.scrollLeft || docEl.scrollLeft;
|
|
7739 |
|
|
7740 |
this._map._container.focus();
|
|
7741 |
|
|
7742 |
window.scrollTo(left, top);
|
|
7743 |
},
|
|
7744 |
|
|
7745 |
_onFocus: function () {
|
|
7746 |
this._focused = true;
|
|
7747 |
this._map.fire('focus');
|
|
7748 |
},
|
|
7749 |
|
|
7750 |
_onBlur: function () {
|
|
7751 |
this._focused = false;
|
|
7752 |
this._map.fire('blur');
|
|
7753 |
},
|
|
7754 |
|
|
7755 |
_setPanOffset: function (pan) {
|
|
7756 |
var keys = this._panKeys = {},
|
|
7757 |
codes = this.keyCodes,
|
|
7758 |
i, len;
|
|
7759 |
|
|
7760 |
for (i = 0, len = codes.left.length; i < len; i++) {
|
|
7761 |
keys[codes.left[i]] = [-1 * pan, 0];
|
|
7762 |
}
|
|
7763 |
for (i = 0, len = codes.right.length; i < len; i++) {
|
|
7764 |
keys[codes.right[i]] = [pan, 0];
|
|
7765 |
}
|
|
7766 |
for (i = 0, len = codes.down.length; i < len; i++) {
|
|
7767 |
keys[codes.down[i]] = [0, pan];
|
|
7768 |
}
|
|
7769 |
for (i = 0, len = codes.up.length; i < len; i++) {
|
|
7770 |
keys[codes.up[i]] = [0, -1 * pan];
|
|
7771 |
}
|
|
7772 |
},
|
|
7773 |
|
|
7774 |
_setZoomOffset: function (zoom) {
|
|
7775 |
var keys = this._zoomKeys = {},
|
|
7776 |
codes = this.keyCodes,
|
|
7777 |
i, len;
|
|
7778 |
|
|
7779 |
for (i = 0, len = codes.zoomIn.length; i < len; i++) {
|
|
7780 |
keys[codes.zoomIn[i]] = zoom;
|
|
7781 |
}
|
|
7782 |
for (i = 0, len = codes.zoomOut.length; i < len; i++) {
|
|
7783 |
keys[codes.zoomOut[i]] = -zoom;
|
|
7784 |
}
|
|
7785 |
},
|
|
7786 |
|
|
7787 |
_addHooks: function () {
|
|
7788 |
L.DomEvent.on(document, 'keydown', this._onKeyDown, this);
|
|
7789 |
},
|
|
7790 |
|
|
7791 |
_removeHooks: function () {
|
|
7792 |
L.DomEvent.off(document, 'keydown', this._onKeyDown, this);
|
|
7793 |
},
|
|
7794 |
|
|
7795 |
_onKeyDown: function (e) {
|
|
7796 |
var key = e.keyCode,
|
|
7797 |
map = this._map;
|
|
7798 |
|
|
7799 |
if (key in this._panKeys) {
|
|
7800 |
|
|
7801 |
if (map._panAnim && map._panAnim._inProgress) { return; }
|
|
7802 |
|
|
7803 |
map.panBy(this._panKeys[key]);
|
|
7804 |
|
|
7805 |
if (map.options.maxBounds) {
|
|
7806 |
map.panInsideBounds(map.options.maxBounds);
|
|
7807 |
}
|
|
7808 |
|
|
7809 |
} else if (key in this._zoomKeys) {
|
|
7810 |
map.setZoom(map.getZoom() + this._zoomKeys[key]);
|
|
7811 |
|
|
7812 |
} else {
|
|
7813 |
return;
|
|
7814 |
}
|
|
7815 |
|
|
7816 |
L.DomEvent.stop(e);
|
|
7817 |
}
|
|
7818 |
});
|
|
7819 |
|
|
7820 |
L.Map.addInitHook('addHandler', 'keyboard', L.Map.Keyboard);
|
|
7821 |
|
|
7822 |
|
|
7823 |
/*
|
|
7824 |
* L.Handler.MarkerDrag is used internally by L.Marker to make the markers draggable.
|
|
7825 |
*/
|
|
7826 |
|
|
7827 |
L.Handler.MarkerDrag = L.Handler.extend({
|
|
7828 |
initialize: function (marker) {
|
|
7829 |
this._marker = marker;
|
|
7830 |
},
|
|
7831 |
|
|
7832 |
addHooks: function () {
|
|
7833 |
var icon = this._marker._icon;
|
|
7834 |
if (!this._draggable) {
|
|
7835 |
this._draggable = new L.Draggable(icon, icon);
|
|
7836 |
}
|
|
7837 |
|
|
7838 |
this._draggable
|
|
7839 |
.on('dragstart', this._onDragStart, this)
|
|
7840 |
.on('drag', this._onDrag, this)
|
|
7841 |
.on('dragend', this._onDragEnd, this);
|
|
7842 |
this._draggable.enable();
|
|
7843 |
L.DomUtil.addClass(this._marker._icon, 'leaflet-marker-draggable');
|
|
7844 |
},
|
|
7845 |
|
|
7846 |
removeHooks: function () {
|
|
7847 |
this._draggable
|
|
7848 |
.off('dragstart', this._onDragStart, this)
|
|
7849 |
.off('drag', this._onDrag, this)
|
|
7850 |
.off('dragend', this._onDragEnd, this);
|
|
7851 |
|
|
7852 |
this._draggable.disable();
|
|
7853 |
L.DomUtil.removeClass(this._marker._icon, 'leaflet-marker-draggable');
|
|
7854 |
},
|
|
7855 |
|
|
7856 |
moved: function () {
|
|
7857 |
return this._draggable && this._draggable._moved;
|
|
7858 |
},
|
|
7859 |
|
|
7860 |
_onDragStart: function () {
|
|
7861 |
this._marker
|
|
7862 |
.closePopup()
|
|
7863 |
.fire('movestart')
|
|
7864 |
.fire('dragstart');
|
|
7865 |
},
|
|
7866 |
|
|
7867 |
_onDrag: function () {
|
|
7868 |
var marker = this._marker,
|
|
7869 |
shadow = marker._shadow,
|
|
7870 |
iconPos = L.DomUtil.getPosition(marker._icon),
|
|
7871 |
latlng = marker._map.layerPointToLatLng(iconPos);
|
|
7872 |
|
|
7873 |
// update shadow position
|
|
7874 |
if (shadow) {
|
|
7875 |
L.DomUtil.setPosition(shadow, iconPos);
|
|
7876 |
}
|
|
7877 |
|
|
7878 |
marker._latlng = latlng;
|
|
7879 |
|
|
7880 |
marker
|
|
7881 |
.fire('move', {latlng: latlng})
|
|
7882 |
.fire('drag');
|
|
7883 |
},
|
|
7884 |
|
|
7885 |
_onDragEnd: function (e) {
|
|
7886 |
this._marker
|
|
7887 |
.fire('moveend')
|
|
7888 |
.fire('dragend', e);
|
|
7889 |
}
|
|
7890 |
});
|
|
7891 |
|
|
7892 |
|
|
7893 |
/*
|
|
7894 |
* L.Control is a base class for implementing map controls. Handles positioning.
|
|
7895 |
* All other controls extend from this class.
|
|
7896 |
*/
|
|
7897 |
|
|
7898 |
L.Control = L.Class.extend({
|
|
7899 |
options: {
|
|
7900 |
position: 'topright'
|
|
7901 |
},
|
|
7902 |
|
|
7903 |
initialize: function (options) {
|
|
7904 |
L.setOptions(this, options);
|
|
7905 |
},
|
|
7906 |
|
|
7907 |
getPosition: function () {
|
|
7908 |
return this.options.position;
|
|
7909 |
},
|
|
7910 |
|
|
7911 |
setPosition: function (position) {
|
|
7912 |
var map = this._map;
|
|
7913 |
|
|
7914 |
if (map) {
|
|
7915 |
map.removeControl(this);
|
|
7916 |
}
|
|
7917 |
|
|
7918 |
this.options.position = position;
|
|
7919 |
|
|
7920 |
if (map) {
|
|
7921 |
map.addControl(this);
|
|
7922 |
}
|
|
7923 |
|
|
7924 |
return this;
|
|
7925 |
},
|
|
7926 |
|
|
7927 |
getContainer: function () {
|
|
7928 |
return this._container;
|
|
7929 |
},
|
|
7930 |
|
|
7931 |
addTo: function (map) {
|
|
7932 |
this._map = map;
|
|
7933 |
|
|
7934 |
var container = this._container = this.onAdd(map),
|
|
7935 |
pos = this.getPosition(),
|
|
7936 |
corner = map._controlCorners[pos];
|
|
7937 |
|
|
7938 |
L.DomUtil.addClass(container, 'leaflet-control');
|
|
7939 |
|
|
7940 |
if (pos.indexOf('bottom') !== -1) {
|
|
7941 |
corner.insertBefore(container, corner.firstChild);
|
|
7942 |
} else {
|
|
7943 |
corner.appendChild(container);
|
|
7944 |
}
|
|
7945 |
|
|
7946 |
return this;
|
|
7947 |
},
|
|
7948 |
|
|
7949 |
removeFrom: function (map) {
|
|
7950 |
var pos = this.getPosition(),
|
|
7951 |
corner = map._controlCorners[pos];
|
|
7952 |
|
|
7953 |
corner.removeChild(this._container);
|
|
7954 |
this._map = null;
|
|
7955 |
|
|
7956 |
if (this.onRemove) {
|
|
7957 |
this.onRemove(map);
|
|
7958 |
}
|
|
7959 |
|
|
7960 |
return this;
|
|
7961 |
},
|
|
7962 |
|
|
7963 |
_refocusOnMap: function () {
|
|
7964 |
if (this._map) {
|
|
7965 |
this._map.getContainer().focus();
|
|
7966 |
}
|
|
7967 |
}
|
|
7968 |
});
|
|
7969 |
|
|
7970 |
L.control = function (options) {
|
|
7971 |
return new L.Control(options);
|
|
7972 |
};
|
|
7973 |
|
|
7974 |
|
|
7975 |
// adds control-related methods to L.Map
|
|
7976 |
|
|
7977 |
L.Map.include({
|
|
7978 |
addControl: function (control) {
|
|
7979 |
control.addTo(this);
|
|
7980 |
return this;
|
|
7981 |
},
|
|
7982 |
|
|
7983 |
removeControl: function (control) {
|
|
7984 |
control.removeFrom(this);
|
|
7985 |
return this;
|
|
7986 |
},
|
|
7987 |
|
|
7988 |
_initControlPos: function () {
|
|
7989 |
var corners = this._controlCorners = {},
|
|
7990 |
l = 'leaflet-',
|
|
7991 |
container = this._controlContainer =
|
|
7992 |
L.DomUtil.create('div', l + 'control-container', this._container);
|
|
7993 |
|
|
7994 |
function createCorner(vSide, hSide) {
|
|
7995 |
var className = l + vSide + ' ' + l + hSide;
|
|
7996 |
|
|
7997 |
corners[vSide + hSide] = L.DomUtil.create('div', className, container);
|
|
7998 |
}
|
|
7999 |
|
|
8000 |
createCorner('top', 'left');
|
|
8001 |
createCorner('top', 'right');
|
|
8002 |
createCorner('bottom', 'left');
|
|
8003 |
createCorner('bottom', 'right');
|
|
8004 |
},
|
|
8005 |
|
|
8006 |
_clearControlPos: function () {
|
|
8007 |
this._container.removeChild(this._controlContainer);
|
|
8008 |
}
|
|
8009 |
});
|
|
8010 |
|
|
8011 |
|
|
8012 |
/*
|
|
8013 |
* L.Control.Zoom is used for the default zoom buttons on the map.
|
|
8014 |
*/
|
|
8015 |
|
|
8016 |
L.Control.Zoom = L.Control.extend({
|
|
8017 |
options: {
|
|
8018 |
position: 'topleft',
|
|
8019 |
zoomInText: '+',
|
|
8020 |
zoomInTitle: 'Zoom in',
|
|
8021 |
zoomOutText: '-',
|
|
8022 |
zoomOutTitle: 'Zoom out'
|
|
8023 |
},
|
|
8024 |
|
|
8025 |
onAdd: function (map) {
|
|
8026 |
var zoomName = 'leaflet-control-zoom',
|
|
8027 |
container = L.DomUtil.create('div', zoomName + ' leaflet-bar');
|
|
8028 |
|
|
8029 |
this._map = map;
|
|
8030 |
|
|
8031 |
this._zoomInButton = this._createButton(
|
|
8032 |
this.options.zoomInText, this.options.zoomInTitle,
|
|
8033 |
zoomName + '-in', container, this._zoomIn, this);
|
|
8034 |
this._zoomOutButton = this._createButton(
|
|
8035 |
this.options.zoomOutText, this.options.zoomOutTitle,
|
|
8036 |
zoomName + '-out', container, this._zoomOut, this);
|
|
8037 |
|
|
8038 |
this._updateDisabled();
|
|
8039 |
map.on('zoomend zoomlevelschange', this._updateDisabled, this);
|
|
8040 |
|
|
8041 |
return container;
|
|
8042 |
},
|
|
8043 |
|
|
8044 |
onRemove: function (map) {
|
|
8045 |
map.off('zoomend zoomlevelschange', this._updateDisabled, this);
|
|
8046 |
},
|
|
8047 |
|
|
8048 |
_zoomIn: function (e) {
|
|
8049 |
this._map.zoomIn(e.shiftKey ? 3 : 1);
|
|
8050 |
},
|
|
8051 |
|
|
8052 |
_zoomOut: function (e) {
|
|
8053 |
this._map.zoomOut(e.shiftKey ? 3 : 1);
|
|
8054 |
},
|
|
8055 |
|
|
8056 |
_createButton: function (html, title, className, container, fn, context) {
|
|
8057 |
var link = L.DomUtil.create('a', className, container);
|
|
8058 |
link.innerHTML = html;
|
|
8059 |
link.href = '#';
|
|
8060 |
link.title = title;
|
|
8061 |
|
|
8062 |
var stop = L.DomEvent.stopPropagation;
|
|
8063 |
|
|
8064 |
L.DomEvent
|
|
8065 |
.on(link, 'click', stop)
|
|
8066 |
.on(link, 'mousedown', stop)
|
|
8067 |
.on(link, 'dblclick', stop)
|
|
8068 |
.on(link, 'click', L.DomEvent.preventDefault)
|
|
8069 |
.on(link, 'click', fn, context)
|
|
8070 |
.on(link, 'click', this._refocusOnMap, context);
|
|
8071 |
|
|
8072 |
return link;
|
|
8073 |
},
|
|
8074 |
|
|
8075 |
_updateDisabled: function () {
|
|
8076 |
var map = this._map,
|
|
8077 |
className = 'leaflet-disabled';
|
|
8078 |
|
|
8079 |
L.DomUtil.removeClass(this._zoomInButton, className);
|
|
8080 |
L.DomUtil.removeClass(this._zoomOutButton, className);
|
|
8081 |
|
|
8082 |
if (map._zoom === map.getMinZoom()) {
|
|
8083 |
L.DomUtil.addClass(this._zoomOutButton, className);
|
|
8084 |
}
|
|
8085 |
if (map._zoom === map.getMaxZoom()) {
|
|
8086 |
L.DomUtil.addClass(this._zoomInButton, className);
|
|
8087 |
}
|
|
8088 |
}
|
|
8089 |
});
|
|
8090 |
|
|
8091 |
L.Map.mergeOptions({
|
|
8092 |
zoomControl: true
|
|
8093 |
});
|
|
8094 |
|
|
8095 |
L.Map.addInitHook(function () {
|
|
8096 |
if (this.options.zoomControl) {
|
|
8097 |
this.zoomControl = new L.Control.Zoom();
|
|
8098 |
this.addControl(this.zoomControl);
|
|
8099 |
}
|
|
8100 |
});
|
|
8101 |
|
|
8102 |
L.control.zoom = function (options) {
|
|
8103 |
return new L.Control.Zoom(options);
|
|
8104 |
};
|
|
8105 |
|
|
8106 |
|
|
8107 |
|
|
8108 |
/*
|
|
8109 |
* L.Control.Attribution is used for displaying attribution on the map (added by default).
|
|
8110 |
*/
|
|
8111 |
|
|
8112 |
L.Control.Attribution = L.Control.extend({
|
|
8113 |
options: {
|
|
8114 |
position: 'bottomright',
|
|
8115 |
prefix: '<a href="http://leafletjs.com" title="A JS library for interactive maps">Leaflet</a>'
|
|
8116 |
},
|
|
8117 |
|
|
8118 |
initialize: function (options) {
|
|
8119 |
L.setOptions(this, options);
|
|
8120 |
|
|
8121 |
this._attributions = {};
|
|
8122 |
},
|
|
8123 |
|
|
8124 |
onAdd: function (map) {
|
|
8125 |
this._container = L.DomUtil.create('div', 'leaflet-control-attribution');
|
|
8126 |
L.DomEvent.disableClickPropagation(this._container);
|
|
8127 |
|
|
8128 |
for (var i in map._layers) {
|
|
8129 |
if (map._layers[i].getAttribution) {
|
|
8130 |
this.addAttribution(map._layers[i].getAttribution());
|
|
8131 |
}
|
|
8132 |
}
|
|
8133 |
|
|
8134 |
map
|
|
8135 |
.on('layeradd', this._onLayerAdd, this)
|
|
8136 |
.on('layerremove', this._onLayerRemove, this);
|
|
8137 |
|
|
8138 |
this._update();
|
|
8139 |
|
|
8140 |
return this._container;
|
|
8141 |
},
|
|
8142 |
|
|
8143 |
onRemove: function (map) {
|
|
8144 |
map
|
|
8145 |
.off('layeradd', this._onLayerAdd)
|
|
8146 |
.off('layerremove', this._onLayerRemove);
|
|
8147 |
|
|
8148 |
},
|
|
8149 |
|
|
8150 |
setPrefix: function (prefix) {
|
|
8151 |
this.options.prefix = prefix;
|
|
8152 |
this._update();
|
|
8153 |
return this;
|
|
8154 |
},
|
|
8155 |
|
|
8156 |
addAttribution: function (text) {
|
|
8157 |
if (!text) { return; }
|
|
8158 |
|
|
8159 |
if (!this._attributions[text]) {
|
|
8160 |
this._attributions[text] = 0;
|
|
8161 |
}
|
|
8162 |
this._attributions[text]++;
|
|
8163 |
|
|
8164 |
this._update();
|
|
8165 |
|
|
8166 |
return this;
|
|
8167 |
},
|
|
8168 |
|
|
8169 |
removeAttribution: function (text) {
|
|
8170 |
if (!text) { return; }
|
|
8171 |
|
|
8172 |
if (this._attributions[text]) {
|
|
8173 |
this._attributions[text]--;
|
|
8174 |
this._update();
|
|
8175 |
}
|
|
8176 |
|
|
8177 |
return this;
|
|
8178 |
},
|
|
8179 |
|
|
8180 |
_update: function () {
|
|
8181 |
if (!this._map) { return; }
|
|
8182 |
|
|
8183 |
var attribs = [];
|
|
8184 |
|
|
8185 |
for (var i in this._attributions) {
|
|
8186 |
if (this._attributions[i]) {
|
|
8187 |
attribs.push(i);
|
|
8188 |
}
|
|
8189 |
}
|
|
8190 |
|
|
8191 |
var prefixAndAttribs = [];
|
|
8192 |
|
|
8193 |
if (this.options.prefix) {
|
|
8194 |
prefixAndAttribs.push(this.options.prefix);
|
|
8195 |
}
|
|
8196 |
if (attribs.length) {
|
|
8197 |
prefixAndAttribs.push(attribs.join(', '));
|
|
8198 |
}
|
|
8199 |
|
|
8200 |
this._container.innerHTML = prefixAndAttribs.join(' | ');
|
|
8201 |
},
|
|
8202 |
|
|
8203 |
_onLayerAdd: function (e) {
|
|
8204 |
if (e.layer.getAttribution) {
|
|
8205 |
this.addAttribution(e.layer.getAttribution());
|
|
8206 |
}
|
|
8207 |
},
|
|
8208 |
|
|
8209 |
_onLayerRemove: function (e) {
|
|
8210 |
if (e.layer.getAttribution) {
|
|
8211 |
this.removeAttribution(e.layer.getAttribution());
|
|
8212 |
}
|
|
8213 |
}
|
|
8214 |
});
|
|
8215 |
|
|
8216 |
L.Map.mergeOptions({
|
|
8217 |
attributionControl: true
|
|
8218 |
});
|
|
8219 |
|
|
8220 |
L.Map.addInitHook(function () {
|
|
8221 |
if (this.options.attributionControl) {
|
|
8222 |
this.attributionControl = (new L.Control.Attribution()).addTo(this);
|
|
8223 |
}
|
|
8224 |
});
|
|
8225 |
|
|
8226 |
L.control.attribution = function (options) {
|
|
8227 |
return new L.Control.Attribution(options);
|
|
8228 |
};
|
|
8229 |
|
|
8230 |
|
|
8231 |
/*
|
|
8232 |
* L.Control.Scale is used for displaying metric/imperial scale on the map.
|
|
8233 |
*/
|
|
8234 |
|
|
8235 |
L.Control.Scale = L.Control.extend({
|
|
8236 |
options: {
|
|
8237 |
position: 'bottomleft',
|
|
8238 |
maxWidth: 100,
|
|
8239 |
metric: true,
|
|
8240 |
imperial: true,
|
|
8241 |
updateWhenIdle: false
|
|
8242 |
},
|
|
8243 |
|
|
8244 |
onAdd: function (map) {
|
|
8245 |
this._map = map;
|
|
8246 |
|
|
8247 |
var className = 'leaflet-control-scale',
|
|
8248 |
container = L.DomUtil.create('div', className),
|
|
8249 |
options = this.options;
|
|
8250 |
|
|
8251 |
this._addScales(options, className, container);
|
|
8252 |
|
|
8253 |
map.on(options.updateWhenIdle ? 'moveend' : 'move', this._update, this);
|
|
8254 |
map.whenReady(this._update, this);
|
|
8255 |
|
|
8256 |
return container;
|
|
8257 |
},
|
|
8258 |
|
|
8259 |
onRemove: function (map) {
|
|
8260 |
map.off(this.options.updateWhenIdle ? 'moveend' : 'move', this._update, this);
|
|
8261 |
},
|
|
8262 |
|
|
8263 |
_addScales: function (options, className, container) {
|
|
8264 |
if (options.metric) {
|
|
8265 |
this._mScale = L.DomUtil.create('div', className + '-line', container);
|
|
8266 |
}
|
|
8267 |
if (options.imperial) {
|
|
8268 |
this._iScale = L.DomUtil.create('div', className + '-line', container);
|
|
8269 |
}
|
|
8270 |
},
|
|
8271 |
|
|
8272 |
_update: function () {
|
|
8273 |
var bounds = this._map.getBounds(),
|
|
8274 |
centerLat = bounds.getCenter().lat,
|
|
8275 |
halfWorldMeters = 6378137 * Math.PI * Math.cos(centerLat * Math.PI / 180),
|
|
8276 |
dist = halfWorldMeters * (bounds.getNorthEast().lng - bounds.getSouthWest().lng) / 180,
|
|
8277 |
|
|
8278 |
size = this._map.getSize(),
|
|
8279 |
options = this.options,
|
|
8280 |
maxMeters = 0;
|
|
8281 |
|
|
8282 |
if (size.x > 0) {
|
|
8283 |
maxMeters = dist * (options.maxWidth / size.x);
|
|
8284 |
}
|
|
8285 |
|
|
8286 |
this._updateScales(options, maxMeters);
|
|
8287 |
},
|
|
8288 |
|
|
8289 |
_updateScales: function (options, maxMeters) {
|
|
8290 |
if (options.metric && maxMeters) {
|
|
8291 |
this._updateMetric(maxMeters);
|
|
8292 |
}
|
|
8293 |
|
|
8294 |
if (options.imperial && maxMeters) {
|
|
8295 |
this._updateImperial(maxMeters);
|
|
8296 |
}
|
|
8297 |
},
|
|
8298 |
|
|
8299 |
_updateMetric: function (maxMeters) {
|
|
8300 |
var meters = this._getRoundNum(maxMeters);
|
|
8301 |
|
|
8302 |
this._mScale.style.width = this._getScaleWidth(meters / maxMeters) + 'px';
|
|
8303 |
this._mScale.innerHTML = meters < 1000 ? meters + ' m' : (meters / 1000) + ' km';
|
|
8304 |
},
|
|
8305 |
|
|
8306 |
_updateImperial: function (maxMeters) {
|
|
8307 |
var maxFeet = maxMeters * 3.2808399,
|
|
8308 |
scale = this._iScale,
|
|
8309 |
maxMiles, miles, feet;
|
|
8310 |
|
|
8311 |
if (maxFeet > 5280) {
|
|
8312 |
maxMiles = maxFeet / 5280;
|
|
8313 |
miles = this._getRoundNum(maxMiles);
|
|
8314 |
|
|
8315 |
scale.style.width = this._getScaleWidth(miles / maxMiles) + 'px';
|
|
8316 |
scale.innerHTML = miles + ' mi';
|
|
8317 |
|
|
8318 |
} else {
|
|
8319 |
feet = this._getRoundNum(maxFeet);
|
|
8320 |
|
|
8321 |
scale.style.width = this._getScaleWidth(feet / maxFeet) + 'px';
|
|
8322 |
scale.innerHTML = feet + ' ft';
|
|
8323 |
}
|
|
8324 |
},
|
|
8325 |
|
|
8326 |
_getScaleWidth: function (ratio) {
|
|
8327 |
return Math.round(this.options.maxWidth * ratio) - 10;
|
|
8328 |
},
|
|
8329 |
|
|
8330 |
_getRoundNum: function (num) {
|
|
8331 |
var pow10 = Math.pow(10, (Math.floor(num) + '').length - 1),
|
|
8332 |
d = num / pow10;
|
|
8333 |
|
|
8334 |
d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : 1;
|
|
8335 |
|
|
8336 |
return pow10 * d;
|
|
8337 |
}
|
|
8338 |
});
|
|
8339 |
|
|
8340 |
L.control.scale = function (options) {
|
|
8341 |
return new L.Control.Scale(options);
|
|
8342 |
};
|
|
8343 |
|
|
8344 |
|
|
8345 |
/*
|
|
8346 |
* L.Control.Layers is a control to allow users to switch between different layers on the map.
|
|
8347 |
*/
|
|
8348 |
|
|
8349 |
L.Control.Layers = L.Control.extend({
|
|
8350 |
options: {
|
|
8351 |
collapsed: true,
|
|
8352 |
position: 'topright',
|
|
8353 |
autoZIndex: true
|
|
8354 |
},
|
|
8355 |
|
|
8356 |
initialize: function (baseLayers, overlays, options) {
|
|
8357 |
L.setOptions(this, options);
|
|
8358 |
|
|
8359 |
this._layers = {};
|
|
8360 |
this._lastZIndex = 0;
|
|
8361 |
this._handlingClick = false;
|
|
8362 |
|
|
8363 |
for (var i in baseLayers) {
|
|
8364 |
this._addLayer(baseLayers[i], i);
|
|
8365 |
}
|
|
8366 |
|
|
8367 |
for (i in overlays) {
|
|
8368 |
this._addLayer(overlays[i], i, true);
|
|
8369 |
}
|
|
8370 |
},
|
|
8371 |
|
|
8372 |
onAdd: function (map) {
|
|
8373 |
this._initLayout();
|
|
8374 |
this._update();
|
|
8375 |
|
|
8376 |
map
|
|
8377 |
.on('layeradd', this._onLayerChange, this)
|
|
8378 |
.on('layerremove', this._onLayerChange, this);
|
|
8379 |
|
|
8380 |
return this._container;
|
|
8381 |
},
|
|
8382 |
|
|
8383 |
onRemove: function (map) {
|
|
8384 |
map
|
|
8385 |
.off('layeradd', this._onLayerChange, this)
|
|
8386 |
.off('layerremove', this._onLayerChange, this);
|
|
8387 |
},
|
|
8388 |
|
|
8389 |
addBaseLayer: function (layer, name) {
|
|
8390 |
this._addLayer(layer, name);
|
|
8391 |
this._update();
|
|
8392 |
return this;
|
|
8393 |
},
|
|
8394 |
|
|
8395 |
addOverlay: function (layer, name) {
|
|
8396 |
this._addLayer(layer, name, true);
|
|
8397 |
this._update();
|
|
8398 |
return this;
|
|
8399 |
},
|
|
8400 |
|
|
8401 |
removeLayer: function (layer) {
|
|
8402 |
var id = L.stamp(layer);
|
|
8403 |
delete this._layers[id];
|
|
8404 |
this._update();
|
|
8405 |
return this;
|
|
8406 |
},
|
|
8407 |
|
|
8408 |
_initLayout: function () {
|
|
8409 |
var className = 'leaflet-control-layers',
|
|
8410 |
container = this._container = L.DomUtil.create('div', className);
|
|
8411 |
|
|
8412 |
//Makes this work on IE10 Touch devices by stopping it from firing a mouseout event when the touch is released
|
|
8413 |
container.setAttribute('aria-haspopup', true);
|
|
8414 |
|
|
8415 |
if (!L.Browser.touch) {
|
|
8416 |
L.DomEvent
|
|
8417 |
.disableClickPropagation(container)
|
|
8418 |
.disableScrollPropagation(container);
|
|
8419 |
} else {
|
|
8420 |
L.DomEvent.on(container, 'click', L.DomEvent.stopPropagation);
|
|
8421 |
}
|
|
8422 |
|
|
8423 |
var form = this._form = L.DomUtil.create('form', className + '-list');
|
|
8424 |
|
|
8425 |
if (this.options.collapsed) {
|
|
8426 |
if (!L.Browser.android) {
|
|
8427 |
L.DomEvent
|
|
8428 |
.on(container, 'mouseover', this._expand, this)
|
|
8429 |
.on(container, 'mouseout', this._collapse, this);
|
|
8430 |
}
|
|
8431 |
var link = this._layersLink = L.DomUtil.create('a', className + '-toggle', container);
|
|
8432 |
link.href = '#';
|
|
8433 |
link.title = 'Layers';
|
|
8434 |
|
|
8435 |
if (L.Browser.touch) {
|
|
8436 |
L.DomEvent
|
|
8437 |
.on(link, 'click', L.DomEvent.stop)
|
|
8438 |
.on(link, 'click', this._expand, this);
|
|
8439 |
}
|
|
8440 |
else {
|
|
8441 |
L.DomEvent.on(link, 'focus', this._expand, this);
|
|
8442 |
}
|
|
8443 |
//Work around for Firefox android issue https://github.com/Leaflet/Leaflet/issues/2033
|
|
8444 |
L.DomEvent.on(form, 'click', function () {
|
|
8445 |
setTimeout(L.bind(this._onInputClick, this), 0);
|
|
8446 |
}, this);
|
|
8447 |
|
|
8448 |
this._map.on('click', this._collapse, this);
|
|
8449 |
// TODO keyboard accessibility
|
|
8450 |
} else {
|
|
8451 |
this._expand();
|
|
8452 |
}
|
|
8453 |
|
|
8454 |
this._baseLayersList = L.DomUtil.create('div', className + '-base', form);
|
|
8455 |
this._separator = L.DomUtil.create('div', className + '-separator', form);
|
|
8456 |
this._overlaysList = L.DomUtil.create('div', className + '-overlays', form);
|
|
8457 |
|
|
8458 |
container.appendChild(form);
|
|
8459 |
},
|
|
8460 |
|
|
8461 |
_addLayer: function (layer, name, overlay) {
|
|
8462 |
var id = L.stamp(layer);
|
|
8463 |
|
|
8464 |
this._layers[id] = {
|
|
8465 |
layer: layer,
|
|
8466 |
name: name,
|
|
8467 |
overlay: overlay
|
|
8468 |
};
|
|
8469 |
|
|
8470 |
if (this.options.autoZIndex && layer.setZIndex) {
|
|
8471 |
this._lastZIndex++;
|
|
8472 |
layer.setZIndex(this._lastZIndex);
|
|
8473 |
}
|
|
8474 |
},
|
|
8475 |
|
|
8476 |
_update: function () {
|
|
8477 |
if (!this._container) {
|
|
8478 |
return;
|
|
8479 |
}
|
|
8480 |
|
|
8481 |
this._baseLayersList.innerHTML = '';
|
|
8482 |
this._overlaysList.innerHTML = '';
|
|
8483 |
|
|
8484 |
var baseLayersPresent = false,
|
|
8485 |
overlaysPresent = false,
|
|
8486 |
i, obj;
|
|
8487 |
|
|
8488 |
for (i in this._layers) {
|
|
8489 |
obj = this._layers[i];
|
|
8490 |
this._addItem(obj);
|
|
8491 |
overlaysPresent = overlaysPresent || obj.overlay;
|
|
8492 |
baseLayersPresent = baseLayersPresent || !obj.overlay;
|
|
8493 |
}
|
|
8494 |
|
|
8495 |
this._separator.style.display = overlaysPresent && baseLayersPresent ? '' : 'none';
|
|
8496 |
},
|
|
8497 |
|
|
8498 |
_onLayerChange: function (e) {
|
|
8499 |
var obj = this._layers[L.stamp(e.layer)];
|
|
8500 |
|
|
8501 |
if (!obj) { return; }
|
|
8502 |
|
|
8503 |
if (!this._handlingClick) {
|
|
8504 |
this._update();
|
|
8505 |
}
|
|
8506 |
|
|
8507 |
var type = obj.overlay ?
|
|
8508 |
(e.type === 'layeradd' ? 'overlayadd' : 'overlayremove') :
|
|
8509 |
(e.type === 'layeradd' ? 'baselayerchange' : null);
|
|
8510 |
|
|
8511 |
if (type) {
|
|
8512 |
this._map.fire(type, obj);
|
|
8513 |
}
|
|
8514 |
},
|
|
8515 |
|
|
8516 |
// IE7 bugs out if you create a radio dynamically, so you have to do it this hacky way (see http://bit.ly/PqYLBe)
|
|
8517 |
_createRadioElement: function (name, checked) {
|
|
8518 |
|
|
8519 |
var radioHtml = '<input type="radio" class="leaflet-control-layers-selector" name="' + name + '"';
|
|
8520 |
if (checked) {
|
|
8521 |
radioHtml += ' checked="checked"';
|
|
8522 |
}
|
|
8523 |
radioHtml += '/>';
|
|
8524 |
|
|
8525 |
var radioFragment = document.createElement('div');
|
|
8526 |
radioFragment.innerHTML = radioHtml;
|
|
8527 |
|
|
8528 |
return radioFragment.firstChild;
|
|
8529 |
},
|
|
8530 |
|
|
8531 |
_addItem: function (obj) {
|
|
8532 |
var label = document.createElement('label'),
|
|
8533 |
input,
|
|
8534 |
checked = this._map.hasLayer(obj.layer);
|
|
8535 |
|
|
8536 |
if (obj.overlay) {
|
|
8537 |
input = document.createElement('input');
|
|
8538 |
input.type = 'checkbox';
|
|
8539 |
input.className = 'leaflet-control-layers-selector';
|
|
8540 |
input.defaultChecked = checked;
|
|
8541 |
} else {
|
|
8542 |
input = this._createRadioElement('leaflet-base-layers', checked);
|
|
8543 |
}
|
|
8544 |
|
|
8545 |
input.layerId = L.stamp(obj.layer);
|
|
8546 |
|
|
8547 |
L.DomEvent.on(input, 'click', this._onInputClick, this);
|
|
8548 |
|
|
8549 |
var name = document.createElement('span');
|
|
8550 |
name.innerHTML = ' ' + obj.name;
|
|
8551 |
|
|
8552 |
label.appendChild(input);
|
|
8553 |
label.appendChild(name);
|
|
8554 |
|
|
8555 |
var container = obj.overlay ? this._overlaysList : this._baseLayersList;
|
|
8556 |
container.appendChild(label);
|
|
8557 |
|
|
8558 |
return label;
|
|
8559 |
},
|
|
8560 |
|
|
8561 |
_onInputClick: function () {
|
|
8562 |
var i, input, obj,
|
|
8563 |
inputs = this._form.getElementsByTagName('input'),
|
|
8564 |
inputsLen = inputs.length;
|
|
8565 |
|
|
8566 |
this._handlingClick = true;
|
|
8567 |
|
|
8568 |
for (i = 0; i < inputsLen; i++) {
|
|
8569 |
input = inputs[i];
|
|
8570 |
obj = this._layers[input.layerId];
|
|
8571 |
|
|
8572 |
if (input.checked && !this._map.hasLayer(obj.layer)) {
|
|
8573 |
this._map.addLayer(obj.layer);
|
|
8574 |
|
|
8575 |
} else if (!input.checked && this._map.hasLayer(obj.layer)) {
|
|
8576 |
this._map.removeLayer(obj.layer);
|
|
8577 |
}
|
|
8578 |
}
|
|
8579 |
|
|
8580 |
this._handlingClick = false;
|
|
8581 |
|
|
8582 |
this._refocusOnMap();
|
|
8583 |
},
|
|
8584 |
|
|
8585 |
_expand: function () {
|
|
8586 |
L.DomUtil.addClass(this._container, 'leaflet-control-layers-expanded');
|
|
8587 |
},
|
|
8588 |
|
|
8589 |
_collapse: function () {
|
|
8590 |
this._container.className = this._container.className.replace(' leaflet-control-layers-expanded', '');
|
|
8591 |
}
|
|
8592 |
});
|
|
8593 |
|
|
8594 |
L.control.layers = function (baseLayers, overlays, options) {
|
|
8595 |
return new L.Control.Layers(baseLayers, overlays, options);
|
|
8596 |
};
|
|
8597 |
|
|
8598 |
|
|
8599 |
/*
|
|
8600 |
* L.PosAnimation is used by Leaflet internally for pan animations.
|
|
8601 |
*/
|
|
8602 |
|
|
8603 |
L.PosAnimation = L.Class.extend({
|
|
8604 |
includes: L.Mixin.Events,
|
|
8605 |
|
|
8606 |
run: function (el, newPos, duration, easeLinearity) { // (HTMLElement, Point[, Number, Number])
|
|
8607 |
this.stop();
|
|
8608 |
|
|
8609 |
this._el = el;
|
|
8610 |
this._inProgress = true;
|
|
8611 |
this._newPos = newPos;
|
|
8612 |
|
|
8613 |
this.fire('start');
|
|
8614 |
|
|
8615 |
el.style[L.DomUtil.TRANSITION] = 'all ' + (duration || 0.25) +
|
|
8616 |
's cubic-bezier(0,0,' + (easeLinearity || 0.5) + ',1)';
|
|
8617 |
|
|
8618 |
L.DomEvent.on(el, L.DomUtil.TRANSITION_END, this._onTransitionEnd, this);
|
|
8619 |
L.DomUtil.setPosition(el, newPos);
|
|
8620 |
|
|
8621 |
// toggle reflow, Chrome flickers for some reason if you don't do this
|
|
8622 |
L.Util.falseFn(el.offsetWidth);
|
|
8623 |
|
|
8624 |
// there's no native way to track value updates of transitioned properties, so we imitate this
|
|
8625 |
this._stepTimer = setInterval(L.bind(this._onStep, this), 50);
|
|
8626 |
},
|
|
8627 |
|
|
8628 |
stop: function () {
|
|
8629 |
if (!this._inProgress) { return; }
|
|
8630 |
|
|
8631 |
// if we just removed the transition property, the element would jump to its final position,
|
|
8632 |
// so we need to make it stay at the current position
|
|
8633 |
|
|
8634 |
L.DomUtil.setPosition(this._el, this._getPos());
|
|
8635 |
this._onTransitionEnd();
|
|
8636 |
L.Util.falseFn(this._el.offsetWidth); // force reflow in case we are about to start a new animation
|
|
8637 |
},
|
|
8638 |
|
|
8639 |
_onStep: function () {
|
|
8640 |
var stepPos = this._getPos();
|
|
8641 |
if (!stepPos) {
|
|
8642 |
this._onTransitionEnd();
|
|
8643 |
return;
|
|
8644 |
}
|
|
8645 |
// jshint camelcase: false
|
|
8646 |
// make L.DomUtil.getPosition return intermediate position value during animation
|
|
8647 |
this._el._leaflet_pos = stepPos;
|
|
8648 |
|
|
8649 |
this.fire('step');
|
|
8650 |
},
|
|
8651 |
|
|
8652 |
// you can't easily get intermediate values of properties animated with CSS3 Transitions,
|
|
8653 |
// we need to parse computed style (in case of transform it returns matrix string)
|
|
8654 |
|
|
8655 |
_transformRe: /([-+]?(?:\d*\.)?\d+)\D*, ([-+]?(?:\d*\.)?\d+)\D*\)/,
|
|
8656 |
|
|
8657 |
_getPos: function () {
|
|
8658 |
var left, top, matches,
|
|
8659 |
el = this._el,
|
|
8660 |
style = window.getComputedStyle(el);
|
|
8661 |
|
|
8662 |
if (L.Browser.any3d) {
|
|
8663 |
matches = style[L.DomUtil.TRANSFORM].match(this._transformRe);
|
|
8664 |
if (!matches) { return; }
|
|
8665 |
left = parseFloat(matches[1]);
|
|
8666 |
top = parseFloat(matches[2]);
|
|
8667 |
} else {
|
|
8668 |
left = parseFloat(style.left);
|
|
8669 |
top = parseFloat(style.top);
|
|
8670 |
}
|
|
8671 |
|
|
8672 |
return new L.Point(left, top, true);
|
|
8673 |
},
|
|
8674 |
|
|
8675 |
_onTransitionEnd: function () {
|
|
8676 |
L.DomEvent.off(this._el, L.DomUtil.TRANSITION_END, this._onTransitionEnd, this);
|
|
8677 |
|
|
8678 |
if (!this._inProgress) { return; }
|
|
8679 |
this._inProgress = false;
|
|
8680 |
|
|
8681 |
this._el.style[L.DomUtil.TRANSITION] = '';
|
|
8682 |
|
|
8683 |
// jshint camelcase: false
|
|
8684 |
// make sure L.DomUtil.getPosition returns the final position value after animation
|
|
8685 |
this._el._leaflet_pos = this._newPos;
|
|
8686 |
|
|
8687 |
clearInterval(this._stepTimer);
|
|
8688 |
|
|
8689 |
this.fire('step').fire('end');
|
|
8690 |
}
|
|
8691 |
|
|
8692 |
});
|
|
8693 |
|
|
8694 |
|
|
8695 |
/*
|
|
8696 |
* Extends L.Map to handle panning animations.
|
|
8697 |
*/
|
|
8698 |
|
|
8699 |
L.Map.include({
|
|
8700 |
|
|
8701 |
setView: function (center, zoom, options) {
|
|
8702 |
|
|
8703 |
zoom = zoom === undefined ? this._zoom : this._limitZoom(zoom);
|
|
8704 |
center = this._limitCenter(L.latLng(center), zoom, this.options.maxBounds);
|
|
8705 |
options = options || {};
|
|
8706 |
|
|
8707 |
if (this._panAnim) {
|
|
8708 |
this._panAnim.stop();
|
|
8709 |
}
|
|
8710 |
|
|
8711 |
if (this._loaded && !options.reset && options !== true) {
|
|
8712 |
|
|
8713 |
if (options.animate !== undefined) {
|
|
8714 |
options.zoom = L.extend({animate: options.animate}, options.zoom);
|
|
8715 |
options.pan = L.extend({animate: options.animate}, options.pan);
|
|
8716 |
}
|
|
8717 |
|
|
8718 |
// try animating pan or zoom
|
|
8719 |
var animated = (this._zoom !== zoom) ?
|
|
8720 |
this._tryAnimatedZoom && this._tryAnimatedZoom(center, zoom, options.zoom) :
|
|
8721 |
this._tryAnimatedPan(center, options.pan);
|
|
8722 |
|
|
8723 |
if (animated) {
|
|
8724 |
// prevent resize handler call, the view will refresh after animation anyway
|
|
8725 |
clearTimeout(this._sizeTimer);
|
|
8726 |
return this;
|
|
8727 |
}
|
|
8728 |
}
|
|
8729 |
|
|
8730 |
// animation didn't start, just reset the map view
|
|
8731 |
this._resetView(center, zoom);
|
|
8732 |
|
|
8733 |
return this;
|
|
8734 |
},
|
|
8735 |
|
|
8736 |
panBy: function (offset, options) {
|
|
8737 |
offset = L.point(offset).round();
|
|
8738 |
options = options || {};
|
|
8739 |
|
|
8740 |
if (!offset.x && !offset.y) {
|
|
8741 |
return this;
|
|
8742 |
}
|
|
8743 |
|
|
8744 |
if (!this._panAnim) {
|
|
8745 |
this._panAnim = new L.PosAnimation();
|
|
8746 |
|
|
8747 |
this._panAnim.on({
|
|
8748 |
'step': this._onPanTransitionStep,
|
|
8749 |
'end': this._onPanTransitionEnd
|
|
8750 |
}, this);
|
|
8751 |
}
|
|
8752 |
|
|
8753 |
// don't fire movestart if animating inertia
|
|
8754 |
if (!options.noMoveStart) {
|
|
8755 |
this.fire('movestart');
|
|
8756 |
}
|
|
8757 |
|
|
8758 |
// animate pan unless animate: false specified
|
|
8759 |
if (options.animate !== false) {
|
|
8760 |
L.DomUtil.addClass(this._mapPane, 'leaflet-pan-anim');
|
|
8761 |
|
|
8762 |
var newPos = this._getMapPanePos().subtract(offset);
|
|
8763 |
this._panAnim.run(this._mapPane, newPos, options.duration || 0.25, options.easeLinearity);
|
|
8764 |
} else {
|
|
8765 |
this._rawPanBy(offset);
|
|
8766 |
this.fire('move').fire('moveend');
|
|
8767 |
}
|
|
8768 |
|
|
8769 |
return this;
|
|
8770 |
},
|
|
8771 |
|
|
8772 |
_onPanTransitionStep: function () {
|
|
8773 |
this.fire('move');
|
|
8774 |
},
|
|
8775 |
|
|
8776 |
_onPanTransitionEnd: function () {
|
|
8777 |
L.DomUtil.removeClass(this._mapPane, 'leaflet-pan-anim');
|
|
8778 |
this.fire('moveend');
|
|
8779 |
},
|
|
8780 |
|
|
8781 |
_tryAnimatedPan: function (center, options) {
|
|
8782 |
// difference between the new and current centers in pixels
|
|
8783 |
var offset = this._getCenterOffset(center)._floor();
|
|
8784 |
|
|
8785 |
// don't animate too far unless animate: true specified in options
|
|
8786 |
if ((options && options.animate) !== true && !this.getSize().contains(offset)) { return false; }
|
|
8787 |
|
|
8788 |
this.panBy(offset, options);
|
|
8789 |
|
|
8790 |
return true;
|
|
8791 |
}
|
|
8792 |
});
|
|
8793 |
|
|
8794 |
|
|
8795 |
/*
|
|
8796 |
* L.PosAnimation fallback implementation that powers Leaflet pan animations
|
|
8797 |
* in browsers that don't support CSS3 Transitions.
|
|
8798 |
*/
|
|
8799 |
|
|
8800 |
L.PosAnimation = L.DomUtil.TRANSITION ? L.PosAnimation : L.PosAnimation.extend({
|
|
8801 |
|
|
8802 |
run: function (el, newPos, duration, easeLinearity) { // (HTMLElement, Point[, Number, Number])
|
|
8803 |
this.stop();
|
|
8804 |
|
|
8805 |
this._el = el;
|
|
8806 |
this._inProgress = true;
|
|
8807 |
this._duration = duration || 0.25;
|
|
8808 |
this._easeOutPower = 1 / Math.max(easeLinearity || 0.5, 0.2);
|
|
8809 |
|
|
8810 |
this._startPos = L.DomUtil.getPosition(el);
|
|
8811 |
this._offset = newPos.subtract(this._startPos);
|
|
8812 |
this._startTime = +new Date();
|
|
8813 |
|
|
8814 |
this.fire('start');
|
|
8815 |
|
|
8816 |
this._animate();
|
|
8817 |
},
|
|
8818 |
|
|
8819 |
stop: function () {
|
|
8820 |
if (!this._inProgress) { return; }
|
|
8821 |
|
|
8822 |
this._step();
|
|
8823 |
this._complete();
|
|
8824 |
},
|
|
8825 |
|
|
8826 |
_animate: function () {
|
|
8827 |
// animation loop
|
|
8828 |
this._animId = L.Util.requestAnimFrame(this._animate, this);
|
|
8829 |
this._step();
|
|
8830 |
},
|
|
8831 |
|
|
8832 |
_step: function () {
|
|
8833 |
var elapsed = (+new Date()) - this._startTime,
|
|
8834 |
duration = this._duration * 1000;
|
|
8835 |
|
|
8836 |
if (elapsed < duration) {
|
|
8837 |
this._runFrame(this._easeOut(elapsed / duration));
|
|
8838 |
} else {
|
|
8839 |
this._runFrame(1);
|
|
8840 |
this._complete();
|
|
8841 |
}
|
|
8842 |
},
|
|
8843 |
|
|
8844 |
_runFrame: function (progress) {
|
|
8845 |
var pos = this._startPos.add(this._offset.multiplyBy(progress));
|
|
8846 |
L.DomUtil.setPosition(this._el, pos);
|
|
8847 |
|
|
8848 |
this.fire('step');
|
|
8849 |
},
|
|
8850 |
|
|
8851 |
_complete: function () {
|
|
8852 |
L.Util.cancelAnimFrame(this._animId);
|
|
8853 |
|
|
8854 |
this._inProgress = false;
|
|
8855 |
this.fire('end');
|
|
8856 |
},
|
|
8857 |
|
|
8858 |
_easeOut: function (t) {
|
|
8859 |
return 1 - Math.pow(1 - t, this._easeOutPower);
|
|
8860 |
}
|
|
8861 |
});
|
|
8862 |
|
|
8863 |
|
|
8864 |
/*
|
|
8865 |
* Extends L.Map to handle zoom animations.
|
|
8866 |
*/
|
|
8867 |
|
|
8868 |
L.Map.mergeOptions({
|
|
8869 |
zoomAnimation: true,
|
|
8870 |
zoomAnimationThreshold: 4
|
|
8871 |
});
|
|
8872 |
|
|
8873 |
if (L.DomUtil.TRANSITION) {
|
|
8874 |
|
|
8875 |
L.Map.addInitHook(function () {
|
|
8876 |
// don't animate on browsers without hardware-accelerated transitions or old Android/Opera
|
|
8877 |
this._zoomAnimated = this.options.zoomAnimation && L.DomUtil.TRANSITION &&
|
|
8878 |
L.Browser.any3d && !L.Browser.android23 && !L.Browser.mobileOpera;
|
|
8879 |
|
|
8880 |
// zoom transitions run with the same duration for all layers, so if one of transitionend events
|
|
8881 |
// happens after starting zoom animation (propagating to the map pane), we know that it ended globally
|
|
8882 |
if (this._zoomAnimated) {
|
|
8883 |
L.DomEvent.on(this._mapPane, L.DomUtil.TRANSITION_END, this._catchTransitionEnd, this);
|
|
8884 |
}
|
|
8885 |
});
|
|
8886 |
}
|
|
8887 |
|
|
8888 |
L.Map.include(!L.DomUtil.TRANSITION ? {} : {
|
|
8889 |
|
|
8890 |
_catchTransitionEnd: function (e) {
|
|
8891 |
if (this._animatingZoom && e.propertyName.indexOf('transform') >= 0) {
|
|
8892 |
this._onZoomTransitionEnd();
|
|
8893 |
}
|
|
8894 |
},
|
|
8895 |
|
|
8896 |
_nothingToAnimate: function () {
|
|
8897 |
return !this._container.getElementsByClassName('leaflet-zoom-animated').length;
|
|
8898 |
},
|
|
8899 |
|
|
8900 |
_tryAnimatedZoom: function (center, zoom, options) {
|
|
8901 |
|
|
8902 |
if (this._animatingZoom) { return true; }
|
|
8903 |
|
|
8904 |
options = options || {};
|
|
8905 |
|
|
8906 |
// don't animate if disabled, not supported or zoom difference is too large
|
|
8907 |
if (!this._zoomAnimated || options.animate === false || this._nothingToAnimate() ||
|
|
8908 |
Math.abs(zoom - this._zoom) > this.options.zoomAnimationThreshold) { return false; }
|
|
8909 |
|
|
8910 |
// offset is the pixel coords of the zoom origin relative to the current center
|
|
8911 |
var scale = this.getZoomScale(zoom),
|
|
8912 |
offset = this._getCenterOffset(center)._divideBy(1 - 1 / scale),
|
|
8913 |
origin = this._getCenterLayerPoint()._add(offset);
|
|
8914 |
|
|
8915 |
// don't animate if the zoom origin isn't within one screen from the current center, unless forced
|
|
8916 |
if (options.animate !== true && !this.getSize().contains(offset)) { return false; }
|
|
8917 |
|
|
8918 |
this
|
|
8919 |
.fire('movestart')
|
|
8920 |
.fire('zoomstart');
|
|
8921 |
|
|
8922 |
this._animateZoom(center, zoom, origin, scale, null, true);
|
|
8923 |
|
|
8924 |
return true;
|
|
8925 |
},
|
|
8926 |
|
|
8927 |
_animateZoom: function (center, zoom, origin, scale, delta, backwards, forTouchZoom) {
|
|
8928 |
|
|
8929 |
if (!forTouchZoom) {
|
|
8930 |
this._animatingZoom = true;
|
|
8931 |
}
|
|
8932 |
|
|
8933 |
// put transform transition on all layers with leaflet-zoom-animated class
|
|
8934 |
L.DomUtil.addClass(this._mapPane, 'leaflet-zoom-anim');
|
|
8935 |
|
|
8936 |
// remember what center/zoom to set after animation
|
|
8937 |
this._animateToCenter = center;
|
|
8938 |
this._animateToZoom = zoom;
|
|
8939 |
|
|
8940 |
// disable any dragging during animation
|
|
8941 |
if (L.Draggable) {
|
|
8942 |
L.Draggable._disabled = true;
|
|
8943 |
}
|
|
8944 |
|
|
8945 |
L.Util.requestAnimFrame(function () {
|
|
8946 |
this.fire('zoomanim', {
|
|
8947 |
center: center,
|
|
8948 |
zoom: zoom,
|
|
8949 |
origin: origin,
|
|
8950 |
scale: scale,
|
|
8951 |
delta: delta,
|
|
8952 |
backwards: backwards
|
|
8953 |
});
|
|
8954 |
}, this);
|
|
8955 |
},
|
|
8956 |
|
|
8957 |
_onZoomTransitionEnd: function () {
|
|
8958 |
|
|
8959 |
this._animatingZoom = false;
|
|
8960 |
|
|
8961 |
L.DomUtil.removeClass(this._mapPane, 'leaflet-zoom-anim');
|
|
8962 |
|
|
8963 |
this._resetView(this._animateToCenter, this._animateToZoom, true, true);
|
|
8964 |
|
|
8965 |
if (L.Draggable) {
|
|
8966 |
L.Draggable._disabled = false;
|
|
8967 |
}
|
|
8968 |
}
|
|
8969 |
});
|
|
8970 |
|
|
8971 |
|
|
8972 |
/*
|
|
8973 |
Zoom animation logic for L.TileLayer.
|
|
8974 |
*/
|
|
8975 |
|
|
8976 |
L.TileLayer.include({
|
|
8977 |
_animateZoom: function (e) {
|
|
8978 |
if (!this._animating) {
|
|
8979 |
this._animating = true;
|
|
8980 |
this._prepareBgBuffer();
|
|
8981 |
}
|
|
8982 |
|
|
8983 |
var bg = this._bgBuffer,
|
|
8984 |
transform = L.DomUtil.TRANSFORM,
|
|
8985 |
initialTransform = e.delta ? L.DomUtil.getTranslateString(e.delta) : bg.style[transform],
|
|
8986 |
scaleStr = L.DomUtil.getScaleString(e.scale, e.origin);
|
|
8987 |
|
|
8988 |
bg.style[transform] = e.backwards ?
|
|
8989 |
scaleStr + ' ' + initialTransform :
|
|
8990 |
initialTransform + ' ' + scaleStr;
|
|
8991 |
},
|
|
8992 |
|
|
8993 |
_endZoomAnim: function () {
|
|
8994 |
var front = this._tileContainer,
|
|
8995 |
bg = this._bgBuffer;
|
|
8996 |
|
|
8997 |
front.style.visibility = '';
|
|
8998 |
front.parentNode.appendChild(front); // Bring to fore
|
|
8999 |
|
|
9000 |
// force reflow
|
|
9001 |
L.Util.falseFn(bg.offsetWidth);
|
|
9002 |
|
|
9003 |
this._animating = false;
|
|
9004 |
},
|
|
9005 |
|
|
9006 |
_clearBgBuffer: function () {
|
|
9007 |
var map = this._map;
|
|
9008 |
|
|
9009 |
if (map && !map._animatingZoom && !map.touchZoom._zooming) {
|
|
9010 |
this._bgBuffer.innerHTML = '';
|
|
9011 |
this._bgBuffer.style[L.DomUtil.TRANSFORM] = '';
|
|
9012 |
}
|
|
9013 |
},
|
|
9014 |
|
|
9015 |
_prepareBgBuffer: function () {
|
|
9016 |
|
|
9017 |
var front = this._tileContainer,
|
|
9018 |
bg = this._bgBuffer;
|
|
9019 |
|
|
9020 |
// if foreground layer doesn't have many tiles but bg layer does,
|
|
9021 |
// keep the existing bg layer and just zoom it some more
|
|
9022 |
|
|
9023 |
var bgLoaded = this._getLoadedTilesPercentage(bg),
|
|
9024 |
frontLoaded = this._getLoadedTilesPercentage(front);
|
|
9025 |
|
|
9026 |
if (bg && bgLoaded > 0.5 && frontLoaded < 0.5) {
|
|
9027 |
|
|
9028 |
front.style.visibility = 'hidden';
|
|
9029 |
this._stopLoadingImages(front);
|
|
9030 |
return;
|
|
9031 |
}
|
|
9032 |
|
|
9033 |
// prepare the buffer to become the front tile pane
|
|
9034 |
bg.style.visibility = 'hidden';
|
|
9035 |
bg.style[L.DomUtil.TRANSFORM] = '';
|
|
9036 |
|
|
9037 |
// switch out the current layer to be the new bg layer (and vice-versa)
|
|
9038 |
this._tileContainer = bg;
|
|
9039 |
bg = this._bgBuffer = front;
|
|
9040 |
|
|
9041 |
this._stopLoadingImages(bg);
|
|
9042 |
|
|
9043 |
//prevent bg buffer from clearing right after zoom
|
|
9044 |
clearTimeout(this._clearBgBufferTimer);
|
|
9045 |
},
|
|
9046 |
|
|
9047 |
_getLoadedTilesPercentage: function (container) {
|
|
9048 |
var tiles = container.getElementsByTagName('img'),
|
|
9049 |
i, len, count = 0;
|
|
9050 |
|
|
9051 |
for (i = 0, len = tiles.length; i < len; i++) {
|
|
9052 |
if (tiles[i].complete) {
|
|
9053 |
count++;
|
|
9054 |
}
|
|
9055 |
}
|
|
9056 |
return count / len;
|
|
9057 |
},
|
|
9058 |
|
|
9059 |
// stops loading all tiles in the background layer
|
|
9060 |
_stopLoadingImages: function (container) {
|
|
9061 |
var tiles = Array.prototype.slice.call(container.getElementsByTagName('img')),
|
|
9062 |
i, len, tile;
|
|
9063 |
|
|
9064 |
for (i = 0, len = tiles.length; i < len; i++) {
|
|
9065 |
tile = tiles[i];
|
|
9066 |
|
|
9067 |
if (!tile.complete) {
|
|
9068 |
tile.onload = L.Util.falseFn;
|
|
9069 |
tile.onerror = L.Util.falseFn;
|
|
9070 |
tile.src = L.Util.emptyImageUrl;
|
|
9071 |
|
|
9072 |
tile.parentNode.removeChild(tile);
|
|
9073 |
}
|
|
9074 |
}
|
|
9075 |
}
|
|
9076 |
});
|
|
9077 |
|
|
9078 |
|
|
9079 |
/*
|
|
9080 |
* Provides L.Map with convenient shortcuts for using browser geolocation features.
|
|
9081 |
*/
|
|
9082 |
|
|
9083 |
L.Map.include({
|
|
9084 |
_defaultLocateOptions: {
|
|
9085 |
watch: false,
|
|
9086 |
setView: false,
|
|
9087 |
maxZoom: Infinity,
|
|
9088 |
timeout: 10000,
|
|
9089 |
maximumAge: 0,
|
|
9090 |
enableHighAccuracy: false
|
|
9091 |
},
|
|
9092 |
|
|
9093 |
locate: function (/*Object*/ options) {
|
|
9094 |
|
|
9095 |
options = this._locateOptions = L.extend(this._defaultLocateOptions, options);
|
|
9096 |
|
|
9097 |
if (!navigator.geolocation) {
|
|
9098 |
this._handleGeolocationError({
|
|
9099 |
code: 0,
|
|
9100 |
message: 'Geolocation not supported.'
|
|
9101 |
});
|
|
9102 |
return this;
|
|
9103 |
}
|
|
9104 |
|
|
9105 |
var onResponse = L.bind(this._handleGeolocationResponse, this),
|
|
9106 |
onError = L.bind(this._handleGeolocationError, this);
|
|
9107 |
|
|
9108 |
if (options.watch) {
|
|
9109 |
this._locationWatchId =
|
|
9110 |
navigator.geolocation.watchPosition(onResponse, onError, options);
|
|
9111 |
} else {
|
|
9112 |
navigator.geolocation.getCurrentPosition(onResponse, onError, options);
|
|
9113 |
}
|
|
9114 |
return this;
|
|
9115 |
},
|
|
9116 |
|
|
9117 |
stopLocate: function () {
|
|
9118 |
if (navigator.geolocation) {
|
|
9119 |
navigator.geolocation.clearWatch(this._locationWatchId);
|
|
9120 |
}
|
|
9121 |
if (this._locateOptions) {
|
|
9122 |
this._locateOptions.setView = false;
|
|
9123 |
}
|
|
9124 |
return this;
|
|
9125 |
},
|
|
9126 |
|
|
9127 |
_handleGeolocationError: function (error) {
|
|
9128 |
var c = error.code,
|
|
9129 |
message = error.message ||
|
|
9130 |
(c === 1 ? 'permission denied' :
|
|
9131 |
(c === 2 ? 'position unavailable' : 'timeout'));
|
|
9132 |
|
|
9133 |
if (this._locateOptions.setView && !this._loaded) {
|
|
9134 |
this.fitWorld();
|
|
9135 |
}
|
|
9136 |
|
|
9137 |
this.fire('locationerror', {
|
|
9138 |
code: c,
|
|
9139 |
message: 'Geolocation error: ' + message + '.'
|
|
9140 |
});
|
|
9141 |
},
|
|
9142 |
|
|
9143 |
_handleGeolocationResponse: function (pos) {
|
|
9144 |
var lat = pos.coords.latitude,
|
|
9145 |
lng = pos.coords.longitude,
|
|
9146 |
latlng = new L.LatLng(lat, lng),
|
|
9147 |
|
|
9148 |
latAccuracy = 180 * pos.coords.accuracy / 40075017,
|
|
9149 |
lngAccuracy = latAccuracy / Math.cos(L.LatLng.DEG_TO_RAD * lat),
|
|
9150 |
|
|
9151 |
bounds = L.latLngBounds(
|
|
9152 |
[lat - latAccuracy, lng - lngAccuracy],
|
|
9153 |
[lat + latAccuracy, lng + lngAccuracy]),
|
|
9154 |
|
|
9155 |
options = this._locateOptions;
|
|
9156 |
|
|
9157 |
if (options.setView) {
|
|
9158 |
var zoom = Math.min(this.getBoundsZoom(bounds), options.maxZoom);
|
|
9159 |
this.setView(latlng, zoom);
|
|
9160 |
}
|
|
9161 |
|
|
9162 |
var data = {
|
|
9163 |
latlng: latlng,
|
|
9164 |
bounds: bounds,
|
|
9165 |
timestamp: pos.timestamp
|
|
9166 |
};
|
|
9167 |
|
|
9168 |
for (var i in pos.coords) {
|
|
9169 |
if (typeof pos.coords[i] === 'number') {
|
|
9170 |
data[i] = pos.coords[i];
|
|
9171 |
}
|
|
9172 |
}
|
|
9173 |
|
|
9174 |
this.fire('locationfound', data);
|
|
9175 |
}
|
|
9176 |
});
|
|
9177 |
|
|
9178 |
|
|
9179 |
}(window, document));⏎
|