diff --git a/WebContent/base/OSRM.Map.js b/WebContent/base/OSRM.Map.js index 98e95962f..d75586867 100644 --- a/WebContent/base/OSRM.Map.js +++ b/WebContent/base/OSRM.Map.js @@ -84,7 +84,7 @@ zoomed: function(e) { OSRM.Routing.getRoute_Redraw({keepAlternative:true}); }, contextmenu: function(e) {;}, -mousemove: function(e) { OSRM.Via.drawDragMarker(e); }, +mousemove: function(e) { },//OSRM.Via.drawDragMarker(e); }, click: function(e) { OSRM.GUI.deactivateTooltip( "CLICKING" ); if( !OSRM.G.markers.hasSource() ) { diff --git a/WebContent/leaflet/images/layers.png b/WebContent/leaflet/images/layers.png index 3db9dd8db..9be965fc8 100644 Binary files a/WebContent/leaflet/images/layers.png and b/WebContent/leaflet/images/layers.png differ diff --git a/WebContent/leaflet/images/marker.png b/WebContent/leaflet/images/marker.png deleted file mode 100644 index bef032e62..000000000 Binary files a/WebContent/leaflet/images/marker.png and /dev/null differ diff --git a/WebContent/leaflet/images/popup-close.png b/WebContent/leaflet/images/popup-close.png deleted file mode 100644 index c8faec5ea..000000000 Binary files a/WebContent/leaflet/images/popup-close.png and /dev/null differ diff --git a/WebContent/leaflet/leaflet-src.js b/WebContent/leaflet/leaflet-src.js index f65851fc7..4caee62d1 100644 --- a/WebContent/leaflet/leaflet-src.js +++ b/WebContent/leaflet/leaflet-src.js @@ -1,41 +1,27 @@ /* - Copyright (c) 2010-2011, CloudMade, Vladimir Agafonkin - Leaflet is a modern open-source JavaScript library for interactive maps. + Copyright (c) 2010-2012, CloudMade, Vladimir Agafonkin + Leaflet is an open-source JavaScript library for mobile-friendly interactive maps. http://leaflet.cloudmade.com */ +(function (window, undefined) { -(function (root) { - root.L = { - VERSION: '0.3', +var L, originalL; - ROOT_URL: root.L_ROOT_URL || (function () { - var scripts = document.getElementsByTagName('script'), - leafletRe = /\/?leaflet[\-\._]?([\w\-\._]*)\.js\??/; +if (typeof exports !== undefined + '') { + L = exports; +} else { + originalL = window.L; + L = {}; - var i, len, src, matches; - - for (i = 0, len = scripts.length; i < len; i++) { - src = scripts[i].src; - matches = src.match(leafletRe); - - if (matches) { - if (matches[1] === 'include') { - return '../../dist/'; - } - return src.split(leafletRe)[0] + '/'; - } - } - return ''; - }()), - - noConflict: function () { - root.L = this._originalL; - return this; - }, - - _originalL: root.L + L.noConflict = function () { + window.L = originalL; + return this; }; -}(this)); + + window.L = L; +} + +L.version = '0.4.4'; /* @@ -56,9 +42,10 @@ L.Util = { return dest; }, - bind: function (/*Function*/ fn, /*Object*/ obj) /*-> Object*/ { + bind: function (fn, obj) { // (Function, Object) -> Function + var args = arguments.length > 2 ? Array.prototype.slice.call(arguments, 2) : null; return function () { - return fn.apply(obj, arguments); + return fn.apply(obj, args || arguments); }; }, @@ -70,46 +57,29 @@ L.Util = { }; }()), - requestAnimFrame: (function () { - function timeoutDefer(callback) { - window.setTimeout(callback, 1000 / 60); - } - - var requestFn = window.requestAnimationFrame || - window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || - window.oRequestAnimationFrame || - window.msRequestAnimationFrame || - timeoutDefer; - - return function (callback, context, immediate, contextEl) { - callback = context ? L.Util.bind(callback, context) : callback; - if (immediate && requestFn === timeoutDefer) { - callback(); - } else { - requestFn(callback, contextEl); - } - }; - }()), - limitExecByInterval: function (fn, time, context) { - var lock, execOnUnlock, args; - function exec() { - lock = false; - if (execOnUnlock) { - args.callee.apply(context, args); - execOnUnlock = false; - } - } - return function () { - args = arguments; - if (!lock) { - lock = true; - setTimeout(exec, time); - fn.apply(context, args); - } else { + var lock, execOnUnlock; + + return function wrapperFn() { + var args = arguments; + + if (lock) { execOnUnlock = true; + return; } + + lock = true; + + setTimeout(function () { + lock = false; + + if (execOnUnlock) { + wrapperFn.apply(context, args); + execOnUnlock = false; + } + }, time); + + fn.apply(context, args); }; }, @@ -122,8 +92,13 @@ L.Util = { return Math.round(num * pow) / pow; }, + splitWords: function (str) { + return str.replace(/^\s+|\s+$/g, '').split(/\s+/); + }, + setOptions: function (obj, options) { obj.options = L.Util.extend({}, obj.options, options); + return obj.options; }, getParamString: function (obj) { @@ -144,9 +119,57 @@ L.Util = { } return value; }); - } + }, + + emptyImageUrl: 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=' }; +(function () { + + function getPrefixed(name) { + var i, fn, + prefixes = ['webkit', 'moz', 'o', 'ms']; + + for (i = 0; i < prefixes.length && !fn; i++) { + fn = window[prefixes[i] + name]; + } + + return fn; + } + + function timeoutDefer(fn) { + return window.setTimeout(fn, 1000 / 60); + } + + var requestFn = window.requestAnimationFrame || + getPrefixed('RequestAnimationFrame') || timeoutDefer; + + var cancelFn = window.cancelAnimationFrame || + getPrefixed('CancelAnimationFrame') || + getPrefixed('CancelRequestAnimationFrame') || + function (id) { + window.clearTimeout(id); + }; + + + L.Util.requestAnimFrame = function (fn, context, immediate, element) { + fn = L.Util.bind(fn, context); + + if (immediate && requestFn === timeoutDefer) { + fn(); + } else { + return requestFn.call(window, fn, element); + } + }; + + L.Util.cancelAnimFrame = function (id) { + if (id) { + cancelFn.call(window, id); + } + }; + +}()); + /* * Class powers the OOP facilities of the library. Thanks to John Resig and Dean Edwards for inspiration! @@ -166,20 +189,15 @@ L.Class.extend = function (/*Object*/ props) /*-> Class*/ { // instantiate class without calling constructor var F = function () {}; F.prototype = this.prototype; + var proto = new F(); - proto.constructor = NewClass; + NewClass.prototype = proto; - // add superclass access - NewClass.superclass = this.prototype; - - // add class name - //proto.className = props; - //inherit parent's statics for (var i in this) { - if (this.hasOwnProperty(i) && i !== 'prototype' && i !== 'superclass') { + if (this.hasOwnProperty(i) && i !== 'prototype') { NewClass[i] = this[i]; } } @@ -204,58 +222,97 @@ L.Class.extend = function (/*Object*/ props) /*-> Class*/ { // mix given properties into the prototype L.Util.extend(proto, props); - // allow inheriting further - NewClass.extend = L.Class.extend; - - // method for adding properties to prototype - NewClass.include = function (props) { - L.Util.extend(this.prototype, props); - }; - return NewClass; }; +// method for adding properties to prototype +L.Class.include = function (props) { + L.Util.extend(this.prototype, props); +}; + +L.Class.mergeOptions = function (options) { + L.Util.extend(this.prototype.options, options); +}; + /* * L.Mixin.Events adds custom events functionality to Leaflet classes */ +var key = '_leaflet_events'; + L.Mixin = {}; L.Mixin.Events = { - addEventListener: function (/*String*/ type, /*Function*/ fn, /*(optional) Object*/ context) { - var events = this._leaflet_events = this._leaflet_events || {}; - events[type] = events[type] || []; - events[type].push({ - action: fn, - context: context || this - }); - return this; - }, - - hasEventListeners: function (/*String*/ type) /*-> Boolean*/ { - var k = '_leaflet_events'; - return (k in this) && (type in this[k]) && (this[k][type].length > 0); - }, - - removeEventListener: function (/*String*/ type, /*Function*/ fn, /*(optional) Object*/ context) { - if (!this.hasEventListeners(type)) { + + addEventListener: function (types, fn, context) { // (String, Function[, Object]) or (Object[, Object]) + var events = this[key] = this[key] || {}, + type, i, len; + + // Types can be a map of types/handlers + if (typeof types === 'object') { + for (type in types) { + if (types.hasOwnProperty(type)) { + this.addEventListener(type, types[type], fn); + } + } + return this; } - - for (var i = 0, events = this._leaflet_events, len = events[type].length; i < len; i++) { - if ( - (events[type][i].action === fn) && - (!context || (events[type][i].context === context)) - ) { - events[type].splice(i, 1); - return this; - } + + types = L.Util.splitWords(types); + + for (i = 0, len = types.length; i < len; i++) { + events[types[i]] = events[types[i]] || []; + events[types[i]].push({ + action: fn, + context: context || this + }); } + return this; }, - fireEvent: function (/*String*/ type, /*(optional) Object*/ data) { + hasEventListeners: function (type) { // (String) -> Boolean + return (key in this) && (type in this[key]) && (this[key][type].length > 0); + }, + + removeEventListener: function (types, fn, context) { // (String[, Function, Object]) or (Object[, Object]) + var events = this[key], + type, i, len, listeners, j; + + if (typeof types === 'object') { + for (type in types) { + if (types.hasOwnProperty(type)) { + this.removeEventListener(type, types[type], fn); + } + } + + return this; + } + + types = L.Util.splitWords(types); + + for (i = 0, len = types.length; i < len; i++) { + + if (this.hasEventListeners(types[i])) { + listeners = events[types[i]]; + + for (j = listeners.length - 1; j >= 0; j--) { + if ( + (!fn || listeners[j].action === fn) && + (!context || (listeners[j].context === context)) + ) { + listeners.splice(j, 1); + } + } + } + } + + return this; + }, + + fireEvent: function (type, data) { // (String[, Object]) if (!this.hasEventListeners(type)) { return this; } @@ -265,7 +322,7 @@ L.Mixin.Events = { target: this }, data); - var listeners = this._leaflet_events[type].slice(); + var listeners = this[key][type].slice(); for (var i = 0, len = listeners.length; i < len; i++) { listeners[i].action.call(listeners[i].context || this, event); @@ -283,54 +340,76 @@ L.Mixin.Events.fire = L.Mixin.Events.fireEvent; (function () { var ua = navigator.userAgent.toLowerCase(), ie = !!window.ActiveXObject, + ie6 = ie && !window.XMLHttpRequest, webkit = ua.indexOf("webkit") !== -1, - mobile = typeof orientation !== 'undefined' ? true : false, + gecko = ua.indexOf("gecko") !== -1, + //Terrible browser detection to work around a safari / iOS / android browser bug. See TileLayer._addTile and debug/hacks/jitter.html + chrome = ua.indexOf("chrome") !== -1, + opera = window.opera, android = ua.indexOf("android") !== -1, - opera = window.opera; + android23 = ua.search("android [23]") !== -1, + mobile = typeof orientation !== undefined + '' ? true : false, + doc = document.documentElement, + ie3d = ie && ('transition' in doc.style), + webkit3d = webkit && ('WebKitCSSMatrix' in window) && ('m11' in new window.WebKitCSSMatrix()), + gecko3d = gecko && ('MozPerspective' in doc.style), + opera3d = opera && ('OTransition' in doc.style); + + var touch = !window.L_NO_TOUCH && (function () { + var startName = 'ontouchstart'; + + // WebKit, etc + if (startName in doc) { + return true; + } + + // Firefox/Gecko + var div = document.createElement('div'), + supported = false; + + if (!div.setAttribute) { + return false; + } + div.setAttribute(startName, 'return;'); + + if (typeof div[startName] === 'function') { + supported = true; + } + + div.removeAttribute(startName); + div = null; + + return supported; + }()); + + var retina = (('devicePixelRatio' in window && window.devicePixelRatio > 1) || ('matchMedia' in window && window.matchMedia("(min-resolution:144dpi)").matches)); L.Browser = { + ua: ua, ie: ie, - ie6: ie && !window.XMLHttpRequest, - + ie6: ie6, webkit: webkit, - webkit3d: webkit && ('WebKitCSSMatrix' in window) && ('m11' in new window.WebKitCSSMatrix()), - - gecko: ua.indexOf("gecko") !== -1, - + gecko: gecko, opera: opera, - android: android, - mobileWebkit: mobile && webkit, - mobileOpera: mobile && opera, + android23: android23, + + chrome: chrome, + + ie3d: ie3d, + webkit3d: webkit3d, + gecko3d: gecko3d, + opera3d: opera3d, + any3d: !window.L_DISABLE_3D && (ie3d || webkit3d || gecko3d || opera3d), mobile: mobile, - touch: (function () { - var touchSupported = false, - startName = 'ontouchstart'; + mobileWebkit: mobile && webkit, + mobileWebkit3d: mobile && webkit3d, + mobileOpera: mobile && opera, - // WebKit, etc - if (startName in document.documentElement) { - return true; - } + touch: touch, - // Firefox/Gecko - var e = document.createElement('div'); - - // If no support for basic event stuff, unlikely to have touch support - if (!e.setAttribute || !e.removeAttribute) { - return false; - } - - e.setAttribute(startName, 'return;'); - if (typeof e[startName] === 'function') { - touchSupported = true; - } - - e.removeAttribute(startName); - e = null; - - return touchSupported; - }()) + retina: retina }; }()); @@ -346,7 +425,7 @@ L.Point = function (/*Number*/ x, /*Number*/ y, /*Boolean*/ round) { L.Point.prototype = { add: function (point) { - return this.clone()._add(point); + return this.clone()._add(L.point(point)); }, _add: function (point) { @@ -356,7 +435,7 @@ L.Point.prototype = { }, subtract: function (point) { - return this.clone()._subtract(point); + return this.clone()._subtract(L.point(point)); }, // destructive subtract (faster) @@ -370,13 +449,16 @@ L.Point.prototype = { return new L.Point(this.x / num, this.y / num, round); }, - multiplyBy: function (num) { - return new L.Point(this.x * num, this.y * num); + multiplyBy: function (num, round) { + return new L.Point(this.x * num, this.y * num, round); }, distanceTo: function (point) { + point = L.point(point); + var x = point.x - this.x, y = point.y - this.y; + return Math.sqrt(x * x + y * y); }, @@ -391,6 +473,16 @@ L.Point.prototype = { return this; }, + floor: function () { + return this.clone()._floor(); + }, + + _floor: function () { + this.x = Math.floor(this.x); + this.y = Math.floor(this.y); + return this; + }, + clone: function () { return new L.Point(this.x, this.y); }, @@ -402,44 +494,75 @@ L.Point.prototype = { } }; +L.point = function (x, y, round) { + if (x instanceof L.Point) { + return x; + } + if (x instanceof Array) { + return new L.Point(x[0], x[1]); + } + if (isNaN(x)) { + return x; + } + return new L.Point(x, y, round); +}; + /* * L.Bounds represents a rectangular area on the screen in pixel coordinates. */ L.Bounds = L.Class.extend({ - initialize: function (min, max) { //(Point, Point) or Point[] - if (!min) { - return; - } - var points = (min instanceof Array ? min : [min, max]); + + initialize: function (a, b) { //(Point, Point) or Point[] + if (!a) { return; } + + var points = b ? [a, b] : a; + for (var i = 0, len = points.length; i < len; i++) { this.extend(points[i]); } }, // extend the bounds to contain the given point - extend: function (/*Point*/ point) { + extend: function (point) { // (Point) + point = L.point(point); + if (!this.min && !this.max) { - this.min = new L.Point(point.x, point.y); - this.max = new L.Point(point.x, point.y); + this.min = point.clone(); + this.max = point.clone(); } else { this.min.x = Math.min(point.x, this.min.x); this.max.x = Math.max(point.x, this.max.x); this.min.y = Math.min(point.y, this.min.y); this.max.y = Math.max(point.y, this.max.y); } + return this; }, - getCenter: function (round)/*->Point*/ { + getCenter: function (round) { // (Boolean) -> Point return new L.Point( (this.min.x + this.max.x) / 2, (this.min.y + this.max.y) / 2, round); }, - contains: function (/*Bounds or Point*/ obj)/*->Boolean*/ { + getBottomLeft: function () { // -> Point + return new L.Point(this.min.x, this.max.y); + }, + + getTopRight: function () { // -> Point + return new L.Point(this.max.x, this.min.y); + }, + + contains: function (obj) { // (Bounds) or (Point) -> Boolean var min, max; + if (typeof obj[0] === 'number' || obj instanceof L.Point) { + obj = L.point(obj); + } else { + obj = L.bounds(obj); + } + if (obj instanceof L.Bounds) { min = obj.min; max = obj.max; @@ -453,7 +576,9 @@ L.Bounds = L.Class.extend({ (max.y <= this.max.y); }, - intersects: function (/*Bounds*/ bounds) { + intersects: function (bounds) { // (Bounds) -> Boolean + bounds = L.bounds(bounds); + var min = this.min, max = this.max, min2 = bounds.min, @@ -467,6 +592,13 @@ L.Bounds = L.Class.extend({ }); +L.bounds = function (a, b) { // (Bounds) or (Point, Point) or (Point[]) + if (!a || a instanceof L.Bounds) { + return a; + } + return new L.Bounds(a, b); +}; + /* * L.Transformation is an utility class to perform simple point transformations through a 2d-matrix. @@ -536,6 +668,12 @@ L.DomUtil = { L.DomUtil.getStyle(el, 'position') === 'absolute') { break; } + if (L.DomUtil.getStyle(el, 'position') === 'fixed') { + top += docBody.scrollTop || 0; + left += docBody.scrollLeft || 0; + break; + } + el = el.offsetParent; } while (el); @@ -591,24 +729,41 @@ L.DomUtil = { }, removeClass: function (el, name) { - el.className = el.className.replace(/(\S+)\s*/g, function (w, match) { + function replaceFn(w, match) { if (match === name) { return ''; } return w; - }).replace(/^\s+/, ''); + } + el.className = el.className + .replace(/(\S+)\s*/g, replaceFn) + .replace(/(^\s+|\s+$)/, ''); }, setOpacity: function (el, value) { - if (L.Browser.ie) { - el.style.filter = 'alpha(opacity=' + Math.round(value * 100) + ')'; - } else { + + if ('opacity' in el.style) { el.style.opacity = value; + + } else if (L.Browser.ie) { + + var filter = false, + filterName = 'DXImageTransform.Microsoft.Alpha'; + + // filters collection throws an error if we try to retrieve a filter that doesn't exist + try { filter = el.filters.item(filterName); } catch (e) {} + + value = Math.round(value * 100); + + if (filter) { + filter.Enabled = (value !== 100); + filter.Opacity = value; + } else { + el.style.filter += ' progid:' + filterName + '(opacity=' + value + ')'; + } } }, - //TODO refactor away this ugly translate/position mess - testProp: function (props) { var style = document.documentElement.style; @@ -621,9 +776,15 @@ L.DomUtil = { }, getTranslateString: function (point) { - return L.DomUtil.TRANSLATE_OPEN + - point.x + 'px,' + point.y + 'px' + - L.DomUtil.TRANSLATE_CLOSE; + // On webkit browsers (Chrome/Safari/MobileSafari/Android) using translate3d instead of translate + // makes animation smoother as it ensures HW accel is used. Firefox 13 doesn't care + // (same speed either way), Opera 12 doesn't support translate3d + + var is3d = L.Browser.webkit3d, + open = 'translate' + (is3d ? '3d' : '') + '(', + close = (is3d ? ',0' : '') + ')'; + + return open + point.x + 'px,' + point.y + 'px' + close; }, getScaleString: function (scale, origin) { @@ -634,14 +795,14 @@ L.DomUtil = { return preTranslateStr + scaleStr + postTranslateStr; }, - setPosition: function (el, point) { + setPosition: function (el, point, disable3D) { el._leaflet_pos = point; - if (L.Browser.webkit3d) { + if (!disable3D && L.Browser.any3d) { el.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString(point); - if (L.Browser.android) { - el.style['-webkit-perspective'] = '1000'; - el.style['-webkit-backface-visibility'] = 'hidden'; + // workaround for Android 2/3 stability (https://github.com/CloudMade/Leaflet/issues/69) + if (L.Browser.mobileWebkit3d) { + el.style.WebkitBackfaceVisibility = 'hidden'; } } else { el.style.left = point.x + 'px'; @@ -656,10 +817,7 @@ L.DomUtil = { L.Util.extend(L.DomUtil, { TRANSITION: L.DomUtil.testProp(['transition', 'webkitTransition', 'OTransition', 'MozTransition', 'msTransition']), - TRANSFORM: L.DomUtil.testProp(['transformProperty', 'WebkitTransform', 'OTransform', 'MozTransform', 'msTransform']), - - TRANSLATE_OPEN: 'translate' + (L.Browser.webkit3d ? '3d(' : '('), - TRANSLATE_CLOSE: L.Browser.webkit3d ? ',0)' : ')' + TRANSFORM: L.DomUtil.testProp(['transform', 'WebkitTransform', 'OTransform', 'MozTransform', 'msTransform']) }); @@ -667,7 +825,7 @@ L.Util.extend(L.DomUtil, { CM.LatLng represents a geographical point with latitude and longtitude coordinates. */ -L.LatLng = function (/*Number*/ rawLat, /*Number*/ rawLng, /*Boolean*/ noWrap) { +L.LatLng = function (rawLat, rawLng, noWrap) { // (Number, Number[, Boolean]) var lat = parseFloat(rawLat), lng = parseFloat(rawLng); @@ -680,7 +838,6 @@ L.LatLng = function (/*Number*/ rawLat, /*Number*/ rawLng, /*Boolean*/ noWrap) { lng = (lng + 180) % 360 + ((lng < -180 || lng === 180) ? 180 : -180); // wrap longtitude into -180..180 } - //TODO change to lat() & lng() this.lat = lat; this.lng = lng; }; @@ -692,23 +849,25 @@ L.Util.extend(L.LatLng, { }); L.LatLng.prototype = { - equals: function (/*LatLng*/ obj) { - if (!(obj instanceof L.LatLng)) { - return false; - } + equals: function (obj) { // (LatLng) -> Boolean + if (!obj) { return false; } + + obj = L.latLng(obj); var margin = Math.max(Math.abs(this.lat - obj.lat), Math.abs(this.lng - obj.lng)); return margin <= L.LatLng.MAX_MARGIN; }, - toString: function () { + toString: function () { // -> String return 'LatLng(' + L.Util.formatNum(this.lat) + ', ' + L.Util.formatNum(this.lng) + ')'; }, // Haversine distance formula, see http://en.wikipedia.org/wiki/Haversine_formula - distanceTo: function (/*LatLng*/ other)/*->Double*/ { + distanceTo: function (other) { // (LatLng) -> Number + other = L.latLng(other); + var R = 6378137, // earth radius in meters d2r = L.LatLng.DEG_TO_RAD, dLat = (other.lat - this.lat) * d2r, @@ -724,6 +883,19 @@ L.LatLng.prototype = { } }; +L.latLng = function (a, b, c) { // (LatLng) or ([Number, Number]) or (Number, Number, Boolean) + if (a instanceof L.LatLng) { + return a; + } + if (a instanceof Array) { + return new L.LatLng(a[0], a[1]); + } + if (isNaN(a)) { + return a; + } + return new L.LatLng(a, b, c); +}; + /* * L.LatLngBounds represents a rectangular area on the map in geographical coordinates. @@ -731,29 +903,54 @@ L.LatLng.prototype = { L.LatLngBounds = L.Class.extend({ initialize: function (southWest, northEast) { // (LatLng, LatLng) or (LatLng[]) - if (!southWest) { - return; - } - var latlngs = (southWest instanceof Array ? southWest : [southWest, northEast]); + if (!southWest) { return; } + + var latlngs = northEast ? [southWest, northEast] : southWest; + for (var i = 0, len = latlngs.length; i < len; i++) { this.extend(latlngs[i]); } }, - // extend the bounds to contain the given point - extend: function (/*LatLng*/ latlng) { - if (!this._southWest && !this._northEast) { - this._southWest = new L.LatLng(latlng.lat, latlng.lng, true); - this._northEast = new L.LatLng(latlng.lat, latlng.lng, true); + // extend the bounds to contain the given point or bounds + extend: function (obj) { // (LatLng) or (LatLngBounds) + if (typeof obj[0] === 'number' || obj instanceof L.LatLng) { + obj = L.latLng(obj); } else { - this._southWest.lat = Math.min(latlng.lat, this._southWest.lat); - this._southWest.lng = Math.min(latlng.lng, this._southWest.lng); - this._northEast.lat = Math.max(latlng.lat, this._northEast.lat); - this._northEast.lng = Math.max(latlng.lng, this._northEast.lng); + obj = L.latLngBounds(obj); } + + if (obj instanceof L.LatLng) { + if (!this._southWest && !this._northEast) { + this._southWest = new L.LatLng(obj.lat, obj.lng, true); + this._northEast = new L.LatLng(obj.lat, obj.lng, true); + } else { + this._southWest.lat = Math.min(obj.lat, this._southWest.lat); + this._southWest.lng = Math.min(obj.lng, this._southWest.lng); + + this._northEast.lat = Math.max(obj.lat, this._northEast.lat); + this._northEast.lng = Math.max(obj.lng, this._northEast.lng); + } + } else if (obj instanceof L.LatLngBounds) { + this.extend(obj._southWest); + this.extend(obj._northEast); + } + return this; }, - getCenter: function () /*-> LatLng*/ { + // extend the bounds by a percentage + pad: function (bufferRatio) { // (Number) -> LatLngBounds + var sw = this._southWest, + ne = this._northEast, + heightBuffer = Math.abs(sw.lat - ne.lat) * bufferRatio, + widthBuffer = Math.abs(sw.lng - ne.lng) * bufferRatio; + + return new L.LatLngBounds( + new L.LatLng(sw.lat - heightBuffer, sw.lng - widthBuffer), + new L.LatLng(ne.lat + heightBuffer, ne.lng + widthBuffer)); + }, + + getCenter: function () { // -> LatLng return new L.LatLng( (this._southWest.lat + this._northEast.lat) / 2, (this._southWest.lng + this._northEast.lng) / 2); @@ -775,7 +972,13 @@ L.LatLngBounds = L.Class.extend({ return new L.LatLng(this._southWest.lat, this._northEast.lng, true); }, - contains: function (/*LatLngBounds or LatLng*/ obj) /*-> Boolean*/ { + contains: function (obj) { // (LatLngBounds) or (LatLng) -> Boolean + if (typeof obj[0] === 'number' || obj instanceof L.LatLng) { + obj = L.latLng(obj); + } else { + obj = L.latLngBounds(obj); + } + var sw = this._southWest, ne = this._northEast, sw2, ne2; @@ -791,7 +994,9 @@ L.LatLngBounds = L.Class.extend({ (sw2.lng >= sw.lng) && (ne2.lng <= ne.lng); }, - intersects: function (/*LatLngBounds*/ bounds) { + intersects: function (bounds) { // (LatLngBounds) + bounds = L.latLngBounds(bounds); + var sw = this._southWest, ne = this._northEast, sw2 = bounds.getSouthWest(), @@ -807,11 +1012,27 @@ L.LatLngBounds = L.Class.extend({ var sw = this._southWest, ne = this._northEast; return [sw.lng, sw.lat, ne.lng, ne.lat].join(','); + }, + + equals: function (bounds) { // (LatLngBounds) + if (!bounds) { return false; } + + bounds = L.latLngBounds(bounds); + + return this._southWest.equals(bounds.getSouthWest()) && + this._northEast.equals(bounds.getNorthEast()); } }); //TODO International date line? +L.latLngBounds = function (a, b) { // (LatLngBounds) or (LatLng, LatLng) + if (!a || a instanceof L.LatLngBounds) { + return a; + } + return new L.LatLngBounds(a, b); +}; + /* * L.Projection contains various geographical projections used by CRS classes. @@ -824,7 +1045,7 @@ L.Projection = {}; L.Projection.SphericalMercator = { MAX_LATITUDE: 85.0511287798, - project: function (/*LatLng*/ latlng) /*-> Point*/ { + project: function (latlng) { // (LatLng) -> Point var d = L.LatLng.DEG_TO_RAD, max = this.MAX_LATITUDE, lat = Math.max(Math.min(max, latlng.lat), -max), @@ -835,12 +1056,13 @@ L.Projection.SphericalMercator = { return new L.Point(x, y); }, - unproject: function (/*Point*/ point, /*Boolean*/ unbounded) /*-> LatLng*/ { + unproject: function (point) { // (Point, Boolean) -> LatLng var d = L.LatLng.RAD_TO_DEG, lng = point.x * d, lat = (2 * Math.atan(Math.exp(point.y)) - (Math.PI / 2)) * d; - return new L.LatLng(lat, lng, unbounded); + // TODO refactor LatLng wrapping + return new L.LatLng(lat, lng, true); } }; @@ -851,27 +1073,34 @@ L.Projection.LonLat = { return new L.Point(latlng.lng, latlng.lat); }, - unproject: function (point, unbounded) { - return new L.LatLng(point.y, point.x, unbounded); + unproject: function (point) { + return new L.LatLng(point.y, point.x, true); } }; L.CRS = { - latLngToPoint: function (/*LatLng*/ latlng, /*Number*/ scale)/*-> Point*/ { - var projectedPoint = this.projection.project(latlng); + latLngToPoint: function (latlng, zoom) { // (LatLng, Number) -> Point + var projectedPoint = this.projection.project(latlng), + scale = this.scale(zoom); + return this.transformation._transform(projectedPoint, scale); }, - pointToLatLng: function (/*Point*/ point, /*Number*/ scale, /*(optional) Boolean*/ unbounded)/*-> LatLng*/ { - var untransformedPoint = this.transformation.untransform(point, scale); - return this.projection.unproject(untransformedPoint, unbounded); - //TODO get rid of 'unbounded' everywhere + pointToLatLng: function (point, zoom) { // (Point, Number[, Boolean]) -> LatLng + var scale = this.scale(zoom), + untransformedPoint = this.transformation.untransform(point, scale); + + return this.projection.unproject(untransformedPoint); }, project: function (latlng) { return this.projection.project(latlng); + }, + + scale: function (zoom) { + return 256 * Math.pow(2, zoom); } }; @@ -883,7 +1112,7 @@ L.CRS.EPSG3857 = L.Util.extend({}, L.CRS, { projection: L.Projection.SphericalMercator, transformation: new L.Transformation(0.5 / Math.PI, 0.5, -0.5 / Math.PI, 0.5), - project: function (/*LatLng*/ latlng)/*-> Point*/ { + project: function (latlng) { // (LatLng) -> Point var projectedPoint = this.projection.project(latlng), earthRadius = 6378137; return projectedPoint.multiplyBy(earthRadius); @@ -909,81 +1138,40 @@ L.CRS.EPSG4326 = L.Util.extend({}, L.CRS, { */ L.Map = L.Class.extend({ + includes: L.Mixin.Events, options: { - // projection - crs: L.CRS.EPSG3857 || L.CRS.EPSG4326, - scale: function (zoom) { - return 256 * Math.pow(2, zoom); - }, + crs: L.CRS.EPSG3857, - // state - center: null, - zoom: null, - layers: [], + /* + center: LatLng, + zoom: Number, + layers: Array, + */ - // interaction - dragging: true, - touchZoom: L.Browser.touch && !L.Browser.android, - scrollWheelZoom: !L.Browser.touch, - doubleClickZoom: true, - boxZoom: true, - - // controls - zoomControl: true, - attributionControl: true, - - // animation - fadeAnimation: L.DomUtil.TRANSITION && !L.Browser.android, - zoomAnimation: L.DomUtil.TRANSITION && !L.Browser.android && !L.Browser.mobileOpera, - - // misc + fadeAnimation: L.DomUtil.TRANSITION && !L.Browser.android23, trackResize: true, - closePopupOnClick: true, - worldCopyJump: true + markerZoomAnimation: L.DomUtil.TRANSITION && L.Browser.any3d }, - - // constructor - initialize: function (id, options) { // (HTMLElement or String, Object) - L.Util.setOptions(this, options); - - this._container = L.DomUtil.get(id); - - if (this._container._leaflet) { - throw new Error("Map container is already initialized."); - } - this._container._leaflet = true; + options = L.Util.setOptions(this, options); + this._initContainer(id); this._initLayout(); + this._initHooks(); + this._initEvents(); - if (L.DomEvent) { - this._initEvents(); - if (L.Handler) { - this._initInteraction(); - } - if (L.Control) { - this._initControls(); - } + if (options.maxBounds) { + this.setMaxBounds(options.maxBounds); } - if (this.options.maxBounds) { - this.setMaxBounds(this.options.maxBounds); + if (options.center && options.zoom !== undefined) { + this.setView(L.latLng(options.center), options.zoom, true); } - var center = this.options.center, - zoom = this.options.zoom; - - if (center !== null && zoom !== null) { - this.setView(center, zoom, true); - } - - var layers = this.options.layers; - layers = (layers instanceof Array ? layers : [layers]); - this._tileLayersNum = 0; - this._initLayers(layers); + this._initLayers(options.layers); }, @@ -991,8 +1179,7 @@ L.Map = L.Class.extend({ // replaced by animation-powered implementation in Map.PanAnimation.js setView: function (center, zoom) { - // reset the map view - this._resetView(center, this._limitZoom(zoom)); + this._resetView(L.latLng(center), this._limitZoom(zoom)); return this; }, @@ -1010,12 +1197,13 @@ L.Map = L.Class.extend({ fitBounds: function (bounds) { // (LatLngBounds) var zoom = this.getBoundsZoom(bounds); - return this.setView(bounds.getCenter(), zoom); + return this.setView(L.latLngBounds(bounds).getCenter(), zoom); }, fitWorld: function () { var sw = new L.LatLng(-60, -170), - ne = new L.LatLng(85, 179); + ne = new L.LatLng(85, 179); + return this.fitBounds(new L.LatLngBounds(sw, ne)); }, @@ -1027,15 +1215,15 @@ L.Map = L.Class.extend({ // replaced with animated panBy in Map.Animation.js this.fire('movestart'); - this._rawPanBy(offset); + this._rawPanBy(L.point(offset)); this.fire('move'); - this.fire('moveend'); - - return this; + return this.fire('moveend'); }, setMaxBounds: function (bounds) { + bounds = L.latLngBounds(bounds); + this.options.maxBounds = bounds; if (!bounds) { @@ -1054,17 +1242,20 @@ L.Map = L.Class.extend({ this.panInsideBounds(bounds); } } + return this; }, panInsideBounds: function (bounds) { + bounds = L.latLngBounds(bounds); + var viewBounds = this.getBounds(), - viewSw = this.project(viewBounds.getSouthWest()), - viewNe = this.project(viewBounds.getNorthEast()), - sw = this.project(bounds.getSouthWest()), - ne = this.project(bounds.getNorthEast()), - dx = 0, - dy = 0; + viewSw = this.project(viewBounds.getSouthWest()), + viewNe = this.project(viewBounds.getNorthEast()), + sw = this.project(bounds.getSouthWest()), + ne = this.project(bounds.getNorthEast()), + dx = 0, + dy = 0; if (viewNe.y < ne.y) { // north dy = ne.y - viewNe.y; @@ -1082,33 +1273,32 @@ L.Map = L.Class.extend({ return this.panBy(new L.Point(dx, dy, true)); }, - addLayer: function (layer, insertAtTheTop) { + addLayer: function (layer) { + // TODO method is too big, refactor + var id = L.Util.stamp(layer); - if (this._layers[id]) { - return this; - } + if (this._layers[id]) { return this; } this._layers[id] = layer; + // TODO getMaxZoom, getMinZoom in ILayer (instead of options) if (layer.options && !isNaN(layer.options.maxZoom)) { this._layersMaxZoom = Math.max(this._layersMaxZoom || 0, layer.options.maxZoom); } if (layer.options && !isNaN(layer.options.minZoom)) { this._layersMinZoom = Math.min(this._layersMinZoom || Infinity, layer.options.minZoom); } - //TODO getMaxZoom, getMinZoom in ILayer (instead of options) + // TODO looks ugly, refactor!!! if (this.options.zoomAnimation && L.TileLayer && (layer instanceof L.TileLayer)) { this._tileLayersNum++; - layer.on('load', this._onTileLayerLoad, this); - } - if (this.attributionControl && layer.getAttribution) { - this.attributionControl.addAttribution(layer.getAttribution()); + this._tileLayersToLoad++; + layer.on('load', this._onTileLayerLoad, this); } var onMapLoad = function () { - layer.onAdd(this, insertAtTheTop); + layer.onAdd(this); this.fire('layeradd', {layer: layer}); }; @@ -1124,21 +1314,20 @@ L.Map = L.Class.extend({ removeLayer: function (layer) { var id = L.Util.stamp(layer); - if (this._layers[id]) { - layer.onRemove(this); - delete this._layers[id]; + if (!this._layers[id]) { return; } - if (this.options.zoomAnimation && L.TileLayer && (layer instanceof L.TileLayer)) { - this._tileLayersNum--; - layer.off('load', this._onTileLayerLoad, this); - } - if (this.attributionControl && layer.getAttribution) { - this.attributionControl.removeAttribution(layer.getAttribution()); - } + layer.onRemove(this); - this.fire('layerremove', {layer: layer}); + delete this._layers[id]; + + // TODO looks ugly, refactor + if (this.options.zoomAnimation && L.TileLayer && (layer instanceof L.TileLayer)) { + this._tileLayersNum--; + this._tileLayersToLoad--; + layer.off('load', this._onTileLayerLoad, this); } - return this; + + return this.fire('layerremove', {layer: layer}); }, hasLayer: function (layer) { @@ -1146,7 +1335,7 @@ L.Map = L.Class.extend({ return this._layers.hasOwnProperty(id); }, - invalidateSize: function () { + invalidateSize: function (animate) { var oldSize = this.getSize(); this._sizeChanged = true; @@ -1155,18 +1344,32 @@ L.Map = L.Class.extend({ this.setMaxBounds(this.options.maxBounds); } - if (!this._loaded) { - return this; + if (!this._loaded) { return this; } + + var offset = oldSize.subtract(this.getSize()).divideBy(2, true); + + if (animate === true) { + this.panBy(offset); + } else { + this._rawPanBy(offset); + + this.fire('move'); + + clearTimeout(this._sizeTimer); + this._sizeTimer = setTimeout(L.Util.bind(this.fire, this, 'moveend'), 200); } + return this; + }, - this._rawPanBy(oldSize.subtract(this.getSize()).divideBy(2, true)); + // TODO handler.addTo + addHandler: function (name, HandlerClass) { + if (!HandlerClass) { return; } - this.fire('move'); + this[name] = new HandlerClass(this); - clearTimeout(this._sizeTimer); - this._sizeTimer = setTimeout(L.Util.bind(function () { - this.fire('moveend'); - }, this), 200); + if (this.options[name]) { + this[name].enable(); + } return this; }, @@ -1174,10 +1377,8 @@ L.Map = L.Class.extend({ // public methods for getting map state - getCenter: function (unbounded) { // (Boolean) - var viewHalf = this.getSize().divideBy(2), - centerPoint = this._getTopLeftPoint().add(viewHalf); - return this.unproject(centerPoint, this._zoom, unbounded); + getCenter: function () { // (Boolean) -> LatLng + return this.layerPointToLatLng(this._getCenterLayerPoint()); }, getZoom: function () { @@ -1186,36 +1387,39 @@ L.Map = L.Class.extend({ getBounds: function () { var bounds = this.getPixelBounds(), - sw = this.unproject(new L.Point(bounds.min.x, bounds.max.y), this._zoom, true), - ne = this.unproject(new L.Point(bounds.max.x, bounds.min.y), this._zoom, true); + sw = this.unproject(bounds.getBottomLeft()), + ne = this.unproject(bounds.getTopRight()); + return new L.LatLngBounds(sw, ne); }, getMinZoom: function () { var z1 = this.options.minZoom || 0, - z2 = this._layersMinZoom || 0, - z3 = this._boundsMinZoom || 0; + z2 = this._layersMinZoom || 0, + z3 = this._boundsMinZoom || 0; return Math.max(z1, z2, z3); }, getMaxZoom: function () { - var z1 = isNaN(this.options.maxZoom) ? Infinity : this.options.maxZoom, - z2 = this._layersMaxZoom || Infinity; + var z1 = this.options.maxZoom === undefined ? Infinity : this.options.maxZoom, + z2 = this._layersMaxZoom === undefined ? Infinity : this._layersMaxZoom; return Math.min(z1, z2); }, - getBoundsZoom: function (bounds, inside) { // (LatLngBounds) + getBoundsZoom: function (bounds, inside) { // (LatLngBounds, Boolean) -> Number + bounds = L.latLngBounds(bounds); + var size = this.getSize(), - zoom = this.options.minZoom || 0, - maxZoom = this.getMaxZoom(), - ne = bounds.getNorthEast(), - sw = bounds.getSouthWest(), - boundsSize, - nePoint, - swPoint, - zoomNotFound = true; + zoom = this.options.minZoom || 0, + maxZoom = this.getMaxZoom(), + ne = bounds.getNorthEast(), + sw = bounds.getSouthWest(), + boundsSize, + nePoint, + swPoint, + zoomNotFound = true; if (inside) { zoom--; @@ -1225,14 +1429,14 @@ L.Map = L.Class.extend({ zoom++; nePoint = this.project(ne, zoom); swPoint = this.project(sw, zoom); - boundsSize = new L.Point(nePoint.x - swPoint.x, swPoint.y - nePoint.y); + boundsSize = new L.Point(Math.abs(nePoint.x - swPoint.x), Math.abs(swPoint.y - nePoint.y)); if (!inside) { - zoomNotFound = (boundsSize.x <= size.x) && (boundsSize.y <= size.y); + zoomNotFound = boundsSize.x <= size.x && boundsSize.y <= size.y; } else { - zoomNotFound = (boundsSize.x < size.x) || (boundsSize.y < size.y); + zoomNotFound = boundsSize.x < size.x || boundsSize.y < size.y; } - } while (zoomNotFound && (zoom <= maxZoom)); + } while (zoomNotFound && zoom <= maxZoom); if (zoomNotFound && inside) { return null; @@ -1243,16 +1447,18 @@ L.Map = L.Class.extend({ getSize: function () { if (!this._size || this._sizeChanged) { - this._size = new L.Point(this._container.clientWidth, this._container.clientHeight); + this._size = new L.Point( + this._container.clientWidth, + this._container.clientHeight); + this._sizeChanged = false; } return this._size; }, getPixelBounds: function () { - var topLeftPoint = this._getTopLeftPoint(), - size = this.getSize(); - return new L.Bounds(topLeftPoint, topLeftPoint.add(size)); + var topLeftPoint = this._getTopLeftPoint(); + return new L.Bounds(topLeftPoint, topLeftPoint.add(this.getSize())); }, getPixelOrigin: function () { @@ -1263,9 +1469,62 @@ L.Map = L.Class.extend({ return this._panes; }, + getContainer: function () { + return this._container; + }, + + + // TODO replace with universal implementation after refactoring projections + + getZoomScale: function (toZoom) { + var crs = this.options.crs; + return crs.scale(toZoom) / crs.scale(this._zoom); + }, + + getScaleZoom: function (scale) { + return this._zoom + (Math.log(scale) / Math.LN2); + }, + // conversion methods + project: function (latlng, zoom) { // (LatLng[, Number]) -> Point + zoom = zoom === undefined ? this._zoom : zoom; + return this.options.crs.latLngToPoint(L.latLng(latlng), zoom); + }, + + unproject: function (point, zoom) { // (Point[, Number]) -> LatLng + zoom = zoom === undefined ? this._zoom : zoom; + return this.options.crs.pointToLatLng(L.point(point), zoom); + }, + + layerPointToLatLng: function (point) { // (Point) + var projectedPoint = L.point(point).add(this._initialTopLeftPoint); + return this.unproject(projectedPoint); + }, + + latLngToLayerPoint: function (latlng) { // (LatLng) + var projectedPoint = this.project(L.latLng(latlng))._round(); + return projectedPoint._subtract(this._initialTopLeftPoint); + }, + + containerPointToLayerPoint: function (point) { // (Point) + return L.point(point).subtract(this._getMapPanePos()); + }, + + layerPointToContainerPoint: function (point) { // (Point) + return L.point(point).add(this._getMapPanePos()); + }, + + containerPointToLatLng: function (point) { + var layerPoint = this.containerPointToLayerPoint(L.point(point)); + return this.layerPointToLatLng(layerPoint); + }, + + latLngToContainerPoint: function (latlng) { + return this.layerPointToContainerPoint(this.latLngToLayerPoint(L.latLng(latlng))); + }, + mouseEventToContainerPoint: function (e) { // (MouseEvent) return L.DomEvent.getMousePosition(e, this._container); }, @@ -1278,48 +1537,36 @@ L.Map = L.Class.extend({ return this.layerPointToLatLng(this.mouseEventToLayerPoint(e)); }, - containerPointToLayerPoint: function (point) { // (Point) - return point.subtract(L.DomUtil.getPosition(this._mapPane)); + + // map initialization methods + + _initContainer: function (id) { + var container = this._container = L.DomUtil.get(id); + + if (container._leaflet) { + throw new Error("Map container is already initialized."); + } + + container._leaflet = true; }, - layerPointToContainerPoint: function (point) { // (Point) - return point.add(L.DomUtil.getPosition(this._mapPane)); - }, - - layerPointToLatLng: function (point) { // (Point) - return this.unproject(point.add(this._initialTopLeftPoint)); - }, - - latLngToLayerPoint: function (latlng) { // (LatLng) - return this.project(latlng)._round()._subtract(this._initialTopLeftPoint); - }, - - project: function (latlng, zoom) { // (LatLng[, Number]) -> Point - zoom = (typeof zoom === 'undefined' ? this._zoom : zoom); - return this.options.crs.latLngToPoint(latlng, this.options.scale(zoom)); - }, - - unproject: function (point, zoom, unbounded) { // (Point[, Number, Boolean]) -> LatLng - zoom = (typeof zoom === 'undefined' ? this._zoom : zoom); - return this.options.crs.pointToLatLng(point, this.options.scale(zoom), unbounded); - }, - - - // private methods that modify map state - _initLayout: function () { var container = this._container; container.innerHTML = ''; + L.DomUtil.addClass(container, 'leaflet-container'); - container.className += ' leaflet-container'; + if (L.Browser.touch) { + L.DomUtil.addClass(container, 'leaflet-touch'); + } if (this.options.fadeAnimation) { - container.className += ' leaflet-fade-anim'; + L.DomUtil.addClass(container, 'leaflet-fade-anim'); } var position = L.DomUtil.getStyle(container, 'position'); - if (position !== 'absolute' && position !== 'relative') { + + if (position !== 'absolute' && position !== 'relative' && position !== 'fixed') { container.style.position = 'relative'; } @@ -1342,13 +1589,47 @@ L.Map = L.Class.extend({ panes.overlayPane = this._createPane('leaflet-overlay-pane'); panes.markerPane = this._createPane('leaflet-marker-pane'); panes.popupPane = this._createPane('leaflet-popup-pane'); + + var zoomHide = ' leaflet-zoom-hide'; + + if (!this.options.markerZoomAnimation) { + L.DomUtil.addClass(panes.markerPane, zoomHide); + L.DomUtil.addClass(panes.shadowPane, zoomHide); + L.DomUtil.addClass(panes.popupPane, zoomHide); + } }, _createPane: function (className, container) { return L.DomUtil.create('div', className, container || this._objectsPane); }, + _initializers: [], + + _initHooks: function () { + var i, len; + for (i = 0, len = this._initializers.length; i < len; i++) { + this._initializers[i].call(this); + } + }, + + _initLayers: function (layers) { + layers = layers ? (layers instanceof Array ? layers : [layers]) : []; + + this._layers = {}; + this._tileLayersNum = 0; + + var i, len; + + for (i = 0, len = layers.length; i < len; i++) { + this.addLayer(layers[i]); + } + }, + + + // private methods that modify map state + _resetView: function (center, zoom, preserveMapOffset, afterZoomAnim) { + var zoomChanged = (this._zoom !== zoom); if (!afterZoomAnim) { @@ -1366,18 +1647,20 @@ L.Map = L.Class.extend({ if (!preserveMapOffset) { L.DomUtil.setPosition(this._mapPane, new L.Point(0, 0)); } else { - var offset = L.DomUtil.getPosition(this._mapPane); - this._initialTopLeftPoint._add(offset); + this._initialTopLeftPoint._add(this._getMapPanePos()); } this._tileLayersToLoad = this._tileLayersNum; + this.fire('viewreset', {hard: !preserveMapOffset}); this.fire('move'); + if (zoomChanged || afterZoomAnim) { this.fire('zoomend'); } - this.fire('moveend'); + + this.fire('moveend', {hard: !preserveMapOffset}); if (!this._loaded) { this._loaded = true; @@ -1385,107 +1668,69 @@ L.Map = L.Class.extend({ } }, - _initLayers: function (layers) { - this._layers = {}; - - var i, len; - - for (i = 0, len = layers.length; i < len; i++) { - this.addLayer(layers[i]); - } - }, - - _initControls: function () { - if (this.options.zoomControl) { - this.addControl(new L.Control.Zoom()); - } - if (this.options.attributionControl) { - this.attributionControl = new L.Control.Attribution(); - this.addControl(this.attributionControl); - } - }, - _rawPanBy: function (offset) { - var mapPaneOffset = L.DomUtil.getPosition(this._mapPane); - L.DomUtil.setPosition(this._mapPane, mapPaneOffset.subtract(offset)); + L.DomUtil.setPosition(this._mapPane, this._getMapPanePos().subtract(offset)); }, // map events _initEvents: function () { - L.DomEvent.addListener(this._container, 'click', this._onMouseClick, this); + if (!L.DomEvent) { return; } - var events = ['dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'contextmenu']; + L.DomEvent.on(this._container, 'click', this._onMouseClick, this); - var i, len; + var events = ['dblclick', 'mousedown', 'mouseup', 'mouseenter', 'mouseleave', 'mousemove', 'contextmenu'], + i, len; for (i = 0, len = events.length; i < len; i++) { - L.DomEvent.addListener(this._container, events[i], this._fireMouseEvent, this); + L.DomEvent.on(this._container, events[i], this._fireMouseEvent, this); } if (this.options.trackResize) { - L.DomEvent.addListener(window, 'resize', this._onResize, this); + L.DomEvent.on(window, 'resize', this._onResize, this); } }, _onResize: function () { - L.Util.requestAnimFrame(this.invalidateSize, this, false, this._container); + L.Util.cancelAnimFrame(this._resizeRequest); + this._resizeRequest = L.Util.requestAnimFrame(this.invalidateSize, this, false, this._container); }, _onMouseClick: function (e) { - if (!this._loaded || (this.dragging && this.dragging.moved())) { - return; - } + if (!this._loaded || (this.dragging && this.dragging.moved())) { return; } - this.fire('pre' + e.type); + this.fire('preclick'); this._fireMouseEvent(e); }, _fireMouseEvent: function (e) { - if (!this._loaded) { - return; - } + if (!this._loaded) { return; } var type = e.type; + type = (type === 'mouseenter' ? 'mouseover' : (type === 'mouseleave' ? 'mouseout' : type)); - if (!this.hasEventListeners(type)) { - return; - } + if (!this.hasEventListeners(type)) { return; } if (type === 'contextmenu') { L.DomEvent.preventDefault(e); } - + + var containerPoint = this.mouseEventToContainerPoint(e), + layerPoint = this.containerPointToLayerPoint(containerPoint), + latlng = this.layerPointToLatLng(layerPoint); + this.fire(type, { - latlng: this.mouseEventToLatLng(e), - layerPoint: this.mouseEventToLayerPoint(e) + latlng: latlng, + layerPoint: layerPoint, + containerPoint: containerPoint, + originalEvent: e }); }, - _initInteraction: function () { - var handlers = { - dragging: L.Map.Drag, - touchZoom: L.Map.TouchZoom, - doubleClickZoom: L.Map.DoubleClickZoom, - scrollWheelZoom: L.Map.ScrollWheelZoom, - boxZoom: L.Map.BoxZoom - }; - - var i; - for (i in handlers) { - if (handlers.hasOwnProperty(i) && handlers[i]) { - this[i] = new handlers[i](this); - if (this.options[i]) { - this[i].enable(); - } - // TODO move enabling to handler contructor - } - } - }, - _onTileLayerLoad: function () { + // TODO super-ugly, refactor!!! // clear scaled tiles after all new tiles are loaded (for performance) this._tileLayersToLoad--; if (this._tileLayersNum && !this._tileLayersToLoad && this._tileBg) { @@ -1497,27 +1742,59 @@ L.Map = L.Class.extend({ // private methods for getting map state + _getMapPanePos: function () { + return L.DomUtil.getPosition(this._mapPane); + }, + _getTopLeftPoint: function () { if (!this._loaded) { throw new Error('Set map center and zoom first.'); } - var offset = L.DomUtil.getPosition(this._mapPane); - return this._initialTopLeftPoint.subtract(offset); + return this._initialTopLeftPoint.subtract(this._getMapPanePos()); }, - _getNewTopLeftPoint: function (center) { + _getNewTopLeftPoint: function (center, zoom) { var viewHalf = this.getSize().divideBy(2); - return this.project(center).subtract(viewHalf).round(); + // TODO round on display, not calculation to increase precision? + return this.project(center, zoom)._subtract(viewHalf)._round(); + }, + + _latLngToNewLayerPoint: function (latlng, newZoom, newCenter) { + var topLeft = this._getNewTopLeftPoint(newCenter, newZoom).add(this._getMapPanePos()); + return this.project(latlng, newZoom)._subtract(topLeft); + }, + + _getCenterLayerPoint: function () { + return this.containerPointToLayerPoint(this.getSize().divideBy(2)); + }, + + _getCenterOffset: function (center) { + return this.latLngToLayerPoint(center).subtract(this._getCenterLayerPoint()); }, _limitZoom: function (zoom) { - var min = this.getMinZoom(); - var max = this.getMaxZoom(); + var min = this.getMinZoom(), + max = this.getMaxZoom(); + return Math.max(min, Math.min(max, zoom)); } }); +L.Map.addInitHook = function (fn) { + var args = Array.prototype.slice.call(arguments, 1); + + var init = typeof fn === 'function' ? fn : function () { + this[fn].apply(this, args); + }; + + this.prototype._initializers.push(init); +}; + +L.map = function (id, options) { + return new L.Map(id, options); +}; + L.Projection.Mercator = { @@ -1526,7 +1803,7 @@ L.Projection.Mercator = { R_MINOR: 6356752.3142, R_MAJOR: 6378137, - project: function (/*LatLng*/ latlng) /*-> Point*/ { + project: function (latlng) { // (LatLng) -> Point var d = L.LatLng.DEG_TO_RAD, max = this.MAX_LATITUDE, lat = Math.max(Math.min(max, latlng.lat), -max), @@ -1546,7 +1823,7 @@ L.Projection.Mercator = { return new L.Point(x, y); }, - unproject: function (/*Point*/ point, /*Boolean*/ unbounded) /*-> LatLng*/ { + unproject: function (point) { // (Point, Boolean) -> LatLng var d = L.LatLng.RAD_TO_DEG, r = this.R_MAJOR, r2 = this.R_MINOR, @@ -1567,7 +1844,7 @@ L.Projection.Mercator = { phi += dphi; } - return new L.LatLng(phi * d, lng, unbounded); + return new L.LatLng(phi * d, lng, true); } }; @@ -1577,6 +1854,7 @@ L.CRS.EPSG3395 = L.Util.extend({}, L.CRS, { code: 'EPSG:3395', projection: L.Projection.Mercator, + transformation: (function () { var m = L.Projection.Mercator, r = m.R_MAJOR, @@ -1601,32 +1879,47 @@ L.TileLayer = L.Class.extend({ subdomains: 'abc', errorTileUrl: '', attribution: '', + zoomOffset: 0, opacity: 1, - scheme: 'xyz', + /* (undefined works too) + zIndex: null, + tms: false, continuousWorld: false, noWrap: false, - zoomOffset: 0, zoomReverse: false, - + detectRetina: false, + reuseTiles: false, + */ unloadInvisibleTiles: L.Browser.mobile, - updateWhenIdle: L.Browser.mobile, - reuseTiles: false + updateWhenIdle: L.Browser.mobile }, - initialize: function (url, options, urlParams) { - L.Util.setOptions(this, options); + initialize: function (url, options) { + options = L.Util.setOptions(this, options); + + // detecting retina displays, adjusting tileSize and zoom levels + if (options.detectRetina && L.Browser.retina && options.maxZoom > 0) { + + options.tileSize = Math.floor(options.tileSize / 2); + options.zoomOffset++; + + if (options.minZoom > 0) { + options.minZoom--; + } + this.options.maxZoom--; + } this._url = url; - this._urlParams = urlParams; - if (typeof this.options.subdomains === 'string') { - this.options.subdomains = this.options.subdomains.split(''); + var subdomains = this.options.subdomains; + + if (typeof subdomains === 'string') { + this.options.subdomains = subdomains.split(''); } }, - onAdd: function (map, insertAtTheBottom) { + onAdd: function (map) { this._map = map; - this._insertAtTheBottom = insertAtTheBottom; // create a container div for tiles this._initContainer(); @@ -1635,11 +1928,12 @@ L.TileLayer = L.Class.extend({ this._createTileProto(); // set up events - map.on('viewreset', this._resetCallback, this); + map.on({ + 'viewreset': this._resetCallback, + 'moveend': this._update + }, this); - if (this.options.updateWhenIdle) { - map.on('moveend', this._update, this); - } else { + if (!this.options.updateWhenIdle) { this._limitedUpdate = L.Util.limitExecByInterval(this._update, 150, this); map.on('move', this._limitedUpdate, this); } @@ -1648,17 +1942,47 @@ L.TileLayer = L.Class.extend({ this._update(); }, + addTo: function (map) { + map.addLayer(this); + return this; + }, + onRemove: function (map) { - this._map.getPanes().tilePane.removeChild(this._container); - this._container = null; + map._panes.tilePane.removeChild(this._container); - this._map.off('viewreset', this._resetCallback, this); + map.off({ + 'viewreset': this._resetCallback, + 'moveend': this._update + }, this); - if (this.options.updateWhenIdle) { - this._map.off('moveend', this._update, this); - } else { - this._map.off('move', this._limitedUpdate, this); + if (!this.options.updateWhenIdle) { + map.off('move', this._limitedUpdate, this); } + + this._container = null; + this._map = null; + }, + + bringToFront: function () { + var pane = this._map._panes.tilePane; + + if (this._container) { + pane.appendChild(this._container); + this._setAutoZIndex(pane, Math.max); + } + + return this; + }, + + bringToBack: function () { + var pane = this._map._panes.tilePane; + + if (this._container) { + pane.insertBefore(this._container, pane.firstChild); + this._setAutoZIndex(pane, Math.min); + } + + return this; }, getAttribution: function () { @@ -1668,38 +1992,94 @@ L.TileLayer = L.Class.extend({ setOpacity: function (opacity) { this.options.opacity = opacity; - this._setOpacity(opacity); + if (this._map) { + this._updateOpacity(); + } + + return this; + }, + + setZIndex: function (zIndex) { + this.options.zIndex = zIndex; + this._updateZIndex(); + + return this; + }, + + setUrl: function (url, noRedraw) { + this._url = url; + + if (!noRedraw) { + this.redraw(); + } + + return this; + }, + + redraw: function () { + if (this._map) { + this._map._panes.tilePane.empty = false; + this._reset(true); + this._update(); + } + return this; + }, + + _updateZIndex: function () { + if (this._container && this.options.zIndex !== undefined) { + this._container.style.zIndex = this.options.zIndex; + } + }, + + _setAutoZIndex: function (pane, compare) { + + var layers = pane.getElementsByClassName('leaflet-layer'), + edgeZIndex = -compare(Infinity, -Infinity), // -Ifinity for max, Infinity for min + zIndex; + + for (var i = 0, len = layers.length; i < len; i++) { + + if (layers[i] !== this._container) { + zIndex = parseInt(layers[i].style.zIndex, 10); + + if (!isNaN(zIndex)) { + edgeZIndex = compare(edgeZIndex, zIndex); + } + } + } + + this._container.style.zIndex = isFinite(edgeZIndex) ? edgeZIndex + compare(1, -1) : ''; + }, + + _updateOpacity: function () { + L.DomUtil.setOpacity(this._container, this.options.opacity); // stupid webkit hack to force redrawing of tiles + var i, + tiles = this._tiles; + if (L.Browser.webkit) { - for (var i in this._tiles) { - if (this._tiles.hasOwnProperty(i)) { - this._tiles[i].style.webkitTransform += ' translate(0,0)'; + for (i in tiles) { + if (tiles.hasOwnProperty(i)) { + tiles[i].style.webkitTransform += ' translate(0,0)'; } } } }, - _setOpacity: function (opacity) { - if (opacity < 1) { - L.DomUtil.setOpacity(this._container, opacity); - } - }, - _initContainer: function () { - var tilePane = this._map.getPanes().tilePane, - first = tilePane.firstChild; + var tilePane = this._map._panes.tilePane; if (!this._container || tilePane.empty) { this._container = L.DomUtil.create('div', 'leaflet-layer'); - if (this._insertAtTheBottom && first) { - tilePane.insertBefore(this._container, first); - } else { - tilePane.appendChild(this._container); - } + this._updateZIndex(); - this._setOpacity(this.options.opacity); + tilePane.appendChild(this._container); + + if (this.options.opacity < 1) { + this._updateOpacity(); + } } }, @@ -1708,13 +2088,17 @@ L.TileLayer = L.Class.extend({ }, _reset: function (clearOldContainer) { - var key; - for (key in this._tiles) { - if (this._tiles.hasOwnProperty(key)) { - this.fire("tileunload", {tile: this._tiles[key]}); + var key, + tiles = this._tiles; + + for (key in tiles) { + if (tiles.hasOwnProperty(key)) { + this.fire('tileunload', {tile: tiles[key]}); } } + this._tiles = {}; + this._tilesToLoad = 0; if (this.options.reuseTiles) { this._unusedTiles = []; @@ -1723,13 +2107,16 @@ L.TileLayer = L.Class.extend({ if (clearOldContainer && this._container) { this._container.innerHTML = ""; } + this._initContainer(); }, - _update: function () { - var bounds = this._map.getPixelBounds(), - zoom = this._map.getZoom(), - tileSize = this.options.tileSize; + _update: function (e) { + if (this._map._panTransition && this._map._panTransition._inProgress) { return; } + + var bounds = this._map.getPixelBounds(), + zoom = this._map.getZoom(), + tileSize = this.options.tileSize; if (zoom > this.options.maxZoom || zoom < this.options.minZoom) { return; @@ -1754,15 +2141,22 @@ L.TileLayer = L.Class.extend({ var queue = [], center = bounds.getCenter(); - for (var j = bounds.min.y; j <= bounds.max.y; j++) { - for (var i = bounds.min.x; i <= bounds.max.x; i++) { - if ((i + ':' + j) in this._tiles) { - continue; + var j, i, point; + + for (j = bounds.min.y; j <= bounds.max.y; j++) { + for (i = bounds.min.x; i <= bounds.max.x; i++) { + point = new L.Point(i, j); + + if (this._tileShouldBeLoaded(point)) { + queue.push(point); } - queue.push(new L.Point(i, j)); } } + var tilesToLoad = queue.length; + + if (tilesToLoad === 0) { return; } + // load tiles in order of their distance to center queue.sort(function (a, b) { return a.distanceTo(center) - b.distanceTo(center); @@ -1770,16 +2164,39 @@ L.TileLayer = L.Class.extend({ var fragment = document.createDocumentFragment(); - this._tilesToLoad = queue.length; - for (var k = 0, len = this._tilesToLoad; k < len; k++) { - this._addTile(queue[k], fragment); + // if its the first batch of tiles to load + if (!this._tilesToLoad) { + this.fire('loading'); + } + + this._tilesToLoad += tilesToLoad; + + for (i = 0; i < tilesToLoad; i++) { + this._addTile(queue[i], fragment); } this._container.appendChild(fragment); }, + _tileShouldBeLoaded: function (tilePoint) { + if ((tilePoint.x + ':' + tilePoint.y) in this._tiles) { + return false; // already loaded + } + + if (!this.options.continuousWorld) { + var limit = this._getWrapTileNum(); + + if (this.options.noWrap && (tilePoint.x < 0 || tilePoint.x >= limit) || + tilePoint.y < 0 || tilePoint.y >= limit) { + return false; // exceeds world bounds + } + } + + return true; + }, + _removeOtherTiles: function (bounds) { - var kArr, x, y, key, tile; + var kArr, x, y, key; for (key in this._tiles) { if (this._tiles.hasOwnProperty(key)) { @@ -1789,63 +2206,63 @@ L.TileLayer = L.Class.extend({ // remove tile if it's out of bounds if (x < bounds.min.x || x > bounds.max.x || y < bounds.min.y || y > bounds.max.y) { - - tile = this._tiles[key]; - this.fire("tileunload", {tile: tile, url: tile.src}); - - if (tile.parentNode === this._container) { - this._container.removeChild(tile); - } - if (this.options.reuseTiles) { - this._unusedTiles.push(this._tiles[key]); - } - tile.src = 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='; - - delete this._tiles[key]; + this._removeTile(key); } } } }, - _addTile: function (tilePoint, container) { - var tilePos = this._getTilePos(tilePoint), - zoom = this._map.getZoom(), - key = tilePoint.x + ':' + tilePoint.y, - tileLimit = Math.pow(2, this._getOffsetZoom(zoom)); + _removeTile: function (key) { + var tile = this._tiles[key]; - // wrap tile coordinates - if (!this.options.continuousWorld) { - if (!this.options.noWrap) { - tilePoint.x = ((tilePoint.x % tileLimit) + tileLimit) % tileLimit; - } else if (tilePoint.x < 0 || tilePoint.x >= tileLimit) { - this._tilesToLoad--; - return; - } + this.fire("tileunload", {tile: tile, url: tile.src}); - if (tilePoint.y < 0 || tilePoint.y >= tileLimit) { - this._tilesToLoad--; - return; - } + if (this.options.reuseTiles) { + L.DomUtil.removeClass(tile, 'leaflet-tile-loaded'); + this._unusedTiles.push(tile); + } else if (tile.parentNode === this._container) { + this._container.removeChild(tile); } + if (!L.Browser.android) { //For https://github.com/CloudMade/Leaflet/issues/137 + tile.src = L.Util.emptyImageUrl; + } + + delete this._tiles[key]; + }, + + _addTile: function (tilePoint, container) { + var tilePos = this._getTilePos(tilePoint); + // get unused tile - or create a new tile var tile = this._getTile(); - L.DomUtil.setPosition(tile, tilePos); - this._tiles[key] = tile; + // Chrome 20 layouts much faster with top/left (Verify with timeline, frames) + // android 4 browser has display issues with top/left and requires transform instead + // android 3 browser not tested + // android 2 browser requires top/left or tiles disappear on load or first drag (reappear after zoom) https://github.com/CloudMade/Leaflet/issues/866 + // (other browsers don't currently care) - see debug/hacks/jitter.html for an example + L.DomUtil.setPosition(tile, tilePos, L.Browser.chrome || L.Browser.android23); - if (this.options.scheme === 'tms') { - tilePoint.y = tileLimit - tilePoint.y - 1; + this._tiles[tilePoint.x + ':' + tilePoint.y] = tile; + + this._loadTile(tile, tilePoint); + + if (tile.parentNode !== this._container) { + container.appendChild(tile); } - - this._loadTile(tile, tilePoint, zoom); - - container.appendChild(tile); }, - _getOffsetZoom: function (zoom) { - zoom = this.options.zoomReverse ? this.options.maxZoom - zoom : zoom; - return zoom + this.options.zoomOffset; + _getZoomForUrl: function () { + + var options = this.options, + zoom = this._map.getZoom(); + + if (options.zoomReverse) { + zoom = options.maxZoom - zoom; + } + + return zoom + options.zoomOffset; }, _getTilePos: function (tilePoint) { @@ -1857,25 +2274,48 @@ L.TileLayer = L.Class.extend({ // image-specific code (override to implement e.g. Canvas or SVG tile layer) - getTileUrl: function (tilePoint, zoom) { - var subdomains = this.options.subdomains, - s = this.options.subdomains[(tilePoint.x + tilePoint.y) % subdomains.length]; + getTileUrl: function (tilePoint) { + this._adjustTilePoint(tilePoint); return L.Util.template(this._url, L.Util.extend({ - s: s, - z: this._getOffsetZoom(zoom), + s: this._getSubdomain(tilePoint), + z: this._getZoomForUrl(), x: tilePoint.x, y: tilePoint.y - }, this._urlParams)); + }, this.options)); + }, + + _getWrapTileNum: function () { + // TODO refactor, limit is not valid for non-standard projections + return Math.pow(2, this._getZoomForUrl()); + }, + + _adjustTilePoint: function (tilePoint) { + + var limit = this._getWrapTileNum(); + + // wrap tile coordinates + if (!this.options.continuousWorld && !this.options.noWrap) { + tilePoint.x = ((tilePoint.x % limit) + limit) % limit; + } + + if (this.options.tms) { + tilePoint.y = limit - tilePoint.y - 1; + } + }, + + _getSubdomain: function (tilePoint) { + var index = (tilePoint.x + tilePoint.y) % this.options.subdomains.length; + return this.options.subdomains[index]; }, _createTileProto: function () { - this._tileImg = L.DomUtil.create('img', 'leaflet-tile'); - this._tileImg.galleryimg = 'no'; + var img = this._tileImg = L.DomUtil.create('img', 'leaflet-tile'); + img.galleryimg = 'no'; var tileSize = this.options.tileSize; - this._tileImg.style.width = tileSize + 'px'; - this._tileImg.style.height = tileSize + 'px'; + img.style.width = tileSize + 'px'; + img.style.height = tileSize + 'px'; }, _getTile: function () { @@ -1897,40 +2337,61 @@ L.TileLayer = L.Class.extend({ return tile; }, - _loadTile: function (tile, tilePoint, zoom) { - tile._layer = this; - tile.onload = this._tileOnLoad; + _loadTile: function (tile, tilePoint) { + tile._layer = this; + tile.onload = this._tileOnLoad; tile.onerror = this._tileOnError; - tile.src = this.getTileUrl(tilePoint, zoom); + + tile.src = this.getTileUrl(tilePoint); }, + _tileLoaded: function () { + this._tilesToLoad--; + if (!this._tilesToLoad) { + this.fire('load'); + } + }, + _tileOnLoad: function (e) { var layer = this._layer; - this.className += ' leaflet-tile-loaded'; + //Only if we are loading an actual image + if (this.src !== L.Util.emptyImageUrl) { + L.DomUtil.addClass(this, 'leaflet-tile-loaded'); - layer.fire('tileload', {tile: this, url: this.src}); - - layer._tilesToLoad--; - if (!layer._tilesToLoad) { - layer.fire('load'); + layer.fire('tileload', { + tile: this, + url: this.src + }); } + + layer._tileLoaded(); }, _tileOnError: function (e) { var layer = this._layer; - layer.fire('tileerror', {tile: this, url: this.src}); + layer.fire('tileerror', { + tile: this, + url: this.src + }); var newUrl = layer.options.errorTileUrl; if (newUrl) { this.src = newUrl; } - } + + layer._tileLoaded(); + } }); +L.tileLayer = function (url, options) { + return new L.TileLayer(url, options); +}; + L.TileLayer.WMS = L.TileLayer.extend({ + defaultWmsParams: { service: 'WMS', request: 'GetMap', @@ -1941,43 +2402,73 @@ L.TileLayer.WMS = L.TileLayer.extend({ transparent: false }, - initialize: function (/*String*/ url, /*Object*/ options) { + initialize: function (url, options) { // (String, Object) + this._url = url; - this.wmsParams = L.Util.extend({}, this.defaultWmsParams); - this.wmsParams.width = this.wmsParams.height = this.options.tileSize; + var wmsParams = L.Util.extend({}, this.defaultWmsParams); + + if (options.detectRetina && L.Browser.retina) { + wmsParams.width = wmsParams.height = this.options.tileSize * 2; + } else { + wmsParams.width = wmsParams.height = this.options.tileSize; + } for (var i in options) { // all keys that are not TileLayer options go to WMS params if (!this.options.hasOwnProperty(i)) { - this.wmsParams[i] = options[i]; + wmsParams[i] = options[i]; } } + this.wmsParams = wmsParams; + L.Util.setOptions(this, options); }, onAdd: function (map) { - var projectionKey = (parseFloat(this.wmsParams.version) >= 1.3 ? 'crs' : 'srs'); + + var projectionKey = parseFloat(this.wmsParams.version) >= 1.3 ? 'crs' : 'srs'; this.wmsParams[projectionKey] = map.options.crs.code; L.TileLayer.prototype.onAdd.call(this, map); }, - getTileUrl: function (/*Point*/ tilePoint, /*Number*/ zoom)/*-> String*/ { - var tileSize = this.options.tileSize, + getTileUrl: function (tilePoint, zoom) { // (Point, Number) -> String + + var map = this._map, + crs = map.options.crs, + tileSize = this.options.tileSize, + nwPoint = tilePoint.multiplyBy(tileSize), sePoint = nwPoint.add(new L.Point(tileSize, tileSize)), - nwMap = this._map.unproject(nwPoint, this._zoom, true), - seMap = this._map.unproject(sePoint, this._zoom, true), - nw = this._map.options.crs.project(nwMap), - se = this._map.options.crs.project(seMap), - bbox = [nw.x, se.y, se.x, nw.y].join(','); - return this._url + L.Util.getParamString(this.wmsParams) + "&bbox=" + bbox; + nw = crs.project(map.unproject(nwPoint, zoom)), + se = crs.project(map.unproject(sePoint, zoom)), + + bbox = [nw.x, se.y, se.x, nw.y].join(','), + + url = L.Util.template(this._url, {s: this._getSubdomain(tilePoint)}); + + return url + L.Util.getParamString(this.wmsParams) + "&bbox=" + bbox; + }, + + setParams: function (params, noRedraw) { + + L.Util.extend(this.wmsParams, params); + + if (!noRedraw) { + this.redraw(); + } + + return this; } }); +L.tileLayer.wms = function (url, options) { + return new L.TileLayer.WMS(url, options); +}; + L.TileLayer.Canvas = L.TileLayer.extend({ options: { @@ -1989,9 +2480,13 @@ L.TileLayer.Canvas = L.TileLayer.extend({ }, redraw: function () { - for (var i in this._tiles) { - var tile = this._tiles[i]; - this._redrawTile(tile); + var i, + tiles = this._tiles; + + for (i in tiles) { + if (tiles.hasOwnProperty(i)) { + this._redrawTile(tiles[i]); + } } }, @@ -2000,11 +2495,11 @@ L.TileLayer.Canvas = L.TileLayer.extend({ }, _createTileProto: function () { - this._canvasProto = L.DomUtil.create('canvas', 'leaflet-tile'); + var proto = this._canvasProto = L.DomUtil.create('canvas', 'leaflet-tile'); var tileSize = this.options.tileSize; - this._canvasProto.width = tileSize; - this._canvasProto.height = tileSize; + proto.width = tileSize; + proto.height = tileSize; }, _createTile: function () { @@ -2035,12 +2530,22 @@ L.TileLayer.Canvas = L.TileLayer.extend({ }); +L.tileLayer.canvas = function (options) { + return new L.TileLayer.Canvas(options); +}; + L.ImageOverlay = L.Class.extend({ includes: L.Mixin.Events, - initialize: function (/*String*/ url, /*LatLngBounds*/ bounds) { + options: { + opacity: 1 + }, + + initialize: function (url, bounds, options) { // (String, LatLngBounds, Object) this._url = url; - this._bounds = bounds; + this._bounds = L.latLngBounds(bounds); + + L.Util.setOptions(this, options); }, onAdd: function (map) { @@ -2050,22 +2555,64 @@ L.ImageOverlay = L.Class.extend({ this._initImage(); } - map.getPanes().overlayPane.appendChild(this._image); + map._panes.overlayPane.appendChild(this._image); map.on('viewreset', this._reset, this); + + if (map.options.zoomAnimation && L.Browser.any3d) { + map.on('zoomanim', this._animateZoom, this); + } + this._reset(); }, onRemove: function (map) { map.getPanes().overlayPane.removeChild(this._image); + map.off('viewreset', this._reset, this); + + if (map.options.zoomAnimation) { + map.off('zoomanim', this._animateZoom, this); + } + }, + + addTo: function (map) { + map.addLayer(this); + return this; + }, + + setOpacity: function (opacity) { + this.options.opacity = opacity; + this._updateOpacity(); + return this; + }, + + // TODO remove bringToFront/bringToBack duplication from TileLayer/Path + bringToFront: function () { + if (this._image) { + this._map._panes.overlayPane.appendChild(this._image); + } + return this; + }, + + bringToBack: function () { + var pane = this._map._panes.overlayPane; + if (this._image) { + pane.insertBefore(this._image, pane.firstChild); + } + return this; }, _initImage: function () { this._image = L.DomUtil.create('img', 'leaflet-image-layer'); - this._image.style.visibility = 'hidden'; - //TODO opacity option + if (this._map.options.zoomAnimation && L.Browser.any3d) { + L.DomUtil.addClass(this._image, 'leaflet-zoom-animated'); + } else { + L.DomUtil.addClass(this._image, 'leaflet-zoom-hide'); + } + + this._updateOpacity(); //TODO createImage util method to remove duplication L.Util.extend(this._image, { @@ -2077,38 +2624,61 @@ L.ImageOverlay = L.Class.extend({ }); }, + _animateZoom: function (e) { + var map = this._map, + image = this._image, + scale = map.getZoomScale(e.zoom), + nw = this._bounds.getNorthWest(), + se = this._bounds.getSouthEast(), + topLeft = map._latLngToNewLayerPoint(nw, e.zoom, e.center), + size = map._latLngToNewLayerPoint(se, e.zoom, e.center).subtract(topLeft), + currentSize = map.latLngToLayerPoint(se).subtract(map.latLngToLayerPoint(nw)), + origin = topLeft.add(size.subtract(currentSize).divideBy(2)); + + image.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString(origin) + ' scale(' + scale + ') '; + }, + _reset: function () { - var topLeft = this._map.latLngToLayerPoint(this._bounds.getNorthWest()), - bottomRight = this._map.latLngToLayerPoint(this._bounds.getSouthEast()), - size = bottomRight.subtract(topLeft); + var image = this._image, + topLeft = this._map.latLngToLayerPoint(this._bounds.getNorthWest()), + size = this._map.latLngToLayerPoint(this._bounds.getSouthEast()).subtract(topLeft); - L.DomUtil.setPosition(this._image, topLeft); + L.DomUtil.setPosition(image, topLeft); - this._image.style.width = size.x + 'px'; - this._image.style.height = size.y + 'px'; + image.style.width = size.x + 'px'; + image.style.height = size.y + 'px'; }, _onImageLoad: function () { - this._image.style.visibility = ''; this.fire('load'); + }, + + _updateOpacity: function () { + L.DomUtil.setOpacity(this._image, this.options.opacity); } }); +L.imageOverlay = function (url, bounds, options) { + return new L.ImageOverlay(url, bounds, options); +}; + L.Icon = L.Class.extend({ - iconUrl: L.ROOT_URL + 'images/marker.png', - shadowUrl: L.ROOT_URL + 'images/marker-shadow.png', + options: { + /* + iconUrl: (String) (required) + iconSize: (Point) (can be set through CSS) + iconAnchor: (Point) (centered by default if size is specified, can be set in CSS with negative margins) + popupAnchor: (Point) (if not specified, popup opens in the anchor point) + shadowUrl: (Point) (no shadow by default) + shadowSize: (Point) + shadowAnchor: (Point) + */ + className: '' + }, - iconSize: new L.Point(25, 41), - shadowSize: new L.Point(41, 41), - - iconAnchor: new L.Point(13, 41), - popupAnchor: new L.Point(0, -33), - - initialize: function (iconUrl) { - if (iconUrl) { - this.iconUrl = iconUrl; - } + initialize: function (options) { + L.Util.setOptions(this, options); }, createIcon: function () { @@ -2120,35 +2690,52 @@ L.Icon = L.Class.extend({ }, _createIcon: function (name) { - var size = this[name + 'Size'], - src = this[name + 'Url']; - if (!src && name === 'shadow') { + var src = this._getIconUrl(name); + + if (!src) { + if (name === 'icon') { + throw new Error("iconUrl not set in Icon options (see the docs)."); + } return null; } - var img; - if (!src) { - img = this._createDiv(); - } - else { - img = this._createImg(src); - } - - img.className = 'leaflet-marker-' + name; - - img.style.marginLeft = (-this.iconAnchor.x) + 'px'; - img.style.marginTop = (-this.iconAnchor.y) + 'px'; - - if (size) { - img.style.width = size.x + 'px'; - img.style.height = size.y + 'px'; - } + var img = this._createImg(src); + this._setIconStyles(img, name); return img; }, + _setIconStyles: function (img, name) { + var options = this.options, + size = L.point(options[name + 'Size']), + anchor; + + if (name === 'shadow') { + anchor = L.point(options.shadowAnchor || options.iconAnchor); + } else { + anchor = L.point(options.iconAnchor); + } + + if (!anchor && size) { + anchor = size.divideBy(2, true); + } + + img.className = 'leaflet-marker-' + name + ' ' + options.className; + + if (anchor) { + img.style.marginLeft = (-anchor.x) + 'px'; + img.style.marginTop = (-anchor.y) + 'px'; + } + + if (size) { + img.style.width = size.x + 'px'; + img.style.height = size.y + 'px'; + } + }, + _createImg: function (src) { var el; + if (!L.Browser.ie6) { el = document.createElement('img'); el.src = src; @@ -2159,11 +2746,60 @@ L.Icon = L.Class.extend({ return el; }, - _createDiv: function () { - return document.createElement('div'); + _getIconUrl: function (name) { + return this.options[name + 'Url']; } }); +L.icon = function (options) { + return new L.Icon(options); +}; + + + +L.Icon.Default = L.Icon.extend({ + + options: { + iconSize: new L.Point(25, 41), + iconAnchor: new L.Point(13, 41), + popupAnchor: new L.Point(1, -34), + + shadowSize: new L.Point(41, 41) + }, + + _getIconUrl: function (name) { + var key = name + 'Url'; + + if (this.options[key]) { + return this.options[key]; + } + + var path = L.Icon.Default.imagePath; + + if (!path) { + throw new Error("Couldn't autodetect L.Icon.Default.imagePath, set it manually."); + } + + return path + '/marker-' + name + '.png'; + } +}); + +L.Icon.Default.imagePath = (function () { + var scripts = document.getElementsByTagName('script'), + leafletRe = /\/?leaflet[\-\._]?([\w\-\._]*)\.js\??/; + + var i, len, src, matches; + + for (i = 0, len = scripts.length; i < len; i++) { + src = scripts[i].src; + matches = src.match(leafletRe); + + if (matches) { + return src.split(leafletRe)[0] + '/images'; + } + } +}()); + /* * L.Marker is used to display clickable/draggable icons on the map. @@ -2174,25 +2810,35 @@ L.Marker = L.Class.extend({ includes: L.Mixin.Events, options: { - icon: new L.Icon(), + icon: new L.Icon.Default(), title: '', clickable: true, draggable: false, - zIndexOffset: 0 + zIndexOffset: 0, + opacity: 1 }, initialize: function (latlng, options) { L.Util.setOptions(this, options); - this._latlng = latlng; + this._latlng = L.latLng(latlng); }, onAdd: function (map) { this._map = map; - this._initIcon(); + map.on('viewreset', this.update, this); - map.on('viewreset', this._reset, this); - this._reset(); + this._initIcon(); + this.update(); + + if (map.options.zoomAnimation && map.options.markerZoomAnimation) { + map.on('zoomanim', this._animateZoom, this); + } + }, + + addTo: function (map) { + map.addLayer(this); + return this; }, onRemove: function (map) { @@ -2203,9 +2849,12 @@ L.Marker = L.Class.extend({ this.closePopup(); } - this._map = null; + map.off({ + 'viewreset': this.update, + 'zoomanim': this._animateZoom + }, this); - map.off('viewreset', this._reset, this); + this._map = null; }, getLatLng: function () { @@ -2213,21 +2862,18 @@ L.Marker = L.Class.extend({ }, setLatLng: function (latlng) { - this._latlng = latlng; - if (this._icon) { - this._reset(); + this._latlng = L.latLng(latlng); - if (this._popup) { - this._popup.setLatLng(this._latlng); - } + this.update(); + + if (this._popup) { + this._popup.setLatLng(latlng); } }, setZIndexOffset: function (offset) { this.options.zIndexOffset = offset; - if (this._icon) { - this._reset(); - } + this.update(); }, setIcon: function (icon) { @@ -2239,42 +2885,73 @@ L.Marker = L.Class.extend({ if (this._map) { this._initIcon(); - this._reset(); + this.update(); } }, - _initIcon: function () { - if (!this._icon) { - this._icon = this.options.icon.createIcon(); + update: function () { + if (!this._icon) { return; } - if (this.options.title) { - this._icon.title = this.options.title; + var pos = this._map.latLngToLayerPoint(this._latlng).round(); + this._setPos(pos); + }, + + _initIcon: function () { + var options = this.options, + map = this._map, + animation = (map.options.zoomAnimation && map.options.markerZoomAnimation), + classToAdd = animation ? 'leaflet-zoom-animated' : 'leaflet-zoom-hide', + needOpacityUpdate = false; + + if (!this._icon) { + this._icon = options.icon.createIcon(); + + if (options.title) { + this._icon.title = options.title; } this._initInteraction(); + needOpacityUpdate = (this.options.opacity < 1); + + L.DomUtil.addClass(this._icon, classToAdd); } if (!this._shadow) { - this._shadow = this.options.icon.createShadow(); + this._shadow = options.icon.createShadow(); + + if (this._shadow) { + L.DomUtil.addClass(this._shadow, classToAdd); + needOpacityUpdate = (this.options.opacity < 1); + } } - this._map._panes.markerPane.appendChild(this._icon); + if (needOpacityUpdate) { + this._updateOpacity(); + } + + var panes = this._map._panes; + + panes.markerPane.appendChild(this._icon); + if (this._shadow) { - this._map._panes.shadowPane.appendChild(this._shadow); + panes.shadowPane.appendChild(this._shadow); } }, _removeIcon: function () { - this._map._panes.markerPane.removeChild(this._icon); + var panes = this._map._panes; + + panes.markerPane.removeChild(this._icon); + if (this._shadow) { - this._map._panes.shadowPane.removeChild(this._shadow); + panes.shadowPane.removeChild(this._shadow); } + this._icon = this._shadow = null; }, - _reset: function () { - var pos = this._map.latLngToLayerPoint(this._latlng).round(); - + _setPos: function (pos) { L.DomUtil.setPosition(this._icon, pos); + if (this._shadow) { L.DomUtil.setPosition(this._shadow, pos); } @@ -2282,16 +2959,25 @@ L.Marker = L.Class.extend({ this._icon.style.zIndex = pos.y + this.options.zIndexOffset; }, + _animateZoom: function (opt) { + var pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center); + + this._setPos(pos); + }, + _initInteraction: function () { - if (this.options.clickable) { - this._icon.className += ' leaflet-clickable'; + if (!this.options.clickable) { + return; + } - L.DomEvent.addListener(this._icon, 'click', this._onMouseClick, this); + var icon = this._icon, + events = ['dblclick', 'mousedown', 'mouseover', 'mouseout']; - var events = ['dblclick', 'mousedown', 'mouseover', 'mouseout']; - for (var i = 0; i < events.length; i++) { - L.DomEvent.addListener(this._icon, events[i], this._fireMouseEvent, this); - } + L.DomUtil.addClass(icon, 'leaflet-clickable'); + L.DomEvent.on(icon, 'click', this._onMouseClick, this); + + for (var i = 0; i < events.length; i++) { + L.DomEvent.on(icon, events[i], this._fireMouseEvent, this); } if (L.Handler.MarkerDrag) { @@ -2306,26 +2992,95 @@ L.Marker = L.Class.extend({ _onMouseClick: function (e) { L.DomEvent.stopPropagation(e); if (this.dragging && this.dragging.moved()) { return; } - this.fire(e.type); + if (this._map.dragging && this._map.dragging.moved()) { return; } + this.fire(e.type, { + originalEvent: e + }); }, _fireMouseEvent: function (e) { - this.fire(e.type); - L.DomEvent.stopPropagation(e); + this.fire(e.type, { + originalEvent: e + }); + if (e.type !== 'mousedown') { + L.DomEvent.stopPropagation(e); + } + }, + + setOpacity: function (opacity) { + this.options.opacity = opacity; + if (this._map) { + this._updateOpacity(); + } + }, + + _updateOpacity: function () { + L.DomUtil.setOpacity(this._icon, this.options.opacity); + if (this._shadow) { + L.DomUtil.setOpacity(this._shadow, this.options.opacity); + } } }); +L.marker = function (latlng, options) { + return new L.Marker(latlng, options); +}; +L.DivIcon = L.Icon.extend({ + options: { + iconSize: new L.Point(12, 12), // also can be set through CSS + /* + iconAnchor: (Point) + popupAnchor: (Point) + html: (String) + bgPos: (Point) + */ + className: 'leaflet-div-icon' + }, + + createIcon: function () { + var div = document.createElement('div'), + options = this.options; + + if (options.html) { + div.innerHTML = options.html; + } + + if (options.bgPos) { + div.style.backgroundPosition = + (-options.bgPos.x) + 'px ' + (-options.bgPos.y) + 'px'; + } + + this._setIconStyles(div, 'icon'); + return div; + }, + + createShadow: function () { + return null; + } +}); + +L.divIcon = function (options) { + return new L.DivIcon(options); +}; + + + +L.Map.mergeOptions({ + closePopupOnClick: true +}); + L.Popup = L.Class.extend({ includes: L.Mixin.Events, options: { minWidth: 50, maxWidth: 300, + maxHeight: null, autoPan: true, closeButton: true, - offset: new L.Point(0, 2), + offset: new L.Point(0, 6), autoPanPadding: new L.Point(5, 5), className: '' }, @@ -2338,79 +3093,114 @@ L.Popup = L.Class.extend({ onAdd: function (map) { this._map = map; + if (!this._container) { this._initLayout(); } this._updateContent(); - this._container.style.opacity = '0'; + var animFade = map.options.fadeAnimation; - this._map._panes.popupPane.appendChild(this._container); - this._map.on('viewreset', this._updatePosition, this); + if (animFade) { + L.DomUtil.setOpacity(this._container, 0); + } + map._panes.popupPane.appendChild(this._container); - if (this._map.options.closePopupOnClick) { - this._map.on('preclick', this._close, this); + map.on('viewreset', this._updatePosition, this); + + if (L.Browser.any3d) { + map.on('zoomanim', this._zoomAnimation, this); + } + + if (map.options.closePopupOnClick) { + map.on('preclick', this._close, this); } this._update(); - this._container.style.opacity = '1'; //TODO fix ugly opacity hack + if (animFade) { + L.DomUtil.setOpacity(this._container, 1); + } + }, - this._opened = true; + addTo: function (map) { + map.addLayer(this); + return this; + }, + + openOn: function (map) { + map.openPopup(this); + return this; }, onRemove: function (map) { map._panes.popupPane.removeChild(this._container); - L.Util.falseFn(this._container.offsetWidth); - map.off('viewreset', this._updatePosition, this); - map.off('click', this._close, this); + L.Util.falseFn(this._container.offsetWidth); // force reflow - this._container.style.opacity = '0'; + map.off({ + viewreset: this._updatePosition, + preclick: this._close, + zoomanim: this._zoomAnimation + }, this); - this._opened = false; + if (map.options.fadeAnimation) { + L.DomUtil.setOpacity(this._container, 0); + } + + this._map = null; }, setLatLng: function (latlng) { - this._latlng = latlng; - if (this._opened) { - this._update(); - } + this._latlng = L.latLng(latlng); + this._update(); return this; }, setContent: function (content) { this._content = content; - if (this._opened) { - this._update(); - } + this._update(); return this; }, _close: function () { - if (this._opened) { - this._map.closePopup(); + var map = this._map; + + if (map) { + map._popup = null; + + map + .removeLayer(this) + .fire('popupclose', {popup: this}); } }, _initLayout: function () { - this._container = L.DomUtil.create('div', 'leaflet-popup ' + this.options.className); + var prefix = 'leaflet-popup', + container = this._container = L.DomUtil.create('div', prefix + ' ' + this.options.className + ' leaflet-zoom-animated'), + closeButton; if (this.options.closeButton) { - this._closeButton = L.DomUtil.create('a', 'leaflet-popup-close-button', this._container); - this._closeButton.href = '#close'; - L.DomEvent.addListener(this._closeButton, 'click', this._onCloseButtonClick, this); + closeButton = this._closeButton = L.DomUtil.create('a', prefix + '-close-button', container); + closeButton.href = '#close'; + closeButton.innerHTML = '×'; + + L.DomEvent.on(closeButton, 'click', this._onCloseButtonClick, this); } - this._wrapper = L.DomUtil.create('div', 'leaflet-popup-content-wrapper', this._container); - L.DomEvent.disableClickPropagation(this._wrapper); - this._contentNode = L.DomUtil.create('div', 'leaflet-popup-content', this._wrapper); + var wrapper = this._wrapper = L.DomUtil.create('div', prefix + '-content-wrapper', container); + L.DomEvent.disableClickPropagation(wrapper); - this._tipContainer = L.DomUtil.create('div', 'leaflet-popup-tip-container', this._container); - this._tip = L.DomUtil.create('div', 'leaflet-popup-tip', this._tipContainer); + this._contentNode = L.DomUtil.create('div', prefix + '-content', wrapper); + L.DomEvent.on(this._contentNode, 'mousewheel', L.DomEvent.stopPropagation); + + this._tipContainer = L.DomUtil.create('div', prefix + '-tip-container', container); + this._tip = L.DomUtil.create('div', prefix + '-tip', this._tipContainer); }, _update: function () { + if (!this._map) { return; } + this._container.style.visibility = 'hidden'; this._updateContent(); @@ -2423,70 +3213,106 @@ L.Popup = L.Class.extend({ }, _updateContent: function () { - if (!this._content) { - return; - } + if (!this._content) { return; } if (typeof this._content === 'string') { this._contentNode.innerHTML = this._content; } else { - this._contentNode.innerHTML = ''; + while (this._contentNode.hasChildNodes()) { + this._contentNode.removeChild(this._contentNode.firstChild); + } this._contentNode.appendChild(this._content); } + this.fire('contentupdate'); }, _updateLayout: function () { - this._container.style.width = ''; - this._container.style.whiteSpace = 'nowrap'; + var container = this._contentNode, + style = container.style; - var width = this._container.offsetWidth; + style.width = ''; + style.whiteSpace = 'nowrap'; - this._container.style.width = (width > this.options.maxWidth ? - this.options.maxWidth : (width < this.options.minWidth ? this.options.minWidth : width)) + 'px'; - this._container.style.whiteSpace = ''; + var width = container.offsetWidth; + width = Math.min(width, this.options.maxWidth); + width = Math.max(width, this.options.minWidth); + + style.width = (width + 1) + 'px'; + style.whiteSpace = ''; + + style.height = ''; + + var height = container.offsetHeight, + maxHeight = this.options.maxHeight, + scrolledClass = 'leaflet-popup-scrolled'; + + if (maxHeight && height > maxHeight) { + style.height = maxHeight + 'px'; + L.DomUtil.addClass(container, scrolledClass); + } else { + L.DomUtil.removeClass(container, scrolledClass); + } this._containerWidth = this._container.offsetWidth; }, _updatePosition: function () { - var pos = this._map.latLngToLayerPoint(this._latlng); + var pos = this._map.latLngToLayerPoint(this._latlng), + is3d = L.Browser.any3d, + offset = this.options.offset; - this._containerBottom = -pos.y - this.options.offset.y; - this._containerLeft = pos.x - Math.round(this._containerWidth / 2) + this.options.offset.x; + if (is3d) { + L.DomUtil.setPosition(this._container, pos); + } + this._containerBottom = -offset.y - (is3d ? 0 : pos.y); + this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x + (is3d ? 0 : pos.x); + + //Bottom position the popup in case the height of the popup changes (images loading etc) this._container.style.bottom = this._containerBottom + 'px'; this._container.style.left = this._containerLeft + 'px'; }, + _zoomAnimation: function (opt) { + var pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center); + + L.DomUtil.setPosition(this._container, pos); + }, + _adjustPan: function () { - if (!this.options.autoPan) { - return; + if (!this.options.autoPan) { return; } + + var map = this._map, + containerHeight = this._container.offsetHeight, + containerWidth = this._containerWidth, + + layerPos = new L.Point(this._containerLeft, -containerHeight - this._containerBottom); + + if (L.Browser.any3d) { + layerPos._add(L.DomUtil.getPosition(this._container)); } - var containerHeight = this._container.offsetHeight, - layerPos = new L.Point( - this._containerLeft, - -containerHeight - this._containerBottom), - containerPos = this._map.layerPointToContainerPoint(layerPos), - adjustOffset = new L.Point(0, 0), + var containerPos = map.layerPointToContainerPoint(layerPos), padding = this.options.autoPanPadding, - size = this._map.getSize(); + size = map.getSize(), + dx = 0, + dy = 0; if (containerPos.x < 0) { - adjustOffset.x = containerPos.x - padding.x; + dx = containerPos.x - padding.x; } - if (containerPos.x + this._containerWidth > size.x) { - adjustOffset.x = containerPos.x + this._containerWidth - size.x + padding.x; + if (containerPos.x + containerWidth > size.x) { + dx = containerPos.x + containerWidth - size.x + padding.x; } if (containerPos.y < 0) { - adjustOffset.y = containerPos.y - padding.y; + dy = containerPos.y - padding.y; } if (containerPos.y + containerHeight > size.y) { - adjustOffset.y = containerPos.y + containerHeight - size.y + padding.y; + dy = containerPos.y + containerHeight - size.y + padding.y; } - if (adjustOffset.x || adjustOffset.y) { - this._map.panBy(adjustOffset); + if (dx || dy) { + map.panBy(new L.Point(dx, dy)); } }, @@ -2496,6 +3322,10 @@ L.Popup = L.Class.extend({ } }); +L.popup = function (options, source) { + return new L.Popup(options, source); +}; + /* * Popup extension to L.Marker, adding openPopup & bindPopup methods. @@ -2503,8 +3333,8 @@ L.Popup = L.Class.extend({ L.Marker.include({ openPopup: function () { - this._popup.setLatLng(this._latlng); - if (this._map) { + if (this._popup && this._map) { + this._popup.setLatLng(this._latlng); this._map.openPopup(this._popup); } @@ -2519,14 +3349,22 @@ L.Marker.include({ }, bindPopup: function (content, options) { - options = L.Util.extend({offset: this.options.icon.popupAnchor}, options); + var anchor = L.point(this.options.icon.options.popupAnchor) || new L.Point(0, 0); + + anchor = anchor.add(L.Popup.prototype.options.offset); + + if (options && options.offset) { + anchor = anchor.add(options.offset); + } + + options = L.Util.extend({offset: anchor}, options); if (!this._popup) { this.on('click', this.openPopup, this); } - this._popup = new L.Popup(options, this); - this._popup.setContent(content); + this._popup = new L.Popup(options, this) + .setContent(content); return this; }, @@ -2545,24 +3383,22 @@ L.Marker.include({ L.Map.include({ openPopup: function (popup) { this.closePopup(); + this._popup = popup; - this.addLayer(popup); - this.fire('popupopen', { popup: this._popup }); - - return this; + + return this + .addLayer(popup) + .fire('popupopen', {popup: this._popup}); }, closePopup: function () { if (this._popup) { - this.removeLayer(this._popup); - this.fire('popupclose', { popup: this._popup }); - this._popup = null; + this._popup._close(); } return this; } }); - /* * L.LayerGroup is a class to combine several layers so you can manipulate the group (e.g. add/remove it) as one layer. */ @@ -2571,8 +3407,10 @@ L.LayerGroup = L.Class.extend({ initialize: function (layers) { this._layers = {}; + var i, len; + if (layers) { - for (var i = 0, len = layers.length; i < len; i++) { + for (i = 0, len = layers.length; i < len; i++) { this.addLayer(layers[i]); } } @@ -2580,26 +3418,30 @@ L.LayerGroup = L.Class.extend({ addLayer: function (layer) { var id = L.Util.stamp(layer); + this._layers[id] = layer; if (this._map) { this._map.addLayer(layer); } + return this; }, removeLayer: function (layer) { var id = L.Util.stamp(layer); + delete this._layers[id]; if (this._map) { this._map.removeLayer(layer); } + return this; }, clearLayers: function () { - this._iterateLayers(this.removeLayer, this); + this.eachLayer(this.removeLayer, this); return this; }, @@ -2616,20 +3458,26 @@ L.LayerGroup = L.Class.extend({ } } } + return this; }, onAdd: function (map) { this._map = map; - this._iterateLayers(map.addLayer, map); + this.eachLayer(map.addLayer, map); }, onRemove: function (map) { - this._iterateLayers(map.removeLayer, map); - delete this._map; + this.eachLayer(map.removeLayer, map); + this._map = null; }, - _iterateLayers: function (method, context) { + addTo: function (map) { + map.addLayer(this); + return this; + }, + + eachLayer: function (method, context) { for (var i in this._layers) { if (this._layers.hasOwnProperty(i)) { method.call(context, this._layers[i]); @@ -2638,6 +3486,10 @@ L.LayerGroup = L.Class.extend({ } }); +L.layerGroup = function (layers) { + return new L.LayerGroup(layers); +}; + /* * L.FeatureGroup extends L.LayerGroup by introducing mouse events and bindPopup method shared between a group of layers. @@ -2647,17 +3499,35 @@ L.FeatureGroup = L.LayerGroup.extend({ includes: L.Mixin.Events, addLayer: function (layer) { - this._initEvents(layer); + if (this._layers[L.Util.stamp(layer)]) { + return this; + } + + layer.on('click dblclick mouseover mouseout mousemove contextmenu', this._propagateEvent, this); + L.LayerGroup.prototype.addLayer.call(this, layer); if (this._popupContent && layer.bindPopup) { layer.bindPopup(this._popupContent); } + + return this; + }, + + removeLayer: function (layer) { + layer.off('click dblclick mouseover mouseout mousemove contextmenu', this._propagateEvent, this); + + L.LayerGroup.prototype.removeLayer.call(this, layer); + + if (this._popupContent) { + return this.invoke('unbindPopup'); + } else { + return this; + } }, bindPopup: function (content) { this._popupContent = content; - return this.invoke('bindPopup', content); }, @@ -2665,21 +3535,34 @@ L.FeatureGroup = L.LayerGroup.extend({ return this.invoke('setStyle', style); }, - _events: ['click', 'dblclick', 'mouseover', 'mouseout'], + bringToFront: function () { + return this.invoke('bringToFront'); + }, - _initEvents: function (layer) { - for (var i = 0, len = this._events.length; i < len; i++) { - layer.on(this._events[i], this._propagateEvent, this); - } + bringToBack: function () { + return this.invoke('bringToBack'); + }, + + getBounds: function () { + var bounds = new L.LatLngBounds(); + this.eachLayer(function (layer) { + bounds.extend(layer instanceof L.Marker ? layer.getLatLng() : layer.getBounds()); + }, this); + return bounds; }, _propagateEvent: function (e) { - e.layer = e.target; + e.layer = e.target; e.target = this; + this.fire(e.type, e); } }); +L.featureGroup = function (layers) { + return new L.FeatureGroup(layers); +}; + /* * L.Path is a base class for rendering vector paths on a map. It's inherited by Polyline, Circle, etc. @@ -2691,12 +3574,17 @@ L.Path = L.Class.extend({ statics: { // how much to extend the clip area around the map view // (relative to its size, e.g. 0.5 is half the screen in each direction) - CLIP_PADDING: 0.5 + // set in such way that SVG element doesn't exceed 1280px (vector layers flicker on dragend if it is) + CLIP_PADDING: L.Browser.mobile ? + Math.max(0, Math.min(0.5, + (1280 / Math.max(window.innerWidth, window.innerHeight) - 1) / 2)) + : 0.5 }, options: { stroke: true, color: '#0033ff', + dashArray: null, weight: 5, opacity: 0.5, @@ -2704,10 +3592,7 @@ L.Path = L.Class.extend({ fillColor: null, //same as color by default fillOpacity: 0.2, - clickable: true, - - // TODO remove this, as all paths now update on moveend - updateOnMoveEnd: true + clickable: true }, initialize: function (options) { @@ -2717,24 +3602,44 @@ L.Path = L.Class.extend({ onAdd: function (map) { this._map = map; - this._initElements(); - this._initEvents(); + if (!this._container) { + this._initElements(); + this._initEvents(); + } + this.projectLatlngs(); this._updatePath(); - map.on('viewreset', this.projectLatlngs, this); + if (this._container) { + this._map._pathRoot.appendChild(this._container); + } - this._updateTrigger = this.options.updateOnMoveEnd ? 'moveend' : 'viewreset'; - map.on(this._updateTrigger, this._updatePath, this); + map.on({ + 'viewreset': this.projectLatlngs, + 'moveend': this._updatePath + }, this); + }, + + addTo: function (map) { + map.addLayer(this); + return this; }, onRemove: function (map) { - this._map = null; - map._pathRoot.removeChild(this._container); - map.off('viewreset', this.projectLatlngs, this); - map.off(this._updateTrigger, this._updatePath, this); + this._map = null; + + if (L.Browser.vml) { + this._container = null; + this._stroke = null; + this._fill = null; + } + + map.off({ + 'viewreset': this.projectLatlngs, + 'moveend': this._updatePath + }, this); }, projectLatlngs: function () { @@ -2743,17 +3648,20 @@ L.Path = L.Class.extend({ setStyle: function (style) { L.Util.setOptions(this, style); + if (this._container) { this._updateStyle(); } + return this; }, - _redraw: function () { + redraw: function () { if (this._map) { this.projectLatlngs(); this._updatePath(); } + return this; } }); @@ -2761,9 +3669,8 @@ L.Map.include({ _updatePathViewport: function () { var p = L.Path.CLIP_PADDING, size = this.getSize(), - //TODO this._map._getMapPanePos() panePos = L.DomUtil.getPosition(this._mapPane), - min = panePos.multiplyBy(-1).subtract(size.multiplyBy(p)), + min = panePos.multiplyBy(-1)._subtract(size.multiplyBy(p)), max = min.add(size.multiplyBy(1 + p * 2)); this._pathViewport = new L.Bounds(min, max); @@ -2777,16 +3684,32 @@ L.Browser.svg = !!(document.createElementNS && document.createElementNS(L.Path.S L.Path = L.Path.extend({ statics: { - SVG: L.Browser.svg, - _createElement: function (name) { - return document.createElementNS(L.Path.SVG_NS, name); + SVG: L.Browser.svg + }, + + bringToFront: function () { + if (this._container) { + this._map._pathRoot.appendChild(this._container); } + return this; + }, + + bringToBack: function () { + if (this._container) { + var root = this._map._pathRoot; + root.insertBefore(this._container, root.firstChild); + } + return this; }, getPathString: function () { // form path string here }, + _createElement: function (name) { + return document.createElementNS(L.Path.SVG_NS, name); + }, + _initElements: function () { this._map._initPathRoot(); this._initPath(); @@ -2794,12 +3717,10 @@ L.Path = L.Path.extend({ }, _initPath: function () { - this._container = L.Path._createElement('g'); + this._container = this._createElement('g'); - this._path = L.Path._createElement('path'); + this._path = this._createElement('path'); this._container.appendChild(this._path); - - this._map._pathRoot.appendChild(this._container); }, _initStyle: function () { @@ -2809,8 +3730,6 @@ L.Path = L.Path.extend({ } if (this.options.fill) { this._path.setAttribute('fill-rule', 'evenodd'); - } else { - this._path.setAttribute('fill', 'none'); } this._updateStyle(); }, @@ -2820,10 +3739,19 @@ L.Path = L.Path.extend({ this._path.setAttribute('stroke', this.options.color); this._path.setAttribute('stroke-opacity', this.options.opacity); this._path.setAttribute('stroke-width', this.options.weight); + if (this.options.dashArray) { + this._path.setAttribute('stroke-dasharray', this.options.dashArray); + } else { + this._path.removeAttribute('stroke-dasharray'); + } + } else { + this._path.setAttribute('stroke', 'none'); } if (this.options.fill) { this._path.setAttribute('fill', this.options.fillColor || this.options.color); this._path.setAttribute('fill-opacity', this.options.fillOpacity); + } else { + this._path.setAttribute('fill', 'none'); } }, @@ -2839,15 +3767,15 @@ L.Path = L.Path.extend({ // TODO remove duplication with L.Map _initEvents: function () { if (this.options.clickable) { - if (!L.Browser.vml) { + if (L.Browser.svg || !L.Browser.vml) { this._path.setAttribute('class', 'leaflet-clickable'); } - L.DomEvent.addListener(this._container, 'click', this._onMouseClick, this); + L.DomEvent.on(this._container, 'click', this._onMouseClick, this); - var events = ['dblclick', 'mousedown', 'mouseover', 'mouseout', 'mousemove']; + var events = ['dblclick', 'mousedown', 'mouseover', 'mouseout', 'mousemove', 'contextmenu']; for (var i = 0; i < events.length; i++) { - L.DomEvent.addListener(this._container, events[i], this._fireMouseEvent, this); + L.DomEvent.on(this._container, events[i], this._fireMouseEvent, this); } } }, @@ -2856,33 +3784,80 @@ L.Path = L.Path.extend({ if (this._map.dragging && this._map.dragging.moved()) { return; } + this._fireMouseEvent(e); + + L.DomEvent.stopPropagation(e); }, _fireMouseEvent: function (e) { if (!this.hasEventListeners(e.type)) { return; } + + if (e.type === 'contextmenu') { + L.DomEvent.preventDefault(e); + } + + var map = this._map, + containerPoint = map.mouseEventToContainerPoint(e), + layerPoint = map.containerPointToLayerPoint(containerPoint), + latlng = map.layerPointToLatLng(layerPoint); + this.fire(e.type, { - latlng: this._map.mouseEventToLatLng(e), - layerPoint: this._map.mouseEventToLayerPoint(e) + latlng: latlng, + layerPoint: layerPoint, + containerPoint: containerPoint, + originalEvent: e }); - L.DomEvent.stopPropagation(e); } }); L.Map.include({ _initPathRoot: function () { if (!this._pathRoot) { - this._pathRoot = L.Path._createElement('svg'); + this._pathRoot = L.Path.prototype._createElement('svg'); this._panes.overlayPane.appendChild(this._pathRoot); + if (this.options.zoomAnimation && L.Browser.any3d) { + this._pathRoot.setAttribute('class', ' leaflet-zoom-animated'); + + this.on({ + 'zoomanim': this._animatePathZoom, + 'zoomend': this._endPathZoom + }); + } else { + this._pathRoot.setAttribute('class', ' leaflet-zoom-hide'); + } + this.on('moveend', this._updateSvgViewport); this._updateSvgViewport(); } }, + _animatePathZoom: function (opt) { + var scale = this.getZoomScale(opt.zoom), + offset = this._getCenterOffset(opt.center).divideBy(1 - 1 / scale), + viewportPos = this.containerPointToLayerPoint(this.getSize().multiplyBy(-L.Path.CLIP_PADDING)), + origin = viewportPos.add(offset).round(); + + this._pathRoot.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString((origin.multiplyBy(-1).add(L.DomUtil.getPosition(this._pathRoot)).multiplyBy(scale).add(origin))) + ' scale(' + scale + ') '; + + this._pathZooming = true; + }, + + _endPathZoom: function () { + this._pathZooming = false; + }, + _updateSvgViewport: function () { + if (this._pathZooming) { + // Do not update SVGs while a zoom animation is going on otherwise the animation will break. + // When the zoom animation ends we will be updated again anyway + // This fixes the case where you do a momentum move and zoom while the move is still ongoing. + return; + } + this._updatePathViewport(); var vp = this._pathViewport, @@ -2894,8 +3869,7 @@ L.Map.include({ pane = this._panes.overlayPane; // Hack to make flicker on drag end on mobile webkit less irritating - // Unfortunately I haven't found a good workaround for this yet - if (L.Browser.webkit) { + if (L.Browser.mobileWebkit) { pane.removeChild(root); } @@ -2904,7 +3878,7 @@ L.Map.include({ root.setAttribute('height', height); root.setAttribute('viewBox', [min.x, min.y, width, height].join(' ')); - if (L.Browser.webkit) { + if (L.Browser.mobileWebkit) { pane.appendChild(root); } } @@ -2916,10 +3890,13 @@ L.Map.include({ */ L.Path.include({ + bindPopup: function (content, options) { + if (!this._popup || this._popup.options !== options) { this._popup = new L.Popup(options, this); } + this._popup.setContent(content); if (!this._openPopupAdded) { @@ -2930,6 +3907,18 @@ L.Path.include({ return this; }, + openPopup: function (latlng) { + + if (this._popup) { + latlng = latlng || this._latlng || + this._latlngs[Math.floor(this._latlngs.length / 2)]; + + this._openPopup({latlng: latlng}); + } + + return this; + }, + _openPopup: function (e) { this._popup.setLatLng(e.latlng); this._map.openPopup(this._popup); @@ -2943,91 +3932,116 @@ L.Path.include({ */ L.Browser.vml = (function () { - var d = document.createElement('div'), s; - d.innerHTML = ''; - s = d.firstChild; - s.style.behavior = 'url(#default#VML)'; + try { + var div = document.createElement('div'); + div.innerHTML = ''; - return (s && (typeof s.adj === 'object')); + var shape = div.firstChild; + shape.style.behavior = 'url(#default#VML)'; + + return shape && (typeof shape.adj === 'object'); + } catch (e) { + return false; + } }()); L.Path = L.Browser.svg || !L.Browser.vml ? L.Path : L.Path.extend({ statics: { VML: true, - CLIP_PADDING: 0.02, - _createElement: (function () { - try { - document.namespaces.add('lvml', 'urn:schemas-microsoft-com:vml'); - return function (name) { - return document.createElement(''); - }; - } catch (e) { - return function (name) { - return document.createElement('<' + name + ' xmlns="urn:schemas-microsoft.com:vml" class="lvml">'); - }; - } - }()) + CLIP_PADDING: 0.02 }, + _createElement: (function () { + try { + document.namespaces.add('lvml', 'urn:schemas-microsoft-com:vml'); + return function (name) { + return document.createElement(''); + }; + } catch (e) { + return function (name) { + return document.createElement('<' + name + ' xmlns="urn:schemas-microsoft.com:vml" class="lvml">'); + }; + } + }()), + _initPath: function () { - this._container = L.Path._createElement('shape'); - this._container.className += ' leaflet-vml-shape' + - (this.options.clickable ? ' leaflet-clickable' : ''); - this._container.coordsize = '1 1'; + var container = this._container = this._createElement('shape'); + L.DomUtil.addClass(container, 'leaflet-vml-shape'); + if (this.options.clickable) { + L.DomUtil.addClass(container, 'leaflet-clickable'); + } + container.coordsize = '1 1'; - this._path = L.Path._createElement('path'); - this._container.appendChild(this._path); + this._path = this._createElement('path'); + container.appendChild(this._path); - this._map._pathRoot.appendChild(this._container); + this._map._pathRoot.appendChild(container); }, _initStyle: function () { - if (this.options.stroke) { - this._stroke = L.Path._createElement('stroke'); - this._stroke.endcap = 'round'; - this._container.appendChild(this._stroke); - } else { - this._container.stroked = false; - } - if (this.options.fill) { - this._container.filled = true; - this._fill = L.Path._createElement('fill'); - this._container.appendChild(this._fill); - } else { - this._container.filled = false; - } this._updateStyle(); }, _updateStyle: function () { - if (this.options.stroke) { - this._stroke.weight = this.options.weight + 'px'; - this._stroke.color = this.options.color; - this._stroke.opacity = this.options.opacity; + var stroke = this._stroke, + fill = this._fill, + options = this.options, + container = this._container; + + container.stroked = options.stroke; + container.filled = options.fill; + + if (options.stroke) { + if (!stroke) { + stroke = this._stroke = this._createElement('stroke'); + stroke.endcap = 'round'; + container.appendChild(stroke); + } + stroke.weight = options.weight + 'px'; + stroke.color = options.color; + stroke.opacity = options.opacity; + if (options.dashArray) { + stroke.dashStyle = options.dashArray.replace(/ *, */g, ' '); + } else { + stroke.dashStyle = ''; + } + } else if (stroke) { + container.removeChild(stroke); + this._stroke = null; } - if (this.options.fill) { - this._fill.color = this.options.fillColor || this.options.color; - this._fill.opacity = this.options.fillOpacity; + + if (options.fill) { + if (!fill) { + fill = this._fill = this._createElement('fill'); + container.appendChild(fill); + } + fill.color = options.fillColor || options.color; + fill.opacity = options.fillOpacity; + } else if (fill) { + container.removeChild(fill); + this._fill = null; } }, _updatePath: function () { - this._container.style.display = 'none'; + var style = this._container.style; + + style.display = 'none'; this._path.v = this.getPathString() + ' '; // the space fixes IE empty path string bug - this._container.style.display = ''; + style.display = ''; } }); L.Map.include(L.Browser.svg || !L.Browser.vml ? {} : { _initPathRoot: function () { - if (!this._pathRoot) { - this._pathRoot = document.createElement('div'); - this._pathRoot.className = 'leaflet-vml-container'; - this._panes.overlayPane.appendChild(this._pathRoot); + if (this._pathRoot) { return; } - this.on('moveend', this._updatePathViewport); - this._updatePathViewport(); - } + var root = this._pathRoot = document.createElement('div'); + root.className = 'leaflet-vml-container'; + this._panes.overlayPane.appendChild(root); + + this.on('moveend', this._updatePathViewport); + this._updatePathViewport(); } }); @@ -3047,8 +4061,43 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path : SVG: false }, - options: { - updateOnMoveEnd: true + redraw: function () { + if (this._map) { + this.projectLatlngs(); + this._requestUpdate(); + } + return this; + }, + + setStyle: function (style) { + L.Util.setOptions(this, style); + + if (this._map) { + this._updateStyle(); + this._requestUpdate(); + } + return this; + }, + + onRemove: function (map) { + map + .off('viewreset', this.projectLatlngs, this) + .off('moveend', this._updatePath, this); + + this._requestUpdate(); + + this._map = null; + }, + + _requestUpdate: function () { + if (this._map) { + L.Util.cancelAnimFrame(this._fireMapMoveEnd); + this._updateRequest = L.Util.requestAnimFrame(this._fireMapMoveEnd, this._map); + } + }, + + _fireMapMoveEnd: function () { + this.fire('moveend'); }, _initElements: function () { @@ -3057,12 +4106,14 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path : }, _updateStyle: function () { - if (this.options.stroke) { - this._ctx.lineWidth = this.options.weight; - this._ctx.strokeStyle = this.options.color; + var options = this.options; + + if (options.stroke) { + this._ctx.lineWidth = options.weight; + this._ctx.strokeStyle = options.color; } - if (this.options.fill) { - this._ctx.fillStyle = this.options.fillColor || this.options.color; + if (options.fill) { + this._ctx.fillStyle = options.fillColor || options.color; } }, @@ -3090,34 +4141,30 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path : }, _updatePath: function () { - if (this._checkIfEmpty()) { - return; - } + if (this._checkIfEmpty()) { return; } + + var ctx = this._ctx, + options = this.options; this._drawPath(); - - this._ctx.save(); - + ctx.save(); this._updateStyle(); - var opacity = this.options.opacity, - fillOpacity = this.options.fillOpacity; - - if (this.options.fill) { - if (fillOpacity < 1) { - this._ctx.globalAlpha = fillOpacity; + if (options.fill) { + if (options.fillOpacity < 1) { + ctx.globalAlpha = options.fillOpacity; } - this._ctx.fill(); + ctx.fill(); } - if (this.options.stroke) { - if (opacity < 1) { - this._ctx.globalAlpha = opacity; + if (options.stroke) { + if (options.opacity < 1) { + ctx.globalAlpha = options.opacity; } - this._ctx.stroke(); + ctx.stroke(); } - this._ctx.restore(); + ctx.restore(); // TODO optimization: 1 fill/stroke for all features with equal style instead of 1 for each feature }, @@ -3134,13 +4181,7 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path : if (this._containsPoint(e.layerPoint)) { this.fire('click', e); } - }, - - onRemove: function (map) { - map.off('viewreset', this._projectLatlngs, this); - map.off(this._updateTrigger, this._updatePath, this); - map.fire(this._updateTrigger); - } + } }); L.Map.include((L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? {} : { @@ -3158,12 +4199,21 @@ L.Map.include((L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? {} this._panes.overlayPane.appendChild(root); + if (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) { + //Don't redraw while zooming. See _updateSvgViewport for more details + return; + } this._updatePathViewport(); var vp = this._pathViewport, @@ -3171,7 +4221,7 @@ L.Map.include((L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? {} size = vp.max.subtract(min), root = this._pathRoot; - //TODO check if it's works properly on mobile webkit + //TODO check if this works properly on mobile webkit L.DomUtil.setPosition(root, min); root.width = size.x; root.height = size.y; @@ -3219,7 +4269,7 @@ L.LineUtil = { _simplifyDP: function (points, sqTolerance) { var len = points.length, - ArrayConstructor = typeof Uint8Array !== 'undefined' ? Uint8Array : Array, + ArrayConstructor = typeof Uint8Array !== undefined + '' ? Uint8Array : Array, markers = new ArrayConstructor(len); markers[0] = markers[len - 1] = 1; @@ -3387,20 +4437,27 @@ L.LineUtil = { }; - L.Polyline = L.Path.extend({ initialize: function (latlngs, options) { L.Path.prototype.initialize.call(this, options); - this._latlngs = latlngs; + + this._latlngs = this._convertLatLngs(latlngs); + + // TODO refactor: move to Polyline.Edit.js + if (L.Handler.PolyEdit) { + this.editing = new L.Handler.PolyEdit(this); + + if (this.options.editable) { + this.editing.enable(); + } + } }, options: { // how much to simplify the polyline on each zoom level // more = better performance and smoother look, less = more accurate smoothFactor: 1.0, - noClip: false, - - updateOnMoveEnd: true + noClip: false }, projectLatlngs: function () { @@ -3423,20 +4480,19 @@ L.Polyline = L.Path.extend({ }, setLatLngs: function (latlngs) { - this._latlngs = latlngs; - this._redraw(); - return this; + this._latlngs = this._convertLatLngs(latlngs); + return this.redraw(); }, addLatLng: function (latlng) { - this._latlngs.push(latlng); - this._redraw(); - return this; + this._latlngs.push(L.latLng(latlng)); + return this.redraw(); }, spliceLatLngs: function (index, howMany) { var removed = [].splice.apply(this._latlngs, arguments); - this._redraw(); + this._convertLatLngs(this._latlngs); + this.redraw(); return removed; }, @@ -3448,10 +4504,10 @@ L.Polyline = L.Path.extend({ for (var i = 1, len = points.length; i < len; i++) { p1 = points[i - 1]; p2 = points[i]; - var point = L.LineUtil._sqClosestPointOnSegment(p, p1, p2); - if (point._sqDist < minDistance) { - minDistance = point._sqDist; - minPoint = point; + var sqDist = L.LineUtil._sqClosestPointOnSegment(p, p1, p2, true); + if (sqDist < minDistance) { + minDistance = sqDist; + minPoint = L.LineUtil._sqClosestPointOnSegment(p, p1, p2); } } } @@ -3470,6 +4526,38 @@ L.Polyline = L.Path.extend({ return b; }, + // TODO refactor: move to Polyline.Edit.js + onAdd: function (map) { + L.Path.prototype.onAdd.call(this, map); + + if (this.editing && this.editing.enabled()) { + this.editing.addHooks(); + } + }, + + onRemove: function (map) { + if (this.editing && this.editing.enabled()) { + this.editing.removeHooks(); + } + + L.Path.prototype.onRemove.call(this, map); + }, + + _convertLatLngs: function (latlngs) { + var i, len; + for (i = 0, len = latlngs.length; i < len; i++) { + if (latlngs[i] instanceof Array && typeof latlngs[i][0] !== 'number') { + return; + } + latlngs[i] = L.latLng(latlngs[i]); + } + return latlngs; + }, + + _initEvents: function () { + L.Path.prototype._initEvents.call(this); + }, + _getPathPartStr: function (points) { var round = L.Path.VML; @@ -3527,6 +4615,8 @@ L.Polyline = L.Path.extend({ }, _updatePath: function () { + if (!this._map) { return; } + this._clipPoints(); this._simplifyPoints(); @@ -3534,6 +4624,10 @@ L.Polyline = L.Path.extend({ } }); +L.polyline = function (latlngs, options) { + return new L.Polyline(latlngs, options); +}; + /* * L.PolyUtil contains utilify functions for polygons (clipping, etc.). @@ -3608,8 +4702,8 @@ L.Polygon = L.Polyline.extend({ initialize: function (latlngs, options) { L.Polyline.prototype.initialize.call(this, latlngs, options); - if (latlngs && (latlngs[0] instanceof Array)) { - this._latlngs = latlngs[0]; + if (latlngs && (latlngs[0] instanceof Array) && (typeof latlngs[0][0] !== 'number')) { + this._latlngs = this._convertLatLngs(latlngs[0]); this._holes = latlngs.slice(1); } }, @@ -3661,6 +4755,10 @@ L.Polygon = L.Polyline.extend({ } }); +L.polygon = function (latlngs, options) { + return new L.Polygon(latlngs, options); +}; + /* * Contains L.MultiPolyline and L.MultiPolygon layers. @@ -3678,7 +4776,7 @@ L.Polygon = L.Polyline.extend({ setLatLngs: function (latlngs) { var i = 0, len = latlngs.length; - this._iterateLayers(function (layer) { + this.eachLayer(function (layer) { if (i < len) { layer.setLatLngs(latlngs[i++]); } else { @@ -3689,15 +4787,55 @@ L.Polygon = L.Polyline.extend({ while (i < len) { this.addLayer(new Klass(latlngs[i++], this._options)); } + + return this; } }); } L.MultiPolyline = createMulti(L.Polyline); L.MultiPolygon = createMulti(L.Polygon); + + L.multiPolyline = function (latlngs, options) { + return new L.MultiPolyline(latlngs, options); + }; + + L.multiPolygon = function (latlngs, options) { + return new L.MultiPolygon(latlngs, options); + }; }()); +/* + * L.Rectangle extends Polygon and creates a rectangle when passed a LatLngBounds + */ + +L.Rectangle = L.Polygon.extend({ + initialize: function (latLngBounds, options) { + L.Polygon.prototype.initialize.call(this, this._boundsToLatLngs(latLngBounds), options); + }, + + setBounds: function (latLngBounds) { + this.setLatLngs(this._boundsToLatLngs(latLngBounds)); + }, + + _boundsToLatLngs: function (latLngBounds) { + latLngBounds = L.latLngBounds(latLngBounds); + return [ + latLngBounds.getSouthWest(), + latLngBounds.getNorthWest(), + latLngBounds.getNorthEast(), + latLngBounds.getSouthEast(), + latLngBounds.getSouthWest() + ]; + } +}); + +L.rectangle = function (latLngBounds, options) { + return new L.Rectangle(latLngBounds, options); +}; + + /* * L.Circle is a circle overlay (with a certain radius in meters). */ @@ -3706,7 +4844,7 @@ L.Circle = L.Path.extend({ initialize: function (latlng, radius, options) { L.Path.prototype.initialize.call(this, options); - this._latlng = latlng; + this._latlng = L.latLng(latlng); this._mRadius = radius; }, @@ -3715,27 +4853,38 @@ L.Circle = L.Path.extend({ }, setLatLng: function (latlng) { - this._latlng = latlng; - this._redraw(); - return this; + this._latlng = L.latLng(latlng); + return this.redraw(); }, setRadius: function (radius) { this._mRadius = radius; - this._redraw(); - return this; + return this.redraw(); }, projectLatlngs: function () { - var equatorLength = 40075017, - hLength = equatorLength * Math.cos(L.LatLng.DEG_TO_RAD * this._latlng.lat); - - var lngSpan = (this._mRadius / hLength) * 360, - latlng2 = new L.LatLng(this._latlng.lat, this._latlng.lng - lngSpan, true), + var lngRadius = this._getLngRadius(), + latlng2 = new L.LatLng(this._latlng.lat, this._latlng.lng - lngRadius, true), point2 = this._map.latLngToLayerPoint(latlng2); this._point = this._map.latLngToLayerPoint(this._latlng); - this._radius = Math.round(this._point.x - point2.x); + this._radius = Math.max(Math.round(this._point.x - point2.x), 1); + }, + + getBounds: function () { + var map = this._map, + delta = this._radius * Math.cos(Math.PI / 4), + point = map.project(this._latlng), + swPoint = new L.Point(point.x - delta, point.y + delta), + nePoint = new L.Point(point.x + delta, point.y - delta), + sw = map.unproject(swPoint), + ne = map.unproject(nePoint); + + return new L.LatLngBounds(sw, ne); + }, + + getLatLng: function () { + return this._latlng; }, getPathString: function () { @@ -3757,7 +4906,21 @@ L.Circle = L.Path.extend({ } }, + getRadius: function () { + return this._mRadius; + }, + + _getLngRadius: function () { + var equatorLength = 40075017, + hLength = equatorLength * Math.cos(L.LatLng.DEG_TO_RAD * this._latlng.lat); + + return (this._mRadius / hLength) * 360; + }, + _checkIfEmpty: function () { + if (!this._map) { + return false; + } var vp = this._map._pathViewport, r = this._radius, p = this._point; @@ -3767,6 +4930,10 @@ L.Circle = L.Path.extend({ } }); +L.circle = function (latlng, radius, options) { + return new L.Circle(latlng, radius, options); +}; + /* * L.CircleMarker is a circle overlay with a permanent pixel radius. @@ -3789,11 +4956,14 @@ L.CircleMarker = L.Circle.extend({ setRadius: function (radius) { this._radius = radius; - this._redraw(); - return this; + return this.redraw(); } }); +L.circleMarker = function (latlng, options) { + return new L.CircleMarker(latlng, options); +}; + L.Polyline.include(!L.Path.CANVAS ? {} : { @@ -3868,7 +5038,7 @@ L.Circle.include(!L.Path.CANVAS ? {} : { _drawPath: function () { var p = this._point; this._ctx.beginPath(); - this._ctx.arc(p.x, p.y, this._radius, 0, Math.PI * 2); + this._ctx.arc(p.x, p.y, this._radius, 0, Math.PI * 2, false); }, _containsPoint: function (p) { @@ -3880,59 +5050,83 @@ L.Circle.include(!L.Path.CANVAS ? {} : { }); - L.GeoJSON = L.FeatureGroup.extend({ initialize: function (geojson, options) { L.Util.setOptions(this, options); - this._geojson = geojson; + this._layers = {}; if (geojson) { - this.addGeoJSON(geojson); + this.addData(geojson); } }, - addGeoJSON: function (geojson) { - if (geojson.features) { - for (var i = 0, len = geojson.features.length; i < len; i++) { - this.addGeoJSON(geojson.features[i]); + addData: function (geojson) { + var features = geojson instanceof Array ? geojson : geojson.features, + i, len; + + if (features) { + for (i = 0, len = features.length; i < len; i++) { + this.addData(features[i]); } - return; + return this; } - var isFeature = (geojson.type === 'Feature'), - geometry = (isFeature ? geojson.geometry : geojson), - layer = L.GeoJSON.geometryToLayer(geometry, this.options.pointToLayer); + var options = this.options; - this.fire('featureparse', { - layer: layer, - properties: geojson.properties, - geometryType: geometry.type, - bbox: geojson.bbox, - id: geojson.id - }); + if (options.filter && !options.filter(geojson)) { return; } - this.addLayer(layer); + var layer = L.GeoJSON.geometryToLayer(geojson, options.pointToLayer); + layer.feature = geojson; + + this.resetStyle(layer); + + if (options.onEachFeature) { + options.onEachFeature(geojson, layer); + } + + return this.addLayer(layer); + }, + + resetStyle: function (layer) { + var style = this.options.style; + if (style) { + this._setLayerStyle(layer, style); + } + }, + + setStyle: function (style) { + this.eachLayer(function (layer) { + this._setLayerStyle(layer, style); + }, this); + }, + + _setLayerStyle: function (layer, style) { + if (typeof style === 'function') { + style = style(layer.feature); + } + if (layer.setStyle) { + layer.setStyle(style); + } } }); L.Util.extend(L.GeoJSON, { - geometryToLayer: function (geometry, pointToLayer) { - var coords = geometry.coordinates, - latlng, latlngs, - i, len, - layer, - layers = []; + geometryToLayer: function (geojson, pointToLayer) { + var geometry = geojson.type === 'Feature' ? geojson.geometry : geojson, + coords = geometry.coordinates, + layers = [], + latlng, latlngs, i, len, layer; switch (geometry.type) { case 'Point': latlng = this.coordsToLatLng(coords); - return pointToLayer ? pointToLayer(latlng) : new L.Marker(latlng); + return pointToLayer ? pointToLayer(geojson, latlng) : new L.Marker(latlng); case 'MultiPoint': for (i = 0, len = coords.length; i < len; i++) { latlng = this.coordsToLatLng(coords[i]); - layer = pointToLayer ? pointToLayer(latlng) : new L.Marker(latlng); + layer = pointToLayer ? pointToLayer(geojson, latlng) : new L.Marker(latlng); layers.push(layer); } return new L.FeatureGroup(layers); @@ -3965,26 +5159,34 @@ L.Util.extend(L.GeoJSON, { } }, - coordsToLatLng: function (/*Array*/ coords, /*Boolean*/ reverse)/*: LatLng*/ { + coordsToLatLng: function (coords, reverse) { // (Array, Boolean) -> LatLng var lat = parseFloat(coords[reverse ? 0 : 1]), - lng = parseFloat(coords[reverse ? 1 : 0]); + lng = parseFloat(coords[reverse ? 1 : 0]); + return new L.LatLng(lat, lng, true); }, - coordsToLatLngs: function (/*Array*/ coords, /*Number*/ levelsDeep, /*Boolean*/ reverse)/*: Array*/ { - var latlng, latlngs = [], - i, len = coords.length; + coordsToLatLngs: function (coords, levelsDeep, reverse) { // (Array, Number, Boolean) -> Array + var latlng, + latlngs = [], + i, len; - for (i = 0; i < len; i++) { + for (i = 0, len = coords.length; i < len; i++) { latlng = levelsDeep ? this.coordsToLatLngs(coords[i], levelsDeep - 1, reverse) : this.coordsToLatLng(coords[i], reverse); + latlngs.push(latlng); } + return latlngs; } }); +L.geoJson = function (geojson, options) { + return new L.GeoJSON(geojson, options); +}; + /* * L.DomEvent contains functions for working with DOM events. @@ -3992,59 +5194,69 @@ L.Util.extend(L.GeoJSON, { L.DomEvent = { /* inpired by John Resig, Dean Edwards and YUI addEvent implementations */ - addListener: function (/*HTMLElement*/ obj, /*String*/ type, /*Function*/ fn, /*Object*/ context) { + addListener: function (obj, type, fn, context) { // (HTMLElement, String, Function[, Object]) + var id = L.Util.stamp(fn), - key = '_leaflet_' + type + id; + key = '_leaflet_' + type + id, + handler, originalHandler, newType; - if (obj[key]) { - return; - } + if (obj[key]) { return this; } - var handler = function (e) { + handler = function (e) { return fn.call(context || obj, e || L.DomEvent._getEvent()); }; if (L.Browser.touch && (type === 'dblclick') && this.addDoubleTapListener) { - this.addDoubleTapListener(obj, handler, id); + return this.addDoubleTapListener(obj, handler, id); + } else if ('addEventListener' in obj) { + if (type === 'mousewheel') { obj.addEventListener('DOMMouseScroll', handler, false); obj.addEventListener(type, handler, false); + } else if ((type === 'mouseenter') || (type === 'mouseleave')) { - var originalHandler = handler, - newType = (type === 'mouseenter' ? 'mouseover' : 'mouseout'); + + originalHandler = handler; + newType = (type === 'mouseenter' ? 'mouseover' : 'mouseout'); + handler = function (e) { - if (!L.DomEvent._checkMouse(obj, e)) { - return; - } + if (!L.DomEvent._checkMouse(obj, e)) { return; } return originalHandler(e); }; + obj.addEventListener(newType, handler, false); + } else { obj.addEventListener(type, handler, false); } + } else if ('attachEvent' in obj) { obj.attachEvent("on" + type, handler); } obj[key] = handler; + + return this; }, - removeListener: function (/*HTMLElement*/ obj, /*String*/ type, /*Function*/ fn) { + removeListener: function (obj, type, fn) { // (HTMLElement, String, Function) + var id = L.Util.stamp(fn), key = '_leaflet_' + type + id, handler = obj[key]; - if (!handler) { - return; - } + if (!handler) { return; } if (L.Browser.touch && (type === 'dblclick') && this.removeDoubleTapListener) { this.removeDoubleTapListener(obj, id); + } else if ('removeEventListener' in obj) { + if (type === 'mousewheel') { obj.removeEventListener('DOMMouseScroll', handler, false); obj.removeEventListener(type, handler, false); + } else if ((type === 'mouseenter') || (type === 'mouseleave')) { obj.removeEventListener((type === 'mouseenter' ? 'mouseover' : 'mouseout'), handler, false); } else { @@ -4053,15 +5265,76 @@ L.DomEvent = { } else if ('detachEvent' in obj) { obj.detachEvent("on" + type, handler); } + obj[key] = null; + + return this; }, + stopPropagation: function (e) { + + if (e.stopPropagation) { + e.stopPropagation(); + } else { + e.cancelBubble = true; + } + return this; + }, + + disableClickPropagation: function (el) { + + var stop = L.DomEvent.stopPropagation; + + return L.DomEvent + .addListener(el, L.Draggable.START, stop) + .addListener(el, 'click', stop) + .addListener(el, 'dblclick', stop); + }, + + preventDefault: function (e) { + + if (e.preventDefault) { + e.preventDefault(); + } else { + e.returnValue = false; + } + return this; + }, + + stop: function (e) { + return L.DomEvent.preventDefault(e).stopPropagation(e); + }, + + getMousePosition: function (e, container) { + + var body = document.body, + docEl = document.documentElement, + x = e.pageX ? e.pageX : e.clientX + body.scrollLeft + docEl.scrollLeft, + y = e.pageY ? e.pageY : e.clientY + body.scrollTop + docEl.scrollTop, + pos = new L.Point(x, y); + + return (container ? pos._subtract(L.DomUtil.getViewportOffset(container)) : pos); + }, + + getWheelDelta: function (e) { + + var delta = 0; + + if (e.wheelDelta) { + delta = e.wheelDelta / 120; + } + if (e.detail) { + delta = -e.detail / 3; + } + return delta; + }, + + // check if element really left/entered the event target (for mouseenter/mouseleave) _checkMouse: function (el, e) { + var related = e.relatedTarget; - if (!related) { - return true; - } + if (!related) { return true; } try { while (related && (related !== el)) { @@ -4070,12 +5343,12 @@ L.DomEvent = { } catch (err) { return false; } - return (related !== el); }, - /*jshint noarg:false */ // evil magic for IE - _getEvent: function () { + /*jshint noarg:false */ + _getEvent: function () { // evil magic for IE + var e = window.event; if (!e) { var caller = arguments.callee.caller; @@ -4088,59 +5361,12 @@ L.DomEvent = { } } return e; - }, - /*jshint noarg:false */ - - stopPropagation: function (/*Event*/ e) { - if (e.stopPropagation) { - e.stopPropagation(); - } else { - e.cancelBubble = true; - } - }, - - disableClickPropagation: function (/*HTMLElement*/ el) { - L.DomEvent.addListener(el, L.Draggable.START, L.DomEvent.stopPropagation); - L.DomEvent.addListener(el, 'click', L.DomEvent.stopPropagation); - L.DomEvent.addListener(el, 'dblclick', L.DomEvent.stopPropagation); - }, - - preventDefault: function (/*Event*/ e) { - if (e.preventDefault) { - e.preventDefault(); - } else { - e.returnValue = false; - } - }, - - stop: function (e) { - L.DomEvent.preventDefault(e); - L.DomEvent.stopPropagation(e); - }, - - getMousePosition: function (e, container) { - var x = e.pageX ? e.pageX : e.clientX + - document.body.scrollLeft + document.documentElement.scrollLeft, - y = e.pageY ? e.pageY : e.clientY + - document.body.scrollTop + document.documentElement.scrollTop, - pos = new L.Point(x, y); - return (container ? - pos.subtract(L.DomUtil.getViewportOffset(container)) : pos); - }, - - getWheelDelta: function (e) { - var delta = 0; - if (e.wheelDelta) { - delta = e.wheelDelta / 120; - } - if (e.detail) { - delta = -e.detail / 3; - } - return delta; } + /*jshint noarg:false */ }; - +L.DomEvent.on = L.DomEvent.addListener; +L.DomEvent.off = L.DomEvent.removeListener; /* * L.Draggable allows you to add dragging capabilities to any element. Supports mobile devices too. @@ -4165,7 +5391,7 @@ L.Draggable = L.Class.extend({ if (this._enabled) { return; } - L.DomEvent.addListener(this._dragStartTarget, L.Draggable.START, this._onDown, this); + L.DomEvent.on(this._dragStartTarget, L.Draggable.START, this._onDown, this); this._enabled = true; }, @@ -4173,8 +5399,9 @@ L.Draggable = L.Class.extend({ if (!this._enabled) { return; } - L.DomEvent.removeListener(this._dragStartTarget, L.Draggable.START, this._onDown); + L.DomEvent.off(this._dragStartTarget, L.Draggable.START, this._onDown); this._enabled = false; + this._moved = false; }, _onDown: function (e) { @@ -4182,7 +5409,10 @@ L.Draggable = L.Class.extend({ return; } + this._simulateClick = true; + if (e.touches && e.touches.length > 1) { + this._simulateClick = false; return; } @@ -4192,7 +5422,7 @@ L.Draggable = L.Class.extend({ L.DomEvent.preventDefault(e); if (L.Browser.touch && el.tagName.toLowerCase() === 'a') { - el.className += ' leaflet-active'; + L.DomUtil.addClass(el, 'leaflet-active'); } this._moved = false; @@ -4200,37 +5430,39 @@ L.Draggable = L.Class.extend({ return; } - if (!L.Browser.touch) { - L.DomUtil.disableTextSelection(); - this._setMovingCursor(); - } - this._startPos = this._newPos = L.DomUtil.getPosition(this._element); this._startPoint = new L.Point(first.clientX, first.clientY); - L.DomEvent.addListener(document, L.Draggable.MOVE, this._onMove, this); - L.DomEvent.addListener(document, L.Draggable.END, this._onUp, this); + L.DomEvent.on(document, L.Draggable.MOVE, this._onMove, this); + L.DomEvent.on(document, L.Draggable.END, this._onUp, this); }, _onMove: function (e) { - if (e.touches && e.touches.length > 1) { - return; - } + if (e.touches && e.touches.length > 1) { return; } + + var first = (e.touches && e.touches.length === 1 ? e.touches[0] : e), + newPoint = new L.Point(first.clientX, first.clientY), + diffVec = newPoint.subtract(this._startPoint); + + if (!diffVec.x && !diffVec.y) { return; } L.DomEvent.preventDefault(e); - var first = (e.touches && e.touches.length === 1 ? e.touches[0] : e); - if (!this._moved) { this.fire('dragstart'); this._moved = true; + + if (!L.Browser.touch) { + L.DomUtil.disableTextSelection(); + this._setMovingCursor(); + } } + + this._newPos = this._startPos.add(diffVec); this._moving = true; - var newPoint = new L.Point(first.clientX, first.clientY); - this._newPos = this._startPos.add(newPoint).subtract(this._startPoint); - - L.Util.requestAnimFrame(this._updatePosition, this, true, this._dragStartTarget); + L.Util.cancelAnimFrame(this._animRequest); + this._animRequest = L.Util.requestAnimFrame(this._updatePosition, this, true, this._dragStartTarget); }, _updatePosition: function () { @@ -4240,13 +5472,13 @@ L.Draggable = L.Class.extend({ }, _onUp: function (e) { - if (e.changedTouches) { + if (this._simulateClick && e.changedTouches) { var first = e.changedTouches[0], el = first.target, dist = (this._newPos && this._newPos.distanceTo(this._startPos)) || 0; if (el.tagName.toLowerCase() === 'a') { - el.className = el.className.replace(' leaflet-active', ''); + L.DomUtil.removeClass(el, 'leaflet-active'); } if (dist < L.Draggable.TAP_TOLERANCE) { @@ -4259,22 +5491,24 @@ L.Draggable = L.Class.extend({ this._restoreCursor(); } - L.DomEvent.removeListener(document, L.Draggable.MOVE, this._onMove); - L.DomEvent.removeListener(document, L.Draggable.END, this._onUp); + L.DomEvent.off(document, L.Draggable.MOVE, this._onMove); + L.DomEvent.off(document, L.Draggable.END, this._onUp); if (this._moved) { + // ensure drag is not fired after dragend + L.Util.cancelAnimFrame(this._animRequest); + this.fire('dragend'); } this._moving = false; }, _setMovingCursor: function () { - this._bodyCursor = document.body.style.cursor; - document.body.style.cursor = 'move'; + L.DomUtil.addClass(document.body, 'leaflet-dragging'); }, _restoreCursor: function () { - document.body.style.cursor = this._bodyCursor; + L.DomUtil.removeClass(document.body, 'leaflet-dragging'); }, _simulateEvent: function (type, e) { @@ -4301,17 +5535,15 @@ L.Handler = L.Class.extend({ }, enable: function () { - if (this._enabled) { - return; - } + if (this._enabled) { return; } + this._enabled = true; this.addHooks(); }, disable: function () { - if (!this._enabled) { - return; - } + if (!this._enabled) { return; } + this._enabled = false; this.removeHooks(); }, @@ -4326,19 +5558,32 @@ L.Handler = L.Class.extend({ * L.Handler.MapDrag is used internally by L.Map to make the map draggable. */ +L.Map.mergeOptions({ + dragging: true, + + inertia: !L.Browser.android23, + inertiaDeceleration: 3000, // px/s^2 + inertiaMaxSpeed: 1500, // px/s + inertiaThreshold: L.Browser.touch ? 32 : 14, // ms + + // TODO refactor, move to CRS + worldCopyJump: true +}); + L.Map.Drag = L.Handler.extend({ addHooks: function () { if (!this._draggable) { this._draggable = new L.Draggable(this._map._mapPane, this._map._container); - this._draggable - .on('dragstart', this._onDragStart, this) - .on('drag', this._onDrag, this) - .on('dragend', this._onDragEnd, this); + this._draggable.on({ + 'dragstart': this._onDragStart, + 'drag': this._onDrag, + 'dragend': this._onDragEnd + }, this); var options = this._map.options; - if (options.worldCopyJump && !options.continuousWorld) { + if (options.worldCopyJump) { this._draggable.on('predrag', this._onPreDrag, this); this._map.on('viewreset', this._onViewReset, this); } @@ -4355,12 +5600,36 @@ L.Map.Drag = L.Handler.extend({ }, _onDragStart: function () { - this._map + var map = this._map; + + map .fire('movestart') .fire('dragstart'); + + if (map._panTransition) { + map._panTransition._onTransitionEnd(true); + } + + if (map.options.inertia) { + this._positions = []; + this._times = []; + } }, _onDrag: function () { + if (this._map.options.inertia) { + var time = this._lastTime = +new Date(), + pos = this._lastPos = this._draggable._newPos; + + this._positions.push(pos); + this._times.push(time); + + if (time - this._times[0] > 200) { + this._positions.shift(); + this._times.shift(); + } + } + this._map .fire('move') .fire('drag'); @@ -4370,14 +5639,16 @@ L.Map.Drag = L.Handler.extend({ var pxCenter = this._map.getSize().divideBy(2), pxWorldCenter = this._map.latLngToLayerPoint(new L.LatLng(0, 0)); - this._initialWorldOffset = pxWorldCenter.subtract(pxCenter); + this._initialWorldOffset = pxWorldCenter.subtract(pxCenter).x; + this._worldWidth = this._map.project(new L.LatLng(0, 180)).x; }, _onPreDrag: function () { + // TODO refactor to be able to adjust map pane position after zoom var map = this._map, - worldWidth = map.options.scale(map.getZoom()), + worldWidth = this._worldWidth, halfWidth = Math.round(worldWidth / 2), - dx = this._initialWorldOffset.x, + dx = this._initialWorldOffset, x = this._draggable._newPos.x, newX1 = (x - halfWidth + dx) % worldWidth + halfWidth - dx, newX2 = (x + halfWidth + dx) % worldWidth - halfWidth - dx, @@ -4387,13 +5658,44 @@ L.Map.Drag = L.Handler.extend({ }, _onDragEnd: function () { - var map = this._map; + var map = this._map, + options = map.options, + delay = +new Date() - this._lastTime, - map - .fire('moveend') - .fire('dragend'); + noInertia = !options.inertia || + delay > options.inertiaThreshold || + this._positions[0] === undefined; - if (map.options.maxBounds) { + if (noInertia) { + map.fire('moveend'); + + } else { + + var direction = this._lastPos.subtract(this._positions[0]), + duration = (this._lastTime + delay - this._times[0]) / 1000, + + speedVector = direction.multiplyBy(0.58 / duration), + speed = speedVector.distanceTo(new L.Point(0, 0)), + + limitedSpeed = Math.min(options.inertiaMaxSpeed, speed), + limitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed), + + decelerationDuration = limitedSpeed / options.inertiaDeceleration, + offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round(); + + var panOptions = { + duration: decelerationDuration, + easing: 'ease-out' + }; + + L.Util.requestAnimFrame(L.Util.bind(function () { + this._map.panBy(offset, panOptions); + }, this)); + } + + map.fire('dragend'); + + if (options.maxBounds) { // TODO predrag validation instead of animation L.Util.requestAnimFrame(this._panInsideMaxBounds, map, true, map._container); } @@ -4404,15 +5706,20 @@ L.Map.Drag = L.Handler.extend({ } }); +L.Map.addInitHook('addHandler', 'dragging', L.Map.Drag); + /* * L.Handler.DoubleClickZoom is used internally by L.Map to add double-click zooming. */ +L.Map.mergeOptions({ + doubleClickZoom: true +}); + L.Map.DoubleClickZoom = L.Handler.extend({ addHooks: function () { this._map.on('dblclick', this._onDoubleClick); - // TODO remove 3d argument? }, removeHooks: function () { @@ -4424,28 +5731,34 @@ L.Map.DoubleClickZoom = L.Handler.extend({ } }); +L.Map.addInitHook('addHandler', 'doubleClickZoom', L.Map.DoubleClickZoom); /* * L.Handler.ScrollWheelZoom is used internally by L.Map to enable mouse scroll wheel zooming on the map. */ +L.Map.mergeOptions({ + scrollWheelZoom: !L.Browser.touch +}); + L.Map.ScrollWheelZoom = L.Handler.extend({ addHooks: function () { - L.DomEvent.addListener(this._map._container, 'mousewheel', this._onWheelScroll, this); + L.DomEvent.on(this._map._container, 'mousewheel', this._onWheelScroll, this); this._delta = 0; }, removeHooks: function () { - L.DomEvent.removeListener(this._map._container, 'mousewheel', this._onWheelScroll); + L.DomEvent.off(this._map._container, 'mousewheel', this._onWheelScroll); }, _onWheelScroll: function (e) { var delta = L.DomEvent.getWheelDelta(e); + this._delta += delta; this._lastMousePos = this._map.mouseEventToContainerPoint(e); clearTimeout(this._timer); - this._timer = setTimeout(L.Util.bind(this._performZoom, this), 50); + this._timer = setTimeout(L.Util.bind(this._performZoom, this), 40); L.DomEvent.preventDefault(e); }, @@ -4460,27 +5773,27 @@ L.Map.ScrollWheelZoom = L.Handler.extend({ this._delta = 0; - if (!delta) { - return; - } + if (!delta) { return; } - var newCenter = this._getCenterForScrollWheelZoom(this._lastMousePos, delta), - newZoom = zoom + delta; + var newZoom = zoom + delta, + newCenter = this._getCenterForScrollWheelZoom(this._lastMousePos, newZoom); map.setView(newCenter, newZoom); }, - _getCenterForScrollWheelZoom: function (mousePos, delta) { + _getCenterForScrollWheelZoom: function (mousePos, newZoom) { var map = this._map, - centerPoint = map.getPixelBounds().getCenter(), + scale = map.getZoomScale(newZoom), viewHalf = map.getSize().divideBy(2), - centerOffset = mousePos.subtract(viewHalf).multiplyBy(1 - Math.pow(2, -delta)), - newCenterPoint = centerPoint.add(centerOffset); + centerOffset = mousePos.subtract(viewHalf).multiplyBy(1 - 1 / scale), + newCenterPoint = map._getTopLeftPoint().add(viewHalf).add(centerOffset); - return map.unproject(newCenterPoint, map._zoom, true); + return map.unproject(newCenterPoint); } }); +L.Map.addInitHook('addHandler', 'scrollWheelZoom', L.Map.ScrollWheelZoom); + L.Util.extend(L.DomEvent, { // inspired by Zepto touch code by Thomas Fuchs @@ -4517,12 +5830,14 @@ L.Util.extend(L.DomEvent, { obj.addEventListener(touchstart, onTouchStart, false); obj.addEventListener(touchend, onTouchEnd, false); + return this; }, removeDoubleTapListener: function (obj, id) { var pre = '_leaflet_'; obj.removeEventListener(obj, obj[pre + 'touchstart' + id], false); obj.removeEventListener(obj, obj[pre + 'touchend' + id], false); + return this; } }); @@ -4531,101 +5846,136 @@ L.Util.extend(L.DomEvent, { * L.Handler.TouchZoom is used internally by L.Map to add touch-zooming on Webkit-powered mobile browsers. */ +L.Map.mergeOptions({ + touchZoom: L.Browser.touch && !L.Browser.android23 +}); + L.Map.TouchZoom = L.Handler.extend({ addHooks: function () { - L.DomEvent.addListener(this._map._container, 'touchstart', this._onTouchStart, this); + L.DomEvent.on(this._map._container, 'touchstart', this._onTouchStart, this); }, removeHooks: function () { - L.DomEvent.removeListener(this._map._container, 'touchstart', this._onTouchStart, this); + L.DomEvent.off(this._map._container, 'touchstart', this._onTouchStart, this); }, _onTouchStart: function (e) { - if (!e.touches || e.touches.length !== 2 || this._map._animatingZoom) { - return; - } + var map = this._map; - var p1 = this._map.mouseEventToLayerPoint(e.touches[0]), - p2 = this._map.mouseEventToLayerPoint(e.touches[1]), - viewCenter = this._map.containerPointToLayerPoint(this._map.getSize().divideBy(2)); + if (!e.touches || e.touches.length !== 2 || map._animatingZoom || this._zooming) { return; } + + var p1 = map.mouseEventToLayerPoint(e.touches[0]), + p2 = map.mouseEventToLayerPoint(e.touches[1]), + viewCenter = map._getCenterLayerPoint(); this._startCenter = p1.add(p2).divideBy(2, true); this._startDist = p1.distanceTo(p2); - //this._startTransform = this._map._mapPane.style.webkitTransform; this._moved = false; this._zooming = true; this._centerOffset = viewCenter.subtract(this._startCenter); - L.DomEvent.addListener(document, 'touchmove', this._onTouchMove, this); - L.DomEvent.addListener(document, 'touchend', this._onTouchEnd, this); + L.DomEvent + .on(document, 'touchmove', this._onTouchMove, this) + .on(document, 'touchend', this._onTouchEnd, this); L.DomEvent.preventDefault(e); }, _onTouchMove: function (e) { - if (!e.touches || e.touches.length !== 2) { - return; - } + if (!e.touches || e.touches.length !== 2) { return; } + + var map = this._map; + + var p1 = map.mouseEventToLayerPoint(e.touches[0]), + p2 = map.mouseEventToLayerPoint(e.touches[1]); + + this._scale = p1.distanceTo(p2) / this._startDist; + this._delta = p1.add(p2).divideBy(2, true).subtract(this._startCenter); + + if (this._scale === 1) { return; } if (!this._moved) { - this._map._mapPane.className += ' leaflet-zoom-anim'; + L.DomUtil.addClass(map._mapPane, 'leaflet-zoom-anim leaflet-touching'); - this._map - .fire('zoomstart') + map .fire('movestart') + .fire('zoomstart') ._prepareTileBg(); this._moved = true; } - var p1 = this._map.mouseEventToLayerPoint(e.touches[0]), - p2 = this._map.mouseEventToLayerPoint(e.touches[1]); - - this._scale = p1.distanceTo(p2) / this._startDist; - this._delta = p1.add(p2).divideBy(2, true).subtract(this._startCenter); - - // Used 2 translates instead of transform-origin because of a very strange bug - - // it didn't count the origin on the first touch-zoom but worked correctly afterwards - - this._map._tileBg.style.webkitTransform = [ - L.DomUtil.getTranslateString(this._delta), - L.DomUtil.getScaleString(this._scale, this._startCenter) - ].join(" "); + L.Util.cancelAnimFrame(this._animRequest); + this._animRequest = L.Util.requestAnimFrame(this._updateOnMove, this, true, this._map._container); L.DomEvent.preventDefault(e); }, + _updateOnMove: function () { + var map = this._map, + origin = this._getScaleOrigin(), + center = map.layerPointToLatLng(origin); + + map.fire('zoomanim', { + center: center, + zoom: map.getScaleZoom(this._scale) + }); + + // Used 2 translates instead of transform-origin because of a very strange bug - + // it didn't count the origin on the first touch-zoom but worked correctly afterwards + + map._tileBg.style[L.DomUtil.TRANSFORM] = + L.DomUtil.getTranslateString(this._delta) + ' ' + + L.DomUtil.getScaleString(this._scale, this._startCenter); + }, + _onTouchEnd: function (e) { - if (!this._moved || !this._zooming) { - return; - } + if (!this._moved || !this._zooming) { return; } + + var map = this._map; + this._zooming = false; + L.DomUtil.removeClass(map._mapPane, 'leaflet-touching'); - var oldZoom = this._map.getZoom(), - floatZoomDelta = Math.log(this._scale) / Math.LN2, + L.DomEvent + .off(document, 'touchmove', this._onTouchMove) + .off(document, 'touchend', this._onTouchEnd); + + var origin = this._getScaleOrigin(), + center = map.layerPointToLatLng(origin), + + oldZoom = map.getZoom(), + floatZoomDelta = map.getScaleZoom(this._scale) - oldZoom, roundZoomDelta = (floatZoomDelta > 0 ? Math.ceil(floatZoomDelta) : Math.floor(floatZoomDelta)), - zoom = this._map._limitZoom(oldZoom + roundZoomDelta), - zoomDelta = zoom - oldZoom, - centerOffset = this._centerOffset.subtract(this._delta).divideBy(this._scale), - centerPoint = this._map.getPixelOrigin().add(this._startCenter).add(centerOffset), - center = this._map.unproject(centerPoint); + zoom = map._limitZoom(oldZoom + roundZoomDelta); - L.DomEvent.removeListener(document, 'touchmove', this._onTouchMove); - L.DomEvent.removeListener(document, 'touchend', this._onTouchEnd); + map.fire('zoomanim', { + center: center, + zoom: zoom + }); - var finalScale = Math.pow(2, zoomDelta); + map._runAnimation(center, zoom, map.getZoomScale(zoom) / this._scale, origin, true); + }, - this._map._runAnimation(center, zoom, finalScale / this._scale, this._startCenter.add(centerOffset)); + _getScaleOrigin: function () { + var centerOffset = this._centerOffset.subtract(this._delta).divideBy(this._scale); + return this._startCenter.add(centerOffset); } }); +L.Map.addInitHook('addHandler', 'touchZoom', L.Map.TouchZoom); + /* * L.Handler.ShiftDragZoom is used internally by L.Map to add shift-drag zoom (zoom to a selected bounding box). */ +L.Map.mergeOptions({ + boxZoom: true +}); + L.Map.BoxZoom = L.Handler.extend({ initialize: function (map) { this._map = map; @@ -4634,17 +5984,15 @@ L.Map.BoxZoom = L.Handler.extend({ }, addHooks: function () { - L.DomEvent.addListener(this._container, 'mousedown', this._onMouseDown, this); + L.DomEvent.on(this._container, 'mousedown', this._onMouseDown, this); }, removeHooks: function () { - L.DomEvent.removeListener(this._container, 'mousedown', this._onMouseDown); + L.DomEvent.off(this._container, 'mousedown', this._onMouseDown); }, _onMouseDown: function (e) { - if (!e.shiftKey || ((e.which !== 1) && (e.button !== 1))) { - return false; - } + if (!e.shiftKey || ((e.which !== 1) && (e.button !== 1))) { return false; } L.DomUtil.disableTextSelection(); @@ -4653,28 +6001,33 @@ L.Map.BoxZoom = L.Handler.extend({ this._box = L.DomUtil.create('div', 'leaflet-zoom-box', this._pane); L.DomUtil.setPosition(this._box, this._startLayerPoint); - //TODO move cursor to styles + //TODO refactor: move cursor to styles this._container.style.cursor = 'crosshair'; - L.DomEvent.addListener(document, 'mousemove', this._onMouseMove, this); - L.DomEvent.addListener(document, 'mouseup', this._onMouseUp, this); - - L.DomEvent.preventDefault(e); + L.DomEvent + .on(document, 'mousemove', this._onMouseMove, this) + .on(document, 'mouseup', this._onMouseUp, this) + .preventDefault(e); + + this._map.fire("boxzoomstart"); }, _onMouseMove: function (e) { - var layerPoint = this._map.mouseEventToLayerPoint(e), - dx = layerPoint.x - this._startLayerPoint.x, - dy = layerPoint.y - this._startLayerPoint.y; + var startPoint = this._startLayerPoint, + box = this._box, - var newX = Math.min(layerPoint.x, this._startLayerPoint.x), - newY = Math.min(layerPoint.y, this._startLayerPoint.y), - newPos = new L.Point(newX, newY); + layerPoint = this._map.mouseEventToLayerPoint(e), + offset = layerPoint.subtract(startPoint), - L.DomUtil.setPosition(this._box, newPos); + newPos = new L.Point( + Math.min(layerPoint.x, startPoint.x), + Math.min(layerPoint.y, startPoint.y)); - this._box.style.width = (Math.abs(dx) - 4) + 'px'; - this._box.style.height = (Math.abs(dy) - 4) + 'px'; + L.DomUtil.setPosition(box, newPos); + + // TODO refactor: remove hardcoded 4 pixels + box.style.width = (Math.abs(offset.x) - 4) + 'px'; + box.style.height = (Math.abs(offset.y) - 4) + 'px'; }, _onMouseUp: function (e) { @@ -4683,19 +6036,160 @@ L.Map.BoxZoom = L.Handler.extend({ L.DomUtil.enableTextSelection(); - L.DomEvent.removeListener(document, 'mousemove', this._onMouseMove); - L.DomEvent.removeListener(document, 'mouseup', this._onMouseUp); + L.DomEvent + .off(document, 'mousemove', this._onMouseMove) + .off(document, 'mouseup', this._onMouseUp); - var layerPoint = this._map.mouseEventToLayerPoint(e); + var map = this._map, + layerPoint = map.mouseEventToLayerPoint(e); var bounds = new L.LatLngBounds( - this._map.layerPointToLatLng(this._startLayerPoint), - this._map.layerPointToLatLng(layerPoint)); + map.layerPointToLatLng(this._startLayerPoint), + map.layerPointToLatLng(layerPoint)); - this._map.fitBounds(bounds); + map.fitBounds(bounds); + + map.fire("boxzoomend", { + boxZoomBounds: bounds + }); } }); +L.Map.addInitHook('addHandler', 'boxZoom', L.Map.BoxZoom); + + +L.Map.mergeOptions({ + keyboard: true, + keyboardPanOffset: 80, + keyboardZoomOffset: 1 +}); + +L.Map.Keyboard = L.Handler.extend({ + + // list of e.keyCode values for particular actions + keyCodes: { + left: [37], + right: [39], + down: [40], + up: [38], + zoomIn: [187, 107, 61], + zoomOut: [189, 109] + }, + + initialize: function (map) { + this._map = map; + + this._setPanOffset(map.options.keyboardPanOffset); + this._setZoomOffset(map.options.keyboardZoomOffset); + }, + + addHooks: function () { + var container = this._map._container; + + // make the container focusable by tabbing + if (container.tabIndex === -1) { + container.tabIndex = "0"; + } + + L.DomEvent + .addListener(container, 'focus', this._onFocus, this) + .addListener(container, 'blur', this._onBlur, this) + .addListener(container, 'mousedown', this._onMouseDown, this); + + this._map + .on('focus', this._addHooks, this) + .on('blur', this._removeHooks, this); + }, + + removeHooks: function () { + this._removeHooks(); + + var container = this._map._container; + L.DomEvent + .removeListener(container, 'focus', this._onFocus, this) + .removeListener(container, 'blur', this._onBlur, this) + .removeListener(container, 'mousedown', this._onMouseDown, this); + + this._map + .off('focus', this._addHooks, this) + .off('blur', this._removeHooks, this); + }, + + _onMouseDown: function () { + if (!this._focused) { + this._map._container.focus(); + } + }, + + _onFocus: function () { + this._focused = true; + this._map.fire('focus'); + }, + + _onBlur: function () { + this._focused = false; + this._map.fire('blur'); + }, + + _setPanOffset: function (pan) { + var keys = this._panKeys = {}, + codes = this.keyCodes, + i, len; + + for (i = 0, len = codes.left.length; i < len; i++) { + keys[codes.left[i]] = [-1 * pan, 0]; + } + for (i = 0, len = codes.right.length; i < len; i++) { + keys[codes.right[i]] = [pan, 0]; + } + for (i = 0, len = codes.down.length; i < len; i++) { + keys[codes.down[i]] = [0, pan]; + } + for (i = 0, len = codes.up.length; i < len; i++) { + keys[codes.up[i]] = [0, -1 * pan]; + } + }, + + _setZoomOffset: function (zoom) { + var keys = this._zoomKeys = {}, + codes = this.keyCodes, + i, len; + + for (i = 0, len = codes.zoomIn.length; i < len; i++) { + keys[codes.zoomIn[i]] = zoom; + } + for (i = 0, len = codes.zoomOut.length; i < len; i++) { + keys[codes.zoomOut[i]] = -zoom; + } + }, + + _addHooks: function () { + L.DomEvent.addListener(document, 'keydown', this._onKeyDown, this); + }, + + _removeHooks: function () { + L.DomEvent.removeListener(document, 'keydown', this._onKeyDown, this); + }, + + _onKeyDown: function (e) { + var key = e.keyCode; + + if (this._panKeys.hasOwnProperty(key)) { + this._map.panBy(this._panKeys[key]); + + } else if (this._zoomKeys.hasOwnProperty(key)) { + this._map.setZoom(this._map.getZoom() + this._zoomKeys[key]); + + } else { + return; + } + + L.DomEvent.stop(e); + } +}); + +L.Map.addInitHook('addHandler', 'keyboard', L.Map.Keyboard); + /* * L.Handler.MarkerDrag is used internally by L.Marker to make the markers draggable. @@ -4709,9 +6203,7 @@ L.Handler.MarkerDrag = L.Handler.extend({ addHooks: function () { var icon = this._marker._icon; if (!this._draggable) { - this._draggable = new L.Draggable(icon, icon); - - this._draggable + this._draggable = new L.Draggable(icon, icon) .on('dragstart', this._onDragStart, this) .on('drag', this._onDrag, this) .on('dragend', this._onDragEnd, this); @@ -4756,24 +6248,254 @@ L.Handler.MarkerDrag = L.Handler.extend({ }); +L.Handler.PolyEdit = L.Handler.extend({ + options: { + icon: new L.DivIcon({ + iconSize: new L.Point(8, 8), + className: 'leaflet-div-icon leaflet-editing-icon' + }) + }, -L.Control = {}; + initialize: function (poly, options) { + this._poly = poly; + L.Util.setOptions(this, options); + }, -L.Control.Position = { - TOP_LEFT: 'topLeft', - TOP_RIGHT: 'topRight', - BOTTOM_LEFT: 'bottomLeft', - BOTTOM_RIGHT: 'bottomRight' -}; + addHooks: function () { + if (this._poly._map) { + if (!this._markerGroup) { + this._initMarkers(); + } + this._poly._map.addLayer(this._markerGroup); + } + }, + + removeHooks: function () { + if (this._poly._map) { + this._poly._map.removeLayer(this._markerGroup); + delete this._markerGroup; + delete this._markers; + } + }, + + updateMarkers: function () { + this._markerGroup.clearLayers(); + this._initMarkers(); + }, + + _initMarkers: function () { + if (!this._markerGroup) { + this._markerGroup = new L.LayerGroup(); + } + this._markers = []; + + var latlngs = this._poly._latlngs, + i, j, len, marker; + + // TODO refactor holes implementation in Polygon to support it here + + for (i = 0, len = latlngs.length; i < len; i++) { + + marker = this._createMarker(latlngs[i], i); + marker.on('click', this._onMarkerClick, this); + this._markers.push(marker); + } + + var markerLeft, markerRight; + + for (i = 0, j = len - 1; i < len; j = i++) { + if (i === 0 && !(L.Polygon && (this._poly instanceof L.Polygon))) { + continue; + } + + markerLeft = this._markers[j]; + markerRight = this._markers[i]; + + this._createMiddleMarker(markerLeft, markerRight); + this._updatePrevNext(markerLeft, markerRight); + } + }, + + _createMarker: function (latlng, index) { + var marker = new L.Marker(latlng, { + draggable: true, + icon: this.options.icon + }); + + marker._origLatLng = latlng; + marker._index = index; + + marker.on('drag', this._onMarkerDrag, this); + marker.on('dragend', this._fireEdit, this); + + this._markerGroup.addLayer(marker); + + return marker; + }, + + _fireEdit: function () { + this._poly.fire('edit'); + }, + + _onMarkerDrag: function (e) { + var marker = e.target; + + L.Util.extend(marker._origLatLng, marker._latlng); + + if (marker._middleLeft) { + marker._middleLeft.setLatLng(this._getMiddleLatLng(marker._prev, marker)); + } + if (marker._middleRight) { + marker._middleRight.setLatLng(this._getMiddleLatLng(marker, marker._next)); + } + + this._poly.redraw(); + }, + + _onMarkerClick: function (e) { + // Default action on marker click is to remove that marker, but if we remove the marker when latlng count < 3, we don't have a valid polyline anymore + if (this._poly._latlngs.length < 3) { + return; + } + + var marker = e.target, + i = marker._index; + + // Check existence of previous and next markers since they wouldn't exist for edge points on the polyline + if (marker._prev && marker._next) { + this._createMiddleMarker(marker._prev, marker._next); + this._updatePrevNext(marker._prev, marker._next); + } + + // The marker itself is guaranteed to exist and present in the layer, since we managed to click on it + this._markerGroup.removeLayer(marker); + // Check for the existence of middle left or middle right + if (marker._middleLeft) { + this._markerGroup.removeLayer(marker._middleLeft); + } + if (marker._middleRight) { + this._markerGroup.removeLayer(marker._middleRight); + } + this._markers.splice(i, 1); + this._poly.spliceLatLngs(i, 1); + this._updateIndexes(i, -1); + this._poly.fire('edit'); + }, + + _updateIndexes: function (index, delta) { + this._markerGroup.eachLayer(function (marker) { + if (marker._index > index) { + marker._index += delta; + } + }); + }, + + _createMiddleMarker: function (marker1, marker2) { + var latlng = this._getMiddleLatLng(marker1, marker2), + marker = this._createMarker(latlng), + onClick, + onDragStart, + onDragEnd; + + marker.setOpacity(0.6); + + marker1._middleRight = marker2._middleLeft = marker; + + onDragStart = function () { + var i = marker2._index; + + marker._index = i; + + marker + .off('click', onClick) + .on('click', this._onMarkerClick, this); + + latlng.lat = marker.getLatLng().lat; + latlng.lng = marker.getLatLng().lng; + this._poly.spliceLatLngs(i, 0, latlng); + this._markers.splice(i, 0, marker); + + marker.setOpacity(1); + + this._updateIndexes(i, 1); + marker2._index++; + this._updatePrevNext(marker1, marker); + this._updatePrevNext(marker, marker2); + }; + + onDragEnd = function () { + marker.off('dragstart', onDragStart, this); + marker.off('dragend', onDragEnd, this); + + this._createMiddleMarker(marker1, marker); + this._createMiddleMarker(marker, marker2); + }; + + onClick = function () { + onDragStart.call(this); + onDragEnd.call(this); + this._poly.fire('edit'); + }; + + marker + .on('click', onClick, this) + .on('dragstart', onDragStart, this) + .on('dragend', onDragEnd, this); + + this._markerGroup.addLayer(marker); + }, + + _updatePrevNext: function (marker1, marker2) { + marker1._next = marker2; + marker2._prev = marker1; + }, + + _getMiddleLatLng: function (marker1, marker2) { + var map = this._poly._map, + p1 = map.latLngToLayerPoint(marker1.getLatLng()), + p2 = map.latLngToLayerPoint(marker2.getLatLng()); + + return map.layerPointToLatLng(p1._add(p2).divideBy(2)); + } +}); -L.Map.include({ - addControl: function (control) { - control.onAdd(this); - var pos = control.getPosition(), - corner = this._controlCorners[pos], - container = control.getContainer(); +L.Control = L.Class.extend({ + options: { + position: 'topright' + }, + + initialize: function (options) { + L.Util.setOptions(this, options); + }, + + getPosition: function () { + return this.options.position; + }, + + setPosition: function (position) { + var map = this._map; + + if (map) { + map.removeControl(this); + } + + this.options.position = position; + + if (map) { + map.addControl(this); + } + + return this; + }, + + addTo: function (map) { + this._map = map; + + var container = this._container = this.onAdd(map), + pos = this.getPosition(), + corner = map._controlCorners[pos]; L.DomUtil.addClass(container, 'leaflet-control'); @@ -4782,164 +6504,341 @@ L.Map.include({ } else { corner.appendChild(container); } + + return this; + }, + + removeFrom: function (map) { + var pos = this.getPosition(), + corner = map._controlCorners[pos]; + + corner.removeChild(this._container); + this._map = null; + + if (this.onRemove) { + this.onRemove(map); + } + + return this; + } +}); + +L.control = function (options) { + return new L.Control(options); +}; + + +L.Map.include({ + addControl: function (control) { + control.addTo(this); return this; }, removeControl: function (control) { - var pos = control.getPosition(), - corner = this._controlCorners[pos], - container = control.getContainer(); - - corner.removeChild(container); - - if (control.onRemove) { - control.onRemove(this); - } + control.removeFrom(this); return this; }, _initControlPos: function () { var corners = this._controlCorners = {}, - classPart = 'leaflet-', - top = classPart + 'top', - bottom = classPart + 'bottom', - left = classPart + 'left', - right = classPart + 'right', - controlContainer = L.DomUtil.create('div', classPart + 'control-container', this._container); + l = 'leaflet-', + container = this._controlContainer = + L.DomUtil.create('div', l + 'control-container', this._container); - if (L.Browser.touch) { - controlContainer.className += ' ' + classPart + 'big-buttons'; + function createCorner(vSide, hSide) { + var className = l + vSide + ' ' + l + hSide; + + corners[vSide + hSide] = + L.DomUtil.create('div', className, container); } - corners.topLeft = L.DomUtil.create('div', top + ' ' + left, controlContainer); - corners.topRight = L.DomUtil.create('div', top + ' ' + right, controlContainer); - corners.bottomLeft = L.DomUtil.create('div', bottom + ' ' + left, controlContainer); - corners.bottomRight = L.DomUtil.create('div', bottom + ' ' + right, controlContainer); + createCorner('top', 'left'); + createCorner('top', 'right'); + createCorner('bottom', 'left'); + createCorner('bottom', 'right'); } }); +L.Control.Zoom = L.Control.extend({ + options: { + position: 'topleft' + }, -L.Control.Zoom = L.Class.extend({ onAdd: function (map) { - this._map = map; - this._container = L.DomUtil.create('div', 'leaflet-control-zoom'); + var className = 'leaflet-control-zoom', + container = L.DomUtil.create('div', className); - this._zoomInButton = this._createButton( - 'Zoom in', 'leaflet-control-zoom-in', this._map.zoomIn, this._map); - this._zoomOutButton = this._createButton( - 'Zoom out', 'leaflet-control-zoom-out', this._map.zoomOut, this._map); + this._createButton('Zoom in', className + '-in', container, map.zoomIn, map); + this._createButton('Zoom out', className + '-out', container, map.zoomOut, map); - this._container.appendChild(this._zoomInButton); - this._container.appendChild(this._zoomOutButton); + return container; }, - getContainer: function () { - return this._container; - }, - - getPosition: function () { - return L.Control.Position.TOP_LEFT; - }, - - _createButton: function (title, className, fn, context) { - var link = document.createElement('a'); + _createButton: function (title, className, container, fn, context) { + var link = L.DomUtil.create('a', className, container); link.href = '#'; link.title = title; - link.className = className; - if (!L.Browser.touch) { - L.DomEvent.disableClickPropagation(link); - } - L.DomEvent.addListener(link, 'click', L.DomEvent.preventDefault); - L.DomEvent.addListener(link, 'click', fn, context); + L.DomEvent + .on(link, 'click', L.DomEvent.stopPropagation) + .on(link, 'click', L.DomEvent.preventDefault) + .on(link, 'click', fn, context) + .on(link, 'dblclick', L.DomEvent.stopPropagation); return link; } }); +L.Map.mergeOptions({ + zoomControl: true +}); + +L.Map.addInitHook(function () { + if (this.options.zoomControl) { + this.zoomControl = new L.Control.Zoom(); + this.addControl(this.zoomControl); + } +}); + +L.control.zoom = function (options) { + return new L.Control.Zoom(options); +}; + +L.Control.Attribution = L.Control.extend({ + options: { + position: 'bottomright', + prefix: 'Powered by Leaflet' + }, + + initialize: function (options) { + L.Util.setOptions(this, options); -L.Control.Attribution = L.Class.extend({ - initialize: function (prefix) { - this._prefix = prefix || 'Powered by Leaflet'; this._attributions = {}; }, onAdd: function (map) { this._container = L.DomUtil.create('div', 'leaflet-control-attribution'); L.DomEvent.disableClickPropagation(this._container); - this._map = map; + + map + .on('layeradd', this._onLayerAdd, this) + .on('layerremove', this._onLayerRemove, this); + this._update(); - }, - getPosition: function () { - return L.Control.Position.BOTTOM_RIGHT; - }, - - getContainer: function () { return this._container; }, + onRemove: function (map) { + map + .off('layeradd', this._onLayerAdd) + .off('layerremove', this._onLayerRemove); + + }, + setPrefix: function (prefix) { - this._prefix = prefix; + this.options.prefix = prefix; this._update(); + return this; }, addAttribution: function (text) { - if (!text) { - return; - } + if (!text) { return; } + if (!this._attributions[text]) { this._attributions[text] = 0; } this._attributions[text]++; + this._update(); + + return this; }, removeAttribution: function (text) { - if (!text) { - return; - } + if (!text) { return; } + this._attributions[text]--; this._update(); + + return this; }, _update: function () { - if (!this._map) { - return; - } + if (!this._map) { return; } var attribs = []; for (var i in this._attributions) { - if (this._attributions.hasOwnProperty(i) && this._attributions[i]) { // DS_CHANGE: fix for attribution bug (also changed in leaflet.js!) + if (this._attributions.hasOwnProperty(i) && this._attributions[i]) { attribs.push(i); } } var prefixAndAttribs = []; - if (this._prefix) { - prefixAndAttribs.push(this._prefix); + + if (this.options.prefix) { + prefixAndAttribs.push(this.options.prefix); } if (attribs.length) { prefixAndAttribs.push(attribs.join(', ')); } - this._container.innerHTML = prefixAndAttribs.join(' — '); + this._container.innerHTML = prefixAndAttribs.join(' — '); + }, + + _onLayerAdd: function (e) { + if (e.layer.getAttribution) { + this.addAttribution(e.layer.getAttribution()); + } + }, + + _onLayerRemove: function (e) { + if (e.layer.getAttribution) { + this.removeAttribution(e.layer.getAttribution()); + } } }); +L.Map.mergeOptions({ + attributionControl: true +}); + +L.Map.addInitHook(function () { + if (this.options.attributionControl) { + this.attributionControl = (new L.Control.Attribution()).addTo(this); + } +}); + +L.control.attribution = function (options) { + return new L.Control.Attribution(options); +}; -L.Control.Layers = L.Class.extend({ +L.Control.Scale = L.Control.extend({ options: { - collapsed: true + position: 'bottomleft', + maxWidth: 100, + metric: true, + imperial: true, + updateWhenIdle: false + }, + + onAdd: function (map) { + this._map = map; + + var className = 'leaflet-control-scale', + container = L.DomUtil.create('div', className), + options = this.options; + + this._addScales(options, className, container); + + map.on(options.updateWhenIdle ? 'moveend' : 'move', this._update, this); + this._update(); + + return container; + }, + + onRemove: function (map) { + map.off(this.options.updateWhenIdle ? 'moveend' : 'move', this._update, this); + }, + + _addScales: function (options, className, container) { + if (options.metric) { + this._mScale = L.DomUtil.create('div', className + '-line', container); + } + if (options.imperial) { + this._iScale = L.DomUtil.create('div', className + '-line', container); + } + }, + + _update: function () { + var bounds = this._map.getBounds(), + centerLat = bounds.getCenter().lat, + halfWorldMeters = 6378137 * Math.PI * Math.cos(centerLat * Math.PI / 180), + dist = halfWorldMeters * (bounds.getNorthEast().lng - bounds.getSouthWest().lng) / 180, + + size = this._map.getSize(), + options = this.options, + maxMeters = 0; + + if (size.x > 0) { + maxMeters = dist * (options.maxWidth / size.x); + } + + this._updateScales(options, maxMeters); + }, + + _updateScales: function (options, maxMeters) { + if (options.metric && maxMeters) { + this._updateMetric(maxMeters); + } + + if (options.imperial && maxMeters) { + this._updateImperial(maxMeters); + } + }, + + _updateMetric: function (maxMeters) { + var meters = this._getRoundNum(maxMeters); + + this._mScale.style.width = this._getScaleWidth(meters / maxMeters) + 'px'; + this._mScale.innerHTML = meters < 1000 ? meters + ' m' : (meters / 1000) + ' km'; + }, + + _updateImperial: function (maxMeters) { + var maxFeet = maxMeters * 3.2808399, + scale = this._iScale, + maxMiles, miles, feet; + + if (maxFeet > 5280) { + maxMiles = maxFeet / 5280; + miles = this._getRoundNum(maxMiles); + + scale.style.width = this._getScaleWidth(miles / maxMiles) + 'px'; + scale.innerHTML = miles + ' mi'; + + } else { + feet = this._getRoundNum(maxFeet); + + scale.style.width = this._getScaleWidth(feet / maxFeet) + 'px'; + scale.innerHTML = feet + ' ft'; + } + }, + + _getScaleWidth: function (ratio) { + return Math.round(this.options.maxWidth * ratio) - 10; + }, + + _getRoundNum: function (num) { + var pow10 = Math.pow(10, (Math.floor(num) + '').length - 1), + d = num / pow10; + + d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : 1; + + return pow10 * d; + } +}); + +L.control.scale = function (options) { + return new L.Control.Scale(options); +}; + + + +L.Control.Layers = L.Control.extend({ + options: { + collapsed: true, + position: 'topright', + autoZIndex: true }, initialize: function (baseLayers, overlays, options) { L.Util.setOptions(this, options); this._layers = {}; + this._lastZIndex = 0; for (var i in baseLayers) { if (baseLayers.hasOwnProperty(i)) { @@ -4955,20 +6854,12 @@ L.Control.Layers = L.Class.extend({ }, onAdd: function (map) { - this._map = map; - this._initLayout(); this._update(); - }, - getContainer: function () { return this._container; }, - getPosition: function () { - return L.Control.Position.TOP_RIGHT; - }, - addBaseLayer: function (layer, name) { this._addLayer(layer, name); this._update(); @@ -4989,49 +6880,62 @@ L.Control.Layers = L.Class.extend({ }, _initLayout: function () { - this._container = L.DomUtil.create('div', 'leaflet-control-layers'); + var className = 'leaflet-control-layers', + container = this._container = L.DomUtil.create('div', className); + if (!L.Browser.touch) { - L.DomEvent.disableClickPropagation(this._container); + L.DomEvent.disableClickPropagation(container); + } else { + L.DomEvent.on(container, 'click', L.DomEvent.stopPropagation); } - this._form = L.DomUtil.create('form', 'leaflet-control-layers-list'); + var form = this._form = L.DomUtil.create('form', className + '-list'); if (this.options.collapsed) { - L.DomEvent.addListener(this._container, 'mouseover', this._expand, this); - L.DomEvent.addListener(this._container, 'mouseout', this._collapse, this); + L.DomEvent + .on(container, 'mouseover', this._expand, this) + .on(container, 'mouseout', this._collapse, this); - var link = this._layersLink = L.DomUtil.create('a', 'leaflet-control-layers-toggle'); + var link = this._layersLink = L.DomUtil.create('a', className + '-toggle', container); link.href = '#'; link.title = 'Layers'; if (L.Browser.touch) { - L.DomEvent.addListener(link, 'click', this._expand, this); - //L.DomEvent.disableClickPropagation(link); - } else { - L.DomEvent.addListener(link, 'focus', this._expand, this); + L.DomEvent + .on(link, 'click', L.DomEvent.stopPropagation) + .on(link, 'click', L.DomEvent.preventDefault) + .on(link, 'click', this._expand, this); } + else { + L.DomEvent.on(link, 'focus', this._expand, this); + } + this._map.on('movestart', this._collapse, this); // TODO keyboard accessibility - - this._container.appendChild(link); } else { this._expand(); } - this._baseLayersList = L.DomUtil.create('div', 'leaflet-control-layers-base', this._form); - this._separator = L.DomUtil.create('div', 'leaflet-control-layers-separator', this._form); - this._overlaysList = L.DomUtil.create('div', 'leaflet-control-layers-overlays', this._form); + this._baseLayersList = L.DomUtil.create('div', className + '-base', form); + this._separator = L.DomUtil.create('div', className + '-separator', form); + this._overlaysList = L.DomUtil.create('div', className + '-overlays', form); - this._container.appendChild(this._form); + container.appendChild(form); }, _addLayer: function (layer, name, overlay) { var id = L.Util.stamp(layer); + this._layers[id] = { layer: layer, name: name, overlay: overlay }; + + if (this.options.autoZIndex && layer.setZIndex) { + this._lastZIndex++; + layer.setZIndex(this._lastZIndex); + } }, _update: function () { @@ -5057,18 +6961,37 @@ L.Control.Layers = L.Class.extend({ this._separator.style.display = (overlaysPresent && baseLayersPresent ? '' : 'none'); }, - _addItem: function (obj, onclick) { - var label = document.createElement('label'); + // IE7 bugs out if you create a radio dynamically, so you have to do it this hacky way (see http://bit.ly/PqYLBe) + _createRadioElement: function (name, checked) { - var input = document.createElement('input'); - if (!obj.overlay) { - input.name = 'leaflet-base-layers'; + var radioHtml = ' 0.5 && + this._getLoadedTilesPercentage(tilePane) < 0.5) { + + tilePane.style.visibility = 'hidden'; + tilePane.empty = true; + this._stopLoadingImages(tilePane); + return; + } + + if (!tileBg) { + tileBg = this._tileBg = this._createPane('leaflet-tile-pane', this._mapPane); + tileBg.style.zIndex = 1; + } + // prepare the background pane to become the main tile pane - //tileBg.innerHTML = ''; tileBg.style[L.DomUtil.TRANSFORM] = ''; tileBg.style.visibility = 'hidden'; // tells tile layers to reinitialize their containers - tileBg.empty = true; - tilePane.empty = false; + tileBg.empty = true; //new FG + tilePane.empty = false; //new BG + //Switch out the current layer to be the new bg layer (And vice-versa) this._tilePane = this._panes.tilePane = tileBg; - this._tileBg = tilePane; + var newTileBg = this._tileBg = tilePane; - if (!this._tileBg.transition) { - this._tileBg.transition = new L.Transition(this._tileBg, {duration: 0.3, easing: 'cubic-bezier(0.25,0.1,0.25,0.75)'}); - this._tileBg.transition.on('end', this._onZoomTransitionEnd, this); + L.DomUtil.addClass(newTileBg, 'leaflet-zoom-animated'); + + this._stopLoadingImages(newTileBg); + }, + + _getLoadedTilesPercentage: function (container) { + var tiles = container.getElementsByTagName('img'), + i, len, count = 0; + + for (i = 0, len = tiles.length; i < len; i++) { + if (tiles[i].complete) { + count++; + } } - - this._stopLoadingBgTiles(); + return count / len; }, // stops loading all tiles in the background layer - _stopLoadingBgTiles: function () { - var tiles = [].slice.call(this._tileBg.getElementsByTagName('img')); + _stopLoadingImages: function (container) { + var tiles = Array.prototype.slice.call(container.getElementsByTagName('img')), + i, len, tile; - for (var i = 0, len = tiles.length; i < len; i++) { - if (!tiles[i].complete) { - tiles[i].onload = L.Util.falseFn; - tiles[i].onerror = L.Util.falseFn; - tiles[i].src = 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='; + for (i = 0, len = tiles.length; i < len; i++) { + tile = tiles[i]; - tiles[i].parentNode.removeChild(tiles[i]); - tiles[i] = null; + if (!tile.complete) { + tile.onload = L.Util.falseFn; + tile.onerror = L.Util.falseFn; + tile.src = L.Util.emptyImageUrl; + + tile.parentNode.removeChild(tile); } } }, _onZoomTransitionEnd: function () { this._restoreTileFront(); - - L.Util.falseFn(this._tileBg.offsetWidth); + L.Util.falseFn(this._tileBg.offsetWidth); // force reflow this._resetView(this._animateToCenter, this._animateToZoom, true, true); - this._mapPane.className = this._mapPane.className.replace(' leaflet-zoom-anim', ''); //TODO toggleClass util + L.DomUtil.removeClass(this._mapPane, 'leaflet-zoom-anim'); this._animatingZoom = false; }, @@ -5585,22 +7550,25 @@ L.Map.include(!L.DomUtil.TRANSITION ? {} : { */ L.Map.include({ + _defaultLocateOptions: { + watch: false, + setView: false, + maxZoom: Infinity, + timeout: 10000, + maximumAge: 0, + enableHighAccuracy: false + }, + locate: function (/*Object*/ options) { - this._locationOptions = options = L.Util.extend({ - watch: false, - setView: false, - maxZoom: Infinity, - timeout: 10000, - maximumAge: 0, - enableHighAccuracy: false - }, options); + options = this._locationOptions = L.Util.extend(this._defaultLocateOptions, options); if (!navigator.geolocation) { - return this.fire('locationerror', { + this._handleGeolocationError({ code: 0, message: "Geolocation not supported." }); + return this; } var onResponse = L.Util.bind(this._handleGeolocationResponse, this), @@ -5618,19 +7586,13 @@ L.Map.include({ if (navigator.geolocation) { navigator.geolocation.clearWatch(this._locationWatchId); } - }, - - locateAndSetView: function (maxZoom, options) { - options = L.Util.extend({ - maxZoom: maxZoom || Infinity, - setView: true - }, options); - return this.locate(options); + return this; }, _handleGeolocationError: function (error) { var c = error.code, - message = (c === 1 ? "permission denied" : + message = error.message || + (c === 1 ? "permission denied" : (c === 2 ? "position unavailable" : "timeout")); if (this._locationOptions.setView && !this._loaded) { @@ -5646,16 +7608,19 @@ L.Map.include({ _handleGeolocationResponse: function (pos) { var latAccuracy = 180 * pos.coords.accuracy / 4e7, lngAccuracy = latAccuracy * 2, + lat = pos.coords.latitude, lng = pos.coords.longitude, - latlng = new L.LatLng(lat, lng); + latlng = new L.LatLng(lat, lng), - var sw = new L.LatLng(lat - latAccuracy, lng - lngAccuracy), + sw = new L.LatLng(lat - latAccuracy, lng - lngAccuracy), ne = new L.LatLng(lat + latAccuracy, lng + lngAccuracy), - bounds = new L.LatLngBounds(sw, ne); + bounds = new L.LatLngBounds(sw, ne), - if (this._locationOptions.setView) { - var zoom = Math.min(this.getBoundsZoom(bounds), this._locationOptions.maxZoom); + options = this._locationOptions; + + if (options.setView) { + var zoom = Math.min(this.getBoundsZoom(bounds), options.maxZoom); this.setView(latlng, zoom); } @@ -5668,3 +7633,6 @@ L.Map.include({ }); + + +}(this)); \ No newline at end of file diff --git a/WebContent/leaflet/leaflet.css b/WebContent/leaflet/leaflet.css index 119ddb2bc..c76c54a68 100644 --- a/WebContent/leaflet/leaflet.css +++ b/WebContent/leaflet/leaflet.css @@ -11,14 +11,13 @@ .leaflet-popup-pane, .leaflet-overlay-pane svg, .leaflet-zoom-box, -.leaflet-image-layer { /* TODO optimize classes */ +.leaflet-image-layer, +.leaflet-layer { /* TODO optimize classes */ position: absolute; } .leaflet-container { overflow: hidden; - } -.leaflet-tile-pane, .leaflet-container { - -webkit-transform: translate3d(0,0,0); + outline: 0; } .leaflet-tile, .leaflet-marker-icon, @@ -34,44 +33,50 @@ .leaflet-clickable { cursor: pointer; } +.leaflet-dragging, .leaflet-dragging .leaflet-clickable { + cursor: move; + } .leaflet-container img { + /* map is broken in FF if you have max-width: 100% on tiles */ max-width: none !important; } +.leaflet-container img.leaflet-image-layer { + /* stupid Android 2 doesn't understand "max-width: none" properly */ + max-width: 15000px !important; + } .leaflet-tile-pane { z-index: 2; } - .leaflet-objects-pane { z-index: 3; } .leaflet-overlay-pane { z-index: 4; } .leaflet-shadow-pane { z-index: 5; } .leaflet-marker-pane { z-index: 6; } .leaflet-popup-pane { z-index: 7; } -.leaflet-zoom-box { - width: 0; - height: 0; - } - .leaflet-tile { - visibility: hidden; + filter: inherit; + visibility: hidden; } .leaflet-tile-loaded { visibility: inherit; } -a.leaflet-active { - outline: 2px solid orange; - } - +.leaflet-zoom-box { + width: 0; + height: 0; + } /* Leaflet controls */ .leaflet-control { position: relative; z-index: 7; + pointer-events: auto; } .leaflet-top, .leaflet-bottom { position: absolute; + z-index: 1000; + pointer-events: none; } .leaflet-top { top: 0; @@ -105,7 +110,7 @@ a.leaflet-active { margin-right: 10px; } -.leaflet-control-zoom, .leaflet-control-layers { +.leaflet-control-zoom { -moz-border-radius: 7px; -webkit-border-radius: 7px; border-radius: 7px; @@ -132,7 +137,7 @@ a.leaflet-active { .leaflet-control-zoom a:hover { background-color: #fff; } -.leaflet-big-buttons .leaflet-control-zoom a { +.leaflet-touch .leaflet-control-zoom a { width: 27px; height: 27px; } @@ -145,18 +150,18 @@ a.leaflet-active { } .leaflet-control-layers { - -moz-box-shadow: 0 0 7px #999; - -webkit-box-shadow: 0 0 7px #999; - box-shadow: 0 0 7px #999; - + box-shadow: 0 1px 7px #999; background: #f8f8f9; + -moz-border-radius: 8px; + -webkit-border-radius: 8px; + border-radius: 8px; } .leaflet-control-layers a { background-image: url(images/layers.png); width: 36px; height: 36px; } -.leaflet-big-buttons .leaflet-control-layers a { +.leaflet-touch .leaflet-control-layers a { width: 44px; height: 44px; } @@ -189,23 +194,60 @@ a.leaflet-active { } .leaflet-container .leaflet-control-attribution { - margin: 0; - padding: 0 5px; - - font: 11px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif; - color: #333; - background-color: rgba(255, 255, 255, 0.7); + box-shadow: 0 0 5px #bbb; + margin: 0; + } - -moz-box-shadow: 0 0 7px #ccc; - -webkit-box-shadow: 0 0 7px #ccc; - box-shadow: 0 0 7px #ccc; +.leaflet-control-attribution, +.leaflet-control-scale-line { + padding: 0 5px; + color: #333; + } + +.leaflet-container .leaflet-control-attribution, +.leaflet-container .leaflet-control-scale { + font: 11px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif; + } + +.leaflet-left .leaflet-control-scale { + margin-left: 5px; + } +.leaflet-bottom .leaflet-control-scale { + margin-bottom: 5px; + } + +.leaflet-control-scale-line { + border: 2px solid #777; + border-top: none; + color: black; + line-height: 1; + font-size: 10px; + padding-bottom: 2px; + text-shadow: 1px 1px 1px #fff; + background-color: rgba(255, 255, 255, 0.5); + } +.leaflet-control-scale-line:not(:first-child) { + border-top: 2px solid #777; + padding-top: 1px; + border-bottom: none; + margin-top: -2px; + } +.leaflet-control-scale-line:not(:first-child):not(:last-child) { + border-bottom: 2px solid #777; + } + +.leaflet-touch .leaflet-control-attribution, .leaflet-touch .leaflet-control-layers { + box-shadow: none; + } +.leaflet-touch .leaflet-control-layers { + border: 5px solid #bbb; } -/* Fade animations */ +/* Zoom and fade animations */ -.leaflet-fade-anim .leaflet-tile { +.leaflet-fade-anim .leaflet-tile, .leaflet-fade-anim .leaflet-popup { opacity: 0; -webkit-transition: opacity 0.2s linear; @@ -213,30 +255,27 @@ a.leaflet-active { -o-transition: opacity 0.2s linear; transition: opacity 0.2s linear; } -.leaflet-fade-anim .leaflet-tile-loaded { +.leaflet-fade-anim .leaflet-tile-loaded, .leaflet-fade-anim .leaflet-map-pane .leaflet-popup { opacity: 1; } -.leaflet-fade-anim .leaflet-popup { - opacity: 0; - - -webkit-transition: opacity 0.2s linear; - -moz-transition: opacity 0.2s linear; - -o-transition: opacity 0.2s linear; - transition: opacity 0.2s linear; - } -.leaflet-fade-anim .leaflet-map-pane .leaflet-popup { - opacity: 1; +.leaflet-zoom-anim .leaflet-zoom-animated { + -webkit-transition: -webkit-transform 0.25s cubic-bezier(0.25,0.1,0.25,0.75); + -moz-transition: -moz-transform 0.25s cubic-bezier(0.25,0.1,0.25,0.75); + -o-transition: -o-transform 0.25s cubic-bezier(0.25,0.1,0.25,0.75); + transition: transform 0.25s cubic-bezier(0.25,0.1,0.25,0.75); } -.leaflet-zoom-anim .leaflet-tile { - -webkit-transition: none; - -moz-transition: none; - -o-transition: none; - transition: none; - } +.leaflet-zoom-anim .leaflet-tile, +.leaflet-pan-anim .leaflet-tile, +.leaflet-touching .leaflet-zoom-animated { + -webkit-transition: none; + -moz-transition: none; + -o-transition: none; + transition: none; + } -.leaflet-zoom-anim .leaflet-objects-pane { +.leaflet-zoom-anim .leaflet-zoom-hide { visibility: hidden; } @@ -246,19 +285,18 @@ a.leaflet-active { .leaflet-popup { position: absolute; text-align: center; - -webkit-transform: translate3d(0,0,0); } .leaflet-popup-content-wrapper { padding: 1px; text-align: left; } .leaflet-popup-content { - margin: 19px; + margin: 14px 20px; } .leaflet-popup-tip-container { margin: 0 auto; width: 40px; - height: 16px; + height: 20px; position: relative; overflow: hidden; } @@ -275,19 +313,30 @@ a.leaflet-active { -o-transform: rotate(45deg); transform: rotate(45deg); } -.leaflet-popup-close-button { +.leaflet-container a.leaflet-popup-close-button { position: absolute; - top: 9px; - right: 9px; - - width: 10px; - height: 10px; - - overflow: hidden; + top: 0; + right: 0; + padding: 4px 5px 0 0; + text-align: center; + width: 18px; + height: 14px; + font: 16px/14px Tahoma, Verdana, sans-serif; + color: #c3c3c3; + text-decoration: none; + font-weight: bold; + } +.leaflet-container a.leaflet-popup-close-button:hover { + color: #999; } .leaflet-popup-content p { margin: 18px 0; } +.leaflet-popup-scrolled { + overflow: auto; + border-bottom: 1px solid #ddd; + border-top: 1px solid #ddd; + } /* Visual appearance */ @@ -298,17 +347,27 @@ a.leaflet-active { .leaflet-container a { color: #0078A8; } +.leaflet-container a.leaflet-active { + outline: 2px solid orange; + } .leaflet-zoom-box { border: 2px dotted #05f; background: white; opacity: 0.5; } +.leaflet-div-icon { + background: #fff; + border: 1px solid #666; + } +.leaflet-editing-icon { + border-radius: 2px; + } .leaflet-popup-content-wrapper, .leaflet-popup-tip { background: white; - box-shadow: 0 1px 10px #888; - -moz-box-shadow: 0 1px 10px #888; - -webkit-box-shadow: 0 1px 14px #999; + box-shadow: 0 3px 10px #888; + -moz-box-shadow: 0 3px 10px #888; + -webkit-box-shadow: 0 3px 14px #999; } .leaflet-popup-content-wrapper { -moz-border-radius: 20px; @@ -318,6 +377,3 @@ a.leaflet-active { .leaflet-popup-content { font: 12px/1.4 "Helvetica Neue", Arial, Helvetica, sans-serif; } -.leaflet-popup-close-button { - background: white url(images/popup-close.png); - } diff --git a/WebContent/leaflet/leaflet.ie.css b/WebContent/leaflet/leaflet.ie.css index a120c0cb4..9d2a52fba 100644 --- a/WebContent/leaflet/leaflet.ie.css +++ b/WebContent/leaflet/leaflet.ie.css @@ -1,7 +1,3 @@ -.leaflet-tile { - filter: inherit; - } - .leaflet-vml-shape { width: 1px; height: 1px; diff --git a/WebContent/leaflet/leaflet.js b/WebContent/leaflet/leaflet.js index e02f0d5f8..d2ce4f8d5 100644 --- a/WebContent/leaflet/leaflet.js +++ b/WebContent/leaflet/leaflet.js @@ -1,6 +1,6 @@ /* - Copyright (c) 2010-2011, CloudMade, Vladimir Agafonkin - Leaflet is a modern open-source JavaScript library for interactive maps. + Copyright (c) 2010-2012, CloudMade, Vladimir Agafonkin + Leaflet is an open-source JavaScript library for mobile-friendly interactive maps. http://leaflet.cloudmade.com */ -(function(a){a.L={VERSION:"0.3",ROOT_URL:a.L_ROOT_URL||function(){var a=document.getElementsByTagName("script"),b=/\/?leaflet[\-\._]?([\w\-\._]*)\.js\??/,c,d,e,f;for(c=0,d=a.length;c0},removeEventListener:function(a,b,c){if(!this.hasEventListeners(a))return this;for(var d=0,e=this._leaflet_events,f=e[a].length;d=this.min.x&&c.x<=this.max.x&&b.y>=this.min.y&&c.y<=this.max.y},intersects:function(a){var b=this.min,c=this.max,d=a.min,e=a.max,f=e.x>=b.x&&d.x<=c.x,g=e.y>=b.y&&d.y<=c.y;return f&&g}}),L.Transformation=L.Class.extend({initialize:function(a,b,c,d){this._a=a,this._b=b,this._c=c,this._d=d},transform:function(a,b){return this._transform(a.clone(),b)},_transform:function(a,b){return b=b||1,a.x=b*(this._a*a.x+this._b),a.y=b*(this._c*a.y+this._d),a},untransform:function(a,b){return b=b||1,new L.Point((a.x/b-this._b)/this._a,(a.y/b-this._d)/this._c)}}),L.DomUtil={get:function(a){return typeof a=="string"?document.getElementById(a):a},getStyle:function(a,b){var c=a.style[b];!c&&a.currentStyle&&(c=a.currentStyle[b]);if(!c||c==="auto"){var d=document.defaultView.getComputedStyle(a,null);c=d?d[b]:null}return c==="auto"?null:c},getViewportOffset:function(a){var b=0,c=0,d=a,e=document.body;do{b+=d.offsetTop||0,c+=d.offsetLeft||0;if(d.offsetParent===e&&L.DomUtil.getStyle(d,"position")==="absolute")break;d=d.offsetParent}while(d);d=a;do{if(d===e)break;b-=d.scrollTop||0,c-=d.scrollLeft||0,d=d.parentNode}while(d);return new L.Point(c,b)},create:function(a,b,c){var d=document.createElement(a);return d.className=b,c&&c.appendChild(d),d},disableTextSelection:function(){document.selection&&document.selection.empty&&document.selection.empty(),this._onselectstart||(this._onselectstart=document.onselectstart,document.onselectstart=L.Util.falseFn)},enableTextSelection:function(){document.onselectstart=this._onselectstart,this._onselectstart=null},hasClass:function(a,b){return a.className.length>0&&RegExp("(^|\\s)"+b+"(\\s|$)").test(a.className)},addClass:function(a,b){L.DomUtil.hasClass(a,b)||(a.className+=(a.className?" ":"")+b)},removeClass:function(a,b){a.className=a.className.replace(/(\S+)\s*/g,function(a,c){return c===b?"":a}).replace(/^\s+/,"")},setOpacity:function(a,b){L.Browser.ie?a.style.filter="alpha(opacity="+Math.round(b*100)+")":a.style.opacity=b},testProp:function(a){var b=document.documentElement.style;for(var c=0;c=b.lat&&e.lat<=c.lat&&d.lng>=b.lng&&e.lng<=c.lng},intersects:function(a){var b=this._southWest,c=this._northEast,d=a.getSouthWest(),e=a.getNorthEast(),f=e.lat>=b.lat&&d.lat<=c.lat,g=e.lng>=b.lng&&d.lng<=c.lng;return f&&g},toBBoxString:function(){var a=this._southWest,b=this._northEast;return[a.lng,a.lat,b.lng,b.lat].join(",")}}),L.Projection={},L.Projection.SphericalMercator={MAX_LATITUDE:85.0511287798,project:function(a){var b=L.LatLng.DEG_TO_RAD,c=this.MAX_LATITUDE,d=Math.max(Math.min(c,a.lat),-c),e=a.lng*b,f=d*b;return f=Math.log(Math.tan(Math.PI/4+f/2)),new L.Point(e,f)},unproject:function(a,b){var c=L.LatLng.RAD_TO_DEG,d=a.x*c,e=(2*Math.atan(Math.exp(a.y))-Math.PI/2)*c;return new L.LatLng(e,d,b)}},L.Projection.LonLat={project:function(a){return new L.Point(a.lng,a.lat)},unproject:function(a,b){return new L.LatLng(a.y,a.x,b)}},L.CRS={latLngToPoint:function(a,b){var c=this.projection.project(a);return this.transformation._transform(c,b)},pointToLatLng:function(a,b,c){var d=this.transformation.untransform(a,b);return this.projection.unproject(d,c)},project:function(a){return this.projection.project(a)}},L.CRS.EPSG3857=L.Util.extend({},L.CRS,{code:"EPSG:3857",projection:L.Projection.SphericalMercator,transformation:new L.Transformation(.5/Math.PI,.5,-0.5/Math.PI,.5),project:function(a){var b=this.projection.project(a),c=6378137;return b.multiplyBy(c)}}),L.CRS.EPSG900913=L.Util.extend({},L.CRS.EPSG3857,{code:"EPSG:900913"}),L.CRS.EPSG4326=L.Util.extend({},L.CRS,{code:"EPSG:4326",projection:L.Projection.LonLat,transformation:new L.Transformation(1/360,.5,-1/360,.5)}),L.Map=L.Class.extend({includes:L.Mixin.Events,options:{crs:L.CRS.EPSG3857||L.CRS.EPSG4326,scale:function(a){return 256*Math.pow(2,a)},center:null,zoom:null,layers:[],dragging:!0,touchZoom:L.Browser.touch&&!L.Browser.android,scrollWheelZoom:!L.Browser.touch,doubleClickZoom:!0,boxZoom:!0,zoomControl:!0,attributionControl:!0,fadeAnimation:L.DomUtil.TRANSITION&&!L.Browser.android,zoomAnimation:L.DomUtil.TRANSITION&&!L.Browser.android&&!L.Browser.mobileOpera,trackResize:!0,closePopupOnClick:!0,worldCopyJump:!0},initialize:function(a,b){L.Util.setOptions(this,b),this._container=L.DomUtil.get(a);if(this._container._leaflet)throw Error("Map container is already initialized.");this._container._leaflet=!0,this._initLayout(),L.DomEvent&&(this._initEvents(),L.Handler&&this._initInteraction(),L.Control&&this._initControls()),this.options.maxBounds&&this.setMaxBounds(this.options.maxBounds);var c=this.options.center,d=this.options.zoom;c!==null&&d!==null&&this.setView(c,d,!0);var e=this.options.layers;e=e instanceof Array?e:[e],this._tileLayersNum=0,this._initLayers(e)},setView:function(a,b){return this._resetView(a,this._limitZoom(b)),this},setZoom:function(a){return this.setView(this.getCenter(),a)},zoomIn:function(){return this.setZoom(this._zoom+1)},zoomOut:function(){return this.setZoom(this._zoom-1)},fitBounds:function(a){var b=this.getBoundsZoom(a);return this.setView(a.getCenter(),b)},fitWorld:function(){var a=new L.LatLng(-60,-170),b=new L.LatLng(85,179);return this.fitBounds(new L.LatLngBounds(a,b))},panTo:function(a){return this.setView(a,this._zoom)},panBy:function(a){return this.fire("movestart"),this._rawPanBy(a),this.fire("move"),this.fire("moveend"),this},setMaxBounds:function(a){this.options.maxBounds=a;if(!a)return this._boundsMinZoom=null,this;var b=this.getBoundsZoom(a,!0);return this._boundsMinZoom=b,this._loaded&&(this._zoomf.x&&(g=f.x-d.x),c.y>e.y&&(h=e.y-c.y),c.xl&&--m>0)o=h*Math.sin(j),n=Math.PI/2-2*Math.atan(i*Math.pow((1-o)/(1+o),.5*h))-j,j+=n;return new L.LatLng(j*c,f,b)}},L.CRS.EPSG3395=L.Util.extend({},L.CRS,{code:"EPSG:3395",projection:L.Projection.Mercator,transformation:function(){var a=L.Projection.Mercator,b=a.R_MAJOR,c=a.R_MINOR;return new L.Transformation(.5/(Math.PI*b),.5,-0.5/(Math.PI*c),.5)}()}),L.TileLayer=L.Class.extend({includes:L.Mixin.Events,options:{minZoom:0,maxZoom:18,tileSize:256,subdomains:"abc",errorTileUrl:"",attribution:"",opacity:1,scheme:"xyz",continuousWorld:!1,noWrap:!1,zoomOffset:0,zoomReverse:!1,unloadInvisibleTiles:L.Browser.mobile,updateWhenIdle:L.Browser.mobile,reuseTiles:!1},initialize:function(a,b,c){L.Util.setOptions(this,b),this._url=a,this._urlParams=c,typeof this.options.subdomains=="string"&&(this.options.subdomains=this.options.subdomains.split(""))},onAdd:function(a,b){this._map=a,this._insertAtTheBottom=b,this._initContainer(),this._createTileProto(),a.on("viewreset",this._resetCallback,this),this.options.updateWhenIdle?a.on("moveend",this._update,this):(this._limitedUpdate=L.Util.limitExecByInterval(this._update,150,this),a.on("move",this._limitedUpdate,this)),this._reset(),this._update()},onRemove:function(a){this._map.getPanes().tilePane.removeChild(this._container),this._container=null,this._map.off("viewreset",this._resetCallback,this),this.options.updateWhenIdle?this._map.off("moveend",this._update,this):this._map.off("move",this._limitedUpdate,this)},getAttribution:function(){return this.options.attribution},setOpacity:function(a){this.options.opacity=a,this._setOpacity(a);if(L.Browser.webkit)for(var b in this._tiles)this._tiles.hasOwnProperty(b)&&(this._tiles[b].style.webkitTransform+=" translate(0,0)")},_setOpacity:function(a){a<1&&L.DomUtil.setOpacity(this._container,a)},_initContainer:function(){var a=this._map.getPanes().tilePane,b=a.firstChild;if(!this._container||a.empty)this._container=L.DomUtil.create("div","leaflet-layer"),this._insertAtTheBottom&&b?a.insertBefore(this._container,b):a.appendChild(this._container),this._setOpacity(this.options.opacity)},_resetCallback:function(a){this._reset(a.hard)},_reset:function(a){var b;for(b in this._tiles)this._tiles.hasOwnProperty(b)&&this.fire("tileunload",{tile:this._tiles[b]});this._tiles={},this.options.reuseTiles&&(this._unusedTiles=[]),a&&this._container&&(this._container.innerHTML=""),this._initContainer()},_update:function(){var a=this._map.getPixelBounds(),b=this._map.getZoom(),c=this.options.tileSize;if(b>this.options.maxZoom||ba.max.x||da.max.y)f=this._tiles[e],this.fire("tileunload",{tile:f,url:f.src}),f.parentNode===this._container&&this._container.removeChild(f),this.options.reuseTiles&&this._unusedTiles.push(this._tiles[e]),f.src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=",delete this._tiles[e]}},_addTile:function(a,b){var c=this._getTilePos(a),d=this._map.getZoom(),e=a.x+":"+a.y,f=Math.pow(2,this._getOffsetZoom(d));if(!this.options.continuousWorld){if(!this.options.noWrap)a.x=(a.x%f+f)%f;else if(a.x<0||a.x>=f){this._tilesToLoad--;return}if(a.y<0||a.y>=f){this._tilesToLoad--;return}}var g=this._getTile();L.DomUtil.setPosition(g,c),this._tiles[e]=g,this.options.scheme==="tms"&&(a.y=f-a.y-1),this._loadTile(g,a,d),b.appendChild(g)},_getOffsetZoom:function(a){return a=this.options.zoomReverse?this.options.maxZoom-a:a,a+this.options.zoomOffset},_getTilePos:function(a){var b=this._map.getPixelOrigin(),c=this.options.tileSize;return a.multiplyBy(c).subtract(b)},getTileUrl:function(a,b){var c=this.options.subdomains,d=this.options.subdomains[(a.x+a.y)%c.length];return L.Util.template(this._url,L.Util.extend({s:d,z:this._getOffsetZoom(b),x:a.x,y:a.y},this._urlParams))},_createTileProto:function(){this._tileImg=L.DomUtil.create("img","leaflet-tile"),this._tileImg.galleryimg="no";var a=this.options.tileSize;this._tileImg.style.width=a+"px",this._tileImg.style.height=a+"px"},_getTile:function(){if(this.options.reuseTiles&&this._unusedTiles.length>0){var a=this._unusedTiles.pop();return this._resetTile(a),a}return this._createTile()},_resetTile:function(a){},_createTile:function(){var a=this._tileImg.cloneNode(!1);return a.onselectstart=a.onmousemove=L.Util.falseFn,a},_loadTile:function(a,b,c){a._layer=this,a.onload=this._tileOnLoad,a.onerror=this._tileOnError,a.src=this.getTileUrl(b,c)},_tileOnLoad:function(a){var b=this._layer;this.className+=" leaflet-tile-loaded",b.fire("tileload",{tile:this,url:this.src}),b._tilesToLoad--,b._tilesToLoad||b.fire("load")},_tileOnError:function(a){var b=this._layer;b.fire("tileerror",{tile:this,url:this.src});var c=b.options.errorTileUrl;c&&(this.src=c)}}),L.TileLayer.WMS=L.TileLayer.extend({defaultWmsParams:{service:"WMS",request:"GetMap",version:"1.1.1",layers:"",styles:"",format:"image/jpeg",transparent:!1},initialize:function(a,b){this._url=a,this.wmsParams=L.Util.extend({},this.defaultWmsParams),this.wmsParams.width=this.wmsParams.height=this.options.tileSize;for(var c in b)this.options.hasOwnProperty(c)||(this.wmsParams[c]=b[c]);L.Util.setOptions(this,b)},onAdd:function(a){var b=parseFloat(this.wmsParams.version)<1.3?"srs":"crs";this.wmsParams[b]=a.options.crs.code,L.TileLayer.prototype.onAdd.call(this,a)},getTileUrl:function(a,b){var c=this.options.tileSize,d=a.multiplyBy(c),e=d.add(new L.Point(c,c)),f=this._map.unproject(d,this._zoom,!0),g=this._map.unproject(e,this._zoom,!0),h=this._map.options.crs.project(f),i=this._map.options.crs.project(g),j=[h.x,i.y,i.x,h.y].join(",");return this._url+L.Util.getParamString(this.wmsParams)+"&bbox="+j}}),L.TileLayer.Canvas=L.TileLayer.extend({options:{async:!1},initialize:function(a){L.Util.setOptions(this,a)},redraw:function(){for(var a in this._tiles){var b=this._tiles[a];this._redrawTile(b)}},_redrawTile:function(a){this.drawTile(a,a._tilePoint,a._zoom)},_createTileProto:function(){this._canvasProto=L.DomUtil.create("canvas","leaflet-tile");var a=this.options.tileSize;this._canvasProto.width=a,this._canvasProto.height=a},_createTile:function(){var a=this._canvasProto.cloneNode(!1);return a.onselectstart=a.onmousemove=L.Util.falseFn,a},_loadTile:function(a,b,c){a._layer=this,a._tilePoint=b,a._zoom=c,this.drawTile(a,b,c),this.options.async||this.tileDrawn(a)},drawTile:function(a,b,c){},tileDrawn:function(a){this._tileOnLoad.call(a)}}),L.ImageOverlay=L.Class.extend({includes:L.Mixin.Events,initialize:function(a,b){this._url=a,this._bounds=b},onAdd:function(a){this._map=a,this._image||this._initImage(),a.getPanes().overlayPane.appendChild(this._image),a.on("viewreset",this._reset,this),this._reset()},onRemove:function(a){a.getPanes().overlayPane.removeChild(this._image),a.off("viewreset",this._reset,this)},_initImage:function(){this._image=L.DomUtil.create("img","leaflet-image-layer"),this._image.style.visibility="hidden",L.Util.extend(this._image,{galleryimg:"no",onselectstart:L.Util.falseFn,onmousemove:L.Util.falseFn,onload:L.Util.bind(this._onImageLoad,this),src:this._url})},_reset:function(){var a=this._map.latLngToLayerPoint(this._bounds.getNorthWest()),b=this._map.latLngToLayerPoint(this._bounds.getSouthEast()),c=b.subtract(a);L.DomUtil.setPosition(this._image,a),this._image.style.width=c.x+"px",this._image.style.height=c.y+"px"},_onImageLoad:function(){this._image.style.visibility="",this.fire("load")}}),L.Icon=L.Class.extend({iconUrl:L.ROOT_URL+"images/marker.png",shadowUrl:L.ROOT_URL+"images/marker-shadow.png",iconSize:new L.Point(25,41),shadowSize:new L.Point(41,41),iconAnchor:new L.Point(13,41),popupAnchor:new L.Point(0,-33),initialize:function(a){a&&(this.iconUrl=a)},createIcon:function(){return this._createIcon("icon")},createShadow:function(){return this._createIcon("shadow")},_createIcon:function(a){var b=this[a+"Size"],c=this[a+"Url"];if(!c&&a==="shadow")return null;var d;return c?d=this._createImg(c):d=this._createDiv(),d.className="leaflet-marker-"+a,d.style.marginLeft=-this.iconAnchor.x+"px",d.style.marginTop=-this.iconAnchor.y+"px",b&&(d.style.width=b.x+"px",d.style.height=b.y+"px"),d},_createImg:function(a){var b;return L.Browser.ie6?(b=document.createElement("div"),b.style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+a+'")'):(b=document.createElement("img"),b.src=a),b},_createDiv:function(){return document.createElement("div")}}),L.Marker=L.Class.extend({includes:L.Mixin.Events,options:{icon:new L.Icon,title:"",clickable:!0,draggable:!1,zIndexOffset:0},initialize:function(a,b){L.Util.setOptions(this,b),this._latlng=a},onAdd:function(a){this._map=a,this._initIcon(),a.on("viewreset",this._reset,this),this._reset()},onRemove:function(a){this._removeIcon(),this.closePopup&&this.closePopup(),this._map=null,a.off("viewreset",this._reset,this)},getLatLng:function(){return this._latlng},setLatLng:function(a){this._latlng=a,this._icon&&(this._reset(),this._popup&&this._popup.setLatLng(this._latlng))},setZIndexOffset:function(a){this.options.zIndexOffset=a,this._icon&&this._reset()},setIcon:function(a){this._map&&this._removeIcon(),this.options.icon=a,this._map&&(this._initIcon(),this._reset())},_initIcon:function(){this._icon||(this._icon=this.options.icon.createIcon(),this.options.title&&(this._icon.title=this.options.title),this._initInteraction()),this._shadow||(this._shadow=this.options.icon.createShadow()),this._map._panes.markerPane.appendChild(this._icon),this._shadow&&this._map._panes.shadowPane.appendChild(this._shadow)},_removeIcon:function(){this._map._panes.markerPane.removeChild(this._icon),this._shadow&&this._map._panes.shadowPane.removeChild(this._shadow),this._icon=this._shadow=null},_reset:function(){var a=this._map.latLngToLayerPoint(this._latlng).round();L.DomUtil.setPosition(this._icon,a),this._shadow&&L.DomUtil.setPosition(this._shadow,a),this._icon.style.zIndex=a.y+this.options.zIndexOffset},_initInteraction:function(){if(this.options.clickable){this._icon.className+=" leaflet-clickable",L.DomEvent.addListener(this._icon,"click",this._onMouseClick,this);var a=["dblclick","mousedown","mouseover","mouseout"];for(var b=0;bthis.options.maxWidth?this.options.maxWidth:af.x&&(d.x=c.x+this._containerWidth-f.x+e.x),c.y<0&&(d.y=c.y-e.y),c.y+a>f.y&&(d.y=c.y+a-f.y+e.y),(d.x||d.y)&&this._map.panBy(d)},_onCloseButtonClick:function(a){this._close(),L.DomEvent.stop(a)}}),L.Marker.include({openPopup:function(){return this._popup.setLatLng(this._latlng),this._map&&this._map.openPopup(this._popup),this},closePopup:function(){return this._popup&&this._popup._close(),this},bindPopup:function(a,b){return b=L.Util.extend({offset:this.options.icon.popupAnchor},b),this._popup||this.on("click",this.openPopup,this),this._popup=new L.Popup(b,this),this._popup.setContent(a),this},unbindPopup:function(){return this._popup&&(this._popup=null,this.off("click",this.openPopup)),this}}),L.Map.include({openPopup:function(a){return this.closePopup(),this._popup=a,this.addLayer(a),this.fire("popupopen",{popup:this._popup}),this},closePopup:function(){return this._popup&&(this.removeLayer(this._popup),this.fire("popupclose",{popup:this._popup}),this._popup=null),this}}),L.LayerGroup=L.Class.extend({initialize:function(a){this._layers={};if(a)for(var b=0,c=a.length;b')}}catch(a){return function(a){return document.createElement("<"+a+' xmlns="urn:schemas-microsoft.com:vml" class="lvml">')}}}()},_initPath:function(){this._container=L.Path._createElement("shape"),this._container.className+=" leaflet-vml-shape"+(this.options.clickable?" leaflet-clickable":""),this._container.coordsize="1 1",this._path=L.Path._createElement("path"),this._container.appendChild(this._path),this._map._pathRoot.appendChild(this._container)},_initStyle:function(){this.options.stroke?(this._stroke=L.Path._createElement("stroke"),this._stroke.endcap="round",this._container.appendChild(this._stroke)):this._container.stroked=!1,this.options.fill?(this._container.filled=!0,this._fill=L.Path._createElement("fill"),this._container.appendChild(this._fill)):this._container.filled=!1,this._updateStyle()},_updateStyle:function(){this.options.stroke&&(this._stroke.weight=this.options.weight+"px",this._stroke.color=this.options.color,this._stroke.opacity=this.options.opacity),this.options.fill&&(this._fill.color=this.options.fillColor||this.options.color,this._fill.opacity=this.options.fillOpacity)},_updatePath:function(){this._container.style.display="none",this._path.v=this.getPathString()+" ",this._container.style.display=""}}),L.Map.include(L.Browser.svg||!L.Browser.vml?{}:{_initPathRoot:function(){this._pathRoot||(this._pathRoot=document.createElement("div"),this._pathRoot.className="leaflet-vml-container",this._panes.overlayPane.appendChild(this._pathRoot),this.on("moveend",this._updatePathViewport),this._updatePathViewport())}}),L.Browser.canvas=function(){return!!document.createElement("canvas").getContext}(),L.Path=L.Path.SVG&&!window.L_PREFER_CANVAS||!L.Browser.canvas?L.Path:L.Path.extend({statics:{CANVAS:!0,SVG:!1},options:{updateOnMoveEnd:!0},_initElements:function(){this._map._initPathRoot(),this._ctx=this._map._canvasCtx},_updateStyle:function(){this.options.stroke&&(this._ctx.lineWidth=this.options.weight,this._ctx.strokeStyle=this.options.color),this.options.fill&&(this._ctx.fillStyle=this.options.fillColor||this.options.color)},_drawPath:function(){var a,b,c,d,e,f;this._ctx.beginPath();for(a=0,c=this._parts.length;af&&(g=h,f=i);f>c&&(b[g]=1,this._simplifyDPStep(a,b,c,d,g),this._simplifyDPStep(a,b,c,g,e))},_reducePoints:function(a,b){var c=[a[0]];for(var d=1,e=0,f=a.length;db&&(c.push(a[d]),e=d);return eb.max.x&&(c|=2),a.yb.max.y&&(c|=8),c},_sqDist:function(a,b){var c=b.x-a.x,d=b.y-a.y;return c*c+d*d},_sqClosestPointOnSegment:function(a,b,c,d){var e=b.x,f=b.y,g=c.x-e,h=c.y-f,i=g*g+h*h,j;return i>0&&(j=((a.x-e)*g+(a.y-f)*h)/i,j>1?(e=c.x,f=c.y):j>0&&(e+=g*j,f+=h*j)),g=a.x-e,h=a.y-f,d?g*g+h*h:new L.Point(e,f)}},L.Polyline=L.Path.extend({initialize:function(a,b){L.Path.prototype.initialize.call(this,b),this._latlngs=a},options:{smoothFactor:1,noClip:!1,updateOnMoveEnd:!0},projectLatlngs:function(){this._originalPoints=[];for(var a=0,b=this._latlngs.length;aa.max.x||c.y-b>a.max.y||c.x+ba.y!=e.y>a.y&&a.x<(e.x-d.x)*(a.y-d.y)/(e.y-d.y)+d.x&&(b=!b)}return b}}:{}),L.Circle.include(L.Path.CANVAS?{_drawPath:function(){var a=this._point;this._ctx.beginPath(),this._ctx.arc(a.x,a.y,this._radius,0,Math.PI*2)},_containsPoint:function(a){var b=this._point,c=this.options.stroke?this.options.weight/2:0;return a.distanceTo(b)<=this._radius+c}}:{}),L.GeoJSON=L.FeatureGroup.extend({initialize:function(a,b){L.Util.setOptions(this,b),this._geojson=a,this._layers={},a&&this.addGeoJSON(a)},addGeoJSON:function(a){if(a.features){for(var b=0,c=a.features.length;b1)return;var b=a.touches&&a.touches.length===1?a.touches[0]:a,c=b.target;L.DomEvent.preventDefault(a),L.Browser.touch&&c.tagName.toLowerCase()==="a"&&(c.className+=" leaflet-active"),this._moved=!1;if(this._moving)return;L.Browser.touch||(L.DomUtil.disableTextSelection(),this._setMovingCursor()),this._startPos=this._newPos=L.DomUtil.getPosition(this._element),this._startPoint=new L.Point(b.clientX,b.clientY),L.DomEvent.addListener(document,L.Draggable.MOVE,this._onMove,this),L.DomEvent.addListener(document,L.Draggable.END,this._onUp,this)},_onMove:function(a){if(a.touches&&a.touches.length>1)return;L.DomEvent.preventDefault(a);var b=a.touches&&a.touches.length===1?a.touches[0]:a;this._moved||(this.fire("dragstart"),this._moved=!0),this._moving=!0;var c=new L.Point(b.clientX,b.clientY);this._newPos=this._startPos.add(c).subtract(this._startPoint),L.Util.requestAnimFrame(this._updatePosition,this,!0,this._dragStartTarget)},_updatePosition:function(){this.fire("predrag"),L.DomUtil.setPosition(this._element,this._newPos),this.fire("drag")},_onUp:function(a){if(a.changedTouches){var b=a.changedTouches[0],c=b.target,d=this._newPos&&this._newPos.distanceTo(this._startPos)||0;c.tagName.toLowerCase()==="a"&&(c.className=c.className.replace(" leaflet-active","")),d0&&c<=f,d=b}function l(a){e&&(g.type="dblclick",b(g),d=null)}var d,e=!1,f=250,g,h="_leaflet_",i="touchstart",j="touchend";a[h+i+c]=k,a[h+j+c]=l,a.addEventListener(i,k,!1),a.addEventListener(j,l,!1)},removeDoubleTapListener:function(a,b){var c="_leaflet_";a.removeEventListener(a,a[c+"touchstart"+b],!1),a.removeEventListener(a,a[c+"touchend"+b],!1)}}),L.Map.TouchZoom=L.Handler.extend({addHooks:function(){L.DomEvent.addListener(this._map._container,"touchstart",this._onTouchStart,this)},removeHooks:function(){L.DomEvent.removeListener(this._map._container,"touchstart",this._onTouchStart,this)},_onTouchStart:function(a){if(!a.touches||a.touches.length!==2||this._map._animatingZoom)return;var b=this._map.mouseEventToLayerPoint(a.touches[0]),c=this._map.mouseEventToLayerPoint(a.touches[1]),d=this._map.containerPointToLayerPoint(this._map.getSize().divideBy(2));this._startCenter=b.add(c).divideBy(2,!0),this._startDist=b.distanceTo(c),this._moved=!1,this._zooming=!0,this._centerOffset=d.subtract(this._startCenter),L.DomEvent.addListener(document,"touchmove",this._onTouchMove,this),L.DomEvent.addListener(document,"touchend",this._onTouchEnd,this),L.DomEvent.preventDefault(a)},_onTouchMove:function(a){if(!a.touches||a.touches.length!==2)return;this._moved||(this._map._mapPane.className+=" leaflet-zoom-anim",this._map.fire("zoomstart").fire("movestart")._prepareTileBg(),this._moved=!0);var b=this._map.mouseEventToLayerPoint(a.touches[0]),c=this._map.mouseEventToLayerPoint(a.touches[1]);this._scale=b.distanceTo(c)/this._startDist,this._delta=b.add(c).divideBy(2,!0).subtract(this._startCenter),this._map._tileBg.style.webkitTransform=[L.DomUtil.getTranslateString(this._delta),L.DomUtil.getScaleString(this._scale,this._startCenter)].join(" "),L.DomEvent.preventDefault(a)},_onTouchEnd:function(a){if(!this._moved||!this._zooming)return;this._zooming=!1;var b=this._map.getZoom(),c=Math.log(this._scale)/Math.LN2,d=c>0?Math.ceil(c):Math.floor(c),e=this._map._limitZoom(b+d),f=e-b,g=this._centerOffset.subtract(this._delta).divideBy(this._scale),h=this._map.getPixelOrigin().add(this._startCenter).add(g),i=this._map.unproject(h);L.DomEvent.removeListener(document,"touchmove",this._onTouchMove),L.DomEvent.removeListener(document,"touchend",this._onTouchEnd);var j=Math.pow(2,f);this._map._runAnimation(i,e,j/this._scale,this._startCenter.add(g))}}),L.Map.BoxZoom=L.Handler.extend({initialize:function(a){this._map=a,this._container=a._container,this._pane=a._panes.overlayPane},addHooks:function(){L.DomEvent.addListener(this._container,"mousedown",this._onMouseDown,this)},removeHooks:function(){L.DomEvent.removeListener(this._container,"mousedown",this._onMouseDown)},_onMouseDown:function(a){if(!a.shiftKey||a.which!==1&&a.button!==1)return!1;L.DomUtil.disableTextSelection(),this._startLayerPoint=this._map.mouseEventToLayerPoint(a),this._box=L.DomUtil.create("div","leaflet-zoom-box",this._pane),L.DomUtil.setPosition(this._box,this._startLayerPoint),this._container.style.cursor="crosshair",L.DomEvent.addListener(document,"mousemove",this._onMouseMove,this),L.DomEvent.addListener(document,"mouseup",this._onMouseUp,this),L.DomEvent.preventDefault(a)},_onMouseMove:function(a){var b=this._map.mouseEventToLayerPoint(a),c=b.x-this._startLayerPoint.x,d=b.y-this._startLayerPoint.y,e=Math.min(b.x,this._startLayerPoint.x),f=Math.min(b.y,this._startLayerPoint.y),g=new L.Point(e,f);L.DomUtil.setPosition(this._box,g),this._box.style.width=Math.abs(c)-4+"px",this._box.style.height=Math.abs(d)-4+"px"},_onMouseUp:function(a){this._pane.removeChild(this._box),this._container.style.cursor="",L.DomUtil.enableTextSelection(),L.DomEvent.removeListener(document,"mousemove",this._onMouseMove),L.DomEvent.removeListener(document,"mouseup",this._onMouseUp);var b=this._map.mouseEventToLayerPoint(a),c=new L.LatLngBounds(this._map.layerPointToLatLng(this._startLayerPoint),this._map.layerPointToLatLng(b));this._map.fitBounds(c)}}),L.Handler.MarkerDrag=L.Handler.extend({initialize:function(a){this._marker=a},addHooks:function(){var a=this._marker._icon;this._draggable||(this._draggable=new L.Draggable(a,a),this._draggable.on("dragstart",this._onDragStart,this).on("drag",this._onDrag,this).on("dragend",this._onDragEnd,this)),this._draggable.enable()},removeHooks:function(){this._draggable.disable()},moved:function(){return this._draggable&&this._draggable._moved},_onDragStart:function(a){this._marker.closePopup().fire("movestart").fire("dragstart")},_onDrag:function(a){var b=L.DomUtil.getPosition(this._marker._icon);this._marker._shadow&&L.DomUtil.setPosition(this._marker._shadow,b),this._marker._latlng=this._marker._map.layerPointToLatLng(b),this._marker.fire("move").fire("drag")},_onDragEnd:function(){this._marker.fire("moveend").fire("dragend")}}),L.Control={},L.Control.Position={TOP_LEFT:"topLeft",TOP_RIGHT:"topRight",BOTTOM_LEFT:"bottomLeft",BOTTOM_RIGHT:"bottomRight"},L.Map.include({addControl:function(a){a.onAdd(this);var b=a.getPosition(),c=this._controlCorners[b],d=a.getContainer();return L.DomUtil.addClass(d,"leaflet-control"),b.indexOf("bottom")!==-1?c.insertBefore(d,c.firstChild):c.appendChild(d),this},removeControl:function(a){var b=a.getPosition(),c=this._controlCorners[b],d=a.getContainer();return c.removeChild(d),a.onRemove&&a.onRemove(this),this},_initControlPos:function(){var a=this._controlCorners={},b="leaflet-",c=b+"top",d=b+"bottom",e=b+"left",f=b+"right",g=L.DomUtil.create("div",b+"control-container",this._container);L.Browser.touch&&(g.className+=" "+b+"big-buttons"),a.topLeft=L.DomUtil.create("div",c+" "+e,g),a.topRight=L.DomUtil.create("div",c+" "+f,g),a.bottomLeft=L.DomUtil.create("div",d+" "+e,g),a.bottomRight=L.DomUtil.create("div",d+" "+f,g)}}),L.Control.Zoom=L.Class.extend({onAdd:function(a){this._map=a,this._container=L.DomUtil.create("div","leaflet-control-zoom"),this._zoomInButton=this._createButton("Zoom in","leaflet-control-zoom-in",this._map.zoomIn,this._map),this._zoomOutButton=this._createButton("Zoom out","leaflet-control-zoom-out",this._map.zoomOut,this._map),this._container.appendChild(this._zoomInButton),this._container.appendChild(this._zoomOutButton)},getContainer:function(){return this._container},getPosition:function(){return L.Control.Position.TOP_LEFT},_createButton:function(a,b,c,d){var e=document.createElement("a");return e.href="#",e.title=a,e.className=b,L.Browser.touch||L.DomEvent.disableClickPropagation(e),L.DomEvent.addListener(e,"click",L.DomEvent.preventDefault),L.DomEvent.addListener(e,"click",c,d),e}}),L.Control.Attribution=L.Class.extend({initialize:function(a){this._prefix=a||'Powered by Leaflet',this._attributions={}},onAdd:function(a){this._container=L.DomUtil.create("div","leaflet-control-attribution"),L.DomEvent.disableClickPropagation(this._container),this._map=a,this._update()},getPosition:function(){return L.Control.Position.BOTTOM_RIGHT},getContainer:function(){return this._container},setPrefix:function(a){this._prefix=a,this._update()},addAttribution:function(a){if(!a)return;this._attributions[a]||(this._attributions[a]=0),this._attributions[a]++,this._update()},removeAttribution:function(a){if(!a)return;this._attributions[a]--,this._update()},_update:function(){if(!this._map)return;var a=[];for(var b in this._attributions)if(this._attributions.hasOwnProperty(b)&&this._attributions[b])a.push(b);var c=[];this._prefix&&c.push(this._prefix),a.length&&c.push(a.join(", ")),this._container.innerHTML=c.join(" — ")}}),L.Control.Layers=L.Class.extend({options:{collapsed:!0},initialize:function(a,b,c){L.Util.setOptions(this,c),this._layers={};for(var d in a)a.hasOwnProperty(d)&&this._addLayer(a[d],d);for(d in b)b.hasOwnProperty(d)&&this._addLayer(b[d],d,!0)},onAdd:function(a){this._map=a,this._initLayout(),this._update()},getContainer:function(){return this._container},getPosition:function(){return L.Control.Position.TOP_RIGHT},addBaseLayer:function(a,b){return this._addLayer(a,b),this._update(),this},addOverlay:function(a,b){return this._addLayer(a,b,!0),this._update(),this},removeLayer:function(a){var b=L.Util.stamp(a);return delete this._layers[b],this._update(),this},_initLayout:function(){this._container=L.DomUtil.create("div","leaflet-control-layers"),L.Browser.touch||L.DomEvent.disableClickPropagation(this._container),this._form=L.DomUtil.create("form","leaflet-control-layers-list");if(this.options.collapsed){L.DomEvent.addListener(this._container,"mouseover",this._expand,this),L.DomEvent.addListener(this._container,"mouseout",this._collapse,this);var a=this._layersLink=L.DomUtil.create("a","leaflet-control-layers-toggle");a.href="#",a.title="Layers",L.Browser.touch?L.DomEvent.addListener(a,"click",this._expand,this):L.DomEvent.addListener(a,"focus",this._expand,this),this._map.on("movestart",this._collapse,this),this._container.appendChild(a)}else this._expand();this._baseLayersList=L.DomUtil.create("div","leaflet-control-layers-base",this._form),this._separator=L.DomUtil.create("div","leaflet-control-layers-separator",this._form),this._overlaysList=L.DomUtil.create("div","leaflet-control-layers-overlays",this._form),this._container.appendChild(this._form)},_addLayer:function(a,b,c){var d=L.Util.stamp(a);this._layers[d]={layer:a,name:b,overlay:c}},_update:function(){if(!this._container)return;this._baseLayersList.innerHTML="",this._overlaysList.innerHTML="";var a=!1,b=!1;for(var c in this._layers)if(this._layers.hasOwnProperty(c)){var d=this._layers[c];this._addItem(d),b=b||d.overlay,a=a||!d.overlay}this._separator.style.display=b&&a?"":"none"},_addItem:function(a,b){var c=document.createElement("label"),d=document.createElement("input");a.overlay||(d.name="leaflet-base-layers"),d.type=a.overlay?"checkbox":"radio",d.checked=this._map.hasLayer(a.layer),d.layerId=L.Util.stamp(a.layer),L.DomEvent.addListener(d,"click",this._onInputClick,this);var e=document.createTextNode(" "+a.name);c.appendChild(d),c.appendChild(e);var f=a.overlay?this._overlaysList:this._baseLayersList;f.appendChild(c)},_onInputClick:function(){var a,b,c,d=this._form.getElementsByTagName("input"),e=d.length;for(a=0;a2?Array.prototype.slice.call(arguments,2):null;return function(){return e.apply(t,n||arguments)}},stamp:function(){var e=0,t="_leaflet_id";return function(n){return n[t]=n[t]||++e,n[t]}}(),limitExecByInterval:function(e,t,n){var r,i;return function s(){var o=arguments;if(r){i=!0;return}r=!0,setTimeout(function(){r=!1,i&&(s.apply(n,o),i=!1)},t),e.apply(n,o)}},falseFn:function(){return!1},formatNum:function(e,t){var n=Math.pow(10,t||5);return Math.round(e*n)/n},splitWords:function(e){return e.replace(/^\s+|\s+$/g,"").split(/\s+/)},setOptions:function(e,t){return e.options=n.Util.extend({},e.options,t),e.options},getParamString:function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n+"="+e[n]);return"?"+t.join("&")},template:function(e,t){return e.replace(/\{ *([\w_]+) *\}/g,function(e,n){var r=t[n];if(!t.hasOwnProperty(n))throw Error("No value provided for variable "+e);return r})},emptyImageUrl:"data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs="},function(){function t(t){var n,r,i=["webkit","moz","o","ms"];for(n=0;n0},removeEventListener:function(e,t,r){var s=this[i],o,u,a,f,l;if(typeof e=="object"){for(o in e)e.hasOwnProperty(o)&&this.removeEventListener(o,e[o],t);return this}e=n.Util.splitWords(e);for(u=0,a=e.length;u=0;l--)(!t||f[l].action===t)&&(!r||f[l].context===r)&&f.splice(l,1)}return this},fireEvent:function(e,t){if(!this.hasEventListeners(e))return this;var r=n.Util.extend({type:e,target:this},t),s=this[i][e].slice();for(var o=0,u=s.length;o1||"matchMedia"in e&&e.matchMedia("(min-resolution:144dpi)").matches;n.Browser={ua:r,ie:i,ie6:s,webkit:o,gecko:u,opera:f,android:l,android23:c,chrome:a,ie3d:d,webkit3d:v,gecko3d:m,opera3d:g,any3d:!e.L_DISABLE_3D&&(d||v||m||g),mobile:h,mobileWebkit:h&&o,mobileWebkit3d:h&&v,mobileOpera:h&&f,touch:y,retina:b}}(),n.Point=function(e,t,n){this.x=n?Math.round(e):e,this.y=n?Math.round(t):t},n.Point.prototype={add:function(e){return this.clone()._add(n.point(e))},_add:function(e){return this.x+=e.x,this.y+=e.y,this},subtract:function(e){return this.clone()._subtract(n.point(e))},_subtract:function(e){return this.x-=e.x,this.y-=e.y,this},divideBy:function(e,t){return new n.Point(this.x/e,this.y/e,t)},multiplyBy:function(e,t){return new n.Point(this.x*e,this.y*e,t)},distanceTo:function(e){e=n.point(e);var t=e.x-this.x,r=e.y-this.y;return Math.sqrt(t*t+r*r)},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},clone:function(){return new n.Point(this.x,this.y)},toString:function(){return"Point("+n.Util.formatNum(this.x)+", "+n.Util.formatNum(this.y)+")"}},n.point=function(e,t,r){return e instanceof n.Point?e:e instanceof Array?new n.Point(e[0],e[1]):isNaN(e)?e:new n.Point(e,t,r)},n.Bounds=n.Class.extend({initialize:function(e,t){if(!e)return;var n=t?[e,t]:e;for(var r=0,i=n.length;r=this.min.x&&r.x<=this.max.x&&t.y>=this.min.y&&r.y<=this.max.y},intersects:function(e){e=n.bounds(e);var t=this.min,r=this.max,i=e.min,s=e.max,o=s.x>=t.x&&i.x<=r.x,u=s.y>=t.y&&i.y<=r.y;return o&&u}}),n.bounds=function(e,t){return!e||e instanceof n.Bounds?e:new n.Bounds(e,t)},n.Transformation=n.Class.extend({initialize:function(e,t,n,r){this._a=e,this._b=t,this._c=n,this._d=r},transform:function(e,t){return this._transform(e.clone(),t)},_transform:function(e,t){return t=t||1,e.x=t*(this._a*e.x+this._b),e.y=t*(this._c*e.y+this._d),e},untransform:function(e,t){return t=t||1,new n.Point((e.x/t-this._b)/this._a,(e.y/t-this._d)/this._c)}}),n.DomUtil={get:function(e){return typeof e=="string"?document.getElementById(e):e},getStyle:function(e,t){var n=e.style[t];!n&&e.currentStyle&&(n=e.currentStyle[t]);if(!n||n==="auto"){var r=document.defaultView.getComputedStyle(e,null);n=r?r[t]:null}return n==="auto"?null:n},getViewportOffset:function(e){var t=0,r=0,i=e,s=document.body;do{t+=i.offsetTop||0,r+=i.offsetLeft||0;if(i.offsetParent===s&&n.DomUtil.getStyle(i,"position")==="absolute")break;if(n.DomUtil.getStyle(i,"position")==="fixed"){t+=s.scrollTop||0,r+=s.scrollLeft||0;break}i=i.offsetParent}while(i);i=e;do{if(i===s)break;t-=i.scrollTop||0,r-=i.scrollLeft||0,i=i.parentNode}while(i);return new n.Point(r,t)},create:function(e,t,n){var r=document.createElement(e);return r.className=t,n&&n.appendChild(r),r},disableTextSelection:function(){document.selection&&document.selection.empty&&document.selection.empty(),this._onselectstart||(this._onselectstart=document.onselectstart,document.onselectstart=n.Util.falseFn)},enableTextSelection:function(){document.onselectstart=this._onselectstart,this._onselectstart=null},hasClass:function(e,t){return e.className.length>0&&RegExp("(^|\\s)"+t+"(\\s|$)").test(e.className)},addClass:function(e,t){n.DomUtil.hasClass(e,t)||(e.className+=(e.className?" ":"")+t)},removeClass:function(e,t){function n(e,n){return n===t?"":e}e.className=e.className.replace(/(\S+)\s*/g,n).replace(/(^\s+|\s+$)/,"")},setOpacity:function(e,t){if("opacity"in e.style)e.style.opacity=t;else if(n.Browser.ie){var r=!1,i="DXImageTransform.Microsoft.Alpha";try{r=e.filters.item(i)}catch(s){}t=Math.round(t*100),r?(r.Enabled=t!==100,r.Opacity=t):e.style.filter+=" progid:"+i+"(opacity="+t+")"}},testProp:function(e){var t=document.documentElement.style;for(var n=0;n=t.lat&&s.lat<=r.lat&&i.lng>=t.lng&&s.lng<=r.lng},intersects:function(e){e=n.latLngBounds(e);var t=this._southWest,r=this._northEast,i=e.getSouthWest(),s=e.getNorthEast(),o=s.lat>=t.lat&&i.lat<=r.lat,u=s.lng>=t.lng&&i.lng<=r.lng;return o&&u},toBBoxString:function(){var e=this._southWest,t=this._northEast;return[e.lng,e.lat,t.lng,t.lat].join(",")},equals:function(e){return e?(e=n.latLngBounds(e),this._southWest.equals(e.getSouthWest())&&this._northEast.equals(e.getNorthEast())):!1}}),n.latLngBounds=function(e,t){return!e||e instanceof n.LatLngBounds?e:new n.LatLngBounds(e,t)},n.Projection={},n.Projection.SphericalMercator={MAX_LATITUDE:85.0511287798,project:function(e){var t=n.LatLng.DEG_TO_RAD,r=this.MAX_LATITUDE,i=Math.max(Math.min(r,e.lat),-r),s=e.lng*t,o=i*t;return o=Math.log(Math.tan(Math.PI/4+o/2)),new n.Point(s,o)},unproject:function(e){var t=n.LatLng.RAD_TO_DEG,r=e.x*t,i=(2*Math.atan(Math.exp(e.y))-Math.PI/2)*t;return new n.LatLng(i,r,!0)}},n.Projection.LonLat={project:function(e){return new n.Point(e.lng,e.lat)},unproject:function(e){return new n.LatLng(e.y,e.x,!0)}},n.CRS={latLngToPoint:function(e,t){var n=this.projection.project(e),r=this.scale(t);return this.transformation._transform(n,r)},pointToLatLng:function(e,t){var n=this.scale(t),r=this.transformation.untransform(e,n);return this.projection.unproject(r)},project:function(e){return this.projection.project(e)},scale:function(e){return 256*Math.pow(2,e)}},n.CRS.EPSG3857=n.Util.extend({},n.CRS,{code:"EPSG:3857",projection:n.Projection.SphericalMercator,transformation:new n.Transformation(.5/Math.PI,.5,-0.5/Math.PI,.5),project:function(e){var t=this.projection.project(e),n=6378137;return t.multiplyBy(n)}}),n.CRS.EPSG900913=n.Util.extend({},n.CRS.EPSG3857,{code:"EPSG:900913"}),n.CRS.EPSG4326=n.Util.extend({},n.CRS,{code:"EPSG:4326",projection:n.Projection.LonLat,transformation:new n.Transformation(1/360,.5,-1/360,.5)}),n.Map=n.Class.extend({includes:n.Mixin.Events,options:{crs:n.CRS.EPSG3857,fadeAnimation:n.DomUtil.TRANSITION&&!n.Browser.android23,trackResize:!0,markerZoomAnimation:n.DomUtil.TRANSITION&&n.Browser.any3d},initialize:function(e,r){r=n.Util.setOptions(this,r),this._initContainer(e),this._initLayout(),this._initHooks(),this._initEvents(),r.maxBounds&&this.setMaxBounds(r.maxBounds),r.center&&r.zoom!==t&&this.setView(n.latLng(r.center),r.zoom,!0),this._initLayers(r.layers)},setView:function(e,t){return this._resetView(n.latLng(e),this._limitZoom(t)),this},setZoom:function(e){return this.setView(this.getCenter(),e)},zoomIn:function(){return this.setZoom(this._zoom+1)},zoomOut:function(){return this.setZoom(this._zoom-1)},fitBounds:function(e){var t=this.getBoundsZoom(e);return this.setView(n.latLngBounds(e).getCenter(),t)},fitWorld:function(){var e=new n.LatLng(-60,-170),t=new n.LatLng(85,179);return this.fitBounds(new n.LatLngBounds(e,t))},panTo:function(e){return this.setView(e,this._zoom)},panBy:function(e){return this.fire("movestart"),this._rawPanBy(n.point(e)),this.fire("move"),this.fire("moveend")},setMaxBounds:function(e){e=n.latLngBounds(e),this.options.maxBounds=e;if(!e)return this._boundsMinZoom=null,this;var t=this.getBoundsZoom(e,!0);return this._boundsMinZoom=t,this._loaded&&(this._zoomo.x&&(u=o.x-i.x),r.y>s.y&&(a=s.y-r.y),r.xc&&--h>0)d=u*Math.sin(f),p=Math.PI/2-2*Math.atan(a*Math.pow((1-d)/(1+d),.5*u))-f,f+=p;return new n.LatLng(f*t,s,!0)}},n.CRS.EPSG3395=n.Util.extend({},n.CRS,{code:"EPSG:3395",projection:n.Projection.Mercator,transformation:function(){var e=n.Projection.Mercator,t=e.R_MAJOR,r=e.R_MINOR;return new n.Transformation(.5/(Math.PI*t),.5,-0.5/(Math.PI*r),.5)}()}),n.TileLayer=n.Class.extend({includes:n.Mixin.Events,options:{minZoom:0,maxZoom:18,tileSize:256,subdomains:"abc",errorTileUrl:"",attribution:"",zoomOffset:0,opacity:1,unloadInvisibleTiles:n.Browser.mobile,updateWhenIdle:n.Browser.mobile},initialize:function(e,t){t=n.Util.setOptions(this,t),t.detectRetina&&n.Browser.retina&&t.maxZoom>0&&(t.tileSize=Math.floor(t.tileSize/2),t.zoomOffset++,t.minZoom>0&&t.minZoom--,this.options.maxZoom--),this._url=e;var r=this.options.subdomains;typeof r=="string"&&(this.options.subdomains=r.split(""))},onAdd:function(e){this._map=e,this._initContainer(),this._createTileProto(),e.on({viewreset:this._resetCallback,moveend:this._update},this),this.options.updateWhenIdle||(this._limitedUpdate=n.Util.limitExecByInterval(this._update,150,this),e.on("move",this._limitedUpdate,this)),this._reset(),this._update()},addTo:function(e){return e.addLayer(this),this},onRemove:function(e){e._panes.tilePane.removeChild(this._container),e.off({viewreset:this._resetCallback,moveend:this._update},this),this.options.updateWhenIdle||e.off("move",this._limitedUpdate,this),this._container=null,this._map=null},bringToFront:function(){var e=this._map._panes.tilePane;return this._container&&(e.appendChild(this._container),this._setAutoZIndex(e,Math.max)),this},bringToBack:function(){var e=this._map._panes.tilePane;return this._container&&(e.insertBefore(this._container,e.firstChild),this._setAutoZIndex(e,Math.min)),this},getAttribution:function(){return this.options.attribution},setOpacity:function(e){return this.options.opacity=e,this._map&&this._updateOpacity(),this},setZIndex:function(e){return this.options.zIndex=e,this._updateZIndex(),this},setUrl:function(e,t){return this._url=e,t||this.redraw(),this},redraw:function(){return this._map&&(this._map._panes.tilePane.empty=!1,this._reset(!0),this._update()),this},_updateZIndex:function(){this._container&&this.options.zIndex!==t&&(this._container.style.zIndex=this.options.zIndex)},_setAutoZIndex:function(e,t){var n=e.getElementsByClassName("leaflet-layer"),r=-t(Infinity,-Infinity),i;for(var s=0,o=n.length;sthis.options.maxZoom||r=t)||e.y<0||e.y>=t)return!1}return!0},_removeOtherTiles:function(e){var t,n,r,i;for(i in this._tiles)this._tiles.hasOwnProperty(i)&&(t=i.split(":"),n=parseInt(t[0],10),r=parseInt(t[1],10),(ne.max.x||re.max.y)&&this._removeTile(i))},_removeTile:function(e){var t=this._tiles[e];this.fire("tileunload",{tile:t,url:t.src}),this.options.reuseTiles?(n.DomUtil.removeClass(t,"leaflet-tile-loaded"),this._unusedTiles.push(t)):t.parentNode===this._container&&this._container.removeChild(t),n.Browser.android||(t.src=n.Util.emptyImageUrl),delete this._tiles[e]},_addTile:function(e,t){var r=this._getTilePos(e),i=this._getTile();n.DomUtil.setPosition(i,r,n.Browser.chrome||n.Browser.android23),this._tiles[e.x+":"+e.y]=i,this._loadTile(i,e),i.parentNode!==this._container&&t.appendChild(i)},_getZoomForUrl:function(){var e=this.options,t=this._map.getZoom();return e.zoomReverse&&(t=e.maxZoom-t),t+e.zoomOffset},_getTilePos:function(e){var t=this._map.getPixelOrigin(),n=this.options.tileSize;return e.multiplyBy(n).subtract(t)},getTileUrl:function(e){return this._adjustTilePoint(e),n.Util.template(this._url,n.Util.extend({s:this._getSubdomain(e),z:this._getZoomForUrl(),x:e.x,y:e.y},this.options))},_getWrapTileNum:function(){return Math.pow(2,this._getZoomForUrl())},_adjustTilePoint:function(e){var t=this._getWrapTileNum();!this.options.continuousWorld&&!this.options.noWrap&&(e.x=(e.x%t+t)%t),this.options.tms&&(e.y=t-e.y-1)},_getSubdomain:function(e){var t=(e.x+e.y)%this.options.subdomains.length;return this.options.subdomains[t]},_createTileProto:function(){var e=this._tileImg=n.DomUtil.create("img","leaflet-tile");e.galleryimg="no";var t=this.options.tileSize;e.style.width=t+"px",e.style.height=t+"px"},_getTile:function(){if(this.options.reuseTiles&&this._unusedTiles.length>0){var e=this._unusedTiles.pop();return this._resetTile(e),e}return this._createTile()},_resetTile:function(e){},_createTile:function(){var e=this._tileImg.cloneNode(!1);return e.onselectstart=e.onmousemove=n.Util.falseFn,e},_loadTile:function(e,t){e._layer=this,e.onload=this._tileOnLoad,e.onerror=this._tileOnError,e.src=this.getTileUrl(t)},_tileLoaded:function(){this._tilesToLoad--,this._tilesToLoad||this.fire("load")},_tileOnLoad:function(e){var t=this._layer;this.src!==n.Util.emptyImageUrl&&(n.DomUtil.addClass(this,"leaflet-tile-loaded"),t.fire("tileload",{tile:this,url:this.src})),t._tileLoaded()},_tileOnError:function(e){var t=this._layer;t.fire("tileerror",{tile:this,url:this.src});var n=t.options.errorTileUrl;n&&(this.src=n),t._tileLoaded()}}),n.tileLayer=function(e,t){return new n.TileLayer(e,t)},n.TileLayer.WMS=n.TileLayer.extend({defaultWmsParams:{service:"WMS",request:"GetMap",version:"1.1.1",layers:"",styles:"",format:"image/jpeg",transparent:!1},initialize:function(e,t){this._url=e;var r=n.Util.extend({},this.defaultWmsParams);t.detectRetina&&n.Browser.retina?r.width=r.height=this.options.tileSize*2:r.width=r.height=this.options.tileSize;for(var i in t)this.options.hasOwnProperty(i)||(r[i]=t[i]);this.wmsParams=r,n.Util.setOptions(this,t)},onAdd:function(e){var t=parseFloat(this.wmsParams.version)>=1.3?"crs":"srs";this.wmsParams[t]=e.options.crs.code,n.TileLayer.prototype.onAdd.call(this,e)},getTileUrl:function(e,t){var r=this._map,i=r.options.crs,s=this.options.tileSize,o=e.multiplyBy(s),u=o.add(new n.Point(s,s)),a=i.project(r.unproject(o,t)),f=i.project(r.unproject(u,t)),l=[a.x,f.y,f.x,a.y].join(","),c=n.Util.template(this._url,{s:this._getSubdomain(e)});return c+n.Util.getParamString(this.wmsParams)+"&bbox="+l},setParams:function(e,t){return n.Util.extend(this.wmsParams,e),t||this.redraw(),this}}),n.tileLayer.wms=function(e,t){return new n.TileLayer.WMS(e,t)},n.TileLayer.Canvas=n.TileLayer.extend({options:{async:!1},initialize:function(e){n.Util.setOptions(this,e)},redraw:function(){var e,t=this._tiles;for(e in t)t.hasOwnProperty(e)&&this._redrawTile(t[e])},_redrawTile:function(e){this.drawTile(e,e._tilePoint,e._zoom)},_createTileProto:function(){var e=this._canvasProto=n.DomUtil.create("canvas","leaflet-tile"),t=this.options.tileSize;e.width=t,e.height=t},_createTile:function(){var e=this._canvasProto.cloneNode(!1);return e.onselectstart=e.onmousemove=n.Util.falseFn,e},_loadTile:function(e,t,n){e._layer=this,e._tilePoint=t,e._zoom=n,this.drawTile(e,t,n),this.options.async||this.tileDrawn(e)},drawTile:function(e,t,n){},tileDrawn:function(e){this._tileOnLoad.call(e)}}),n.tileLayer.canvas=function(e){return new n.TileLayer.Canvas(e)},n.ImageOverlay=n.Class.extend({includes:n.Mixin.Events,options:{opacity:1},initialize:function(e,t,r){this._url=e,this._bounds=n.latLngBounds(t),n.Util.setOptions(this,r)},onAdd:function(e){this._map=e,this._image||this._initImage(),e._panes.overlayPane.appendChild(this._image),e.on("viewreset",this._reset,this),e.options.zoomAnimation&&n.Browser.any3d&&e.on("zoomanim",this._animateZoom,this),this._reset()},onRemove:function(e){e.getPanes().overlayPane.removeChild(this._image),e.off("viewreset",this._reset,this),e.options.zoomAnimation&&e.off("zoomanim",this._animateZoom,this)},addTo:function(e){return e.addLayer(this),this},setOpacity:function(e){return this.options.opacity=e,this._updateOpacity(),this},bringToFront:function(){return this._image&&this._map._panes.overlayPane.appendChild(this._image),this},bringToBack:function(){var e=this._map._panes.overlayPane;return this._image&&e.insertBefore(this._image,e.firstChild),this},_initImage:function(){this._image=n.DomUtil.create("img","leaflet-image-layer"),this._map.options.zoomAnimation&&n.Browser.any3d?n.DomUtil.addClass(this._image,"leaflet-zoom-animated"):n.DomUtil.addClass(this._image,"leaflet-zoom-hide"),this._updateOpacity(),n.Util.extend(this._image,{galleryimg:"no",onselectstart:n.Util.falseFn,onmousemove:n.Util.falseFn,onload:n.Util.bind(this._onImageLoad,this),src:this._url})},_animateZoom:function(e){var t=this._map,r=this._image,i=t.getZoomScale(e.zoom),s=this._bounds.getNorthWest(),o=this._bounds.getSouthEast(),u=t._latLngToNewLayerPoint(s,e.zoom,e.center),a=t._latLngToNewLayerPoint(o,e.zoom,e.center).subtract(u),f=t.latLngToLayerPoint(o).subtract(t.latLngToLayerPoint(s)),l=u.add(a.subtract(f).divideBy(2));r.style[n.DomUtil.TRANSFORM]=n.DomUtil.getTranslateString(l)+" scale("+i+") "},_reset:function(){var e=this._image,t=this._map.latLngToLayerPoint(this._bounds.getNorthWest()),r=this._map.latLngToLayerPoint(this._bounds.getSouthEast()).subtract(t);n.DomUtil.setPosition(e,t),e.style.width=r.x+"px",e.style.height=r.y+"px"},_onImageLoad:function(){this.fire("load")},_updateOpacity:function(){n.DomUtil.setOpacity(this._image,this.options.opacity)}}),n.imageOverlay=function(e,t,r){return new n.ImageOverlay(e,t,r)},n.Icon=n.Class.extend({options:{className:""},initialize:function(e){n.Util.setOptions(this,e)},createIcon:function(){return this._createIcon("icon")},createShadow:function(){return this._createIcon("shadow")},_createIcon:function(e){var t=this._getIconUrl(e);if(!t){if(e==="icon")throw Error("iconUrl not set in Icon options (see the docs).");return null}var n=this._createImg(t);return this._setIconStyles(n,e),n},_setIconStyles:function(e,t){var r=this.options,i=n.point(r[t+"Size"]),s;t==="shadow"?s=n.point(r.shadowAnchor||r.iconAnchor):s=n.point(r.iconAnchor),!s&&i&&(s=i.divideBy(2,!0)),e.className="leaflet-marker-"+t+" "+r.className,s&&(e.style.marginLeft=-s.x+"px",e.style.marginTop=-s.y+"px"),i&&(e.style.width=i.x+"px",e.style.height=i.y+"px")},_createImg:function(e){var t;return n.Browser.ie6?(t=document.createElement("div"),t.style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+e+'")'):(t=document.createElement("img"),t.src=e),t},_getIconUrl:function(e){return this.options[e+"Url"]}}),n.icon=function(e){return new n.Icon(e)},n.Icon.Default=n.Icon.extend({options:{iconSize:new n.Point(25,41),iconAnchor:new n.Point(13,41),popupAnchor:new n.Point(1,-34),shadowSize:new n.Point(41,41)},_getIconUrl:function(e){var t=e+"Url";if(this.options[t])return this.options[t];var r=n.Icon.Default.imagePath;if(!r)throw Error("Couldn't autodetect L.Icon.Default.imagePath, set it manually.");return r+"/marker-"+e+".png"}}),n.Icon.Default.imagePath=function(){var e=document.getElementsByTagName("script"),t=/\/?leaflet[\-\._]?([\w\-\._]*)\.js\??/,n,r,i,s;for(n=0,r=e.length;ns?(t.height=s+"px",n.DomUtil.addClass(e,o)):n.DomUtil.removeClass(e,o),this._containerWidth=this._container.offsetWidth},_updatePosition:function(){var e=this._map.latLngToLayerPoint(this._latlng),t=n.Browser.any3d,r=this.options.offset;t&&n.DomUtil.setPosition(this._container,e),this._containerBottom=-r.y-(t?0:e.y),this._containerLeft=-Math.round(this._containerWidth/2)+r.x+(t?0:e.x),this._container.style.bottom=this._containerBottom+"px",this._container.style.left=this._containerLeft+"px"},_zoomAnimation:function(e){var t=this._map._latLngToNewLayerPoint(this._latlng,e.zoom,e.center);n.DomUtil.setPosition(this._container,t)},_adjustPan:function(){if(!this.options.autoPan)return;var e=this._map,t=this._container.offsetHeight,r=this._containerWidth,i=new n.Point(this._containerLeft,-t-this._containerBottom);n.Browser.any3d&&i._add(n.DomUtil.getPosition(this._container));var s=e.layerPointToContainerPoint(i),o=this.options.autoPanPadding,u=e.getSize(),a=0,f=0;s.x<0&&(a=s.x-o.x),s.x+r>u.x&&(a=s.x+r-u.x+o.x),s.y<0&&(f=s.y-o.y),s.y+t>u.y&&(f=s.y+t-u.y+o.y),(a||f)&&e.panBy(new n.Point(a,f))},_onCloseButtonClick:function(e){this._close(),n.DomEvent.stop(e)}}),n.popup=function(e,t){return new n.Popup(e,t)},n.Marker.include({openPopup:function(){return this._popup&&this._map&&(this._popup.setLatLng(this._latlng),this._map.openPopup(this._popup)),this},closePopup:function(){return this._popup&&this._popup._close(),this},bindPopup:function(e,t){var r=n.point(this.options.icon.options.popupAnchor)||new n.Point(0,0);return r=r.add(n.Popup.prototype.options.offset),t&&t.offset&&(r=r.add(t.offset)),t=n.Util.extend({offset:r},t),this._popup||this.on("click",this.openPopup,this),this._popup=(new n.Popup(t,this)).setContent(e),this},unbindPopup:function(){return this._popup&&(this._popup=null,this.off("click",this.openPopup)),this}}),n.Map.include({openPopup:function(e){return this.closePopup(),this._popup=e,this.addLayer(e).fire("popupopen",{popup:this._popup})},closePopup:function(){return this._popup&&this._popup._close(),this}}),n.LayerGroup=n.Class.extend({initialize:function(e){this._layers={};var t,n;if(e)for(t=0,n=e.length;t';var t=e.firstChild;return t.style.behavior="url(#default#VML)",t&&typeof t.adj=="object"}catch(n){return!1}}(),n.Path=n.Browser.svg||!n.Browser.vml?n.Path:n.Path.extend({statics:{VML:!0,CLIP_PADDING:.02},_createElement:function(){try{return document.namespaces.add("lvml","urn:schemas-microsoft-com:vml"),function(e){return document.createElement("')}}catch(e){return function(e){return document.createElement("<"+e+' xmlns="urn:schemas-microsoft.com:vml" class="lvml">')}}}(),_initPath:function(){var e=this._container=this._createElement("shape");n.DomUtil.addClass(e,"leaflet-vml-shape"),this.options.clickable&&n.DomUtil.addClass(e,"leaflet-clickable"),e.coordsize="1 1",this._path=this._createElement("path"),e.appendChild(this._path),this._map._pathRoot.appendChild(e)},_initStyle:function(){this._updateStyle()},_updateStyle:function(){var e=this._stroke,t=this._fill,n=this.options,r=this._container;r.stroked=n.stroke,r.filled=n.fill,n.stroke?(e||(e=this._stroke=this._createElement("stroke"),e.endcap="round",r.appendChild(e)),e.weight=n.weight+"px",e.color=n.color,e.opacity=n.opacity,n.dashArray?e.dashStyle=n.dashArray.replace(/ *, */g," "):e.dashStyle=""):e&&(r.removeChild(e),this._stroke=null),n.fill?(t||(t=this._fill=this._createElement("fill"),r.appendChild(t)),t.color=n.fillColor||n.color,t.opacity=n.fillOpacity):t&&(r.removeChild(t),this._fill=null)},_updatePath:function(){var e=this._container.style;e.display="none",this._path.v=this.getPathString()+" ",e.display=""}}),n.Map.include(n.Browser.svg||!n.Browser.vml?{}:{_initPathRoot:function(){if(this._pathRoot)return;var e=this._pathRoot=document.createElement("div");e.className="leaflet-vml-container",this._panes.overlayPane.appendChild(e),this.on("moveend",this._updatePathViewport),this._updatePathViewport()}}),n.Browser.canvas=function(){return!!document.createElement("canvas").getContext}(),n.Path=n.Path.SVG&&!e.L_PREFER_CANVAS||!n.Browser.canvas?n.Path:n.Path.extend({statics:{CANVAS:!0,SVG:!1},redraw:function(){return this._map&&(this.projectLatlngs(),this._requestUpdate()),this},setStyle:function(e){return n.Util.setOptions(this,e),this._map&&(this._updateStyle(),this._requestUpdate()),this},onRemove:function(e){e.off("viewreset",this.projectLatlngs,this).off("moveend",this._updatePath,this),this._requestUpdate(),this._map=null},_requestUpdate:function(){this._map&&(n.Util.cancelAnimFrame(this._fireMapMoveEnd),this._updateRequest=n.Util.requestAnimFrame(this._fireMapMoveEnd,this._map))},_fireMapMoveEnd:function(){this.fire("moveend")},_initElements:function(){this._map._initPathRoot(),this._ctx=this._map._canvasCtx},_updateStyle:function(){var e=this.options;e.stroke&&(this._ctx.lineWidth=e.weight,this._ctx.strokeStyle=e.color),e.fill&&(this._ctx.fillStyle=e.fillColor||e.color)},_drawPath:function(){var e,t,r,i,s,o;this._ctx.beginPath();for(e=0,r=this._parts.length;es&&(o=u,s=a);s>n&&(t[o]=1,this._simplifyDPStep(e,t,n,r,o),this._simplifyDPStep(e,t,n,o,i))},_reducePoints:function(e,t){var n=[e[0]];for(var r=1,i=0,s=e.length;rt&&(n.push(e[r]),i=r);return it.max.x&&(n|=2),e.yt.max.y&&(n|=8),n},_sqDist:function(e,t){var n=t.x-e.x,r=t.y-e.y;return n*n+r*r},_sqClosestPointOnSegment:function(e,t,r,i){var s=t.x,o=t.y,u=r.x-s,a=r.y-o,f=u*u+a*a,l;return f>0&&(l=((e.x-s)*u+(e.y-o)*a)/f,l>1?(s=r.x,o=r.y):l>0&&(s+=u*l,o+=a*l)),u=e.x-s,a=e.y-o,i?u*u+a*a:new n.Point(s,o)}},n.Polyline=n.Path.extend({initialize:function(e,t){n.Path.prototype.initialize.call(this,t),this._latlngs=this._convertLatLngs(e),n.Handler.PolyEdit&&(this.editing=new n.Handler.PolyEdit(this),this.options.editable&&this.editing.enable())},options:{smoothFactor:1,noClip:!1},projectLatlngs:function(){this._originalPoints=[];for(var e=0,t=this._latlngs.length;ee.max.x||n.y-t>e.max.y||n.x+te.y!=s.y>e.y&&e.x<(s.x-i.x)*(e.y-i.y)/(s.y-i.y)+i.x&&(t=!t)}return t}}:{}),n.Circle.include(n.Path.CANVAS?{_drawPath:function(){var e=this._point;this._ctx.beginPath(),this._ctx.arc(e.x,e.y,this._radius,0,Math.PI*2,!1)},_containsPoint:function(e){var t=this._point,n=this.options.stroke?this.options.weight/2:0;return e.distanceTo(t)<=this._radius+n}}:{}),n.GeoJSON=n.FeatureGroup.extend({initialize:function(e,t){n.Util.setOptions(this,t),this._layers={},e&&this.addData(e)},addData:function(e){var t=e instanceof Array?e:e.features,r,i;if(t){for(r=0,i=t.length;r1){this._simulateClick=!1;return}var t=e.touches&&e.touches.length===1?e.touches[0]:e,r=t.target;n.DomEvent.preventDefault(e),n.Browser.touch&&r.tagName.toLowerCase()==="a"&&n.DomUtil.addClass(r,"leaflet-active"),this._moved=!1;if(this._moving)return;this._startPos=this._newPos=n.DomUtil.getPosition(this._element),this._startPoint=new n.Point(t.clientX,t.clientY),n.DomEvent.on(document,n.Draggable.MOVE,this._onMove,this),n.DomEvent.on(document,n.Draggable.END,this._onUp,this)},_onMove:function(e){if(e.touches&&e.touches.length>1)return;var t=e.touches&&e.touches.length===1?e.touches[0]:e,r=new n.Point(t.clientX,t.clientY),i=r.subtract(this._startPoint);if(!i.x&&!i.y)return;n.DomEvent.preventDefault(e),this._moved||(this.fire("dragstart"),this._moved=!0,n.Browser.touch||(n.DomUtil.disableTextSelection(),this._setMovingCursor())),this._newPos=this._startPos.add(i),this._moving=!0,n.Util.cancelAnimFrame(this._animRequest),this._animRequest=n.Util.requestAnimFrame(this._updatePosition,this,!0,this._dragStartTarget)},_updatePosition:function(){this.fire("predrag"),n.DomUtil.setPosition(this._element,this._newPos),this.fire("drag")},_onUp:function(e){if(this._simulateClick&&e.changedTouches){var t=e.changedTouches[0],r=t.target,i=this._newPos&&this._newPos.distanceTo(this._startPos)||0;r.tagName.toLowerCase()==="a"&&n.DomUtil.removeClass(r,"leaflet-active"),i200&&(this._positions.shift(),this._times.shift())}this._map.fire("move").fire("drag")},_onViewReset:function(){var e=this._map.getSize().divideBy(2),t=this._map.latLngToLayerPoint(new n.LatLng(0,0));this._initialWorldOffset=t.subtract(e).x,this._worldWidth=this._map.project(new n.LatLng(0,180)).x},_onPreDrag:function(){var e=this._map,t=this._worldWidth,n=Math.round(t/2),r=this._initialWorldOffset,i=this._draggable._newPos.x,s=(i-n+r)%t+n-r,o=(i+n+r)%t-n-r,u=Math.abs(s+r)r.inertiaThreshold||this._positions[0]===t;if(s)e.fire("moveend");else{var o=this._lastPos.subtract(this._positions[0]),u=(this._lastTime+i-this._times[0])/1e3,a=o.multiplyBy(.58/u),f=a.distanceTo(new n.Point(0,0)),l=Math.min(r.inertiaMaxSpeed,f),c=a.multiplyBy(l/f),h=l/r.inertiaDeceleration,p=c.multiplyBy(-h/2).round(),d={duration:h,easing:"ease-out"};n.Util.requestAnimFrame(n.Util.bind(function(){this._map.panBy(p,d)},this))}e.fire("dragend"),r.maxBounds&&n.Util.requestAnimFrame(this._panInsideMaxBounds,e,!0,e._container)},_panInsideMaxBounds:function(){this.panInsideBounds(this.options.maxBounds)}}),n.Map.addInitHook("addHandler","dragging",n.Map.Drag),n.Map.mergeOptions({doubleClickZoom:!0}),n.Map.DoubleClickZoom=n.Handler.extend({addHooks:function(){this._map.on("dblclick",this._onDoubleClick)},removeHooks:function(){this._map.off("dblclick",this._onDoubleClick)},_onDoubleClick:function(e){this.setView(e.latlng,this._zoom+1)}}),n.Map.addInitHook("addHandler","doubleClickZoom",n.Map.DoubleClickZoom),n.Map.mergeOptions({scrollWheelZoom:!n.Browser.touch}),n.Map.ScrollWheelZoom=n.Handler.extend({addHooks:function(){n.DomEvent.on(this._map._container,"mousewheel",this._onWheelScroll,this),this._delta=0},removeHooks:function(){n.DomEvent.off(this._map._container,"mousewheel",this._onWheelScroll)},_onWheelScroll:function(e){var t=n.DomEvent.getWheelDelta(e);this._delta+=t,this._lastMousePos=this._map.mouseEventToContainerPoint(e),clearTimeout(this._timer),this._timer=setTimeout(n.Util.bind(this._performZoom,this),40),n.DomEvent.preventDefault(e)},_performZoom:function(){var e=this._map,t=Math.round(this._delta),n=e.getZoom();t=Math.max(Math.min(t,4),-4),t=e._limitZoom(n+t)-n,this._delta=0;if(!t)return;var r=n+t,i=this._getCenterForScrollWheelZoom(this._lastMousePos,r);e.setView(i,r)},_getCenterForScrollWheelZoom:function(e,t){var n=this._map,r=n.getZoomScale(t),i=n.getSize().divideBy(2),s=e.subtract(i).multiplyBy(1-1/r),o=n._getTopLeftPoint().add(i).add(s);return n.unproject(o)}}),n.Map.addInitHook("addHandler","scrollWheelZoom",n.Map.ScrollWheelZoom),n.Util.extend(n.DomEvent,{addDoubleTapListener:function(e,t,n){function l(e){if(e.touches.length!==1)return;var t=Date.now(),n=t-(r||t);o=e.touches[0],i=n>0&&n<=s,r=t}function c(e){i&&(o.type="dblclick",t(o),r=null)}var r,i=!1,s=250,o,u="_leaflet_",a="touchstart",f="touchend";return e[u+a+n]=l,e[u+f+n]=c,e.addEventListener(a,l,!1),e.addEventListener(f,c,!1),this},removeDoubleTapListener:function(e,t){var n="_leaflet_";return e.removeEventListener(e,e[n+"touchstart"+t],!1),e.removeEventListener(e,e[n+"touchend"+t],!1),this}}),n.Map.mergeOptions({touchZoom:n.Browser.touch&&!n.Browser.android23}),n.Map.TouchZoom=n.Handler.extend({addHooks:function(){n.DomEvent.on(this._map._container,"touchstart",this._onTouchStart,this)},removeHooks:function(){n.DomEvent.off(this._map._container,"touchstart",this._onTouchStart,this)},_onTouchStart:function(e){var t=this._map;if(!e.touches||e.touches.length!==2||t._animatingZoom||this._zooming)return;var r=t.mouseEventToLayerPoint(e.touches[0]),i=t.mouseEventToLayerPoint(e.touches[1]),s=t._getCenterLayerPoint();this._startCenter=r.add(i).divideBy(2,!0),this._startDist=r.distanceTo(i),this._moved=!1,this._zooming=!0,this._centerOffset=s.subtract(this._startCenter),n.DomEvent.on(document,"touchmove",this._onTouchMove,this).on(document,"touchend",this._onTouchEnd,this),n.DomEvent.preventDefault(e)},_onTouchMove:function(e){if(!e.touches||e.touches.length!==2)return;var t=this._map,r=t.mouseEventToLayerPoint(e.touches[0]),i=t.mouseEventToLayerPoint(e.touches[1]);this._scale=r.distanceTo(i)/this._startDist,this._delta=r.add(i).divideBy(2,!0).subtract(this._startCenter);if(this._scale===1)return;this._moved||(n.DomUtil.addClass(t._mapPane,"leaflet-zoom-anim leaflet-touching"),t.fire("movestart").fire("zoomstart")._prepareTileBg(),this._moved=!0),n.Util.cancelAnimFrame(this._animRequest),this._animRequest=n.Util.requestAnimFrame(this._updateOnMove,this,!0,this._map._container),n.DomEvent.preventDefault(e)},_updateOnMove:function(){var e=this._map,t=this._getScaleOrigin(),r=e.layerPointToLatLng(t);e.fire("zoomanim",{center:r,zoom:e.getScaleZoom(this._scale)}),e._tileBg.style[n.DomUtil.TRANSFORM]=n.DomUtil.getTranslateString(this._delta)+" "+n.DomUtil.getScaleString(this._scale,this._startCenter)},_onTouchEnd:function(e){if(!this._moved||!this._zooming)return;var t=this._map;this._zooming=!1,n.DomUtil.removeClass(t._mapPane,"leaflet-touching"),n.DomEvent.off(document,"touchmove",this._onTouchMove).off(document,"touchend",this._onTouchEnd);var r=this._getScaleOrigin(),i=t.layerPointToLatLng(r),s=t.getZoom(),o=t.getScaleZoom(this._scale)-s,u=o>0?Math.ceil(o):Math.floor(o),a=t._limitZoom(s+u);t.fire("zoomanim",{center:i,zoom:a}),t._runAnimation(i,a,t.getZoomScale(a)/this._scale,r,!0)},_getScaleOrigin:function(){var e=this._centerOffset.subtract(this._delta).divideBy(this._scale);return this._startCenter.add(e)}}),n.Map.addInitHook("addHandler","touchZoom",n.Map.TouchZoom),n.Map.mergeOptions({boxZoom:!0}),n.Map.BoxZoom=n.Handler.extend({initialize:function(e){this._map=e,this._container=e._container,this._pane=e._panes.overlayPane},addHooks:function(){n.DomEvent.on(this._container,"mousedown",this._onMouseDown,this)},removeHooks:function(){n.DomEvent.off(this._container,"mousedown",this._onMouseDown)},_onMouseDown:function(e){if(!e.shiftKey||e.which!==1&&e.button!==1)return!1;n.DomUtil.disableTextSelection(),this._startLayerPoint=this._map.mouseEventToLayerPoint(e),this._box=n.DomUtil.create("div","leaflet-zoom-box",this._pane),n.DomUtil.setPosition(this._box,this._startLayerPoint),this._container.style.cursor="crosshair",n.DomEvent.on(document,"mousemove",this._onMouseMove,this).on(document,"mouseup",this._onMouseUp,this).preventDefault(e),this._map.fire("boxzoomstart")},_onMouseMove:function(e){var t=this._startLayerPoint,r=this._box,i=this._map.mouseEventToLayerPoint(e),s=i.subtract(t),o=new n.Point(Math.min(i.x,t.x),Math.min(i.y,t.y));n.DomUtil.setPosition(r,o),r.style.width=Math.abs(s.x)-4+"px",r.style.height=Math.abs(s.y)-4+"px"},_onMouseUp:function(e){this._pane.removeChild(this._box),this._container.style.cursor="",n.DomUtil.enableTextSelection(),n.DomEvent.off(document,"mousemove",this._onMouseMove).off(document,"mouseup",this._onMouseUp);var t=this._map,r=t.mouseEventToLayerPoint(e),i=new n.LatLngBounds(t.layerPointToLatLng(this._startLayerPoint),t.layerPointToLatLng(r));t.fitBounds(i),t.fire("boxzoomend",{boxZoomBounds:i})}}),n.Map.addInitHook("addHandler","boxZoom",n.Map.BoxZoom),n.Map.mergeOptions({keyboard:!0,keyboardPanOffset:80,keyboardZoomOffset:1}),n.Map.Keyboard=n.Handler.extend({keyCodes:{left:[37],right:[39],down:[40],up:[38],zoomIn:[187,107,61],zoomOut:[189,109]},initialize:function(e){this._map=e,this._setPanOffset(e.options.keyboardPanOffset),this._setZoomOffset(e.options.keyboardZoomOffset)},addHooks:function(){var e=this._map._container;e.tabIndex===-1&&(e.tabIndex="0"),n.DomEvent.addListener(e,"focus",this._onFocus,this).addListener(e,"blur",this._onBlur,this).addListener(e,"mousedown",this._onMouseDown,this),this._map.on("focus",this._addHooks,this).on("blur",this._removeHooks,this)},removeHooks:function(){this._removeHooks();var e=this._map._container;n.DomEvent.removeListener(e,"focus",this._onFocus,this).removeListener(e,"blur",this._onBlur,this).removeListener(e,"mousedown",this._onMouseDown,this),this._map.off("focus",this._addHooks,this).off("blur",this._removeHooks,this)},_onMouseDown:function(){this._focused||this._map._container.focus()},_onFocus:function(){this._focused=!0,this._map.fire("focus")},_onBlur:function(){this._focused=!1,this._map.fire("blur")},_setPanOffset:function(e){var t=this._panKeys={},n=this.keyCodes,r,i;for(r=0,i=n.left.length;re&&(n._index+=t)})},_createMiddleMarker:function(e,t){var n=this._getMiddleLatLng(e,t),r=this._createMarker(n),i,s,o;r.setOpacity(.6),e._middleRight=t._middleLeft=r,s=function(){var s=t._index;r._index=s,r.off("click",i).on("click",this._onMarkerClick,this),n.lat=r.getLatLng().lat,n.lng=r.getLatLng().lng,this._poly.spliceLatLngs(s,0,n),this._markers.splice(s,0,r),r.setOpacity(1),this._updateIndexes(s,1),t._index++,this._updatePrevNext(e,r),this._updatePrevNext(r,t)},o=function(){r.off("dragstart",s,this),r.off("dragend",o,this),this._createMiddleMarker(e,r),this._createMiddleMarker(r,t)},i=function(){s.call(this),o.call(this),this._poly.fire("edit")},r.on("click",i,this).on("dragstart",s,this).on("dragend",o,this),this._markerGroup.addLayer(r)},_updatePrevNext:function(e,t){e._next=t,t._prev=e},_getMiddleLatLng:function(e,t){var n=this._poly._map,r=n.latLngToLayerPoint(e.getLatLng()),i=n.latLngToLayerPoint(t.getLatLng());return n.layerPointToLatLng(r._add(i).divideBy(2))}}),n.Control=n.Class.extend({options:{position:"topright"},initialize:function(e){n.Util.setOptions(this,e)},getPosition:function(){return this.options.position},setPosition:function(e){var t=this._map;return t&&t.removeControl(this),this.options.position=e,t&&t.addControl(this),this},addTo:function(e){this._map=e;var t=this._container=this.onAdd(e),r=this.getPosition(),i=e._controlCorners[r];return n.DomUtil.addClass(t,"leaflet-control"),r.indexOf("bottom")!==-1?i.insertBefore(t,i.firstChild):i.appendChild(t),this},removeFrom:function(e){var t=this.getPosition(),n=e._controlCorners[t];return n.removeChild(this._container),this._map=null,this.onRemove&&this.onRemove(e),this}}),n.control=function(e){return new n.Control(e)},n.Map.include({addControl:function(e){return e.addTo(this),this},removeControl:function(e){return e.removeFrom(this),this},_initControlPos:function(){function i(i,s){var o=t+i+" "+t+s;e[i+s]=n.DomUtil.create("div",o,r)}var e=this._controlCorners={},t="leaflet-",r=this._controlContainer=n.DomUtil.create("div",t+"control-container",this._container);i("top","left"),i("top","right"),i("bottom","left"),i("bottom","right")}}),n.Control.Zoom=n.Control.extend({options:{position:"topleft"},onAdd:function(e){var t="leaflet-control-zoom",r=n.DomUtil.create("div",t);return this._createButton("Zoom in",t+"-in",r,e.zoomIn,e),this._createButton("Zoom out",t+"-out",r,e.zoomOut,e),r},_createButton:function(e,t,r,i,s){var o=n.DomUtil.create("a",t,r);return o.href="#",o.title=e,n.DomEvent.on(o,"click",n.DomEvent.stopPropagation).on(o,"click",n.DomEvent.preventDefault).on(o,"click",i,s).on(o,"dblclick",n.DomEvent.stopPropagation),o}}),n.Map.mergeOptions({zoomControl:!0}),n.Map.addInitHook(function(){this.options.zoomControl&&(this.zoomControl=new n.Control.Zoom,this.addControl(this.zoomControl))}),n.control.zoom=function(e){return new n.Control.Zoom(e)},n.Control.Attribution=n.Control.extend({options:{position:"bottomright",prefix:'Powered by Leaflet'},initialize:function(e){n.Util.setOptions(this,e),this._attributions={}},onAdd:function(e){return this._container=n.DomUtil.create("div","leaflet-control-attribution"),n.DomEvent.disableClickPropagation(this._container),e.on("layeradd",this._onLayerAdd,this).on("layerremove",this._onLayerRemove,this),this._update(),this._container},onRemove:function(e){e.off("layeradd",this._onLayerAdd).off("layerremove",this._onLayerRemove)},setPrefix:function(e){return this.options.prefix=e,this._update(),this},addAttribution:function(e){if(!e)return;return this._attributions[e]||(this._attributions[e]=0),this._attributions[e]++,this._update(),this},removeAttribution:function(e){if(!e)return;return this._attributions[e]--,this._update(),this},_update:function(){if(!this._map)return;var e=[];for(var t in this._attributions)this._attributions.hasOwnProperty(t)&&this._attributions[t]&&e.push(t);var n=[];this.options.prefix&&n.push(this.options.prefix),e.length&&n.push(e.join(", ")),this._container.innerHTML=n.join(" — ")},_onLayerAdd:function(e){e.layer.getAttribution&&this.addAttribution(e.layer.getAttribution())},_onLayerRemove:function(e){e.layer.getAttribution&&this.removeAttribution(e.layer.getAttribution())}}),n.Map.mergeOptions({attributionControl:!0}),n.Map.addInitHook(function(){this.options.attributionControl&&(this.attributionControl=(new n.Control.Attribution).addTo(this))}),n.control.attribution=function(e){return new n.Control.Attribution(e)},n.Control.Scale=n.Control.extend({options:{position:"bottomleft",maxWidth:100,metric:!0,imperial:!0,updateWhenIdle:!1},onAdd:function(e){this._map=e;var t="leaflet-control-scale",r=n.DomUtil.create("div",t),i=this.options;return this._addScales(i,t,r),e.on(i.updateWhenIdle?"moveend":"move",this._update,this),this._update(),r},onRemove:function(e){e.off(this.options.updateWhenIdle?"moveend":"move",this._update,this)},_addScales:function(e,t,r){e.metric&&(this._mScale=n.DomUtil.create("div",t+"-line",r)),e.imperial&&(this._iScale=n.DomUtil.create("div",t+"-line",r))},_update:function(){var e=this._map.getBounds(),t=e.getCenter().lat,n=6378137*Math.PI*Math.cos(t*Math.PI/180),r=n*(e.getNorthEast().lng-e.getSouthWest().lng)/180,i=this._map.getSize(),s=this.options,o=0;i.x>0&&(o=r*(s.maxWidth/i.x)),this._updateScales(s,o)},_updateScales:function(e,t){e.metric&&t&&this._updateMetric(t),e.imperial&&t&&this._updateImperial(t)},_updateMetric:function(e){var t=this._getRoundNum(e);this._mScale.style.width=this._getScaleWidth(t/e)+"px",this._mScale.innerHTML=t<1e3?t+" m":t/1e3+" km"},_updateImperial:function(e){var t=e*3.2808399,n=this._iScale,r,i,s;t>5280?(r=t/5280,i=this._getRoundNum(r),n.style.width=this._getScaleWidth(i/r)+"px",n.innerHTML=i+" mi"):(s=this._getRoundNum(t),n.style.width=this._getScaleWidth(s/t)+"px",n.innerHTML=s+" ft")},_getScaleWidth:function(e){return Math.round(this.options.maxWidth*e)-10},_getRoundNum:function(e){var t=Math.pow(10,(Math.floor(e)+"").length-1),n=e/t;return n=n>=10?10:n>=5?5:n>=3?3:n>=2?2:1,t*n}}),n.control.scale=function(e){return new n.Control.Scale(e)},n.Control.Layers=n.Control.extend({options:{collapsed:!0,position:"topright",autoZIndex:!0},initialize:function(e,t,r){n.Util.setOptions(this,r),this._layers={},this._lastZIndex=0;for(var i in e)e.hasOwnProperty(i)&&this._addLayer(e[i],i);for(i in t)t.hasOwnProperty(i)&&this._addLayer(t[i],i,!0)},onAdd:function(e){return this._initLayout(),this._update(),this._container},addBaseLayer:function(e,t){return this._addLayer(e,t),this._update(),this},addOverlay:function(e,t){return this._addLayer(e,t,!0),this._update(),this},removeLayer:function(e){var t=n.Util.stamp(e);return delete this._layers[t],this._update(),this},_initLayout:function(){var e="leaflet-control-layers",t=this._container=n.DomUtil.create("div",e);n.Browser.touch?n.DomEvent.on(t,"click",n.DomEvent.stopPropagation):n.DomEvent.disableClickPropagation(t);var r=this._form=n.DomUtil.create("form",e+"-list");if(this.options.collapsed){n.DomEvent.on(t,"mouseover",this._expand,this).on(t,"mouseout",this._collapse,this);var i=this._layersLink=n.DomUtil.create("a",e+"-toggle",t);i.href="#",i.title="Layers",n.Browser.touch?n.DomEvent.on(i,"click",n.DomEvent.stopPropagation).on(i,"click",n.DomEvent.preventDefault).on(i,"click",this._expand,this):n.DomEvent.on(i,"focus",this._expand,this),this._map.on("movestart",this._collapse,this)}else this._expand();this._baseLayersList=n.DomUtil.create("div",e+"-base",r),this._separator=n.DomUtil.create("div",e+"-separator",r),this._overlaysList=n.DomUtil.create("div",e+"-overlays",r),t.appendChild(r)},_addLayer:function(e,t,r){var i=n.Util.stamp(e);this._layers[i]={layer:e,name:t,overlay:r},this.options.autoZIndex&&e.setZIndex&&(this._lastZIndex++,e.setZIndex(this._lastZIndex))},_update:function(){if(!this._container)return;this._baseLayersList.innerHTML="",this._overlaysList.innerHTML="";var e=!1,t=!1;for(var n in this._layers)if(this._layers.hasOwnProperty(n)){var r=this._layers[n];this._addItem(r),t=t||r.overlay,e=e||!r.overlay}this._separator.style.display=t&&e?"":"none"},_createRadioElement:function(e,t){var n='.5&&this._getLoadedTilesPercentage(e)<.5){e.style.visibility="hidden",e.empty=!0,this._stopLoadingImages(e);return}t||(t=this._tileBg=this._createPane("leaflet-tile-pane",this._mapPane),t.style.zIndex=1),t.style[n.DomUtil.TRANSFORM]="",t.style.visibility="hidden",t.empty=!0,e.empty=!1,this._tilePane=this._panes.tilePane=t;var r=this._tileBg=e;n.DomUtil.addClass(r,"leaflet-zoom-animated"),this._stopLoadingImages(r)},_getLoadedTilesPercentage:function(e){var t=e.getElementsByTagName("img"),n,r,i=0;for(n=0,r=t.length;n