Codebase list leaflet / 102f484
Imported Upstream version 0.7.3 Jonas Smedegaard 9 years ago
20 changed file(s) with 9401 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
1616 test ${TRAVIS_BRANCH} = master ||
1717 test ${TRAVIS_BRANCH} = stable &&
1818 test ${TRAVIS_PULL_REQUEST} = false &&
19 gem install travis-artifacts || true
19 gem install --no-rdoc --no-ri --version 0.8.9 faraday &&
20 gem install --no-rdoc --no-ri travis-artifacts || true
2021 after_success: >
2122 test ${TRAVIS_BRANCH} = master ||
2223 test ${TRAVIS_BRANCH} = stable &&
11 =================
22
33 (all changes without author notice are by [@mourner](https://github.com/mourner))
4
5 ## 0.7.3-dev (stable branch)
6
7 * Added proper **bower** and **component** support (by [@calvinmetcalf](https://github.com/calvinmetcalf)). [#2561](https://github.com/Leaflet/Leaflet/pull/2561) [#1903](https://github.com/Leaflet/Leaflet/issues/1903)
8 * Fixed a bug where dragging the map outside the window caused an error on FF. [#2610](https://github.com/Leaflet/Leaflet/issues/2610)
9 * Fixed a bug where some taps on Android where not working, often falsely perceived as drags (by [@axefrog](https://github.com/axefrog)). [#2503](https://github.com/Leaflet/Leaflet/pull/2503)
10 * Fixed a bug where tapping too quickly on Android ignored most taps. [#2303](https://github.com/Leaflet/Leaflet/issues/2303)
11 * Fixed a bug where calling `setView` (or similar methods) several times in succession could freeze the map. [#2521](https://github.com/Leaflet/Leaflet/issues/2521) [#2236](https://github.com/Leaflet/Leaflet/issues/2236) [#2485](https://github.com/Leaflet/Leaflet/issues/2485)
12 * Fixed a bug where `Control.Layers` wasn't properly removed (by [@jack-kerouac](https://github.com/jack-kerouac)). [#2569](https://github.com/Leaflet/Leaflet/pull/2569)
13 * Fixed a bug that caused `TileLayer` `load` event not to fire properly. [#2510](https://github.com/Leaflet/Leaflet/issues/2510)
14 * Fixed Canvas-based paths not triggering `remove` event when removed (by @adimitrov). [#2486](https://github.com/Leaflet/Leaflet/pull/2486)
15 * Fixed a bug where you could end up with fractional zoom after pinch-zooming in some cases (by [@danzel](https://github.com/danzel). [#2400](https://github.com/Leaflet/Leaflet/pull/2400) [#1943](https://github.com/Leaflet/Leaflet/issues/1934)
416
517 ## 0.7.2 (January 17, 2013)
618
0 {
1 "name": "leaflet",
2 "version": "0.7.3",
3 "description": "JavaScript library for mobile-friendly interactive maps",
4 "main": [
5 "dist/leaflet.js",
6 "dist/leaflet.css",
7 "dist/leaflet-src.js",
8 "dist/images/layers-2x.png",
9 "dist/images/layers.png",
10 "dist/images/marker-icon-2x.png",
11 "dist/images/marker-icon.png",
12 "dist/images/marker-shadow.png"
13 ],
14 "ignore": [
15 ".*",
16 "CHANGELOG.json",
17 "FAQ.md",
18 "debug",
19 "spec",
20 "src",
21 "build"
22 ]
23 }
0 {
1 "name": "leaflet",
2 "description": "JavaScript library for mobile-friendly interactive maps",
3 "main": [
4 "dist/leaflet.js",
5 "dist/leaflet.css",
6 "dist/leaflet-src.js",
7 "dist/images/layers-2x.png",
8 "dist/images/layers.png",
9 "dist/images/marker-icon-2x.png",
10 "dist/images/marker-icon.png",
11 "dist/images/marker-shadow.png"
12 ],
13 "ignore": [
14 ".*",
15 "CHANGELOG.json",
16 "FAQ.md",
17 "debug",
18 "spec",
19 "src",
20 "build"
21 ]
22 }
0 {
1 "name": "leaflet",
2 "description": "JavaScript library for mobile-friendly interactive maps",
3 "scripts": [
4 "dist/leaflet.js",
5 "dist/leaflet-src.js"
6 ],
7 "images":[
8 "dist/images/layers-2x.png",
9 "dist/images/layers.png",
10 "dist/images/marker-icon-2x.png",
11 "dist/images/marker-icon.png",
12 "dist/images/marker-shadow.png"
13 ],
14 "styles":[
15 "dist/leaflet.css"
16 ],
17 "main": "dist/leaflet-src.js"
18 }
0 #!/bin/bash
1
2 # get current version
3 VERSION=$(node --eval "console.log(require('./package.json').version);")
4
5 # Build
6 git checkout -b build
7 npm test || exit 1
8 npm run prepublish
9 git add dist/leaflet-src.js dist/leaflet.js -f
10
11 # create the bower and component files
12 node_modules/copyfiles/copyfiles -u 1 build/*.json ./
13 node_modules/tin/bin/tin -v $VERSION
14 git add component.json bower.json -f
15
16 git commit -m "build v$VERSION"
17
18 # Tag and push
19 git tag v$VERSION
20 git push --tags --force
21
22 # # # Cleanup
23 git checkout stable
24 git branch -D build
0 {
1 "name": "leaflet",
2 "version": "0.7.3",
3 "description": "JavaScript library for mobile-friendly interactive maps",
4 "scripts": [
5 "dist/leaflet.js",
6 "dist/leaflet-src.js"
7 ],
8 "images": [
9 "dist/images/layers-2x.png",
10 "dist/images/layers.png",
11 "dist/images/marker-icon-2x.png",
12 "dist/images/marker-icon.png",
13 "dist/images/marker-shadow.png"
14 ],
15 "styles": [
16 "dist/leaflet.css"
17 ],
18 "main": "dist/leaflet-src.js"
19 }
0 <!DOCTYPE html>
1 <html>
2 <head>
3 <title>Leaflet debug page</title>
4
5 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
6
7 <link rel="stylesheet" href="../css/screen.css" />
8
9 <link rel="stylesheet" href="../../dist/leaflet.css" />
10 </head>
11 <body>
12 <div id="map" style=></div>
13 <script type="text/javascript" src="../../build/deps.js"></script>
14 <script src="../leaflet-include.js"></script>
15 <script>
16 map = L.map('map');
17 L.tileLayer('http://otile1.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg').addTo(map);
18 map.setView([51.505, -0.09], 15);
19 L.circleMarker([51.5, -0.09], {}).addTo(map);
20 L.marker([51.505, -0.09]).addTo(map);
21 map.setZoom(14); //comment this to make it work
22 </script>
23 </body>
24 </html>
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 = '&#215;';
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));
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(t,e,i){var n=t.L,o={};o.version="0.7.3","object"==typeof module&&"object"==typeof module.exports?module.exports=o:"function"==typeof define&&define.amd&&define(o),o.noConflict=function(){return t.L=n,this},t.L=o,o.Util={extend:function(t){var e,i,n,o,s=Array.prototype.slice.call(arguments,1);for(i=0,n=s.length;n>i;i++){o=s[i]||{};for(e in o)o.hasOwnProperty(e)&&(t[e]=o[e])}return t},bind:function(t,e){var i=arguments.length>2?Array.prototype.slice.call(arguments,2):null;return function(){return t.apply(e,i||arguments)}},stamp:function(){var t=0,e="_leaflet_id";return function(i){return i[e]=i[e]||++t,i[e]}}(),invokeEach:function(t,e,i){var n,o;if("object"==typeof t){o=Array.prototype.slice.call(arguments,3);for(n in t)e.apply(i,[n,t[n]].concat(o));return!0}return!1},limitExecByInterval:function(t,e,i){var n,o;return function s(){var a=arguments;return n?void(o=!0):(n=!0,setTimeout(function(){n=!1,o&&(s.apply(i,a),o=!1)},e),void t.apply(i,a))}},falseFn:function(){return!1},formatNum:function(t,e){var i=Math.pow(10,e||5);return Math.round(t*i)/i},trim:function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")},splitWords:function(t){return o.Util.trim(t).split(/\s+/)},setOptions:function(t,e){return t.options=o.extend({},t.options,e),t.options},getParamString:function(t,e,i){var n=[];for(var o in t)n.push(encodeURIComponent(i?o.toUpperCase():o)+"="+encodeURIComponent(t[o]));return(e&&-1!==e.indexOf("?")?"&":"?")+n.join("&")},template:function(t,e){return t.replace(/\{ *([\w_]+) *\}/g,function(t,n){var o=e[n];if(o===i)throw new Error("No value provided for variable "+t);return"function"==typeof o&&(o=o(e)),o})},isArray:Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)},emptyImageUrl:"data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs="},function(){function e(e){var i,n,o=["webkit","moz","o","ms"];for(i=0;i<o.length&&!n;i++)n=t[o[i]+e];return n}function i(e){var i=+new Date,o=Math.max(0,16-(i-n));return n=i+o,t.setTimeout(e,o)}var n=0,s=t.requestAnimationFrame||e("RequestAnimationFrame")||i,a=t.cancelAnimationFrame||e("CancelAnimationFrame")||e("CancelRequestAnimationFrame")||function(e){t.clearTimeout(e)};o.Util.requestAnimFrame=function(e,n,a,r){return e=o.bind(e,n),a&&s===i?void e():s.call(t,e,r)},o.Util.cancelAnimFrame=function(e){e&&a.call(t,e)}}(),o.extend=o.Util.extend,o.bind=o.Util.bind,o.stamp=o.Util.stamp,o.setOptions=o.Util.setOptions,o.Class=function(){},o.Class.extend=function(t){var e=function(){this.initialize&&this.initialize.apply(this,arguments),this._initHooks&&this.callInitHooks()},i=function(){};i.prototype=this.prototype;var n=new i;n.constructor=e,e.prototype=n;for(var s in this)this.hasOwnProperty(s)&&"prototype"!==s&&(e[s]=this[s]);t.statics&&(o.extend(e,t.statics),delete t.statics),t.includes&&(o.Util.extend.apply(null,[n].concat(t.includes)),delete t.includes),t.options&&n.options&&(t.options=o.extend({},n.options,t.options)),o.extend(n,t),n._initHooks=[];var a=this;return e.__super__=a.prototype,n.callInitHooks=function(){if(!this._initHooksCalled){a.prototype.callInitHooks&&a.prototype.callInitHooks.call(this),this._initHooksCalled=!0;for(var t=0,e=n._initHooks.length;e>t;t++)n._initHooks[t].call(this)}},e},o.Class.include=function(t){o.extend(this.prototype,t)},o.Class.mergeOptions=function(t){o.extend(this.prototype.options,t)},o.Class.addInitHook=function(t){var e=Array.prototype.slice.call(arguments,1),i="function"==typeof t?t:function(){this[t].apply(this,e)};this.prototype._initHooks=this.prototype._initHooks||[],this.prototype._initHooks.push(i)};var s="_leaflet_events";o.Mixin={},o.Mixin.Events={addEventListener:function(t,e,i){if(o.Util.invokeEach(t,this.addEventListener,this,e,i))return this;var n,a,r,h,l,u,c,d=this[s]=this[s]||{},p=i&&i!==this&&o.stamp(i);for(t=o.Util.splitWords(t),n=0,a=t.length;a>n;n++)r={action:e,context:i||this},h=t[n],p?(l=h+"_idx",u=l+"_len",c=d[l]=d[l]||{},c[p]||(c[p]=[],d[u]=(d[u]||0)+1),c[p].push(r)):(d[h]=d[h]||[],d[h].push(r));return this},hasEventListeners:function(t){var e=this[s];return!!e&&(t in e&&e[t].length>0||t+"_idx"in e&&e[t+"_idx_len"]>0)},removeEventListener:function(t,e,i){if(!this[s])return this;if(!t)return this.clearAllEventListeners();if(o.Util.invokeEach(t,this.removeEventListener,this,e,i))return this;var n,a,r,h,l,u,c,d,p,_=this[s],m=i&&i!==this&&o.stamp(i);for(t=o.Util.splitWords(t),n=0,a=t.length;a>n;n++)if(r=t[n],u=r+"_idx",c=u+"_len",d=_[u],e){if(h=m&&d?d[m]:_[r]){for(l=h.length-1;l>=0;l--)h[l].action!==e||i&&h[l].context!==i||(p=h.splice(l,1),p[0].action=o.Util.falseFn);i&&d&&0===h.length&&(delete d[m],_[c]--)}}else delete _[r],delete _[u],delete _[c];return this},clearAllEventListeners:function(){return delete this[s],this},fireEvent:function(t,e){if(!this.hasEventListeners(t))return this;var i,n,a,r,h,l=o.Util.extend({},e,{type:t,target:this}),u=this[s];if(u[t])for(i=u[t].slice(),n=0,a=i.length;a>n;n++)i[n].action.call(i[n].context,l);r=u[t+"_idx"];for(h in r)if(i=r[h].slice())for(n=0,a=i.length;a>n;n++)i[n].action.call(i[n].context,l);return this},addOneTimeEventListener:function(t,e,i){if(o.Util.invokeEach(t,this.addOneTimeEventListener,this,e,i))return this;var n=o.bind(function(){this.removeEventListener(t,e,i).removeEventListener(t,n,i)},this);return this.addEventListener(t,e,i).addEventListener(t,n,i)}},o.Mixin.Events.on=o.Mixin.Events.addEventListener,o.Mixin.Events.off=o.Mixin.Events.removeEventListener,o.Mixin.Events.once=o.Mixin.Events.addOneTimeEventListener,o.Mixin.Events.fire=o.Mixin.Events.fireEvent,function(){var n="ActiveXObject"in t,s=n&&!e.addEventListener,a=navigator.userAgent.toLowerCase(),r=-1!==a.indexOf("webkit"),h=-1!==a.indexOf("chrome"),l=-1!==a.indexOf("phantom"),u=-1!==a.indexOf("android"),c=-1!==a.search("android [23]"),d=-1!==a.indexOf("gecko"),p=typeof orientation!=i+"",_=t.navigator&&t.navigator.msPointerEnabled&&t.navigator.msMaxTouchPoints&&!t.PointerEvent,m=t.PointerEvent&&t.navigator.pointerEnabled&&t.navigator.maxTouchPoints||_,f="devicePixelRatio"in t&&t.devicePixelRatio>1||"matchMedia"in t&&t.matchMedia("(min-resolution:144dpi)")&&t.matchMedia("(min-resolution:144dpi)").matches,g=e.documentElement,v=n&&"transition"in g.style,y="WebKitCSSMatrix"in t&&"m11"in new t.WebKitCSSMatrix&&!c,P="MozPerspective"in g.style,L="OTransition"in g.style,x=!t.L_DISABLE_3D&&(v||y||P||L)&&!l,w=!t.L_NO_TOUCH&&!l&&function(){var t="ontouchstart";if(m||t in g)return!0;var i=e.createElement("div"),n=!1;return i.setAttribute?(i.setAttribute(t,"return;"),"function"==typeof i[t]&&(n=!0),i.removeAttribute(t),i=null,n):!1}();o.Browser={ie:n,ielt9:s,webkit:r,gecko:d&&!r&&!t.opera&&!n,android:u,android23:c,chrome:h,ie3d:v,webkit3d:y,gecko3d:P,opera3d:L,any3d:x,mobile:p,mobileWebkit:p&&r,mobileWebkit3d:p&&y,mobileOpera:p&&t.opera,touch:w,msPointer:_,pointer:m,retina:f}}(),o.Point=function(t,e,i){this.x=i?Math.round(t):t,this.y=i?Math.round(e):e},o.Point.prototype={clone:function(){return new o.Point(this.x,this.y)},add:function(t){return this.clone()._add(o.point(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(o.point(t))},_subtract:function(t){return this.x-=t.x,this.y-=t.y,this},divideBy:function(t){return this.clone()._divideBy(t)},_divideBy:function(t){return this.x/=t,this.y/=t,this},multiplyBy:function(t){return this.clone()._multiplyBy(t)},_multiplyBy:function(t){return this.x*=t,this.y*=t,this},round:function(){return this.clone()._round()},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},floor:function(){return this.clone()._floor()},_floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},distanceTo:function(t){t=o.point(t);var e=t.x-this.x,i=t.y-this.y;return Math.sqrt(e*e+i*i)},equals:function(t){return t=o.point(t),t.x===this.x&&t.y===this.y},contains:function(t){return t=o.point(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+o.Util.formatNum(this.x)+", "+o.Util.formatNum(this.y)+")"}},o.point=function(t,e,n){return t instanceof o.Point?t:o.Util.isArray(t)?new o.Point(t[0],t[1]):t===i||null===t?t:new o.Point(t,e,n)},o.Bounds=function(t,e){if(t)for(var i=e?[t,e]:t,n=0,o=i.length;o>n;n++)this.extend(i[n])},o.Bounds.prototype={extend:function(t){return t=o.point(t),this.min||this.max?(this.min.x=Math.min(t.x,this.min.x),this.max.x=Math.max(t.x,this.max.x),this.min.y=Math.min(t.y,this.min.y),this.max.y=Math.max(t.y,this.max.y)):(this.min=t.clone(),this.max=t.clone()),this},getCenter:function(t){return new o.Point((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return new o.Point(this.min.x,this.max.y)},getTopRight:function(){return new o.Point(this.max.x,this.min.y)},getSize:function(){return this.max.subtract(this.min)},contains:function(t){var e,i;return t="number"==typeof t[0]||t instanceof o.Point?o.point(t):o.bounds(t),t instanceof o.Bounds?(e=t.min,i=t.max):e=i=t,e.x>=this.min.x&&i.x<=this.max.x&&e.y>=this.min.y&&i.y<=this.max.y},intersects:function(t){t=o.bounds(t);var e=this.min,i=this.max,n=t.min,s=t.max,a=s.x>=e.x&&n.x<=i.x,r=s.y>=e.y&&n.y<=i.y;return a&&r},isValid:function(){return!(!this.min||!this.max)}},o.bounds=function(t,e){return!t||t instanceof o.Bounds?t:new o.Bounds(t,e)},o.Transformation=function(t,e,i,n){this._a=t,this._b=e,this._c=i,this._d=n},o.Transformation.prototype={transform:function(t,e){return this._transform(t.clone(),e)},_transform:function(t,e){return e=e||1,t.x=e*(this._a*t.x+this._b),t.y=e*(this._c*t.y+this._d),t},untransform:function(t,e){return e=e||1,new o.Point((t.x/e-this._b)/this._a,(t.y/e-this._d)/this._c)}},o.DomUtil={get:function(t){return"string"==typeof t?e.getElementById(t):t},getStyle:function(t,i){var n=t.style[i];if(!n&&t.currentStyle&&(n=t.currentStyle[i]),(!n||"auto"===n)&&e.defaultView){var o=e.defaultView.getComputedStyle(t,null);n=o?o[i]:null}return"auto"===n?null:n},getViewportOffset:function(t){var i,n=0,s=0,a=t,r=e.body,h=e.documentElement;do{if(n+=a.offsetTop||0,s+=a.offsetLeft||0,n+=parseInt(o.DomUtil.getStyle(a,"borderTopWidth"),10)||0,s+=parseInt(o.DomUtil.getStyle(a,"borderLeftWidth"),10)||0,i=o.DomUtil.getStyle(a,"position"),a.offsetParent===r&&"absolute"===i)break;if("fixed"===i){n+=r.scrollTop||h.scrollTop||0,s+=r.scrollLeft||h.scrollLeft||0;break}if("relative"===i&&!a.offsetLeft){var l=o.DomUtil.getStyle(a,"width"),u=o.DomUtil.getStyle(a,"max-width"),c=a.getBoundingClientRect();("none"!==l||"none"!==u)&&(s+=c.left+a.clientLeft),n+=c.top+(r.scrollTop||h.scrollTop||0);break}a=a.offsetParent}while(a);a=t;do{if(a===r)break;n-=a.scrollTop||0,s-=a.scrollLeft||0,a=a.parentNode}while(a);return new o.Point(s,n)},documentIsLtr:function(){return o.DomUtil._docIsLtrCached||(o.DomUtil._docIsLtrCached=!0,o.DomUtil._docIsLtr="ltr"===o.DomUtil.getStyle(e.body,"direction")),o.DomUtil._docIsLtr},create:function(t,i,n){var o=e.createElement(t);return o.className=i,n&&n.appendChild(o),o},hasClass:function(t,e){if(t.classList!==i)return t.classList.contains(e);var n=o.DomUtil._getClass(t);return n.length>0&&new RegExp("(^|\\s)"+e+"(\\s|$)").test(n)},addClass:function(t,e){if(t.classList!==i)for(var n=o.Util.splitWords(e),s=0,a=n.length;a>s;s++)t.classList.add(n[s]);else if(!o.DomUtil.hasClass(t,e)){var r=o.DomUtil._getClass(t);o.DomUtil._setClass(t,(r?r+" ":"")+e)}},removeClass:function(t,e){t.classList!==i?t.classList.remove(e):o.DomUtil._setClass(t,o.Util.trim((" "+o.DomUtil._getClass(t)+" ").replace(" "+e+" "," ")))},_setClass:function(t,e){t.className.baseVal===i?t.className=e:t.className.baseVal=e},_getClass:function(t){return t.className.baseVal===i?t.className:t.className.baseVal},setOpacity:function(t,e){if("opacity"in t.style)t.style.opacity=e;else if("filter"in t.style){var i=!1,n="DXImageTransform.Microsoft.Alpha";try{i=t.filters.item(n)}catch(o){if(1===e)return}e=Math.round(100*e),i?(i.Enabled=100!==e,i.Opacity=e):t.style.filter+=" progid:"+n+"(opacity="+e+")"}},testProp:function(t){for(var i=e.documentElement.style,n=0;n<t.length;n++)if(t[n]in i)return t[n];return!1},getTranslateString:function(t){var e=o.Browser.webkit3d,i="translate"+(e?"3d":"")+"(",n=(e?",0":"")+")";return i+t.x+"px,"+t.y+"px"+n},getScaleString:function(t,e){var i=o.DomUtil.getTranslateString(e.add(e.multiplyBy(-1*t))),n=" scale("+t+") ";return i+n},setPosition:function(t,e,i){t._leaflet_pos=e,!i&&o.Browser.any3d?t.style[o.DomUtil.TRANSFORM]=o.DomUtil.getTranslateString(e):(t.style.left=e.x+"px",t.style.top=e.y+"px")},getPosition:function(t){return t._leaflet_pos}},o.DomUtil.TRANSFORM=o.DomUtil.testProp(["transform","WebkitTransform","OTransform","MozTransform","msTransform"]),o.DomUtil.TRANSITION=o.DomUtil.testProp(["webkitTransition","transition","OTransition","MozTransition","msTransition"]),o.DomUtil.TRANSITION_END="webkitTransition"===o.DomUtil.TRANSITION||"OTransition"===o.DomUtil.TRANSITION?o.DomUtil.TRANSITION+"End":"transitionend",function(){if("onselectstart"in e)o.extend(o.DomUtil,{disableTextSelection:function(){o.DomEvent.on(t,"selectstart",o.DomEvent.preventDefault)},enableTextSelection:function(){o.DomEvent.off(t,"selectstart",o.DomEvent.preventDefault)}});else{var i=o.DomUtil.testProp(["userSelect","WebkitUserSelect","OUserSelect","MozUserSelect","msUserSelect"]);o.extend(o.DomUtil,{disableTextSelection:function(){if(i){var t=e.documentElement.style;this._userSelect=t[i],t[i]="none"}},enableTextSelection:function(){i&&(e.documentElement.style[i]=this._userSelect,delete this._userSelect)}})}o.extend(o.DomUtil,{disableImageDrag:function(){o.DomEvent.on(t,"dragstart",o.DomEvent.preventDefault)},enableImageDrag:function(){o.DomEvent.off(t,"dragstart",o.DomEvent.preventDefault)}})}(),o.LatLng=function(t,e,n){if(t=parseFloat(t),e=parseFloat(e),isNaN(t)||isNaN(e))throw new Error("Invalid LatLng object: ("+t+", "+e+")");this.lat=t,this.lng=e,n!==i&&(this.alt=parseFloat(n))},o.extend(o.LatLng,{DEG_TO_RAD:Math.PI/180,RAD_TO_DEG:180/Math.PI,MAX_MARGIN:1e-9}),o.LatLng.prototype={equals:function(t){if(!t)return!1;t=o.latLng(t);var e=Math.max(Math.abs(this.lat-t.lat),Math.abs(this.lng-t.lng));return e<=o.LatLng.MAX_MARGIN},toString:function(t){return"LatLng("+o.Util.formatNum(this.lat,t)+", "+o.Util.formatNum(this.lng,t)+")"},distanceTo:function(t){t=o.latLng(t);var e=6378137,i=o.LatLng.DEG_TO_RAD,n=(t.lat-this.lat)*i,s=(t.lng-this.lng)*i,a=this.lat*i,r=t.lat*i,h=Math.sin(n/2),l=Math.sin(s/2),u=h*h+l*l*Math.cos(a)*Math.cos(r);return 2*e*Math.atan2(Math.sqrt(u),Math.sqrt(1-u))},wrap:function(t,e){var i=this.lng;return t=t||-180,e=e||180,i=(i+e)%(e-t)+(t>i||i===e?e:t),new o.LatLng(this.lat,i)}},o.latLng=function(t,e){return t instanceof o.LatLng?t:o.Util.isArray(t)?"number"==typeof t[0]||"string"==typeof t[0]?new o.LatLng(t[0],t[1],t[2]):null:t===i||null===t?t:"object"==typeof t&&"lat"in t?new o.LatLng(t.lat,"lng"in t?t.lng:t.lon):e===i?null:new o.LatLng(t,e)},o.LatLngBounds=function(t,e){if(t)for(var i=e?[t,e]:t,n=0,o=i.length;o>n;n++)this.extend(i[n])},o.LatLngBounds.prototype={extend:function(t){if(!t)return this;var e=o.latLng(t);return t=null!==e?e:o.latLngBounds(t),t instanceof o.LatLng?this._southWest||this._northEast?(this._southWest.lat=Math.min(t.lat,this._southWest.lat),this._southWest.lng=Math.min(t.lng,this._southWest.lng),this._northEast.lat=Math.max(t.lat,this._northEast.lat),this._northEast.lng=Math.max(t.lng,this._northEast.lng)):(this._southWest=new o.LatLng(t.lat,t.lng),this._northEast=new o.LatLng(t.lat,t.lng)):t instanceof o.LatLngBounds&&(this.extend(t._southWest),this.extend(t._northEast)),this},pad:function(t){var e=this._southWest,i=this._northEast,n=Math.abs(e.lat-i.lat)*t,s=Math.abs(e.lng-i.lng)*t;return new o.LatLngBounds(new o.LatLng(e.lat-n,e.lng-s),new o.LatLng(i.lat+n,i.lng+s))},getCenter:function(){return new o.LatLng((this._southWest.lat+this._northEast.lat)/2,(this._southWest.lng+this._northEast.lng)/2)},getSouthWest:function(){return this._southWest},getNorthEast:function(){return this._northEast},getNorthWest:function(){return new o.LatLng(this.getNorth(),this.getWest())},getSouthEast:function(){return new o.LatLng(this.getSouth(),this.getEast())},getWest:function(){return this._southWest.lng},getSouth:function(){return this._southWest.lat},getEast:function(){return this._northEast.lng},getNorth:function(){return this._northEast.lat},contains:function(t){t="number"==typeof t[0]||t instanceof o.LatLng?o.latLng(t):o.latLngBounds(t);var e,i,n=this._southWest,s=this._northEast;return t instanceof o.LatLngBounds?(e=t.getSouthWest(),i=t.getNorthEast()):e=i=t,e.lat>=n.lat&&i.lat<=s.lat&&e.lng>=n.lng&&i.lng<=s.lng},intersects:function(t){t=o.latLngBounds(t);var e=this._southWest,i=this._northEast,n=t.getSouthWest(),s=t.getNorthEast(),a=s.lat>=e.lat&&n.lat<=i.lat,r=s.lng>=e.lng&&n.lng<=i.lng;return a&&r},toBBoxString:function(){return[this.getWest(),this.getSouth(),this.getEast(),this.getNorth()].join(",")},equals:function(t){return t?(t=o.latLngBounds(t),this._southWest.equals(t.getSouthWest())&&this._northEast.equals(t.getNorthEast())):!1},isValid:function(){return!(!this._southWest||!this._northEast)}},o.latLngBounds=function(t,e){return!t||t instanceof o.LatLngBounds?t:new o.LatLngBounds(t,e)},o.Projection={},o.Projection.SphericalMercator={MAX_LATITUDE:85.0511287798,project:function(t){var e=o.LatLng.DEG_TO_RAD,i=this.MAX_LATITUDE,n=Math.max(Math.min(i,t.lat),-i),s=t.lng*e,a=n*e;return a=Math.log(Math.tan(Math.PI/4+a/2)),new o.Point(s,a)},unproject:function(t){var e=o.LatLng.RAD_TO_DEG,i=t.x*e,n=(2*Math.atan(Math.exp(t.y))-Math.PI/2)*e;return new o.LatLng(n,i)}},o.Projection.LonLat={project:function(t){return new o.Point(t.lng,t.lat)},unproject:function(t){return new o.LatLng(t.y,t.x)}},o.CRS={latLngToPoint:function(t,e){var i=this.projection.project(t),n=this.scale(e);return this.transformation._transform(i,n)},pointToLatLng:function(t,e){var i=this.scale(e),n=this.transformation.untransform(t,i);return this.projection.unproject(n)},project:function(t){return this.projection.project(t)},scale:function(t){return 256*Math.pow(2,t)},getSize:function(t){var e=this.scale(t);return o.point(e,e)}},o.CRS.Simple=o.extend({},o.CRS,{projection:o.Projection.LonLat,transformation:new o.Transformation(1,0,-1,0),scale:function(t){return Math.pow(2,t)}}),o.CRS.EPSG3857=o.extend({},o.CRS,{code:"EPSG:3857",projection:o.Projection.SphericalMercator,transformation:new o.Transformation(.5/Math.PI,.5,-.5/Math.PI,.5),project:function(t){var e=this.projection.project(t),i=6378137;return e.multiplyBy(i)}}),o.CRS.EPSG900913=o.extend({},o.CRS.EPSG3857,{code:"EPSG:900913"}),o.CRS.EPSG4326=o.extend({},o.CRS,{code:"EPSG:4326",projection:o.Projection.LonLat,transformation:new o.Transformation(1/360,.5,-1/360,.5)}),o.Map=o.Class.extend({includes:o.Mixin.Events,options:{crs:o.CRS.EPSG3857,fadeAnimation:o.DomUtil.TRANSITION&&!o.Browser.android23,trackResize:!0,markerZoomAnimation:o.DomUtil.TRANSITION&&o.Browser.any3d},initialize:function(t,e){e=o.setOptions(this,e),this._initContainer(t),this._initLayout(),this._onResize=o.bind(this._onResize,this),this._initEvents(),e.maxBounds&&this.setMaxBounds(e.maxBounds),e.center&&e.zoom!==i&&this.setView(o.latLng(e.center),e.zoom,{reset:!0}),this._handlers=[],this._layers={},this._zoomBoundLayers={},this._tileLayersNum=0,this.callInitHooks(),this._addLayers(e.layers)},setView:function(t,e){return e=e===i?this.getZoom():e,this._resetView(o.latLng(t),this._limitZoom(e)),this},setZoom:function(t,e){return this._loaded?this.setView(this.getCenter(),t,{zoom:e}):(this._zoom=this._limitZoom(t),this)},zoomIn:function(t,e){return this.setZoom(this._zoom+(t||1),e)},zoomOut:function(t,e){return this.setZoom(this._zoom-(t||1),e)},setZoomAround:function(t,e,i){var n=this.getZoomScale(e),s=this.getSize().divideBy(2),a=t instanceof o.Point?t:this.latLngToContainerPoint(t),r=a.subtract(s).multiplyBy(1-1/n),h=this.containerPointToLatLng(s.add(r));return this.setView(h,e,{zoom:i})},fitBounds:function(t,e){e=e||{},t=t.getBounds?t.getBounds():o.latLngBounds(t);var i=o.point(e.paddingTopLeft||e.padding||[0,0]),n=o.point(e.paddingBottomRight||e.padding||[0,0]),s=this.getBoundsZoom(t,!1,i.add(n)),a=n.subtract(i).divideBy(2),r=this.project(t.getSouthWest(),s),h=this.project(t.getNorthEast(),s),l=this.unproject(r.add(h).divideBy(2).add(a),s);return s=e&&e.maxZoom?Math.min(e.maxZoom,s):s,this.setView(l,s,e)},fitWorld:function(t){return this.fitBounds([[-90,-180],[90,180]],t)},panTo:function(t,e){return this.setView(t,this._zoom,{pan:e})},panBy:function(t){return this.fire("movestart"),this._rawPanBy(o.point(t)),this.fire("move"),this.fire("moveend")},setMaxBounds:function(t){return t=o.latLngBounds(t),this.options.maxBounds=t,t?(this._loaded&&this._panInsideMaxBounds(),this.on("moveend",this._panInsideMaxBounds,this)):this.off("moveend",this._panInsideMaxBounds,this)},panInsideBounds:function(t,e){var i=this.getCenter(),n=this._limitCenter(i,this._zoom,t);return i.equals(n)?this:this.panTo(n,e)},addLayer:function(t){var e=o.stamp(t);return this._layers[e]?this:(this._layers[e]=t,!t.options||isNaN(t.options.maxZoom)&&isNaN(t.options.minZoom)||(this._zoomBoundLayers[e]=t,this._updateZoomLevels()),this.options.zoomAnimation&&o.TileLayer&&t instanceof o.TileLayer&&(this._tileLayersNum++,this._tileLayersToLoad++,t.on("load",this._onTileLayerLoad,this)),this._loaded&&this._layerAdd(t),this)},removeLayer:function(t){var e=o.stamp(t);return this._layers[e]?(this._loaded&&t.onRemove(this),delete this._layers[e],this._loaded&&this.fire("layerremove",{layer:t}),this._zoomBoundLayers[e]&&(delete this._zoomBoundLayers[e],this._updateZoomLevels()),this.options.zoomAnimation&&o.TileLayer&&t instanceof o.TileLayer&&(this._tileLayersNum--,this._tileLayersToLoad--,t.off("load",this._onTileLayerLoad,this)),this):this},hasLayer:function(t){return t?o.stamp(t)in this._layers:!1},eachLayer:function(t,e){for(var i in this._layers)t.call(e,this._layers[i]);return this},invalidateSize:function(t){if(!this._loaded)return this;t=o.extend({animate:!1,pan:!0},t===!0?{animate:!0}:t);var e=this.getSize();this._sizeChanged=!0,this._initialCenter=null;var i=this.getSize(),n=e.divideBy(2).round(),s=i.divideBy(2).round(),a=n.subtract(s);return a.x||a.y?(t.animate&&t.pan?this.panBy(a):(t.pan&&this._rawPanBy(a),this.fire("move"),t.debounceMoveend?(clearTimeout(this._sizeTimer),this._sizeTimer=setTimeout(o.bind(this.fire,this,"moveend"),200)):this.fire("moveend")),this.fire("resize",{oldSize:e,newSize:i})):this},addHandler:function(t,e){if(!e)return this;var i=this[t]=new e(this);return this._handlers.push(i),this.options[t]&&i.enable(),this},remove:function(){this._loaded&&this.fire("unload"),this._initEvents("off");try{delete this._container._leaflet}catch(t){this._container._leaflet=i}return this._clearPanes(),this._clearControlPos&&this._clearControlPos(),this._clearHandlers(),this},getCenter:function(){return this._checkIfLoaded(),this._initialCenter&&!this._moved()?this._initialCenter:this.layerPointToLatLng(this._getCenterLayerPoint())},getZoom:function(){return this._zoom},getBounds:function(){var t=this.getPixelBounds(),e=this.unproject(t.getBottomLeft()),i=this.unproject(t.getTopRight());return new o.LatLngBounds(e,i)},getMinZoom:function(){return this.options.minZoom===i?this._layersMinZoom===i?0:this._layersMinZoom:this.options.minZoom},getMaxZoom:function(){return this.options.maxZoom===i?this._layersMaxZoom===i?1/0:this._layersMaxZoom:this.options.maxZoom},getBoundsZoom:function(t,e,i){t=o.latLngBounds(t);var n,s=this.getMinZoom()-(e?1:0),a=this.getMaxZoom(),r=this.getSize(),h=t.getNorthWest(),l=t.getSouthEast(),u=!0;i=o.point(i||[0,0]);do s++,n=this.project(l,s).subtract(this.project(h,s)).add(i),u=e?n.x<r.x||n.y<r.y:r.contains(n);while(u&&a>=s);return u&&e?null:e?s:s-1},getSize:function(){return(!this._size||this._sizeChanged)&&(this._size=new o.Point(this._container.clientWidth,this._container.clientHeight),this._sizeChanged=!1),this._size.clone()},getPixelBounds:function(){var t=this._getTopLeftPoint();return new o.Bounds(t,t.add(this.getSize()))},getPixelOrigin:function(){return this._checkIfLoaded(),this._initialTopLeftPoint},getPanes:function(){return this._panes},getContainer:function(){return this._container},getZoomScale:function(t){var e=this.options.crs;return e.scale(t)/e.scale(this._zoom)},getScaleZoom:function(t){return this._zoom+Math.log(t)/Math.LN2},project:function(t,e){return e=e===i?this._zoom:e,this.options.crs.latLngToPoint(o.latLng(t),e)},unproject:function(t,e){return e=e===i?this._zoom:e,this.options.crs.pointToLatLng(o.point(t),e)},layerPointToLatLng:function(t){var e=o.point(t).add(this.getPixelOrigin());return this.unproject(e)},latLngToLayerPoint:function(t){var e=this.project(o.latLng(t))._round();return e._subtract(this.getPixelOrigin())},containerPointToLayerPoint:function(t){return o.point(t).subtract(this._getMapPanePos())},layerPointToContainerPoint:function(t){return o.point(t).add(this._getMapPanePos())},containerPointToLatLng:function(t){var e=this.containerPointToLayerPoint(o.point(t));return this.layerPointToLatLng(e)},latLngToContainerPoint:function(t){return this.layerPointToContainerPoint(this.latLngToLayerPoint(o.latLng(t)))},mouseEventToContainerPoint:function(t){return o.DomEvent.getMousePosition(t,this._container)},mouseEventToLayerPoint:function(t){return this.containerPointToLayerPoint(this.mouseEventToContainerPoint(t))},mouseEventToLatLng:function(t){return this.layerPointToLatLng(this.mouseEventToLayerPoint(t))},_initContainer:function(t){var e=this._container=o.DomUtil.get(t);if(!e)throw new Error("Map container not found.");if(e._leaflet)throw new Error("Map container is already initialized.");e._leaflet=!0},_initLayout:function(){var t=this._container;o.DomUtil.addClass(t,"leaflet-container"+(o.Browser.touch?" leaflet-touch":"")+(o.Browser.retina?" leaflet-retina":"")+(o.Browser.ielt9?" leaflet-oldie":"")+(this.options.fadeAnimation?" leaflet-fade-anim":""));var e=o.DomUtil.getStyle(t,"position");"absolute"!==e&&"relative"!==e&&"fixed"!==e&&(t.style.position="relative"),this._initPanes(),this._initControlPos&&this._initControlPos()},_initPanes:function(){var t=this._panes={};this._mapPane=t.mapPane=this._createPane("leaflet-map-pane",this._container),this._tilePane=t.tilePane=this._createPane("leaflet-tile-pane",this._mapPane),t.objectsPane=this._createPane("leaflet-objects-pane",this._mapPane),t.shadowPane=this._createPane("leaflet-shadow-pane"),t.overlayPane=this._createPane("leaflet-overlay-pane"),t.markerPane=this._createPane("leaflet-marker-pane"),t.popupPane=this._createPane("leaflet-popup-pane");var e=" leaflet-zoom-hide";this.options.markerZoomAnimation||(o.DomUtil.addClass(t.markerPane,e),o.DomUtil.addClass(t.shadowPane,e),o.DomUtil.addClass(t.popupPane,e))},_createPane:function(t,e){return o.DomUtil.create("div",t,e||this._panes.objectsPane)},_clearPanes:function(){this._container.removeChild(this._mapPane)},_addLayers:function(t){t=t?o.Util.isArray(t)?t:[t]:[];for(var e=0,i=t.length;i>e;e++)this.addLayer(t[e])},_resetView:function(t,e,i,n){var s=this._zoom!==e;n||(this.fire("movestart"),s&&this.fire("zoomstart")),this._zoom=e,this._initialCenter=t,this._initialTopLeftPoint=this._getNewTopLeftPoint(t),i?this._initialTopLeftPoint._add(this._getMapPanePos()):o.DomUtil.setPosition(this._mapPane,new o.Point(0,0)),this._tileLayersToLoad=this._tileLayersNum;var a=!this._loaded;this._loaded=!0,this.fire("viewreset",{hard:!i}),a&&(this.fire("load"),this.eachLayer(this._layerAdd,this)),this.fire("move"),(s||n)&&this.fire("zoomend"),this.fire("moveend",{hard:!i})},_rawPanBy:function(t){o.DomUtil.setPosition(this._mapPane,this._getMapPanePos().subtract(t))},_getZoomSpan:function(){return this.getMaxZoom()-this.getMinZoom()},_updateZoomLevels:function(){var t,e=1/0,n=-1/0,o=this._getZoomSpan();for(t in this._zoomBoundLayers){var s=this._zoomBoundLayers[t];isNaN(s.options.minZoom)||(e=Math.min(e,s.options.minZoom)),isNaN(s.options.maxZoom)||(n=Math.max(n,s.options.maxZoom))}t===i?this._layersMaxZoom=this._layersMinZoom=i:(this._layersMaxZoom=n,this._layersMinZoom=e),o!==this._getZoomSpan()&&this.fire("zoomlevelschange")},_panInsideMaxBounds:function(){this.panInsideBounds(this.options.maxBounds)},_checkIfLoaded:function(){if(!this._loaded)throw new Error("Set map center and zoom first.")},_initEvents:function(e){if(o.DomEvent){e=e||"on",o.DomEvent[e](this._container,"click",this._onMouseClick,this);var i,n,s=["dblclick","mousedown","mouseup","mouseenter","mouseleave","mousemove","contextmenu"];for(i=0,n=s.length;n>i;i++)o.DomEvent[e](this._container,s[i],this._fireMouseEvent,this);this.options.trackResize&&o.DomEvent[e](t,"resize",this._onResize,this)}},_onResize:function(){o.Util.cancelAnimFrame(this._resizeRequest),this._resizeRequest=o.Util.requestAnimFrame(function(){this.invalidateSize({debounceMoveend:!0})},this,!1,this._container)},_onMouseClick:function(t){!this._loaded||!t._simulated&&(this.dragging&&this.dragging.moved()||this.boxZoom&&this.boxZoom.moved())||o.DomEvent._skipped(t)||(this.fire("preclick"),this._fireMouseEvent(t))},_fireMouseEvent:function(t){if(this._loaded&&!o.DomEvent._skipped(t)){var e=t.type;if(e="mouseenter"===e?"mouseover":"mouseleave"===e?"mouseout":e,this.hasEventListeners(e)){"contextmenu"===e&&o.DomEvent.preventDefault(t);var i=this.mouseEventToContainerPoint(t),n=this.containerPointToLayerPoint(i),s=this.layerPointToLatLng(n);this.fire(e,{latlng:s,layerPoint:n,containerPoint:i,originalEvent:t})}}},_onTileLayerLoad:function(){this._tileLayersToLoad--,this._tileLayersNum&&!this._tileLayersToLoad&&this.fire("tilelayersload")},_clearHandlers:function(){for(var t=0,e=this._handlers.length;e>t;t++)this._handlers[t].disable()},whenReady:function(t,e){return this._loaded?t.call(e||this,this):this.on("load",t,e),this},_layerAdd:function(t){t.onAdd(this),this.fire("layeradd",{layer:t})},_getMapPanePos:function(){return o.DomUtil.getPosition(this._mapPane)},_moved:function(){var t=this._getMapPanePos();return t&&!t.equals([0,0])},_getTopLeftPoint:function(){return this.getPixelOrigin().subtract(this._getMapPanePos())},_getNewTopLeftPoint:function(t,e){var i=this.getSize()._divideBy(2);return this.project(t,e)._subtract(i)._round()},_latLngToNewLayerPoint:function(t,e,i){var n=this._getNewTopLeftPoint(i,e).add(this._getMapPanePos());return this.project(t,e)._subtract(n)},_getCenterLayerPoint:function(){return this.containerPointToLayerPoint(this.getSize()._divideBy(2))},_getCenterOffset:function(t){return this.latLngToLayerPoint(t).subtract(this._getCenterLayerPoint())},_limitCenter:function(t,e,i){if(!i)return t;var n=this.project(t,e),s=this.getSize().divideBy(2),a=new o.Bounds(n.subtract(s),n.add(s)),r=this._getBoundsOffset(a,i,e);return this.unproject(n.add(r),e)},_limitOffset:function(t,e){if(!e)return t;var i=this.getPixelBounds(),n=new o.Bounds(i.min.add(t),i.max.add(t));return t.add(this._getBoundsOffset(n,e))},_getBoundsOffset:function(t,e,i){var n=this.project(e.getNorthWest(),i).subtract(t.min),s=this.project(e.getSouthEast(),i).subtract(t.max),a=this._rebound(n.x,-s.x),r=this._rebound(n.y,-s.y);return new o.Point(a,r)},_rebound:function(t,e){return t+e>0?Math.round(t-e)/2:Math.max(0,Math.ceil(t))-Math.max(0,Math.floor(e))},_limitZoom:function(t){var e=this.getMinZoom(),i=this.getMaxZoom();return Math.max(e,Math.min(i,t))}}),o.map=function(t,e){return new o.Map(t,e)},o.Projection.Mercator={MAX_LATITUDE:85.0840591556,R_MINOR:6356752.314245179,R_MAJOR:6378137,project:function(t){var e=o.LatLng.DEG_TO_RAD,i=this.MAX_LATITUDE,n=Math.max(Math.min(i,t.lat),-i),s=this.R_MAJOR,a=this.R_MINOR,r=t.lng*e*s,h=n*e,l=a/s,u=Math.sqrt(1-l*l),c=u*Math.sin(h);c=Math.pow((1-c)/(1+c),.5*u);var d=Math.tan(.5*(.5*Math.PI-h))/c;return h=-s*Math.log(d),new o.Point(r,h)},unproject:function(t){for(var e,i=o.LatLng.RAD_TO_DEG,n=this.R_MAJOR,s=this.R_MINOR,a=t.x*i/n,r=s/n,h=Math.sqrt(1-r*r),l=Math.exp(-t.y/n),u=Math.PI/2-2*Math.atan(l),c=15,d=1e-7,p=c,_=.1;Math.abs(_)>d&&--p>0;)e=h*Math.sin(u),_=Math.PI/2-2*Math.atan(l*Math.pow((1-e)/(1+e),.5*h))-u,u+=_;
6 return new o.LatLng(u*i,a)}},o.CRS.EPSG3395=o.extend({},o.CRS,{code:"EPSG:3395",projection:o.Projection.Mercator,transformation:function(){var t=o.Projection.Mercator,e=t.R_MAJOR,i=.5/(Math.PI*e);return new o.Transformation(i,.5,-i,.5)}()}),o.TileLayer=o.Class.extend({includes:o.Mixin.Events,options:{minZoom:0,maxZoom:18,tileSize:256,subdomains:"abc",errorTileUrl:"",attribution:"",zoomOffset:0,opacity:1,unloadInvisibleTiles:o.Browser.mobile,updateWhenIdle:o.Browser.mobile},initialize:function(t,e){e=o.setOptions(this,e),e.detectRetina&&o.Browser.retina&&e.maxZoom>0&&(e.tileSize=Math.floor(e.tileSize/2),e.zoomOffset++,e.minZoom>0&&e.minZoom--,this.options.maxZoom--),e.bounds&&(e.bounds=o.latLngBounds(e.bounds)),this._url=t;var i=this.options.subdomains;"string"==typeof i&&(this.options.subdomains=i.split(""))},onAdd:function(t){this._map=t,this._animated=t._zoomAnimated,this._initContainer(),t.on({viewreset:this._reset,moveend:this._update},this),this._animated&&t.on({zoomanim:this._animateZoom,zoomend:this._endZoomAnim},this),this.options.updateWhenIdle||(this._limitedUpdate=o.Util.limitExecByInterval(this._update,150,this),t.on("move",this._limitedUpdate,this)),this._reset(),this._update()},addTo:function(t){return t.addLayer(this),this},onRemove:function(t){this._container.parentNode.removeChild(this._container),t.off({viewreset:this._reset,moveend:this._update},this),this._animated&&t.off({zoomanim:this._animateZoom,zoomend:this._endZoomAnim},this),this.options.updateWhenIdle||t.off("move",this._limitedUpdate,this),this._container=null,this._map=null},bringToFront:function(){var t=this._map._panes.tilePane;return this._container&&(t.appendChild(this._container),this._setAutoZIndex(t,Math.max)),this},bringToBack:function(){var t=this._map._panes.tilePane;return this._container&&(t.insertBefore(this._container,t.firstChild),this._setAutoZIndex(t,Math.min)),this},getAttribution:function(){return this.options.attribution},getContainer:function(){return this._container},setOpacity:function(t){return this.options.opacity=t,this._map&&this._updateOpacity(),this},setZIndex:function(t){return this.options.zIndex=t,this._updateZIndex(),this},setUrl:function(t,e){return this._url=t,e||this.redraw(),this},redraw:function(){return this._map&&(this._reset({hard:!0}),this._update()),this},_updateZIndex:function(){this._container&&this.options.zIndex!==i&&(this._container.style.zIndex=this.options.zIndex)},_setAutoZIndex:function(t,e){var i,n,o,s=t.children,a=-e(1/0,-1/0);for(n=0,o=s.length;o>n;n++)s[n]!==this._container&&(i=parseInt(s[n].style.zIndex,10),isNaN(i)||(a=e(a,i)));this.options.zIndex=this._container.style.zIndex=(isFinite(a)?a:0)+e(1,-1)},_updateOpacity:function(){var t,e=this._tiles;if(o.Browser.ielt9)for(t in e)o.DomUtil.setOpacity(e[t],this.options.opacity);else o.DomUtil.setOpacity(this._container,this.options.opacity)},_initContainer:function(){var t=this._map._panes.tilePane;if(!this._container){if(this._container=o.DomUtil.create("div","leaflet-layer"),this._updateZIndex(),this._animated){var e="leaflet-tile-container";this._bgBuffer=o.DomUtil.create("div",e,this._container),this._tileContainer=o.DomUtil.create("div",e,this._container)}else this._tileContainer=this._container;t.appendChild(this._container),this.options.opacity<1&&this._updateOpacity()}},_reset:function(t){for(var e in this._tiles)this.fire("tileunload",{tile:this._tiles[e]});this._tiles={},this._tilesToLoad=0,this.options.reuseTiles&&(this._unusedTiles=[]),this._tileContainer.innerHTML="",this._animated&&t&&t.hard&&this._clearBgBuffer(),this._initContainer()},_getTileSize:function(){var t=this._map,e=t.getZoom()+this.options.zoomOffset,i=this.options.maxNativeZoom,n=this.options.tileSize;return i&&e>i&&(n=Math.round(t.getZoomScale(e)/t.getZoomScale(i)*n)),n},_update:function(){if(this._map){var t=this._map,e=t.getPixelBounds(),i=t.getZoom(),n=this._getTileSize();if(!(i>this.options.maxZoom||i<this.options.minZoom)){var s=o.bounds(e.min.divideBy(n)._floor(),e.max.divideBy(n)._floor());this._addTilesFromCenterOut(s),(this.options.unloadInvisibleTiles||this.options.reuseTiles)&&this._removeOtherTiles(s)}}},_addTilesFromCenterOut:function(t){var i,n,s,a=[],r=t.getCenter();for(i=t.min.y;i<=t.max.y;i++)for(n=t.min.x;n<=t.max.x;n++)s=new o.Point(n,i),this._tileShouldBeLoaded(s)&&a.push(s);var h=a.length;if(0!==h){a.sort(function(t,e){return t.distanceTo(r)-e.distanceTo(r)});var l=e.createDocumentFragment();for(this._tilesToLoad||this.fire("loading"),this._tilesToLoad+=h,n=0;h>n;n++)this._addTile(a[n],l);this._tileContainer.appendChild(l)}},_tileShouldBeLoaded:function(t){if(t.x+":"+t.y in this._tiles)return!1;var e=this.options;if(!e.continuousWorld){var i=this._getWrapTileNum();if(e.noWrap&&(t.x<0||t.x>=i.x)||t.y<0||t.y>=i.y)return!1}if(e.bounds){var n=e.tileSize,o=t.multiplyBy(n),s=o.add([n,n]),a=this._map.unproject(o),r=this._map.unproject(s);if(e.continuousWorld||e.noWrap||(a=a.wrap(),r=r.wrap()),!e.bounds.intersects([a,r]))return!1}return!0},_removeOtherTiles:function(t){var e,i,n,o;for(o in this._tiles)e=o.split(":"),i=parseInt(e[0],10),n=parseInt(e[1],10),(i<t.min.x||i>t.max.x||n<t.min.y||n>t.max.y)&&this._removeTile(o)},_removeTile:function(t){var e=this._tiles[t];this.fire("tileunload",{tile:e,url:e.src}),this.options.reuseTiles?(o.DomUtil.removeClass(e,"leaflet-tile-loaded"),this._unusedTiles.push(e)):e.parentNode===this._tileContainer&&this._tileContainer.removeChild(e),o.Browser.android||(e.onload=null,e.src=o.Util.emptyImageUrl),delete this._tiles[t]},_addTile:function(t,e){var i=this._getTilePos(t),n=this._getTile();o.DomUtil.setPosition(n,i,o.Browser.chrome),this._tiles[t.x+":"+t.y]=n,this._loadTile(n,t),n.parentNode!==this._tileContainer&&e.appendChild(n)},_getZoomForUrl:function(){var t=this.options,e=this._map.getZoom();return t.zoomReverse&&(e=t.maxZoom-e),e+=t.zoomOffset,t.maxNativeZoom?Math.min(e,t.maxNativeZoom):e},_getTilePos:function(t){var e=this._map.getPixelOrigin(),i=this._getTileSize();return t.multiplyBy(i).subtract(e)},getTileUrl:function(t){return o.Util.template(this._url,o.extend({s:this._getSubdomain(t),z:t.z,x:t.x,y:t.y},this.options))},_getWrapTileNum:function(){var t=this._map.options.crs,e=t.getSize(this._map.getZoom());return e.divideBy(this._getTileSize())._floor()},_adjustTilePoint:function(t){var e=this._getWrapTileNum();this.options.continuousWorld||this.options.noWrap||(t.x=(t.x%e.x+e.x)%e.x),this.options.tms&&(t.y=e.y-t.y-1),t.z=this._getZoomForUrl()},_getSubdomain:function(t){var e=Math.abs(t.x+t.y)%this.options.subdomains.length;return this.options.subdomains[e]},_getTile:function(){if(this.options.reuseTiles&&this._unusedTiles.length>0){var t=this._unusedTiles.pop();return this._resetTile(t),t}return this._createTile()},_resetTile:function(){},_createTile:function(){var t=o.DomUtil.create("img","leaflet-tile");return t.style.width=t.style.height=this._getTileSize()+"px",t.galleryimg="no",t.onselectstart=t.onmousemove=o.Util.falseFn,o.Browser.ielt9&&this.options.opacity!==i&&o.DomUtil.setOpacity(t,this.options.opacity),o.Browser.mobileWebkit3d&&(t.style.WebkitBackfaceVisibility="hidden"),t},_loadTile:function(t,e){t._layer=this,t.onload=this._tileOnLoad,t.onerror=this._tileOnError,this._adjustTilePoint(e),t.src=this.getTileUrl(e),this.fire("tileloadstart",{tile:t,url:t.src})},_tileLoaded:function(){this._tilesToLoad--,this._animated&&o.DomUtil.addClass(this._tileContainer,"leaflet-zoom-animated"),this._tilesToLoad||(this.fire("load"),this._animated&&(clearTimeout(this._clearBgBufferTimer),this._clearBgBufferTimer=setTimeout(o.bind(this._clearBgBuffer,this),500)))},_tileOnLoad:function(){var t=this._layer;this.src!==o.Util.emptyImageUrl&&(o.DomUtil.addClass(this,"leaflet-tile-loaded"),t.fire("tileload",{tile:this,url:this.src})),t._tileLoaded()},_tileOnError:function(){var t=this._layer;t.fire("tileerror",{tile:this,url:this.src});var e=t.options.errorTileUrl;e&&(this.src=e),t._tileLoaded()}}),o.tileLayer=function(t,e){return new o.TileLayer(t,e)},o.TileLayer.WMS=o.TileLayer.extend({defaultWmsParams:{service:"WMS",request:"GetMap",version:"1.1.1",layers:"",styles:"",format:"image/jpeg",transparent:!1},initialize:function(t,e){this._url=t;var i=o.extend({},this.defaultWmsParams),n=e.tileSize||this.options.tileSize;i.width=i.height=e.detectRetina&&o.Browser.retina?2*n:n;for(var s in e)this.options.hasOwnProperty(s)||"crs"===s||(i[s]=e[s]);this.wmsParams=i,o.setOptions(this,e)},onAdd:function(t){this._crs=this.options.crs||t.options.crs,this._wmsVersion=parseFloat(this.wmsParams.version);var e=this._wmsVersion>=1.3?"crs":"srs";this.wmsParams[e]=this._crs.code,o.TileLayer.prototype.onAdd.call(this,t)},getTileUrl:function(t){var e=this._map,i=this.options.tileSize,n=t.multiplyBy(i),s=n.add([i,i]),a=this._crs.project(e.unproject(n,t.z)),r=this._crs.project(e.unproject(s,t.z)),h=this._wmsVersion>=1.3&&this._crs===o.CRS.EPSG4326?[r.y,a.x,a.y,r.x].join(","):[a.x,r.y,r.x,a.y].join(","),l=o.Util.template(this._url,{s:this._getSubdomain(t)});return l+o.Util.getParamString(this.wmsParams,l,!0)+"&BBOX="+h},setParams:function(t,e){return o.extend(this.wmsParams,t),e||this.redraw(),this}}),o.tileLayer.wms=function(t,e){return new o.TileLayer.WMS(t,e)},o.TileLayer.Canvas=o.TileLayer.extend({options:{async:!1},initialize:function(t){o.setOptions(this,t)},redraw:function(){this._map&&(this._reset({hard:!0}),this._update());for(var t in this._tiles)this._redrawTile(this._tiles[t]);return this},_redrawTile:function(t){this.drawTile(t,t._tilePoint,this._map._zoom)},_createTile:function(){var t=o.DomUtil.create("canvas","leaflet-tile");return t.width=t.height=this.options.tileSize,t.onselectstart=t.onmousemove=o.Util.falseFn,t},_loadTile:function(t,e){t._layer=this,t._tilePoint=e,this._redrawTile(t),this.options.async||this.tileDrawn(t)},drawTile:function(){},tileDrawn:function(t){this._tileOnLoad.call(t)}}),o.tileLayer.canvas=function(t){return new o.TileLayer.Canvas(t)},o.ImageOverlay=o.Class.extend({includes:o.Mixin.Events,options:{opacity:1},initialize:function(t,e,i){this._url=t,this._bounds=o.latLngBounds(e),o.setOptions(this,i)},onAdd:function(t){this._map=t,this._image||this._initImage(),t._panes.overlayPane.appendChild(this._image),t.on("viewreset",this._reset,this),t.options.zoomAnimation&&o.Browser.any3d&&t.on("zoomanim",this._animateZoom,this),this._reset()},onRemove:function(t){t.getPanes().overlayPane.removeChild(this._image),t.off("viewreset",this._reset,this),t.options.zoomAnimation&&t.off("zoomanim",this._animateZoom,this)},addTo:function(t){return t.addLayer(this),this},setOpacity:function(t){return this.options.opacity=t,this._updateOpacity(),this},bringToFront:function(){return this._image&&this._map._panes.overlayPane.appendChild(this._image),this},bringToBack:function(){var t=this._map._panes.overlayPane;return this._image&&t.insertBefore(this._image,t.firstChild),this},setUrl:function(t){this._url=t,this._image.src=this._url},getAttribution:function(){return this.options.attribution},_initImage:function(){this._image=o.DomUtil.create("img","leaflet-image-layer"),this._map.options.zoomAnimation&&o.Browser.any3d?o.DomUtil.addClass(this._image,"leaflet-zoom-animated"):o.DomUtil.addClass(this._image,"leaflet-zoom-hide"),this._updateOpacity(),o.extend(this._image,{galleryimg:"no",onselectstart:o.Util.falseFn,onmousemove:o.Util.falseFn,onload:o.bind(this._onImageLoad,this),src:this._url})},_animateZoom:function(t){var e=this._map,i=this._image,n=e.getZoomScale(t.zoom),s=this._bounds.getNorthWest(),a=this._bounds.getSouthEast(),r=e._latLngToNewLayerPoint(s,t.zoom,t.center),h=e._latLngToNewLayerPoint(a,t.zoom,t.center)._subtract(r),l=r._add(h._multiplyBy(.5*(1-1/n)));i.style[o.DomUtil.TRANSFORM]=o.DomUtil.getTranslateString(l)+" scale("+n+") "},_reset:function(){var t=this._image,e=this._map.latLngToLayerPoint(this._bounds.getNorthWest()),i=this._map.latLngToLayerPoint(this._bounds.getSouthEast())._subtract(e);o.DomUtil.setPosition(t,e),t.style.width=i.x+"px",t.style.height=i.y+"px"},_onImageLoad:function(){this.fire("load")},_updateOpacity:function(){o.DomUtil.setOpacity(this._image,this.options.opacity)}}),o.imageOverlay=function(t,e,i){return new o.ImageOverlay(t,e,i)},o.Icon=o.Class.extend({options:{className:""},initialize:function(t){o.setOptions(this,t)},createIcon:function(t){return this._createIcon("icon",t)},createShadow:function(t){return this._createIcon("shadow",t)},_createIcon:function(t,e){var i=this._getIconUrl(t);if(!i){if("icon"===t)throw new Error("iconUrl not set in Icon options (see the docs).");return null}var n;return n=e&&"IMG"===e.tagName?this._createImg(i,e):this._createImg(i),this._setIconStyles(n,t),n},_setIconStyles:function(t,e){var i,n=this.options,s=o.point(n[e+"Size"]);i=o.point("shadow"===e?n.shadowAnchor||n.iconAnchor:n.iconAnchor),!i&&s&&(i=s.divideBy(2,!0)),t.className="leaflet-marker-"+e+" "+n.className,i&&(t.style.marginLeft=-i.x+"px",t.style.marginTop=-i.y+"px"),s&&(t.style.width=s.x+"px",t.style.height=s.y+"px")},_createImg:function(t,i){return i=i||e.createElement("img"),i.src=t,i},_getIconUrl:function(t){return o.Browser.retina&&this.options[t+"RetinaUrl"]?this.options[t+"RetinaUrl"]:this.options[t+"Url"]}}),o.icon=function(t){return new o.Icon(t)},o.Icon.Default=o.Icon.extend({options:{iconSize:[25,41],iconAnchor:[12,41],popupAnchor:[1,-34],shadowSize:[41,41]},_getIconUrl:function(t){var e=t+"Url";if(this.options[e])return this.options[e];o.Browser.retina&&"icon"===t&&(t+="-2x");var i=o.Icon.Default.imagePath;if(!i)throw new Error("Couldn't autodetect L.Icon.Default.imagePath, set it manually.");return i+"/marker-"+t+".png"}}),o.Icon.Default.imagePath=function(){var t,i,n,o,s,a=e.getElementsByTagName("script"),r=/[\/^]leaflet[\-\._]?([\w\-\._]*)\.js\??/;for(t=0,i=a.length;i>t;t++)if(n=a[t].src,o=n.match(r))return s=n.split(r)[0],(s?s+"/":"")+"images"}(),o.Marker=o.Class.extend({includes:o.Mixin.Events,options:{icon:new o.Icon.Default,title:"",alt:"",clickable:!0,draggable:!1,keyboard:!0,zIndexOffset:0,opacity:1,riseOnHover:!1,riseOffset:250},initialize:function(t,e){o.setOptions(this,e),this._latlng=o.latLng(t)},onAdd:function(t){this._map=t,t.on("viewreset",this.update,this),this._initIcon(),this.update(),this.fire("add"),t.options.zoomAnimation&&t.options.markerZoomAnimation&&t.on("zoomanim",this._animateZoom,this)},addTo:function(t){return t.addLayer(this),this},onRemove:function(t){this.dragging&&this.dragging.disable(),this._removeIcon(),this._removeShadow(),this.fire("remove"),t.off({viewreset:this.update,zoomanim:this._animateZoom},this),this._map=null},getLatLng:function(){return this._latlng},setLatLng:function(t){return this._latlng=o.latLng(t),this.update(),this.fire("move",{latlng:this._latlng})},setZIndexOffset:function(t){return this.options.zIndexOffset=t,this.update(),this},setIcon:function(t){return this.options.icon=t,this._map&&(this._initIcon(),this.update()),this._popup&&this.bindPopup(this._popup),this},update:function(){if(this._icon){var t=this._map.latLngToLayerPoint(this._latlng).round();this._setPos(t)}return this},_initIcon:function(){var t=this.options,e=this._map,i=e.options.zoomAnimation&&e.options.markerZoomAnimation,n=i?"leaflet-zoom-animated":"leaflet-zoom-hide",s=t.icon.createIcon(this._icon),a=!1;s!==this._icon&&(this._icon&&this._removeIcon(),a=!0,t.title&&(s.title=t.title),t.alt&&(s.alt=t.alt)),o.DomUtil.addClass(s,n),t.keyboard&&(s.tabIndex="0"),this._icon=s,this._initInteraction(),t.riseOnHover&&o.DomEvent.on(s,"mouseover",this._bringToFront,this).on(s,"mouseout",this._resetZIndex,this);var r=t.icon.createShadow(this._shadow),h=!1;r!==this._shadow&&(this._removeShadow(),h=!0),r&&o.DomUtil.addClass(r,n),this._shadow=r,t.opacity<1&&this._updateOpacity();var l=this._map._panes;a&&l.markerPane.appendChild(this._icon),r&&h&&l.shadowPane.appendChild(this._shadow)},_removeIcon:function(){this.options.riseOnHover&&o.DomEvent.off(this._icon,"mouseover",this._bringToFront).off(this._icon,"mouseout",this._resetZIndex),this._map._panes.markerPane.removeChild(this._icon),this._icon=null},_removeShadow:function(){this._shadow&&this._map._panes.shadowPane.removeChild(this._shadow),this._shadow=null},_setPos:function(t){o.DomUtil.setPosition(this._icon,t),this._shadow&&o.DomUtil.setPosition(this._shadow,t),this._zIndex=t.y+this.options.zIndexOffset,this._resetZIndex()},_updateZIndex:function(t){this._icon.style.zIndex=this._zIndex+t},_animateZoom:function(t){var e=this._map._latLngToNewLayerPoint(this._latlng,t.zoom,t.center).round();this._setPos(e)},_initInteraction:function(){if(this.options.clickable){var t=this._icon,e=["dblclick","mousedown","mouseover","mouseout","contextmenu"];o.DomUtil.addClass(t,"leaflet-clickable"),o.DomEvent.on(t,"click",this._onMouseClick,this),o.DomEvent.on(t,"keypress",this._onKeyPress,this);for(var i=0;i<e.length;i++)o.DomEvent.on(t,e[i],this._fireMouseEvent,this);o.Handler.MarkerDrag&&(this.dragging=new o.Handler.MarkerDrag(this),this.options.draggable&&this.dragging.enable())}},_onMouseClick:function(t){var e=this.dragging&&this.dragging.moved();(this.hasEventListeners(t.type)||e)&&o.DomEvent.stopPropagation(t),e||(this.dragging&&this.dragging._enabled||!this._map.dragging||!this._map.dragging.moved())&&this.fire(t.type,{originalEvent:t,latlng:this._latlng})},_onKeyPress:function(t){13===t.keyCode&&this.fire("click",{originalEvent:t,latlng:this._latlng})},_fireMouseEvent:function(t){this.fire(t.type,{originalEvent:t,latlng:this._latlng}),"contextmenu"===t.type&&this.hasEventListeners(t.type)&&o.DomEvent.preventDefault(t),"mousedown"!==t.type?o.DomEvent.stopPropagation(t):o.DomEvent.preventDefault(t)},setOpacity:function(t){return this.options.opacity=t,this._map&&this._updateOpacity(),this},_updateOpacity:function(){o.DomUtil.setOpacity(this._icon,this.options.opacity),this._shadow&&o.DomUtil.setOpacity(this._shadow,this.options.opacity)},_bringToFront:function(){this._updateZIndex(this.options.riseOffset)},_resetZIndex:function(){this._updateZIndex(0)}}),o.marker=function(t,e){return new o.Marker(t,e)},o.DivIcon=o.Icon.extend({options:{iconSize:[12,12],className:"leaflet-div-icon",html:!1},createIcon:function(t){var i=t&&"DIV"===t.tagName?t:e.createElement("div"),n=this.options;return i.innerHTML=n.html!==!1?n.html:"",n.bgPos&&(i.style.backgroundPosition=-n.bgPos.x+"px "+-n.bgPos.y+"px"),this._setIconStyles(i,"icon"),i},createShadow:function(){return null}}),o.divIcon=function(t){return new o.DivIcon(t)},o.Map.mergeOptions({closePopupOnClick:!0}),o.Popup=o.Class.extend({includes:o.Mixin.Events,options:{minWidth:50,maxWidth:300,autoPan:!0,closeButton:!0,offset:[0,7],autoPanPadding:[5,5],keepInView:!1,className:"",zoomAnimation:!0},initialize:function(t,e){o.setOptions(this,t),this._source=e,this._animated=o.Browser.any3d&&this.options.zoomAnimation,this._isOpen=!1},onAdd:function(t){this._map=t,this._container||this._initLayout();var e=t.options.fadeAnimation;e&&o.DomUtil.setOpacity(this._container,0),t._panes.popupPane.appendChild(this._container),t.on(this._getEvents(),this),this.update(),e&&o.DomUtil.setOpacity(this._container,1),this.fire("open"),t.fire("popupopen",{popup:this}),this._source&&this._source.fire("popupopen",{popup:this})},addTo:function(t){return t.addLayer(this),this},openOn:function(t){return t.openPopup(this),this},onRemove:function(t){t._panes.popupPane.removeChild(this._container),o.Util.falseFn(this._container.offsetWidth),t.off(this._getEvents(),this),t.options.fadeAnimation&&o.DomUtil.setOpacity(this._container,0),this._map=null,this.fire("close"),t.fire("popupclose",{popup:this}),this._source&&this._source.fire("popupclose",{popup:this})},getLatLng:function(){return this._latlng},setLatLng:function(t){return this._latlng=o.latLng(t),this._map&&(this._updatePosition(),this._adjustPan()),this},getContent:function(){return this._content},setContent:function(t){return this._content=t,this.update(),this},update:function(){this._map&&(this._container.style.visibility="hidden",this._updateContent(),this._updateLayout(),this._updatePosition(),this._container.style.visibility="",this._adjustPan())},_getEvents:function(){var t={viewreset:this._updatePosition};return this._animated&&(t.zoomanim=this._zoomAnimation),("closeOnClick"in this.options?this.options.closeOnClick:this._map.options.closePopupOnClick)&&(t.preclick=this._close),this.options.keepInView&&(t.moveend=this._adjustPan),t},_close:function(){this._map&&this._map.closePopup(this)},_initLayout:function(){var t,e="leaflet-popup",i=e+" "+this.options.className+" leaflet-zoom-"+(this._animated?"animated":"hide"),n=this._container=o.DomUtil.create("div",i);this.options.closeButton&&(t=this._closeButton=o.DomUtil.create("a",e+"-close-button",n),t.href="#close",t.innerHTML="&#215;",o.DomEvent.disableClickPropagation(t),o.DomEvent.on(t,"click",this._onCloseButtonClick,this));var s=this._wrapper=o.DomUtil.create("div",e+"-content-wrapper",n);o.DomEvent.disableClickPropagation(s),this._contentNode=o.DomUtil.create("div",e+"-content",s),o.DomEvent.disableScrollPropagation(this._contentNode),o.DomEvent.on(s,"contextmenu",o.DomEvent.stopPropagation),this._tipContainer=o.DomUtil.create("div",e+"-tip-container",n),this._tip=o.DomUtil.create("div",e+"-tip",this._tipContainer)},_updateContent:function(){if(this._content){if("string"==typeof this._content)this._contentNode.innerHTML=this._content;else{for(;this._contentNode.hasChildNodes();)this._contentNode.removeChild(this._contentNode.firstChild);this._contentNode.appendChild(this._content)}this.fire("contentupdate")}},_updateLayout:function(){var t=this._contentNode,e=t.style;e.width="",e.whiteSpace="nowrap";var i=t.offsetWidth;i=Math.min(i,this.options.maxWidth),i=Math.max(i,this.options.minWidth),e.width=i+1+"px",e.whiteSpace="",e.height="";var n=t.offsetHeight,s=this.options.maxHeight,a="leaflet-popup-scrolled";s&&n>s?(e.height=s+"px",o.DomUtil.addClass(t,a)):o.DomUtil.removeClass(t,a),this._containerWidth=this._container.offsetWidth},_updatePosition:function(){if(this._map){var t=this._map.latLngToLayerPoint(this._latlng),e=this._animated,i=o.point(this.options.offset);e&&o.DomUtil.setPosition(this._container,t),this._containerBottom=-i.y-(e?0:t.y),this._containerLeft=-Math.round(this._containerWidth/2)+i.x+(e?0:t.x),this._container.style.bottom=this._containerBottom+"px",this._container.style.left=this._containerLeft+"px"}},_zoomAnimation:function(t){var e=this._map._latLngToNewLayerPoint(this._latlng,t.zoom,t.center);o.DomUtil.setPosition(this._container,e)},_adjustPan:function(){if(this.options.autoPan){var t=this._map,e=this._container.offsetHeight,i=this._containerWidth,n=new o.Point(this._containerLeft,-e-this._containerBottom);this._animated&&n._add(o.DomUtil.getPosition(this._container));var s=t.layerPointToContainerPoint(n),a=o.point(this.options.autoPanPadding),r=o.point(this.options.autoPanPaddingTopLeft||a),h=o.point(this.options.autoPanPaddingBottomRight||a),l=t.getSize(),u=0,c=0;s.x+i+h.x>l.x&&(u=s.x+i-l.x+h.x),s.x-u-r.x<0&&(u=s.x-r.x),s.y+e+h.y>l.y&&(c=s.y+e-l.y+h.y),s.y-c-r.y<0&&(c=s.y-r.y),(u||c)&&t.fire("autopanstart").panBy([u,c])}},_onCloseButtonClick:function(t){this._close(),o.DomEvent.stop(t)}}),o.popup=function(t,e){return new o.Popup(t,e)},o.Map.include({openPopup:function(t,e,i){if(this.closePopup(),!(t instanceof o.Popup)){var n=t;t=new o.Popup(i).setLatLng(e).setContent(n)}return t._isOpen=!0,this._popup=t,this.addLayer(t)},closePopup:function(t){return t&&t!==this._popup||(t=this._popup,this._popup=null),t&&(this.removeLayer(t),t._isOpen=!1),this}}),o.Marker.include({openPopup:function(){return this._popup&&this._map&&!this._map.hasLayer(this._popup)&&(this._popup.setLatLng(this._latlng),this._map.openPopup(this._popup)),this},closePopup:function(){return this._popup&&this._popup._close(),this},togglePopup:function(){return this._popup&&(this._popup._isOpen?this.closePopup():this.openPopup()),this},bindPopup:function(t,e){var i=o.point(this.options.icon.options.popupAnchor||[0,0]);return i=i.add(o.Popup.prototype.options.offset),e&&e.offset&&(i=i.add(e.offset)),e=o.extend({offset:i},e),this._popupHandlersAdded||(this.on("click",this.togglePopup,this).on("remove",this.closePopup,this).on("move",this._movePopup,this),this._popupHandlersAdded=!0),t instanceof o.Popup?(o.setOptions(t,e),this._popup=t):this._popup=new o.Popup(e,this).setContent(t),this},setPopupContent:function(t){return this._popup&&this._popup.setContent(t),this},unbindPopup:function(){return this._popup&&(this._popup=null,this.off("click",this.togglePopup,this).off("remove",this.closePopup,this).off("move",this._movePopup,this),this._popupHandlersAdded=!1),this},getPopup:function(){return this._popup},_movePopup:function(t){this._popup.setLatLng(t.latlng)}}),o.LayerGroup=o.Class.extend({initialize:function(t){this._layers={};var e,i;if(t)for(e=0,i=t.length;i>e;e++)this.addLayer(t[e])},addLayer:function(t){var e=this.getLayerId(t);return this._layers[e]=t,this._map&&this._map.addLayer(t),this},removeLayer:function(t){var e=t in this._layers?t:this.getLayerId(t);return this._map&&this._layers[e]&&this._map.removeLayer(this._layers[e]),delete this._layers[e],this},hasLayer:function(t){return t?t in this._layers||this.getLayerId(t)in this._layers:!1},clearLayers:function(){return this.eachLayer(this.removeLayer,this),this},invoke:function(t){var e,i,n=Array.prototype.slice.call(arguments,1);for(e in this._layers)i=this._layers[e],i[t]&&i[t].apply(i,n);return this},onAdd:function(t){this._map=t,this.eachLayer(t.addLayer,t)},onRemove:function(t){this.eachLayer(t.removeLayer,t),this._map=null},addTo:function(t){return t.addLayer(this),this},eachLayer:function(t,e){for(var i in this._layers)t.call(e,this._layers[i]);return this},getLayer:function(t){return this._layers[t]},getLayers:function(){var t=[];for(var e in this._layers)t.push(this._layers[e]);return t},setZIndex:function(t){return this.invoke("setZIndex",t)},getLayerId:function(t){return o.stamp(t)}}),o.layerGroup=function(t){return new o.LayerGroup(t)},o.FeatureGroup=o.LayerGroup.extend({includes:o.Mixin.Events,statics:{EVENTS:"click dblclick mouseover mouseout mousemove contextmenu popupopen popupclose"},addLayer:function(t){return this.hasLayer(t)?this:("on"in t&&t.on(o.FeatureGroup.EVENTS,this._propagateEvent,this),o.LayerGroup.prototype.addLayer.call(this,t),this._popupContent&&t.bindPopup&&t.bindPopup(this._popupContent,this._popupOptions),this.fire("layeradd",{layer:t}))},removeLayer:function(t){return this.hasLayer(t)?(t in this._layers&&(t=this._layers[t]),t.off(o.FeatureGroup.EVENTS,this._propagateEvent,this),o.LayerGroup.prototype.removeLayer.call(this,t),this._popupContent&&this.invoke("unbindPopup"),this.fire("layerremove",{layer:t})):this},bindPopup:function(t,e){return this._popupContent=t,this._popupOptions=e,this.invoke("bindPopup",t,e)},openPopup:function(t){for(var e in this._layers){this._layers[e].openPopup(t);break}return this},setStyle:function(t){return this.invoke("setStyle",t)},bringToFront:function(){return this.invoke("bringToFront")},bringToBack:function(){return this.invoke("bringToBack")},getBounds:function(){var t=new o.LatLngBounds;return this.eachLayer(function(e){t.extend(e instanceof o.Marker?e.getLatLng():e.getBounds())}),t},_propagateEvent:function(t){t=o.extend({layer:t.target,target:this},t),this.fire(t.type,t)}}),o.featureGroup=function(t){return new o.FeatureGroup(t)},o.Path=o.Class.extend({includes:[o.Mixin.Events],statics:{CLIP_PADDING:function(){var e=o.Browser.mobile?1280:2e3,i=(e/Math.max(t.outerWidth,t.outerHeight)-1)/2;return Math.max(0,Math.min(.5,i))}()},options:{stroke:!0,color:"#0033ff",dashArray:null,lineCap:null,lineJoin:null,weight:5,opacity:.5,fill:!1,fillColor:null,fillOpacity:.2,clickable:!0},initialize:function(t){o.setOptions(this,t)},onAdd:function(t){this._map=t,this._container||(this._initElements(),this._initEvents()),this.projectLatlngs(),this._updatePath(),this._container&&this._map._pathRoot.appendChild(this._container),this.fire("add"),t.on({viewreset:this.projectLatlngs,moveend:this._updatePath},this)},addTo:function(t){return t.addLayer(this),this},onRemove:function(t){t._pathRoot.removeChild(this._container),this.fire("remove"),this._map=null,o.Browser.vml&&(this._container=null,this._stroke=null,this._fill=null),t.off({viewreset:this.projectLatlngs,moveend:this._updatePath},this)},projectLatlngs:function(){},setStyle:function(t){return o.setOptions(this,t),this._container&&this._updateStyle(),this},redraw:function(){return this._map&&(this.projectLatlngs(),this._updatePath()),this}}),o.Map.include({_updatePathViewport:function(){var t=o.Path.CLIP_PADDING,e=this.getSize(),i=o.DomUtil.getPosition(this._mapPane),n=i.multiplyBy(-1)._subtract(e.multiplyBy(t)._round()),s=n.add(e.multiplyBy(1+2*t)._round());this._pathViewport=new o.Bounds(n,s)}}),o.Path.SVG_NS="http://www.w3.org/2000/svg",o.Browser.svg=!(!e.createElementNS||!e.createElementNS(o.Path.SVG_NS,"svg").createSVGRect),o.Path=o.Path.extend({statics:{SVG:o.Browser.svg},bringToFront:function(){var t=this._map._pathRoot,e=this._container;return e&&t.lastChild!==e&&t.appendChild(e),this},bringToBack:function(){var t=this._map._pathRoot,e=this._container,i=t.firstChild;return e&&i!==e&&t.insertBefore(e,i),this},getPathString:function(){},_createElement:function(t){return e.createElementNS(o.Path.SVG_NS,t)},_initElements:function(){this._map._initPathRoot(),this._initPath(),this._initStyle()},_initPath:function(){this._container=this._createElement("g"),this._path=this._createElement("path"),this.options.className&&o.DomUtil.addClass(this._path,this.options.className),this._container.appendChild(this._path)},_initStyle:function(){this.options.stroke&&(this._path.setAttribute("stroke-linejoin","round"),this._path.setAttribute("stroke-linecap","round")),this.options.fill&&this._path.setAttribute("fill-rule","evenodd"),this.options.pointerEvents&&this._path.setAttribute("pointer-events",this.options.pointerEvents),this.options.clickable||this.options.pointerEvents||this._path.setAttribute("pointer-events","none"),this._updateStyle()},_updateStyle:function(){this.options.stroke?(this._path.setAttribute("stroke",this.options.color),this._path.setAttribute("stroke-opacity",this.options.opacity),this._path.setAttribute("stroke-width",this.options.weight),this.options.dashArray?this._path.setAttribute("stroke-dasharray",this.options.dashArray):this._path.removeAttribute("stroke-dasharray"),this.options.lineCap&&this._path.setAttribute("stroke-linecap",this.options.lineCap),this.options.lineJoin&&this._path.setAttribute("stroke-linejoin",this.options.lineJoin)):this._path.setAttribute("stroke","none"),this.options.fill?(this._path.setAttribute("fill",this.options.fillColor||this.options.color),this._path.setAttribute("fill-opacity",this.options.fillOpacity)):this._path.setAttribute("fill","none")},_updatePath:function(){var t=this.getPathString();t||(t="M0 0"),this._path.setAttribute("d",t)},_initEvents:function(){if(this.options.clickable){(o.Browser.svg||!o.Browser.vml)&&o.DomUtil.addClass(this._path,"leaflet-clickable"),o.DomEvent.on(this._container,"click",this._onMouseClick,this);for(var t=["dblclick","mousedown","mouseover","mouseout","mousemove","contextmenu"],e=0;e<t.length;e++)o.DomEvent.on(this._container,t[e],this._fireMouseEvent,this)}},_onMouseClick:function(t){this._map.dragging&&this._map.dragging.moved()||this._fireMouseEvent(t)},_fireMouseEvent:function(t){if(this.hasEventListeners(t.type)){var e=this._map,i=e.mouseEventToContainerPoint(t),n=e.containerPointToLayerPoint(i),s=e.layerPointToLatLng(n);this.fire(t.type,{latlng:s,layerPoint:n,containerPoint:i,originalEvent:t}),"contextmenu"===t.type&&o.DomEvent.preventDefault(t),"mousemove"!==t.type&&o.DomEvent.stopPropagation(t)}}}),o.Map.include({_initPathRoot:function(){this._pathRoot||(this._pathRoot=o.Path.prototype._createElement("svg"),this._panes.overlayPane.appendChild(this._pathRoot),this.options.zoomAnimation&&o.Browser.any3d?(o.DomUtil.addClass(this._pathRoot,"leaflet-zoom-animated"),this.on({zoomanim:this._animatePathZoom,zoomend:this._endPathZoom})):o.DomUtil.addClass(this._pathRoot,"leaflet-zoom-hide"),this.on("moveend",this._updateSvgViewport),this._updateSvgViewport())
7 },_animatePathZoom:function(t){var e=this.getZoomScale(t.zoom),i=this._getCenterOffset(t.center)._multiplyBy(-e)._add(this._pathViewport.min);this._pathRoot.style[o.DomUtil.TRANSFORM]=o.DomUtil.getTranslateString(i)+" scale("+e+") ",this._pathZooming=!0},_endPathZoom:function(){this._pathZooming=!1},_updateSvgViewport:function(){if(!this._pathZooming){this._updatePathViewport();var t=this._pathViewport,e=t.min,i=t.max,n=i.x-e.x,s=i.y-e.y,a=this._pathRoot,r=this._panes.overlayPane;o.Browser.mobileWebkit&&r.removeChild(a),o.DomUtil.setPosition(a,e),a.setAttribute("width",n),a.setAttribute("height",s),a.setAttribute("viewBox",[e.x,e.y,n,s].join(" ")),o.Browser.mobileWebkit&&r.appendChild(a)}}}),o.Path.include({bindPopup:function(t,e){return t instanceof o.Popup?this._popup=t:((!this._popup||e)&&(this._popup=new o.Popup(e,this)),this._popup.setContent(t)),this._popupHandlersAdded||(this.on("click",this._openPopup,this).on("remove",this.closePopup,this),this._popupHandlersAdded=!0),this},unbindPopup:function(){return this._popup&&(this._popup=null,this.off("click",this._openPopup).off("remove",this.closePopup),this._popupHandlersAdded=!1),this},openPopup:function(t){return this._popup&&(t=t||this._latlng||this._latlngs[Math.floor(this._latlngs.length/2)],this._openPopup({latlng:t})),this},closePopup:function(){return this._popup&&this._popup._close(),this},_openPopup:function(t){this._popup.setLatLng(t.latlng),this._map.openPopup(this._popup)}}),o.Browser.vml=!o.Browser.svg&&function(){try{var t=e.createElement("div");t.innerHTML='<v:shape adj="1"/>';var i=t.firstChild;return i.style.behavior="url(#default#VML)",i&&"object"==typeof i.adj}catch(n){return!1}}(),o.Path=o.Browser.svg||!o.Browser.vml?o.Path:o.Path.extend({statics:{VML:!0,CLIP_PADDING:.02},_createElement:function(){try{return e.namespaces.add("lvml","urn:schemas-microsoft-com:vml"),function(t){return e.createElement("<lvml:"+t+' class="lvml">')}}catch(t){return function(t){return e.createElement("<"+t+' xmlns="urn:schemas-microsoft.com:vml" class="lvml">')}}}(),_initPath:function(){var t=this._container=this._createElement("shape");o.DomUtil.addClass(t,"leaflet-vml-shape"+(this.options.className?" "+this.options.className:"")),this.options.clickable&&o.DomUtil.addClass(t,"leaflet-clickable"),t.coordsize="1 1",this._path=this._createElement("path"),t.appendChild(this._path),this._map._pathRoot.appendChild(t)},_initStyle:function(){this._updateStyle()},_updateStyle:function(){var t=this._stroke,e=this._fill,i=this.options,n=this._container;n.stroked=i.stroke,n.filled=i.fill,i.stroke?(t||(t=this._stroke=this._createElement("stroke"),t.endcap="round",n.appendChild(t)),t.weight=i.weight+"px",t.color=i.color,t.opacity=i.opacity,t.dashStyle=i.dashArray?o.Util.isArray(i.dashArray)?i.dashArray.join(" "):i.dashArray.replace(/( *, *)/g," "):"",i.lineCap&&(t.endcap=i.lineCap.replace("butt","flat")),i.lineJoin&&(t.joinstyle=i.lineJoin)):t&&(n.removeChild(t),this._stroke=null),i.fill?(e||(e=this._fill=this._createElement("fill"),n.appendChild(e)),e.color=i.fillColor||i.color,e.opacity=i.fillOpacity):e&&(n.removeChild(e),this._fill=null)},_updatePath:function(){var t=this._container.style;t.display="none",this._path.v=this.getPathString()+" ",t.display=""}}),o.Map.include(o.Browser.svg||!o.Browser.vml?{}:{_initPathRoot:function(){if(!this._pathRoot){var t=this._pathRoot=e.createElement("div");t.className="leaflet-vml-container",this._panes.overlayPane.appendChild(t),this.on("moveend",this._updatePathViewport),this._updatePathViewport()}}}),o.Browser.canvas=function(){return!!e.createElement("canvas").getContext}(),o.Path=o.Path.SVG&&!t.L_PREFER_CANVAS||!o.Browser.canvas?o.Path:o.Path.extend({statics:{CANVAS:!0,SVG:!1},redraw:function(){return this._map&&(this.projectLatlngs(),this._requestUpdate()),this},setStyle:function(t){return o.setOptions(this,t),this._map&&(this._updateStyle(),this._requestUpdate()),this},onRemove:function(t){t.off("viewreset",this.projectLatlngs,this).off("moveend",this._updatePath,this),this.options.clickable&&(this._map.off("click",this._onClick,this),this._map.off("mousemove",this._onMouseMove,this)),this._requestUpdate(),this.fire("remove"),this._map=null},_requestUpdate:function(){this._map&&!o.Path._updateRequest&&(o.Path._updateRequest=o.Util.requestAnimFrame(this._fireMapMoveEnd,this._map))},_fireMapMoveEnd:function(){o.Path._updateRequest=null,this.fire("moveend")},_initElements:function(){this._map._initPathRoot(),this._ctx=this._map._canvasCtx},_updateStyle:function(){var t=this.options;t.stroke&&(this._ctx.lineWidth=t.weight,this._ctx.strokeStyle=t.color),t.fill&&(this._ctx.fillStyle=t.fillColor||t.color)},_drawPath:function(){var t,e,i,n,s,a;for(this._ctx.beginPath(),t=0,i=this._parts.length;i>t;t++){for(e=0,n=this._parts[t].length;n>e;e++)s=this._parts[t][e],a=(0===e?"move":"line")+"To",this._ctx[a](s.x,s.y);this instanceof o.Polygon&&this._ctx.closePath()}},_checkIfEmpty:function(){return!this._parts.length},_updatePath:function(){if(!this._checkIfEmpty()){var t=this._ctx,e=this.options;this._drawPath(),t.save(),this._updateStyle(),e.fill&&(t.globalAlpha=e.fillOpacity,t.fill()),e.stroke&&(t.globalAlpha=e.opacity,t.stroke()),t.restore()}},_initEvents:function(){this.options.clickable&&(this._map.on("mousemove",this._onMouseMove,this),this._map.on("click",this._onClick,this))},_onClick:function(t){this._containsPoint(t.layerPoint)&&this.fire("click",t)},_onMouseMove:function(t){this._map&&!this._map._animatingZoom&&(this._containsPoint(t.layerPoint)?(this._ctx.canvas.style.cursor="pointer",this._mouseInside=!0,this.fire("mouseover",t)):this._mouseInside&&(this._ctx.canvas.style.cursor="",this._mouseInside=!1,this.fire("mouseout",t)))}}),o.Map.include(o.Path.SVG&&!t.L_PREFER_CANVAS||!o.Browser.canvas?{}:{_initPathRoot:function(){var t,i=this._pathRoot;i||(i=this._pathRoot=e.createElement("canvas"),i.style.position="absolute",t=this._canvasCtx=i.getContext("2d"),t.lineCap="round",t.lineJoin="round",this._panes.overlayPane.appendChild(i),this.options.zoomAnimation&&(this._pathRoot.className="leaflet-zoom-animated",this.on("zoomanim",this._animatePathZoom),this.on("zoomend",this._endPathZoom)),this.on("moveend",this._updateCanvasViewport),this._updateCanvasViewport())},_updateCanvasViewport:function(){if(!this._pathZooming){this._updatePathViewport();var t=this._pathViewport,e=t.min,i=t.max.subtract(e),n=this._pathRoot;o.DomUtil.setPosition(n,e),n.width=i.x,n.height=i.y,n.getContext("2d").translate(-e.x,-e.y)}}}),o.LineUtil={simplify:function(t,e){if(!e||!t.length)return t.slice();var i=e*e;return t=this._reducePoints(t,i),t=this._simplifyDP(t,i)},pointToSegmentDistance:function(t,e,i){return Math.sqrt(this._sqClosestPointOnSegment(t,e,i,!0))},closestPointOnSegment:function(t,e,i){return this._sqClosestPointOnSegment(t,e,i)},_simplifyDP:function(t,e){var n=t.length,o=typeof Uint8Array!=i+""?Uint8Array:Array,s=new o(n);s[0]=s[n-1]=1,this._simplifyDPStep(t,s,e,0,n-1);var a,r=[];for(a=0;n>a;a++)s[a]&&r.push(t[a]);return r},_simplifyDPStep:function(t,e,i,n,o){var s,a,r,h=0;for(a=n+1;o-1>=a;a++)r=this._sqClosestPointOnSegment(t[a],t[n],t[o],!0),r>h&&(s=a,h=r);h>i&&(e[s]=1,this._simplifyDPStep(t,e,i,n,s),this._simplifyDPStep(t,e,i,s,o))},_reducePoints:function(t,e){for(var i=[t[0]],n=1,o=0,s=t.length;s>n;n++)this._sqDist(t[n],t[o])>e&&(i.push(t[n]),o=n);return s-1>o&&i.push(t[s-1]),i},clipSegment:function(t,e,i,n){var o,s,a,r=n?this._lastCode:this._getBitCode(t,i),h=this._getBitCode(e,i);for(this._lastCode=h;;){if(!(r|h))return[t,e];if(r&h)return!1;o=r||h,s=this._getEdgeIntersection(t,e,o,i),a=this._getBitCode(s,i),o===r?(t=s,r=a):(e=s,h=a)}},_getEdgeIntersection:function(t,e,i,n){var s=e.x-t.x,a=e.y-t.y,r=n.min,h=n.max;return 8&i?new o.Point(t.x+s*(h.y-t.y)/a,h.y):4&i?new o.Point(t.x+s*(r.y-t.y)/a,r.y):2&i?new o.Point(h.x,t.y+a*(h.x-t.x)/s):1&i?new o.Point(r.x,t.y+a*(r.x-t.x)/s):void 0},_getBitCode:function(t,e){var i=0;return t.x<e.min.x?i|=1:t.x>e.max.x&&(i|=2),t.y<e.min.y?i|=4:t.y>e.max.y&&(i|=8),i},_sqDist:function(t,e){var i=e.x-t.x,n=e.y-t.y;return i*i+n*n},_sqClosestPointOnSegment:function(t,e,i,n){var s,a=e.x,r=e.y,h=i.x-a,l=i.y-r,u=h*h+l*l;return u>0&&(s=((t.x-a)*h+(t.y-r)*l)/u,s>1?(a=i.x,r=i.y):s>0&&(a+=h*s,r+=l*s)),h=t.x-a,l=t.y-r,n?h*h+l*l:new o.Point(a,r)}},o.Polyline=o.Path.extend({initialize:function(t,e){o.Path.prototype.initialize.call(this,e),this._latlngs=this._convertLatLngs(t)},options:{smoothFactor:1,noClip:!1},projectLatlngs:function(){this._originalPoints=[];for(var t=0,e=this._latlngs.length;e>t;t++)this._originalPoints[t]=this._map.latLngToLayerPoint(this._latlngs[t])},getPathString:function(){for(var t=0,e=this._parts.length,i="";e>t;t++)i+=this._getPathPartStr(this._parts[t]);return i},getLatLngs:function(){return this._latlngs},setLatLngs:function(t){return this._latlngs=this._convertLatLngs(t),this.redraw()},addLatLng:function(t){return this._latlngs.push(o.latLng(t)),this.redraw()},spliceLatLngs:function(){var t=[].splice.apply(this._latlngs,arguments);return this._convertLatLngs(this._latlngs,!0),this.redraw(),t},closestLayerPoint:function(t){for(var e,i,n=1/0,s=this._parts,a=null,r=0,h=s.length;h>r;r++)for(var l=s[r],u=1,c=l.length;c>u;u++){e=l[u-1],i=l[u];var d=o.LineUtil._sqClosestPointOnSegment(t,e,i,!0);n>d&&(n=d,a=o.LineUtil._sqClosestPointOnSegment(t,e,i))}return a&&(a.distance=Math.sqrt(n)),a},getBounds:function(){return new o.LatLngBounds(this.getLatLngs())},_convertLatLngs:function(t,e){var i,n,s=e?t:[];for(i=0,n=t.length;n>i;i++){if(o.Util.isArray(t[i])&&"number"!=typeof t[i][0])return;s[i]=o.latLng(t[i])}return s},_initEvents:function(){o.Path.prototype._initEvents.call(this)},_getPathPartStr:function(t){for(var e,i=o.Path.VML,n=0,s=t.length,a="";s>n;n++)e=t[n],i&&e._round(),a+=(n?"L":"M")+e.x+" "+e.y;return a},_clipPoints:function(){var t,e,i,n=this._originalPoints,s=n.length;if(this.options.noClip)return void(this._parts=[n]);this._parts=[];var a=this._parts,r=this._map._pathViewport,h=o.LineUtil;for(t=0,e=0;s-1>t;t++)i=h.clipSegment(n[t],n[t+1],r,t),i&&(a[e]=a[e]||[],a[e].push(i[0]),(i[1]!==n[t+1]||t===s-2)&&(a[e].push(i[1]),e++))},_simplifyPoints:function(){for(var t=this._parts,e=o.LineUtil,i=0,n=t.length;n>i;i++)t[i]=e.simplify(t[i],this.options.smoothFactor)},_updatePath:function(){this._map&&(this._clipPoints(),this._simplifyPoints(),o.Path.prototype._updatePath.call(this))}}),o.polyline=function(t,e){return new o.Polyline(t,e)},o.PolyUtil={},o.PolyUtil.clipPolygon=function(t,e){var i,n,s,a,r,h,l,u,c,d=[1,4,2,8],p=o.LineUtil;for(n=0,l=t.length;l>n;n++)t[n]._code=p._getBitCode(t[n],e);for(a=0;4>a;a++){for(u=d[a],i=[],n=0,l=t.length,s=l-1;l>n;s=n++)r=t[n],h=t[s],r._code&u?h._code&u||(c=p._getEdgeIntersection(h,r,u,e),c._code=p._getBitCode(c,e),i.push(c)):(h._code&u&&(c=p._getEdgeIntersection(h,r,u,e),c._code=p._getBitCode(c,e),i.push(c)),i.push(r));t=i}return t},o.Polygon=o.Polyline.extend({options:{fill:!0},initialize:function(t,e){o.Polyline.prototype.initialize.call(this,t,e),this._initWithHoles(t)},_initWithHoles:function(t){var e,i,n;if(t&&o.Util.isArray(t[0])&&"number"!=typeof t[0][0])for(this._latlngs=this._convertLatLngs(t[0]),this._holes=t.slice(1),e=0,i=this._holes.length;i>e;e++)n=this._holes[e]=this._convertLatLngs(this._holes[e]),n[0].equals(n[n.length-1])&&n.pop();t=this._latlngs,t.length>=2&&t[0].equals(t[t.length-1])&&t.pop()},projectLatlngs:function(){if(o.Polyline.prototype.projectLatlngs.call(this),this._holePoints=[],this._holes){var t,e,i,n;for(t=0,i=this._holes.length;i>t;t++)for(this._holePoints[t]=[],e=0,n=this._holes[t].length;n>e;e++)this._holePoints[t][e]=this._map.latLngToLayerPoint(this._holes[t][e])}},setLatLngs:function(t){return t&&o.Util.isArray(t[0])&&"number"!=typeof t[0][0]?(this._initWithHoles(t),this.redraw()):o.Polyline.prototype.setLatLngs.call(this,t)},_clipPoints:function(){var t=this._originalPoints,e=[];if(this._parts=[t].concat(this._holePoints),!this.options.noClip){for(var i=0,n=this._parts.length;n>i;i++){var s=o.PolyUtil.clipPolygon(this._parts[i],this._map._pathViewport);s.length&&e.push(s)}this._parts=e}},_getPathPartStr:function(t){var e=o.Polyline.prototype._getPathPartStr.call(this,t);return e+(o.Browser.svg?"z":"x")}}),o.polygon=function(t,e){return new o.Polygon(t,e)},function(){function t(t){return o.FeatureGroup.extend({initialize:function(t,e){this._layers={},this._options=e,this.setLatLngs(t)},setLatLngs:function(e){var i=0,n=e.length;for(this.eachLayer(function(t){n>i?t.setLatLngs(e[i++]):this.removeLayer(t)},this);n>i;)this.addLayer(new t(e[i++],this._options));return this},getLatLngs:function(){var t=[];return this.eachLayer(function(e){t.push(e.getLatLngs())}),t}})}o.MultiPolyline=t(o.Polyline),o.MultiPolygon=t(o.Polygon),o.multiPolyline=function(t,e){return new o.MultiPolyline(t,e)},o.multiPolygon=function(t,e){return new o.MultiPolygon(t,e)}}(),o.Rectangle=o.Polygon.extend({initialize:function(t,e){o.Polygon.prototype.initialize.call(this,this._boundsToLatLngs(t),e)},setBounds:function(t){this.setLatLngs(this._boundsToLatLngs(t))},_boundsToLatLngs:function(t){return t=o.latLngBounds(t),[t.getSouthWest(),t.getNorthWest(),t.getNorthEast(),t.getSouthEast()]}}),o.rectangle=function(t,e){return new o.Rectangle(t,e)},o.Circle=o.Path.extend({initialize:function(t,e,i){o.Path.prototype.initialize.call(this,i),this._latlng=o.latLng(t),this._mRadius=e},options:{fill:!0},setLatLng:function(t){return this._latlng=o.latLng(t),this.redraw()},setRadius:function(t){return this._mRadius=t,this.redraw()},projectLatlngs:function(){var t=this._getLngRadius(),e=this._latlng,i=this._map.latLngToLayerPoint([e.lat,e.lng-t]);this._point=this._map.latLngToLayerPoint(e),this._radius=Math.max(this._point.x-i.x,1)},getBounds:function(){var t=this._getLngRadius(),e=this._mRadius/40075017*360,i=this._latlng;return new o.LatLngBounds([i.lat-e,i.lng-t],[i.lat+e,i.lng+t])},getLatLng:function(){return this._latlng},getPathString:function(){var t=this._point,e=this._radius;return this._checkIfEmpty()?"":o.Browser.svg?"M"+t.x+","+(t.y-e)+"A"+e+","+e+",0,1,1,"+(t.x-.1)+","+(t.y-e)+" z":(t._round(),e=Math.round(e),"AL "+t.x+","+t.y+" "+e+","+e+" 0,23592600")},getRadius:function(){return this._mRadius},_getLatRadius:function(){return this._mRadius/40075017*360},_getLngRadius:function(){return this._getLatRadius()/Math.cos(o.LatLng.DEG_TO_RAD*this._latlng.lat)},_checkIfEmpty:function(){if(!this._map)return!1;var t=this._map._pathViewport,e=this._radius,i=this._point;return i.x-e>t.max.x||i.y-e>t.max.y||i.x+e<t.min.x||i.y+e<t.min.y}}),o.circle=function(t,e,i){return new o.Circle(t,e,i)},o.CircleMarker=o.Circle.extend({options:{radius:10,weight:2},initialize:function(t,e){o.Circle.prototype.initialize.call(this,t,null,e),this._radius=this.options.radius},projectLatlngs:function(){this._point=this._map.latLngToLayerPoint(this._latlng)},_updateStyle:function(){o.Circle.prototype._updateStyle.call(this),this.setRadius(this.options.radius)},setLatLng:function(t){return o.Circle.prototype.setLatLng.call(this,t),this._popup&&this._popup._isOpen&&this._popup.setLatLng(t),this},setRadius:function(t){return this.options.radius=this._radius=t,this.redraw()},getRadius:function(){return this._radius}}),o.circleMarker=function(t,e){return new o.CircleMarker(t,e)},o.Polyline.include(o.Path.CANVAS?{_containsPoint:function(t,e){var i,n,s,a,r,h,l,u=this.options.weight/2;for(o.Browser.touch&&(u+=10),i=0,a=this._parts.length;a>i;i++)for(l=this._parts[i],n=0,r=l.length,s=r-1;r>n;s=n++)if((e||0!==n)&&(h=o.LineUtil.pointToSegmentDistance(t,l[s],l[n]),u>=h))return!0;return!1}}:{}),o.Polygon.include(o.Path.CANVAS?{_containsPoint:function(t){var e,i,n,s,a,r,h,l,u=!1;if(o.Polyline.prototype._containsPoint.call(this,t,!0))return!0;for(s=0,h=this._parts.length;h>s;s++)for(e=this._parts[s],a=0,l=e.length,r=l-1;l>a;r=a++)i=e[a],n=e[r],i.y>t.y!=n.y>t.y&&t.x<(n.x-i.x)*(t.y-i.y)/(n.y-i.y)+i.x&&(u=!u);return u}}:{}),o.Circle.include(o.Path.CANVAS?{_drawPath:function(){var t=this._point;this._ctx.beginPath(),this._ctx.arc(t.x,t.y,this._radius,0,2*Math.PI,!1)},_containsPoint:function(t){var e=this._point,i=this.options.stroke?this.options.weight/2:0;return t.distanceTo(e)<=this._radius+i}}:{}),o.CircleMarker.include(o.Path.CANVAS?{_updateStyle:function(){o.Path.prototype._updateStyle.call(this)}}:{}),o.GeoJSON=o.FeatureGroup.extend({initialize:function(t,e){o.setOptions(this,e),this._layers={},t&&this.addData(t)},addData:function(t){var e,i,n,s=o.Util.isArray(t)?t:t.features;if(s){for(e=0,i=s.length;i>e;e++)n=s[e],(n.geometries||n.geometry||n.features||n.coordinates)&&this.addData(s[e]);return this}var a=this.options;if(!a.filter||a.filter(t)){var r=o.GeoJSON.geometryToLayer(t,a.pointToLayer,a.coordsToLatLng,a);return r.feature=o.GeoJSON.asFeature(t),r.defaultOptions=r.options,this.resetStyle(r),a.onEachFeature&&a.onEachFeature(t,r),this.addLayer(r)}},resetStyle:function(t){var e=this.options.style;e&&(o.Util.extend(t.options,t.defaultOptions),this._setLayerStyle(t,e))},setStyle:function(t){this.eachLayer(function(e){this._setLayerStyle(e,t)},this)},_setLayerStyle:function(t,e){"function"==typeof e&&(e=e(t.feature)),t.setStyle&&t.setStyle(e)}}),o.extend(o.GeoJSON,{geometryToLayer:function(t,e,i,n){var s,a,r,h,l="Feature"===t.type?t.geometry:t,u=l.coordinates,c=[];switch(i=i||this.coordsToLatLng,l.type){case"Point":return s=i(u),e?e(t,s):new o.Marker(s);case"MultiPoint":for(r=0,h=u.length;h>r;r++)s=i(u[r]),c.push(e?e(t,s):new o.Marker(s));return new o.FeatureGroup(c);case"LineString":return a=this.coordsToLatLngs(u,0,i),new o.Polyline(a,n);case"Polygon":if(2===u.length&&!u[1].length)throw new Error("Invalid GeoJSON object.");return a=this.coordsToLatLngs(u,1,i),new o.Polygon(a,n);case"MultiLineString":return a=this.coordsToLatLngs(u,1,i),new o.MultiPolyline(a,n);case"MultiPolygon":return a=this.coordsToLatLngs(u,2,i),new o.MultiPolygon(a,n);case"GeometryCollection":for(r=0,h=l.geometries.length;h>r;r++)c.push(this.geometryToLayer({geometry:l.geometries[r],type:"Feature",properties:t.properties},e,i,n));return new o.FeatureGroup(c);default:throw new Error("Invalid GeoJSON object.")}},coordsToLatLng:function(t){return new o.LatLng(t[1],t[0],t[2])},coordsToLatLngs:function(t,e,i){var n,o,s,a=[];for(o=0,s=t.length;s>o;o++)n=e?this.coordsToLatLngs(t[o],e-1,i):(i||this.coordsToLatLng)(t[o]),a.push(n);return a},latLngToCoords:function(t){var e=[t.lng,t.lat];return t.alt!==i&&e.push(t.alt),e},latLngsToCoords:function(t){for(var e=[],i=0,n=t.length;n>i;i++)e.push(o.GeoJSON.latLngToCoords(t[i]));return e},getFeature:function(t,e){return t.feature?o.extend({},t.feature,{geometry:e}):o.GeoJSON.asFeature(e)},asFeature:function(t){return"Feature"===t.type?t:{type:"Feature",properties:{},geometry:t}}});var a={toGeoJSON:function(){return o.GeoJSON.getFeature(this,{type:"Point",coordinates:o.GeoJSON.latLngToCoords(this.getLatLng())})}};o.Marker.include(a),o.Circle.include(a),o.CircleMarker.include(a),o.Polyline.include({toGeoJSON:function(){return o.GeoJSON.getFeature(this,{type:"LineString",coordinates:o.GeoJSON.latLngsToCoords(this.getLatLngs())})}}),o.Polygon.include({toGeoJSON:function(){var t,e,i,n=[o.GeoJSON.latLngsToCoords(this.getLatLngs())];if(n[0].push(n[0][0]),this._holes)for(t=0,e=this._holes.length;e>t;t++)i=o.GeoJSON.latLngsToCoords(this._holes[t]),i.push(i[0]),n.push(i);return o.GeoJSON.getFeature(this,{type:"Polygon",coordinates:n})}}),function(){function t(t){return function(){var e=[];return this.eachLayer(function(t){e.push(t.toGeoJSON().geometry.coordinates)}),o.GeoJSON.getFeature(this,{type:t,coordinates:e})}}o.MultiPolyline.include({toGeoJSON:t("MultiLineString")}),o.MultiPolygon.include({toGeoJSON:t("MultiPolygon")}),o.LayerGroup.include({toGeoJSON:function(){var e,i=this.feature&&this.feature.geometry,n=[];if(i&&"MultiPoint"===i.type)return t("MultiPoint").call(this);var s=i&&"GeometryCollection"===i.type;return this.eachLayer(function(t){t.toGeoJSON&&(e=t.toGeoJSON(),n.push(s?e.geometry:o.GeoJSON.asFeature(e)))}),s?o.GeoJSON.getFeature(this,{geometries:n,type:"GeometryCollection"}):{type:"FeatureCollection",features:n}}})}(),o.geoJson=function(t,e){return new o.GeoJSON(t,e)},o.DomEvent={addListener:function(t,e,i,n){var s,a,r,h=o.stamp(i),l="_leaflet_"+e+h;return t[l]?this:(s=function(e){return i.call(n||t,e||o.DomEvent._getEvent())},o.Browser.pointer&&0===e.indexOf("touch")?this.addPointerListener(t,e,s,h):(o.Browser.touch&&"dblclick"===e&&this.addDoubleTapListener&&this.addDoubleTapListener(t,s,h),"addEventListener"in t?"mousewheel"===e?(t.addEventListener("DOMMouseScroll",s,!1),t.addEventListener(e,s,!1)):"mouseenter"===e||"mouseleave"===e?(a=s,r="mouseenter"===e?"mouseover":"mouseout",s=function(e){return o.DomEvent._checkMouse(t,e)?a(e):void 0},t.addEventListener(r,s,!1)):"click"===e&&o.Browser.android?(a=s,s=function(t){return o.DomEvent._filterClick(t,a)},t.addEventListener(e,s,!1)):t.addEventListener(e,s,!1):"attachEvent"in t&&t.attachEvent("on"+e,s),t[l]=s,this))},removeListener:function(t,e,i){var n=o.stamp(i),s="_leaflet_"+e+n,a=t[s];return a?(o.Browser.pointer&&0===e.indexOf("touch")?this.removePointerListener(t,e,n):o.Browser.touch&&"dblclick"===e&&this.removeDoubleTapListener?this.removeDoubleTapListener(t,n):"removeEventListener"in t?"mousewheel"===e?(t.removeEventListener("DOMMouseScroll",a,!1),t.removeEventListener(e,a,!1)):"mouseenter"===e||"mouseleave"===e?t.removeEventListener("mouseenter"===e?"mouseover":"mouseout",a,!1):t.removeEventListener(e,a,!1):"detachEvent"in t&&t.detachEvent("on"+e,a),t[s]=null,this):this},stopPropagation:function(t){return t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,o.DomEvent._skipped(t),this},disableScrollPropagation:function(t){var e=o.DomEvent.stopPropagation;return o.DomEvent.on(t,"mousewheel",e).on(t,"MozMousePixelScroll",e)},disableClickPropagation:function(t){for(var e=o.DomEvent.stopPropagation,i=o.Draggable.START.length-1;i>=0;i--)o.DomEvent.on(t,o.Draggable.START[i],e);return o.DomEvent.on(t,"click",o.DomEvent._fakeStop).on(t,"dblclick",e)},preventDefault:function(t){return t.preventDefault?t.preventDefault():t.returnValue=!1,this},stop:function(t){return o.DomEvent.preventDefault(t).stopPropagation(t)},getMousePosition:function(t,e){if(!e)return new o.Point(t.clientX,t.clientY);var i=e.getBoundingClientRect();return new o.Point(t.clientX-i.left-e.clientLeft,t.clientY-i.top-e.clientTop)},getWheelDelta:function(t){var e=0;return t.wheelDelta&&(e=t.wheelDelta/120),t.detail&&(e=-t.detail/3),e},_skipEvents:{},_fakeStop:function(t){o.DomEvent._skipEvents[t.type]=!0},_skipped:function(t){var e=this._skipEvents[t.type];return this._skipEvents[t.type]=!1,e},_checkMouse:function(t,e){var i=e.relatedTarget;if(!i)return!0;try{for(;i&&i!==t;)i=i.parentNode}catch(n){return!1}return i!==t},_getEvent:function(){var e=t.event;if(!e)for(var i=arguments.callee.caller;i&&(e=i.arguments[0],!e||t.Event!==e.constructor);)i=i.caller;return e},_filterClick:function(t,e){var i=t.timeStamp||t.originalEvent.timeStamp,n=o.DomEvent._lastClick&&i-o.DomEvent._lastClick;return n&&n>100&&500>n||t.target._simulatedClick&&!t._simulated?void o.DomEvent.stop(t):(o.DomEvent._lastClick=i,e(t))}},o.DomEvent.on=o.DomEvent.addListener,o.DomEvent.off=o.DomEvent.removeListener,o.Draggable=o.Class.extend({includes:o.Mixin.Events,statics:{START:o.Browser.touch?["touchstart","mousedown"]:["mousedown"],END:{mousedown:"mouseup",touchstart:"touchend",pointerdown:"touchend",MSPointerDown:"touchend"},MOVE:{mousedown:"mousemove",touchstart:"touchmove",pointerdown:"touchmove",MSPointerDown:"touchmove"}},initialize:function(t,e){this._element=t,this._dragStartTarget=e||t},enable:function(){if(!this._enabled){for(var t=o.Draggable.START.length-1;t>=0;t--)o.DomEvent.on(this._dragStartTarget,o.Draggable.START[t],this._onDown,this);this._enabled=!0}},disable:function(){if(this._enabled){for(var t=o.Draggable.START.length-1;t>=0;t--)o.DomEvent.off(this._dragStartTarget,o.Draggable.START[t],this._onDown,this);this._enabled=!1,this._moved=!1}},_onDown:function(t){if(this._moved=!1,!(t.shiftKey||1!==t.which&&1!==t.button&&!t.touches||(o.DomEvent.stopPropagation(t),o.Draggable._disabled||(o.DomUtil.disableImageDrag(),o.DomUtil.disableTextSelection(),this._moving)))){var i=t.touches?t.touches[0]:t;this._startPoint=new o.Point(i.clientX,i.clientY),this._startPos=this._newPos=o.DomUtil.getPosition(this._element),o.DomEvent.on(e,o.Draggable.MOVE[t.type],this._onMove,this).on(e,o.Draggable.END[t.type],this._onUp,this)}},_onMove:function(t){if(t.touches&&t.touches.length>1)return void(this._moved=!0);var i=t.touches&&1===t.touches.length?t.touches[0]:t,n=new o.Point(i.clientX,i.clientY),s=n.subtract(this._startPoint);(s.x||s.y)&&(o.Browser.touch&&Math.abs(s.x)+Math.abs(s.y)<3||(o.DomEvent.preventDefault(t),this._moved||(this.fire("dragstart"),this._moved=!0,this._startPos=o.DomUtil.getPosition(this._element).subtract(s),o.DomUtil.addClass(e.body,"leaflet-dragging"),this._lastTarget=t.target||t.srcElement,o.DomUtil.addClass(this._lastTarget,"leaflet-drag-target")),this._newPos=this._startPos.add(s),this._moving=!0,o.Util.cancelAnimFrame(this._animRequest),this._animRequest=o.Util.requestAnimFrame(this._updatePosition,this,!0,this._dragStartTarget)))},_updatePosition:function(){this.fire("predrag"),o.DomUtil.setPosition(this._element,this._newPos),this.fire("drag")},_onUp:function(){o.DomUtil.removeClass(e.body,"leaflet-dragging"),this._lastTarget&&(o.DomUtil.removeClass(this._lastTarget,"leaflet-drag-target"),this._lastTarget=null);for(var t in o.Draggable.MOVE)o.DomEvent.off(e,o.Draggable.MOVE[t],this._onMove).off(e,o.Draggable.END[t],this._onUp);o.DomUtil.enableImageDrag(),o.DomUtil.enableTextSelection(),this._moved&&this._moving&&(o.Util.cancelAnimFrame(this._animRequest),this.fire("dragend",{distance:this._newPos.distanceTo(this._startPos)})),this._moving=!1}}),o.Handler=o.Class.extend({initialize:function(t){this._map=t},enable:function(){this._enabled||(this._enabled=!0,this.addHooks())},disable:function(){this._enabled&&(this._enabled=!1,this.removeHooks())},enabled:function(){return!!this._enabled}}),o.Map.mergeOptions({dragging:!0,inertia:!o.Browser.android23,inertiaDeceleration:3400,inertiaMaxSpeed:1/0,inertiaThreshold:o.Browser.touch?32:18,easeLinearity:.25,worldCopyJump:!1}),o.Map.Drag=o.Handler.extend({addHooks:function(){if(!this._draggable){var t=this._map;this._draggable=new o.Draggable(t._mapPane,t._container),this._draggable.on({dragstart:this._onDragStart,drag:this._onDrag,dragend:this._onDragEnd},this),t.options.worldCopyJump&&(this._draggable.on("predrag",this._onPreDrag,this),t.on("viewreset",this._onViewReset,this),t.whenReady(this._onViewReset,this))}this._draggable.enable()},removeHooks:function(){this._draggable.disable()},moved:function(){return this._draggable&&this._draggable._moved},_onDragStart:function(){var t=this._map;t._panAnim&&t._panAnim.stop(),t.fire("movestart").fire("dragstart"),t.options.inertia&&(this._positions=[],this._times=[])},_onDrag:function(){if(this._map.options.inertia){var t=this._lastTime=+new Date,e=this._lastPos=this._draggable._newPos;this._positions.push(e),this._times.push(t),t-this._times[0]>200&&(this._positions.shift(),this._times.shift())}this._map.fire("move").fire("drag")},_onViewReset:function(){var t=this._map.getSize()._divideBy(2),e=this._map.latLngToLayerPoint([0,0]);this._initialWorldOffset=e.subtract(t).x,this._worldWidth=this._map.project([0,180]).x},_onPreDrag:function(){var t=this._worldWidth,e=Math.round(t/2),i=this._initialWorldOffset,n=this._draggable._newPos.x,o=(n-e+i)%t+e-i,s=(n+e+i)%t-e-i,a=Math.abs(o+i)<Math.abs(s+i)?o:s;this._draggable._newPos.x=a},_onDragEnd:function(t){var e=this._map,i=e.options,n=+new Date-this._lastTime,s=!i.inertia||n>i.inertiaThreshold||!this._positions[0];if(e.fire("dragend",t),s)e.fire("moveend");else{var a=this._lastPos.subtract(this._positions[0]),r=(this._lastTime+n-this._times[0])/1e3,h=i.easeLinearity,l=a.multiplyBy(h/r),u=l.distanceTo([0,0]),c=Math.min(i.inertiaMaxSpeed,u),d=l.multiplyBy(c/u),p=c/(i.inertiaDeceleration*h),_=d.multiplyBy(-p/2).round();_.x&&_.y?(_=e._limitOffset(_,e.options.maxBounds),o.Util.requestAnimFrame(function(){e.panBy(_,{duration:p,easeLinearity:h,noMoveStart:!0})})):e.fire("moveend")}}}),o.Map.addInitHook("addHandler","dragging",o.Map.Drag),o.Map.mergeOptions({doubleClickZoom:!0}),o.Map.DoubleClickZoom=o.Handler.extend({addHooks:function(){this._map.on("dblclick",this._onDoubleClick,this)},removeHooks:function(){this._map.off("dblclick",this._onDoubleClick,this)},_onDoubleClick:function(t){var e=this._map,i=e.getZoom()+(t.originalEvent.shiftKey?-1:1);"center"===e.options.doubleClickZoom?e.setZoom(i):e.setZoomAround(t.containerPoint,i)}}),o.Map.addInitHook("addHandler","doubleClickZoom",o.Map.DoubleClickZoom),o.Map.mergeOptions({scrollWheelZoom:!0}),o.Map.ScrollWheelZoom=o.Handler.extend({addHooks:function(){o.DomEvent.on(this._map._container,"mousewheel",this._onWheelScroll,this),o.DomEvent.on(this._map._container,"MozMousePixelScroll",o.DomEvent.preventDefault),this._delta=0},removeHooks:function(){o.DomEvent.off(this._map._container,"mousewheel",this._onWheelScroll),o.DomEvent.off(this._map._container,"MozMousePixelScroll",o.DomEvent.preventDefault)},_onWheelScroll:function(t){var e=o.DomEvent.getWheelDelta(t);this._delta+=e,this._lastMousePos=this._map.mouseEventToContainerPoint(t),this._startTime||(this._startTime=+new Date);var i=Math.max(40-(+new Date-this._startTime),0);clearTimeout(this._timer),this._timer=setTimeout(o.bind(this._performZoom,this),i),o.DomEvent.preventDefault(t),o.DomEvent.stopPropagation(t)},_performZoom:function(){var t=this._map,e=this._delta,i=t.getZoom();e=e>0?Math.ceil(e):Math.floor(e),e=Math.max(Math.min(e,4),-4),e=t._limitZoom(i+e)-i,this._delta=0,this._startTime=null,e&&("center"===t.options.scrollWheelZoom?t.setZoom(i+e):t.setZoomAround(this._lastMousePos,i+e))}}),o.Map.addInitHook("addHandler","scrollWheelZoom",o.Map.ScrollWheelZoom),o.extend(o.DomEvent,{_touchstart:o.Browser.msPointer?"MSPointerDown":o.Browser.pointer?"pointerdown":"touchstart",_touchend:o.Browser.msPointer?"MSPointerUp":o.Browser.pointer?"pointerup":"touchend",addDoubleTapListener:function(t,i,n){function s(t){var e;if(o.Browser.pointer?(_.push(t.pointerId),e=_.length):e=t.touches.length,!(e>1)){var i=Date.now(),n=i-(r||i);h=t.touches?t.touches[0]:t,l=n>0&&u>=n,r=i}}function a(t){if(o.Browser.pointer){var e=_.indexOf(t.pointerId);if(-1===e)return;_.splice(e,1)}if(l){if(o.Browser.pointer){var n,s={};for(var a in h)n=h[a],s[a]="function"==typeof n?n.bind(h):n;h=s}h.type="dblclick",i(h),r=null}}var r,h,l=!1,u=250,c="_leaflet_",d=this._touchstart,p=this._touchend,_=[];t[c+d+n]=s,t[c+p+n]=a;var m=o.Browser.pointer?e.documentElement:t;return t.addEventListener(d,s,!1),m.addEventListener(p,a,!1),o.Browser.pointer&&m.addEventListener(o.DomEvent.POINTER_CANCEL,a,!1),this},removeDoubleTapListener:function(t,i){var n="_leaflet_";return t.removeEventListener(this._touchstart,t[n+this._touchstart+i],!1),(o.Browser.pointer?e.documentElement:t).removeEventListener(this._touchend,t[n+this._touchend+i],!1),o.Browser.pointer&&e.documentElement.removeEventListener(o.DomEvent.POINTER_CANCEL,t[n+this._touchend+i],!1),this}}),o.extend(o.DomEvent,{POINTER_DOWN:o.Browser.msPointer?"MSPointerDown":"pointerdown",POINTER_MOVE:o.Browser.msPointer?"MSPointerMove":"pointermove",POINTER_UP:o.Browser.msPointer?"MSPointerUp":"pointerup",POINTER_CANCEL:o.Browser.msPointer?"MSPointerCancel":"pointercancel",_pointers:[],_pointerDocumentListener:!1,addPointerListener:function(t,e,i,n){switch(e){case"touchstart":return this.addPointerListenerStart(t,e,i,n);case"touchend":return this.addPointerListenerEnd(t,e,i,n);case"touchmove":return this.addPointerListenerMove(t,e,i,n);default:throw"Unknown touch event type"}},addPointerListenerStart:function(t,i,n,s){var a="_leaflet_",r=this._pointers,h=function(t){o.DomEvent.preventDefault(t);for(var e=!1,i=0;i<r.length;i++)if(r[i].pointerId===t.pointerId){e=!0;
8 break}e||r.push(t),t.touches=r.slice(),t.changedTouches=[t],n(t)};if(t[a+"touchstart"+s]=h,t.addEventListener(this.POINTER_DOWN,h,!1),!this._pointerDocumentListener){var l=function(t){for(var e=0;e<r.length;e++)if(r[e].pointerId===t.pointerId){r.splice(e,1);break}};e.documentElement.addEventListener(this.POINTER_UP,l,!1),e.documentElement.addEventListener(this.POINTER_CANCEL,l,!1),this._pointerDocumentListener=!0}return this},addPointerListenerMove:function(t,e,i,n){function o(t){if(t.pointerType!==t.MSPOINTER_TYPE_MOUSE&&"mouse"!==t.pointerType||0!==t.buttons){for(var e=0;e<a.length;e++)if(a[e].pointerId===t.pointerId){a[e]=t;break}t.touches=a.slice(),t.changedTouches=[t],i(t)}}var s="_leaflet_",a=this._pointers;return t[s+"touchmove"+n]=o,t.addEventListener(this.POINTER_MOVE,o,!1),this},addPointerListenerEnd:function(t,e,i,n){var o="_leaflet_",s=this._pointers,a=function(t){for(var e=0;e<s.length;e++)if(s[e].pointerId===t.pointerId){s.splice(e,1);break}t.touches=s.slice(),t.changedTouches=[t],i(t)};return t[o+"touchend"+n]=a,t.addEventListener(this.POINTER_UP,a,!1),t.addEventListener(this.POINTER_CANCEL,a,!1),this},removePointerListener:function(t,e,i){var n="_leaflet_",o=t[n+e+i];switch(e){case"touchstart":t.removeEventListener(this.POINTER_DOWN,o,!1);break;case"touchmove":t.removeEventListener(this.POINTER_MOVE,o,!1);break;case"touchend":t.removeEventListener(this.POINTER_UP,o,!1),t.removeEventListener(this.POINTER_CANCEL,o,!1)}return this}}),o.Map.mergeOptions({touchZoom:o.Browser.touch&&!o.Browser.android23,bounceAtZoomLimits:!0}),o.Map.TouchZoom=o.Handler.extend({addHooks:function(){o.DomEvent.on(this._map._container,"touchstart",this._onTouchStart,this)},removeHooks:function(){o.DomEvent.off(this._map._container,"touchstart",this._onTouchStart,this)},_onTouchStart:function(t){var i=this._map;if(t.touches&&2===t.touches.length&&!i._animatingZoom&&!this._zooming){var n=i.mouseEventToLayerPoint(t.touches[0]),s=i.mouseEventToLayerPoint(t.touches[1]),a=i._getCenterLayerPoint();this._startCenter=n.add(s)._divideBy(2),this._startDist=n.distanceTo(s),this._moved=!1,this._zooming=!0,this._centerOffset=a.subtract(this._startCenter),i._panAnim&&i._panAnim.stop(),o.DomEvent.on(e,"touchmove",this._onTouchMove,this).on(e,"touchend",this._onTouchEnd,this),o.DomEvent.preventDefault(t)}},_onTouchMove:function(t){var e=this._map;if(t.touches&&2===t.touches.length&&this._zooming){var i=e.mouseEventToLayerPoint(t.touches[0]),n=e.mouseEventToLayerPoint(t.touches[1]);this._scale=i.distanceTo(n)/this._startDist,this._delta=i._add(n)._divideBy(2)._subtract(this._startCenter),1!==this._scale&&(e.options.bounceAtZoomLimits||!(e.getZoom()===e.getMinZoom()&&this._scale<1||e.getZoom()===e.getMaxZoom()&&this._scale>1))&&(this._moved||(o.DomUtil.addClass(e._mapPane,"leaflet-touching"),e.fire("movestart").fire("zoomstart"),this._moved=!0),o.Util.cancelAnimFrame(this._animRequest),this._animRequest=o.Util.requestAnimFrame(this._updateOnMove,this,!0,this._map._container),o.DomEvent.preventDefault(t))}},_updateOnMove:function(){var t=this._map,e=this._getScaleOrigin(),i=t.layerPointToLatLng(e),n=t.getScaleZoom(this._scale);t._animateZoom(i,n,this._startCenter,this._scale,this._delta,!1,!0)},_onTouchEnd:function(){if(!this._moved||!this._zooming)return void(this._zooming=!1);var t=this._map;this._zooming=!1,o.DomUtil.removeClass(t._mapPane,"leaflet-touching"),o.Util.cancelAnimFrame(this._animRequest),o.DomEvent.off(e,"touchmove",this._onTouchMove).off(e,"touchend",this._onTouchEnd);var i=this._getScaleOrigin(),n=t.layerPointToLatLng(i),s=t.getZoom(),a=t.getScaleZoom(this._scale)-s,r=a>0?Math.ceil(a):Math.floor(a),h=t._limitZoom(s+r),l=t.getZoomScale(h)/this._scale;t._animateZoom(n,h,i,l)},_getScaleOrigin:function(){var t=this._centerOffset.subtract(this._delta).divideBy(this._scale);return this._startCenter.add(t)}}),o.Map.addInitHook("addHandler","touchZoom",o.Map.TouchZoom),o.Map.mergeOptions({tap:!0,tapTolerance:15}),o.Map.Tap=o.Handler.extend({addHooks:function(){o.DomEvent.on(this._map._container,"touchstart",this._onDown,this)},removeHooks:function(){o.DomEvent.off(this._map._container,"touchstart",this._onDown,this)},_onDown:function(t){if(t.touches){if(o.DomEvent.preventDefault(t),this._fireClick=!0,t.touches.length>1)return this._fireClick=!1,void clearTimeout(this._holdTimeout);var i=t.touches[0],n=i.target;this._startPos=this._newPos=new o.Point(i.clientX,i.clientY),n.tagName&&"a"===n.tagName.toLowerCase()&&o.DomUtil.addClass(n,"leaflet-active"),this._holdTimeout=setTimeout(o.bind(function(){this._isTapValid()&&(this._fireClick=!1,this._onUp(),this._simulateEvent("contextmenu",i))},this),1e3),o.DomEvent.on(e,"touchmove",this._onMove,this).on(e,"touchend",this._onUp,this)}},_onUp:function(t){if(clearTimeout(this._holdTimeout),o.DomEvent.off(e,"touchmove",this._onMove,this).off(e,"touchend",this._onUp,this),this._fireClick&&t&&t.changedTouches){var i=t.changedTouches[0],n=i.target;n&&n.tagName&&"a"===n.tagName.toLowerCase()&&o.DomUtil.removeClass(n,"leaflet-active"),this._isTapValid()&&this._simulateEvent("click",i)}},_isTapValid:function(){return this._newPos.distanceTo(this._startPos)<=this._map.options.tapTolerance},_onMove:function(t){var e=t.touches[0];this._newPos=new o.Point(e.clientX,e.clientY)},_simulateEvent:function(i,n){var o=e.createEvent("MouseEvents");o._simulated=!0,n.target._simulatedClick=!0,o.initMouseEvent(i,!0,!0,t,1,n.screenX,n.screenY,n.clientX,n.clientY,!1,!1,!1,!1,0,null),n.target.dispatchEvent(o)}}),o.Browser.touch&&!o.Browser.pointer&&o.Map.addInitHook("addHandler","tap",o.Map.Tap),o.Map.mergeOptions({boxZoom:!0}),o.Map.BoxZoom=o.Handler.extend({initialize:function(t){this._map=t,this._container=t._container,this._pane=t._panes.overlayPane,this._moved=!1},addHooks:function(){o.DomEvent.on(this._container,"mousedown",this._onMouseDown,this)},removeHooks:function(){o.DomEvent.off(this._container,"mousedown",this._onMouseDown),this._moved=!1},moved:function(){return this._moved},_onMouseDown:function(t){return this._moved=!1,!t.shiftKey||1!==t.which&&1!==t.button?!1:(o.DomUtil.disableTextSelection(),o.DomUtil.disableImageDrag(),this._startLayerPoint=this._map.mouseEventToLayerPoint(t),void o.DomEvent.on(e,"mousemove",this._onMouseMove,this).on(e,"mouseup",this._onMouseUp,this).on(e,"keydown",this._onKeyDown,this))},_onMouseMove:function(t){this._moved||(this._box=o.DomUtil.create("div","leaflet-zoom-box",this._pane),o.DomUtil.setPosition(this._box,this._startLayerPoint),this._container.style.cursor="crosshair",this._map.fire("boxzoomstart"));var e=this._startLayerPoint,i=this._box,n=this._map.mouseEventToLayerPoint(t),s=n.subtract(e),a=new o.Point(Math.min(n.x,e.x),Math.min(n.y,e.y));o.DomUtil.setPosition(i,a),this._moved=!0,i.style.width=Math.max(0,Math.abs(s.x)-4)+"px",i.style.height=Math.max(0,Math.abs(s.y)-4)+"px"},_finish:function(){this._moved&&(this._pane.removeChild(this._box),this._container.style.cursor=""),o.DomUtil.enableTextSelection(),o.DomUtil.enableImageDrag(),o.DomEvent.off(e,"mousemove",this._onMouseMove).off(e,"mouseup",this._onMouseUp).off(e,"keydown",this._onKeyDown)},_onMouseUp:function(t){this._finish();var e=this._map,i=e.mouseEventToLayerPoint(t);if(!this._startLayerPoint.equals(i)){var n=new o.LatLngBounds(e.layerPointToLatLng(this._startLayerPoint),e.layerPointToLatLng(i));e.fitBounds(n),e.fire("boxzoomend",{boxZoomBounds:n})}},_onKeyDown:function(t){27===t.keyCode&&this._finish()}}),o.Map.addInitHook("addHandler","boxZoom",o.Map.BoxZoom),o.Map.mergeOptions({keyboard:!0,keyboardPanOffset:80,keyboardZoomOffset:1}),o.Map.Keyboard=o.Handler.extend({keyCodes:{left:[37],right:[39],down:[40],up:[38],zoomIn:[187,107,61,171],zoomOut:[189,109,173]},initialize:function(t){this._map=t,this._setPanOffset(t.options.keyboardPanOffset),this._setZoomOffset(t.options.keyboardZoomOffset)},addHooks:function(){var t=this._map._container;-1===t.tabIndex&&(t.tabIndex="0"),o.DomEvent.on(t,"focus",this._onFocus,this).on(t,"blur",this._onBlur,this).on(t,"mousedown",this._onMouseDown,this),this._map.on("focus",this._addHooks,this).on("blur",this._removeHooks,this)},removeHooks:function(){this._removeHooks();var t=this._map._container;o.DomEvent.off(t,"focus",this._onFocus,this).off(t,"blur",this._onBlur,this).off(t,"mousedown",this._onMouseDown,this),this._map.off("focus",this._addHooks,this).off("blur",this._removeHooks,this)},_onMouseDown:function(){if(!this._focused){var i=e.body,n=e.documentElement,o=i.scrollTop||n.scrollTop,s=i.scrollLeft||n.scrollLeft;this._map._container.focus(),t.scrollTo(s,o)}},_onFocus:function(){this._focused=!0,this._map.fire("focus")},_onBlur:function(){this._focused=!1,this._map.fire("blur")},_setPanOffset:function(t){var e,i,n=this._panKeys={},o=this.keyCodes;for(e=0,i=o.left.length;i>e;e++)n[o.left[e]]=[-1*t,0];for(e=0,i=o.right.length;i>e;e++)n[o.right[e]]=[t,0];for(e=0,i=o.down.length;i>e;e++)n[o.down[e]]=[0,t];for(e=0,i=o.up.length;i>e;e++)n[o.up[e]]=[0,-1*t]},_setZoomOffset:function(t){var e,i,n=this._zoomKeys={},o=this.keyCodes;for(e=0,i=o.zoomIn.length;i>e;e++)n[o.zoomIn[e]]=t;for(e=0,i=o.zoomOut.length;i>e;e++)n[o.zoomOut[e]]=-t},_addHooks:function(){o.DomEvent.on(e,"keydown",this._onKeyDown,this)},_removeHooks:function(){o.DomEvent.off(e,"keydown",this._onKeyDown,this)},_onKeyDown:function(t){var e=t.keyCode,i=this._map;if(e in this._panKeys){if(i._panAnim&&i._panAnim._inProgress)return;i.panBy(this._panKeys[e]),i.options.maxBounds&&i.panInsideBounds(i.options.maxBounds)}else{if(!(e in this._zoomKeys))return;i.setZoom(i.getZoom()+this._zoomKeys[e])}o.DomEvent.stop(t)}}),o.Map.addInitHook("addHandler","keyboard",o.Map.Keyboard),o.Handler.MarkerDrag=o.Handler.extend({initialize:function(t){this._marker=t},addHooks:function(){var t=this._marker._icon;this._draggable||(this._draggable=new o.Draggable(t,t)),this._draggable.on("dragstart",this._onDragStart,this).on("drag",this._onDrag,this).on("dragend",this._onDragEnd,this),this._draggable.enable(),o.DomUtil.addClass(this._marker._icon,"leaflet-marker-draggable")},removeHooks:function(){this._draggable.off("dragstart",this._onDragStart,this).off("drag",this._onDrag,this).off("dragend",this._onDragEnd,this),this._draggable.disable(),o.DomUtil.removeClass(this._marker._icon,"leaflet-marker-draggable")},moved:function(){return this._draggable&&this._draggable._moved},_onDragStart:function(){this._marker.closePopup().fire("movestart").fire("dragstart")},_onDrag:function(){var t=this._marker,e=t._shadow,i=o.DomUtil.getPosition(t._icon),n=t._map.layerPointToLatLng(i);e&&o.DomUtil.setPosition(e,i),t._latlng=n,t.fire("move",{latlng:n}).fire("drag")},_onDragEnd:function(t){this._marker.fire("moveend").fire("dragend",t)}}),o.Control=o.Class.extend({options:{position:"topright"},initialize:function(t){o.setOptions(this,t)},getPosition:function(){return this.options.position},setPosition:function(t){var e=this._map;return e&&e.removeControl(this),this.options.position=t,e&&e.addControl(this),this},getContainer:function(){return this._container},addTo:function(t){this._map=t;var e=this._container=this.onAdd(t),i=this.getPosition(),n=t._controlCorners[i];return o.DomUtil.addClass(e,"leaflet-control"),-1!==i.indexOf("bottom")?n.insertBefore(e,n.firstChild):n.appendChild(e),this},removeFrom:function(t){var e=this.getPosition(),i=t._controlCorners[e];return i.removeChild(this._container),this._map=null,this.onRemove&&this.onRemove(t),this},_refocusOnMap:function(){this._map&&this._map.getContainer().focus()}}),o.control=function(t){return new o.Control(t)},o.Map.include({addControl:function(t){return t.addTo(this),this},removeControl:function(t){return t.removeFrom(this),this},_initControlPos:function(){function t(t,s){var a=i+t+" "+i+s;e[t+s]=o.DomUtil.create("div",a,n)}var e=this._controlCorners={},i="leaflet-",n=this._controlContainer=o.DomUtil.create("div",i+"control-container",this._container);t("top","left"),t("top","right"),t("bottom","left"),t("bottom","right")},_clearControlPos:function(){this._container.removeChild(this._controlContainer)}}),o.Control.Zoom=o.Control.extend({options:{position:"topleft",zoomInText:"+",zoomInTitle:"Zoom in",zoomOutText:"-",zoomOutTitle:"Zoom out"},onAdd:function(t){var e="leaflet-control-zoom",i=o.DomUtil.create("div",e+" leaflet-bar");return this._map=t,this._zoomInButton=this._createButton(this.options.zoomInText,this.options.zoomInTitle,e+"-in",i,this._zoomIn,this),this._zoomOutButton=this._createButton(this.options.zoomOutText,this.options.zoomOutTitle,e+"-out",i,this._zoomOut,this),this._updateDisabled(),t.on("zoomend zoomlevelschange",this._updateDisabled,this),i},onRemove:function(t){t.off("zoomend zoomlevelschange",this._updateDisabled,this)},_zoomIn:function(t){this._map.zoomIn(t.shiftKey?3:1)},_zoomOut:function(t){this._map.zoomOut(t.shiftKey?3:1)},_createButton:function(t,e,i,n,s,a){var r=o.DomUtil.create("a",i,n);r.innerHTML=t,r.href="#",r.title=e;var h=o.DomEvent.stopPropagation;return o.DomEvent.on(r,"click",h).on(r,"mousedown",h).on(r,"dblclick",h).on(r,"click",o.DomEvent.preventDefault).on(r,"click",s,a).on(r,"click",this._refocusOnMap,a),r},_updateDisabled:function(){var t=this._map,e="leaflet-disabled";o.DomUtil.removeClass(this._zoomInButton,e),o.DomUtil.removeClass(this._zoomOutButton,e),t._zoom===t.getMinZoom()&&o.DomUtil.addClass(this._zoomOutButton,e),t._zoom===t.getMaxZoom()&&o.DomUtil.addClass(this._zoomInButton,e)}}),o.Map.mergeOptions({zoomControl:!0}),o.Map.addInitHook(function(){this.options.zoomControl&&(this.zoomControl=new o.Control.Zoom,this.addControl(this.zoomControl))}),o.control.zoom=function(t){return new o.Control.Zoom(t)},o.Control.Attribution=o.Control.extend({options:{position:"bottomright",prefix:'<a href="http://leafletjs.com" title="A JS library for interactive maps">Leaflet</a>'},initialize:function(t){o.setOptions(this,t),this._attributions={}},onAdd:function(t){this._container=o.DomUtil.create("div","leaflet-control-attribution"),o.DomEvent.disableClickPropagation(this._container);for(var e in t._layers)t._layers[e].getAttribution&&this.addAttribution(t._layers[e].getAttribution());return t.on("layeradd",this._onLayerAdd,this).on("layerremove",this._onLayerRemove,this),this._update(),this._container},onRemove:function(t){t.off("layeradd",this._onLayerAdd).off("layerremove",this._onLayerRemove)},setPrefix:function(t){return this.options.prefix=t,this._update(),this},addAttribution:function(t){return t?(this._attributions[t]||(this._attributions[t]=0),this._attributions[t]++,this._update(),this):void 0},removeAttribution:function(t){return t?(this._attributions[t]&&(this._attributions[t]--,this._update()),this):void 0},_update:function(){if(this._map){var t=[];for(var e in this._attributions)this._attributions[e]&&t.push(e);var i=[];this.options.prefix&&i.push(this.options.prefix),t.length&&i.push(t.join(", ")),this._container.innerHTML=i.join(" | ")}},_onLayerAdd:function(t){t.layer.getAttribution&&this.addAttribution(t.layer.getAttribution())},_onLayerRemove:function(t){t.layer.getAttribution&&this.removeAttribution(t.layer.getAttribution())}}),o.Map.mergeOptions({attributionControl:!0}),o.Map.addInitHook(function(){this.options.attributionControl&&(this.attributionControl=(new o.Control.Attribution).addTo(this))}),o.control.attribution=function(t){return new o.Control.Attribution(t)},o.Control.Scale=o.Control.extend({options:{position:"bottomleft",maxWidth:100,metric:!0,imperial:!0,updateWhenIdle:!1},onAdd:function(t){this._map=t;var e="leaflet-control-scale",i=o.DomUtil.create("div",e),n=this.options;return this._addScales(n,e,i),t.on(n.updateWhenIdle?"moveend":"move",this._update,this),t.whenReady(this._update,this),i},onRemove:function(t){t.off(this.options.updateWhenIdle?"moveend":"move",this._update,this)},_addScales:function(t,e,i){t.metric&&(this._mScale=o.DomUtil.create("div",e+"-line",i)),t.imperial&&(this._iScale=o.DomUtil.create("div",e+"-line",i))},_update:function(){var t=this._map.getBounds(),e=t.getCenter().lat,i=6378137*Math.PI*Math.cos(e*Math.PI/180),n=i*(t.getNorthEast().lng-t.getSouthWest().lng)/180,o=this._map.getSize(),s=this.options,a=0;o.x>0&&(a=n*(s.maxWidth/o.x)),this._updateScales(s,a)},_updateScales:function(t,e){t.metric&&e&&this._updateMetric(e),t.imperial&&e&&this._updateImperial(e)},_updateMetric:function(t){var e=this._getRoundNum(t);this._mScale.style.width=this._getScaleWidth(e/t)+"px",this._mScale.innerHTML=1e3>e?e+" m":e/1e3+" km"},_updateImperial:function(t){var e,i,n,o=3.2808399*t,s=this._iScale;o>5280?(e=o/5280,i=this._getRoundNum(e),s.style.width=this._getScaleWidth(i/e)+"px",s.innerHTML=i+" mi"):(n=this._getRoundNum(o),s.style.width=this._getScaleWidth(n/o)+"px",s.innerHTML=n+" ft")},_getScaleWidth:function(t){return Math.round(this.options.maxWidth*t)-10},_getRoundNum:function(t){var e=Math.pow(10,(Math.floor(t)+"").length-1),i=t/e;return i=i>=10?10:i>=5?5:i>=3?3:i>=2?2:1,e*i}}),o.control.scale=function(t){return new o.Control.Scale(t)},o.Control.Layers=o.Control.extend({options:{collapsed:!0,position:"topright",autoZIndex:!0},initialize:function(t,e,i){o.setOptions(this,i),this._layers={},this._lastZIndex=0,this._handlingClick=!1;for(var n in t)this._addLayer(t[n],n);for(n in e)this._addLayer(e[n],n,!0)},onAdd:function(t){return this._initLayout(),this._update(),t.on("layeradd",this._onLayerChange,this).on("layerremove",this._onLayerChange,this),this._container},onRemove:function(t){t.off("layeradd",this._onLayerChange,this).off("layerremove",this._onLayerChange,this)},addBaseLayer:function(t,e){return this._addLayer(t,e),this._update(),this},addOverlay:function(t,e){return this._addLayer(t,e,!0),this._update(),this},removeLayer:function(t){var e=o.stamp(t);return delete this._layers[e],this._update(),this},_initLayout:function(){var t="leaflet-control-layers",e=this._container=o.DomUtil.create("div",t);e.setAttribute("aria-haspopup",!0),o.Browser.touch?o.DomEvent.on(e,"click",o.DomEvent.stopPropagation):o.DomEvent.disableClickPropagation(e).disableScrollPropagation(e);var i=this._form=o.DomUtil.create("form",t+"-list");if(this.options.collapsed){o.Browser.android||o.DomEvent.on(e,"mouseover",this._expand,this).on(e,"mouseout",this._collapse,this);var n=this._layersLink=o.DomUtil.create("a",t+"-toggle",e);n.href="#",n.title="Layers",o.Browser.touch?o.DomEvent.on(n,"click",o.DomEvent.stop).on(n,"click",this._expand,this):o.DomEvent.on(n,"focus",this._expand,this),o.DomEvent.on(i,"click",function(){setTimeout(o.bind(this._onInputClick,this),0)},this),this._map.on("click",this._collapse,this)}else this._expand();this._baseLayersList=o.DomUtil.create("div",t+"-base",i),this._separator=o.DomUtil.create("div",t+"-separator",i),this._overlaysList=o.DomUtil.create("div",t+"-overlays",i),e.appendChild(i)},_addLayer:function(t,e,i){var n=o.stamp(t);this._layers[n]={layer:t,name:e,overlay:i},this.options.autoZIndex&&t.setZIndex&&(this._lastZIndex++,t.setZIndex(this._lastZIndex))},_update:function(){if(this._container){this._baseLayersList.innerHTML="",this._overlaysList.innerHTML="";var t,e,i=!1,n=!1;for(t in this._layers)e=this._layers[t],this._addItem(e),n=n||e.overlay,i=i||!e.overlay;this._separator.style.display=n&&i?"":"none"}},_onLayerChange:function(t){var e=this._layers[o.stamp(t.layer)];if(e){this._handlingClick||this._update();var i=e.overlay?"layeradd"===t.type?"overlayadd":"overlayremove":"layeradd"===t.type?"baselayerchange":null;i&&this._map.fire(i,e)}},_createRadioElement:function(t,i){var n='<input type="radio" class="leaflet-control-layers-selector" name="'+t+'"';i&&(n+=' checked="checked"'),n+="/>";var o=e.createElement("div");return o.innerHTML=n,o.firstChild},_addItem:function(t){var i,n=e.createElement("label"),s=this._map.hasLayer(t.layer);t.overlay?(i=e.createElement("input"),i.type="checkbox",i.className="leaflet-control-layers-selector",i.defaultChecked=s):i=this._createRadioElement("leaflet-base-layers",s),i.layerId=o.stamp(t.layer),o.DomEvent.on(i,"click",this._onInputClick,this);var a=e.createElement("span");a.innerHTML=" "+t.name,n.appendChild(i),n.appendChild(a);var r=t.overlay?this._overlaysList:this._baseLayersList;return r.appendChild(n),n},_onInputClick:function(){var t,e,i,n=this._form.getElementsByTagName("input"),o=n.length;for(this._handlingClick=!0,t=0;o>t;t++)e=n[t],i=this._layers[e.layerId],e.checked&&!this._map.hasLayer(i.layer)?this._map.addLayer(i.layer):!e.checked&&this._map.hasLayer(i.layer)&&this._map.removeLayer(i.layer);this._handlingClick=!1,this._refocusOnMap()},_expand:function(){o.DomUtil.addClass(this._container,"leaflet-control-layers-expanded")},_collapse:function(){this._container.className=this._container.className.replace(" leaflet-control-layers-expanded","")}}),o.control.layers=function(t,e,i){return new o.Control.Layers(t,e,i)},o.PosAnimation=o.Class.extend({includes:o.Mixin.Events,run:function(t,e,i,n){this.stop(),this._el=t,this._inProgress=!0,this._newPos=e,this.fire("start"),t.style[o.DomUtil.TRANSITION]="all "+(i||.25)+"s cubic-bezier(0,0,"+(n||.5)+",1)",o.DomEvent.on(t,o.DomUtil.TRANSITION_END,this._onTransitionEnd,this),o.DomUtil.setPosition(t,e),o.Util.falseFn(t.offsetWidth),this._stepTimer=setInterval(o.bind(this._onStep,this),50)},stop:function(){this._inProgress&&(o.DomUtil.setPosition(this._el,this._getPos()),this._onTransitionEnd(),o.Util.falseFn(this._el.offsetWidth))},_onStep:function(){var t=this._getPos();return t?(this._el._leaflet_pos=t,void this.fire("step")):void this._onTransitionEnd()},_transformRe:/([-+]?(?:\d*\.)?\d+)\D*, ([-+]?(?:\d*\.)?\d+)\D*\)/,_getPos:function(){var e,i,n,s=this._el,a=t.getComputedStyle(s);if(o.Browser.any3d){if(n=a[o.DomUtil.TRANSFORM].match(this._transformRe),!n)return;e=parseFloat(n[1]),i=parseFloat(n[2])}else e=parseFloat(a.left),i=parseFloat(a.top);return new o.Point(e,i,!0)},_onTransitionEnd:function(){o.DomEvent.off(this._el,o.DomUtil.TRANSITION_END,this._onTransitionEnd,this),this._inProgress&&(this._inProgress=!1,this._el.style[o.DomUtil.TRANSITION]="",this._el._leaflet_pos=this._newPos,clearInterval(this._stepTimer),this.fire("step").fire("end"))}}),o.Map.include({setView:function(t,e,n){if(e=e===i?this._zoom:this._limitZoom(e),t=this._limitCenter(o.latLng(t),e,this.options.maxBounds),n=n||{},this._panAnim&&this._panAnim.stop(),this._loaded&&!n.reset&&n!==!0){n.animate!==i&&(n.zoom=o.extend({animate:n.animate},n.zoom),n.pan=o.extend({animate:n.animate},n.pan));var s=this._zoom!==e?this._tryAnimatedZoom&&this._tryAnimatedZoom(t,e,n.zoom):this._tryAnimatedPan(t,n.pan);if(s)return clearTimeout(this._sizeTimer),this}return this._resetView(t,e),this},panBy:function(t,e){if(t=o.point(t).round(),e=e||{},!t.x&&!t.y)return this;if(this._panAnim||(this._panAnim=new o.PosAnimation,this._panAnim.on({step:this._onPanTransitionStep,end:this._onPanTransitionEnd},this)),e.noMoveStart||this.fire("movestart"),e.animate!==!1){o.DomUtil.addClass(this._mapPane,"leaflet-pan-anim");var i=this._getMapPanePos().subtract(t);this._panAnim.run(this._mapPane,i,e.duration||.25,e.easeLinearity)}else this._rawPanBy(t),this.fire("move").fire("moveend");return this},_onPanTransitionStep:function(){this.fire("move")},_onPanTransitionEnd:function(){o.DomUtil.removeClass(this._mapPane,"leaflet-pan-anim"),this.fire("moveend")},_tryAnimatedPan:function(t,e){var i=this._getCenterOffset(t)._floor();return(e&&e.animate)===!0||this.getSize().contains(i)?(this.panBy(i,e),!0):!1}}),o.PosAnimation=o.DomUtil.TRANSITION?o.PosAnimation:o.PosAnimation.extend({run:function(t,e,i,n){this.stop(),this._el=t,this._inProgress=!0,this._duration=i||.25,this._easeOutPower=1/Math.max(n||.5,.2),this._startPos=o.DomUtil.getPosition(t),this._offset=e.subtract(this._startPos),this._startTime=+new Date,this.fire("start"),this._animate()},stop:function(){this._inProgress&&(this._step(),this._complete())},_animate:function(){this._animId=o.Util.requestAnimFrame(this._animate,this),this._step()},_step:function(){var t=+new Date-this._startTime,e=1e3*this._duration;e>t?this._runFrame(this._easeOut(t/e)):(this._runFrame(1),this._complete())},_runFrame:function(t){var e=this._startPos.add(this._offset.multiplyBy(t));o.DomUtil.setPosition(this._el,e),this.fire("step")},_complete:function(){o.Util.cancelAnimFrame(this._animId),this._inProgress=!1,this.fire("end")},_easeOut:function(t){return 1-Math.pow(1-t,this._easeOutPower)}}),o.Map.mergeOptions({zoomAnimation:!0,zoomAnimationThreshold:4}),o.DomUtil.TRANSITION&&o.Map.addInitHook(function(){this._zoomAnimated=this.options.zoomAnimation&&o.DomUtil.TRANSITION&&o.Browser.any3d&&!o.Browser.android23&&!o.Browser.mobileOpera,this._zoomAnimated&&o.DomEvent.on(this._mapPane,o.DomUtil.TRANSITION_END,this._catchTransitionEnd,this)}),o.Map.include(o.DomUtil.TRANSITION?{_catchTransitionEnd:function(t){this._animatingZoom&&t.propertyName.indexOf("transform")>=0&&this._onZoomTransitionEnd()},_nothingToAnimate:function(){return!this._container.getElementsByClassName("leaflet-zoom-animated").length},_tryAnimatedZoom:function(t,e,i){if(this._animatingZoom)return!0;if(i=i||{},!this._zoomAnimated||i.animate===!1||this._nothingToAnimate()||Math.abs(e-this._zoom)>this.options.zoomAnimationThreshold)return!1;var n=this.getZoomScale(e),o=this._getCenterOffset(t)._divideBy(1-1/n),s=this._getCenterLayerPoint()._add(o);return i.animate===!0||this.getSize().contains(o)?(this.fire("movestart").fire("zoomstart"),this._animateZoom(t,e,s,n,null,!0),!0):!1},_animateZoom:function(t,e,i,n,s,a,r){r||(this._animatingZoom=!0),o.DomUtil.addClass(this._mapPane,"leaflet-zoom-anim"),this._animateToCenter=t,this._animateToZoom=e,o.Draggable&&(o.Draggable._disabled=!0),o.Util.requestAnimFrame(function(){this.fire("zoomanim",{center:t,zoom:e,origin:i,scale:n,delta:s,backwards:a})},this)},_onZoomTransitionEnd:function(){this._animatingZoom=!1,o.DomUtil.removeClass(this._mapPane,"leaflet-zoom-anim"),this._resetView(this._animateToCenter,this._animateToZoom,!0,!0),o.Draggable&&(o.Draggable._disabled=!1)}}:{}),o.TileLayer.include({_animateZoom:function(t){this._animating||(this._animating=!0,this._prepareBgBuffer());var e=this._bgBuffer,i=o.DomUtil.TRANSFORM,n=t.delta?o.DomUtil.getTranslateString(t.delta):e.style[i],s=o.DomUtil.getScaleString(t.scale,t.origin);e.style[i]=t.backwards?s+" "+n:n+" "+s},_endZoomAnim:function(){var t=this._tileContainer,e=this._bgBuffer;t.style.visibility="",t.parentNode.appendChild(t),o.Util.falseFn(e.offsetWidth),this._animating=!1},_clearBgBuffer:function(){var t=this._map;!t||t._animatingZoom||t.touchZoom._zooming||(this._bgBuffer.innerHTML="",this._bgBuffer.style[o.DomUtil.TRANSFORM]="")},_prepareBgBuffer:function(){var t=this._tileContainer,e=this._bgBuffer,i=this._getLoadedTilesPercentage(e),n=this._getLoadedTilesPercentage(t);return e&&i>.5&&.5>n?(t.style.visibility="hidden",void this._stopLoadingImages(t)):(e.style.visibility="hidden",e.style[o.DomUtil.TRANSFORM]="",this._tileContainer=e,e=this._bgBuffer=t,this._stopLoadingImages(e),void clearTimeout(this._clearBgBufferTimer))},_getLoadedTilesPercentage:function(t){var e,i,n=t.getElementsByTagName("img"),o=0;for(e=0,i=n.length;i>e;e++)n[e].complete&&o++;return o/i},_stopLoadingImages:function(t){var e,i,n,s=Array.prototype.slice.call(t.getElementsByTagName("img"));for(e=0,i=s.length;i>e;e++)n=s[e],n.complete||(n.onload=o.Util.falseFn,n.onerror=o.Util.falseFn,n.src=o.Util.emptyImageUrl,n.parentNode.removeChild(n))}}),o.Map.include({_defaultLocateOptions:{watch:!1,setView:!1,maxZoom:1/0,timeout:1e4,maximumAge:0,enableHighAccuracy:!1},locate:function(t){if(t=this._locateOptions=o.extend(this._defaultLocateOptions,t),!navigator.geolocation)return this._handleGeolocationError({code:0,message:"Geolocation not supported."}),this;var e=o.bind(this._handleGeolocationResponse,this),i=o.bind(this._handleGeolocationError,this);return t.watch?this._locationWatchId=navigator.geolocation.watchPosition(e,i,t):navigator.geolocation.getCurrentPosition(e,i,t),this},stopLocate:function(){return navigator.geolocation&&navigator.geolocation.clearWatch(this._locationWatchId),this._locateOptions&&(this._locateOptions.setView=!1),this},_handleGeolocationError:function(t){var e=t.code,i=t.message||(1===e?"permission denied":2===e?"position unavailable":"timeout");this._locateOptions.setView&&!this._loaded&&this.fitWorld(),this.fire("locationerror",{code:e,message:"Geolocation error: "+i+"."})},_handleGeolocationResponse:function(t){var e=t.coords.latitude,i=t.coords.longitude,n=new o.LatLng(e,i),s=180*t.coords.accuracy/40075017,a=s/Math.cos(o.LatLng.DEG_TO_RAD*e),r=o.latLngBounds([e-s,i-a],[e+s,i+a]),h=this._locateOptions;if(h.setView){var l=Math.min(this.getBoundsZoom(r),h.maxZoom);this.setView(n,l)}var u={latlng:n,bounds:r,timestamp:t.timestamp};for(var c in t.coords)"number"==typeof t.coords[c]&&(u[c]=t.coords[c]);this.fire("locationfound",u)}})}(window,document);
00 {
11 "name": "leaflet",
2 "version": "0.7.2",
2 "version": "0.7.3",
33 "description": "JavaScript library for mobile-friendly interactive maps",
44 "devDependencies": {
55 "jake": "~0.7.4",
77 "uglify-js": "~2.4.3",
88 "mocha": "~1.14.0",
99 "happen": "~0.1.3",
10 "karma": "~0.10.4",
11 "karma-mocha": "~0.1.0"
10 "karma": "~0.12.0",
11 "karma-mocha": "~0.1.1",
12 "karma-coverage": "~0.2.0",
13 "karma-phantomjs-launcher": "^0.1.2",
14 "karma-chrome-launcher": "^0.1.2",
15 "tin": "^0.4.0",
16 "copyfiles": "0.0.1"
1217 },
1318 "main": "dist/leaflet-src.js",
1419 "scripts": {
1520 "test": "jake test",
16 "prepublish": "jake build"
21 "prepublish": "jake build",
22 "publish": "./build/publish.sh"
1723 },
1824 "repository": {
1925 "type": "git",
00
11 describe('TileLayer', function () {
2 var tileUrl = '';
2 var tileUrl = '',
3 map;
4
5 beforeEach(function () {
6 map = L.map(document.createElement('div'));
7 });
8
9 describe("#onAdd", function () {
10 it('is called after viewreset on first map load', function () {
11 var layer = L.tileLayer(tileUrl).addTo(map);
12 layer.onAdd = sinon.spy();
13
14 var onReset = sinon.spy();
15 map.on('viewreset', onReset);
16 map.setView([0, 0], 0);
17
18 expect(onReset.calledBefore(layer.onAdd)).to.be.ok();
19 });
20 });
321
422 describe("#getMaxZoom, #getMinZoom", function () {
5 var map;
6 beforeEach(function () {
7 map = L.map(document.createElement('div'));
8 });
923 describe("when a tilelayer is added to a map with no other layers", function () {
1024 it("has the same zoomlevels as the tilelayer", function () {
1125 var maxZoom = 10,
11 var oldL = window.L,
22 L = {};
33
4 L.version = '0.7.2';
4 L.version = '0.7.3';
55
66 // define Leaflet for Node module pattern loaders, including Browserify
77 if (typeof module === 'object' && typeof module.exports === 'object') {
3737
3838 onRemove: function (map) {
3939 map
40 .off('layeradd', this._onLayerChange)
41 .off('layerremove', this._onLayerChange);
40 .off('layeradd', this._onLayerChange, this)
41 .off('layerremove', this._onLayerChange, this);
4242 },
4343
4444 addBaseLayer: function (layer, name) {
218218 var timeStamp = (e.timeStamp || e.originalEvent.timeStamp),
219219 elapsed = L.DomEvent._lastClick && (timeStamp - L.DomEvent._lastClick);
220220
221 // are they closer together than 1000ms yet more than 100ms?
221 // are they closer together than 500ms yet more than 100ms?
222222 // Android typically triggers them ~300ms apart while multiple listeners
223223 // on the same event should be triggered far faster;
224224 // or check if click is simulated on the element, and if it is, reject any non-simulated events
225225
226 if ((elapsed && elapsed > 100 && elapsed < 1000) || (e.target._simulatedClick && !e._simulated)) {
226 if ((elapsed && elapsed > 100 && elapsed < 500) || (e.target._simulatedClick && !e._simulated)) {
227227 L.DomEvent.stop(e);
228228 return;
229229 }
8181 offset = newPoint.subtract(this._startPoint);
8282
8383 if (!offset.x && !offset.y) { return; }
84 if (L.Browser.touch && Math.abs(offset.x) + Math.abs(offset.y) < 3) { return; }
8485
8586 L.DomEvent.preventDefault(e);
8687
9192 this._startPos = L.DomUtil.getPosition(this._element).subtract(offset);
9293
9394 L.DomUtil.addClass(document.body, 'leaflet-dragging');
94 L.DomUtil.addClass((e.target || e.srcElement), 'leaflet-drag-target');
95 this._lastTarget = e.target || e.srcElement;
96 L.DomUtil.addClass(this._lastTarget, 'leaflet-drag-target');
9597 }
9698
9799 this._newPos = this._startPos.add(offset);
107109 this.fire('drag');
108110 },
109111
110 _onUp: function (e) {
112 _onUp: function () {
111113 L.DomUtil.removeClass(document.body, 'leaflet-dragging');
112 L.DomUtil.removeClass((e.target || e.srcElement), 'leaflet-drag-target');
114
115 if (this._lastTarget) {
116 L.DomUtil.removeClass(this._lastTarget, 'leaflet-drag-target');
117 this._lastTarget = null;
118 }
113119
114120 for (var i in L.Draggable.MOVE) {
115121 L.DomEvent
4141 }
4242
4343 this._requestUpdate();
44
44
45 this.fire('remove');
4546 this._map = null;
4647 },
4748
567567 var loading = !this._loaded;
568568 this._loaded = true;
569569
570 this.fire('viewreset', {hard: !preserveMapOffset});
571
570572 if (loading) {
571573 this.fire('load');
572574 this.eachLayer(this._layerAdd, this);
573575 }
574
575 this.fire('viewreset', {hard: !preserveMapOffset});
576576
577577 this.fire('move');
578578
6060 return true;
6161 },
6262
63 _animateZoom: function (center, zoom, origin, scale, delta, backwards) {
63 _animateZoom: function (center, zoom, origin, scale, delta, backwards, forTouchZoom) {
6464
65 this._animatingZoom = true;
65 if (!forTouchZoom) {
66 this._animatingZoom = true;
67 }
6668
6769 // put transform transition on all layers with leaflet-zoom-animated class
6870 L.DomUtil.addClass(this._mapPane, 'leaflet-zoom-anim');
7678 L.Draggable._disabled = true;
7779 }
7880
79 this.fire('zoomanim', {
80 center: center,
81 zoom: zoom,
82 origin: origin,
83 scale: scale,
84 delta: delta,
85 backwards: backwards
86 });
81 L.Util.requestAnimFrame(function () {
82 this.fire('zoomanim', {
83 center: center,
84 zoom: zoom,
85 origin: origin,
86 scale: scale,
87 delta: delta,
88 backwards: backwards
89 });
90 }, this);
8791 },
8892
8993 _onZoomTransitionEnd: function () {
8484 center = map.layerPointToLatLng(origin),
8585 zoom = map.getScaleZoom(this._scale);
8686
87 map._animateZoom(center, zoom, this._startCenter, this._scale, this._delta);
87 map._animateZoom(center, zoom, this._startCenter, this._scale, this._delta, false, true);
8888 },
8989
9090 _onTouchEnd: function () {