+ _onDoubleClick: function (e) {
+ var map = this._map,
+ oldZoom = map.getZoom(),
+ delta = map.options.zoomDelta,
+ zoom = e.originalEvent.shiftKey ? oldZoom - delta : oldZoom + delta;
+
+ if (map.options.doubleClickZoom === 'center') {
+ map.setZoom(zoom);
+ } else {
+ map.setZoomAround(e.containerPoint, zoom);
+ }
+ }
+});
+
+// @section Handlers
+//
+// Map properties include interaction handlers that allow you to control
+// interaction behavior in runtime, enabling or disabling certain features such
+// as dragging or touch zoom (see `Handler` methods). For example:
+//
+// ```js
+// map.doubleClickZoom.disable();
+// ```
+//
+// @property doubleClickZoom: Handler
+// Double click zoom handler.
+L.Map.addInitHook('addHandler', 'doubleClickZoom', L.Map.DoubleClickZoom);
+
+
+
+/*
+ * L.Handler.ScrollWheelZoom is used by L.Map to enable mouse scroll wheel zoom on the map.
+ */
+
+// @namespace Map
+// @section Interaction Options
+L.Map.mergeOptions({
+ // @section Mousewheel options
+ // @option scrollWheelZoom: Boolean|String = true
+ // Whether the map can be zoomed by using the mouse wheel. If passed `'center'`,
+ // it will zoom to the center of the view regardless of where the mouse was.
+ scrollWheelZoom: true,
+
+ // @option wheelDebounceTime: Number = 40
+ // Limits the rate at which a wheel can fire (in milliseconds). By default
+ // user can't zoom via wheel more often than once per 40 ms.
+ wheelDebounceTime: 40,
+
+ // @option wheelPxPerZoomLevel: Number = 60
+ // How many scroll pixels (as reported by [L.DomEvent.getWheelDelta](#domevent-getwheeldelta))
+ // mean a change of one full zoom level. Smaller values will make wheel-zooming
+ // faster (and vice versa).
+ wheelPxPerZoomLevel: 60
+});
+
+L.Map.ScrollWheelZoom = L.Handler.extend({
+ addHooks: function () {
+ L.DomEvent.on(this._map._container, 'mousewheel', this._onWheelScroll, this);
+
+ this._delta = 0;
+ },
+
+ removeHooks: function () {
+ L.DomEvent.off(this._map._container, 'mousewheel', this._onWheelScroll, this);
+ },
+
+ _onWheelScroll: function (e) {
+ var delta = L.DomEvent.getWheelDelta(e);
+
+ var debounce = this._map.options.wheelDebounceTime;
+
+ this._delta += delta;
+ this._lastMousePos = this._map.mouseEventToContainerPoint(e);
+
+ if (!this._startTime) {
+ this._startTime = +new Date();
+ }
+
+ var left = Math.max(debounce - (+new Date() - this._startTime), 0);
+
+ clearTimeout(this._timer);
+ this._timer = setTimeout(L.bind(this._performZoom, this), left);
+
+ L.DomEvent.stop(e);
+ },
+
+ _performZoom: function () {
+ var map = this._map,
+ zoom = map.getZoom(),
+ snap = this._map.options.zoomSnap || 0;
+
+ map._stop(); // stop panning and fly animations if any
+
+ // map the delta with a sigmoid function to -4..4 range leaning on -1..1
+ var d2 = this._delta / (this._map.options.wheelPxPerZoomLevel * 4),
+ d3 = 4 * Math.log(2 / (1 + Math.exp(-Math.abs(d2)))) / Math.LN2,
+ d4 = snap ? Math.ceil(d3 / snap) * snap : d3,
+ delta = map._limitZoom(zoom + (this._delta > 0 ? d4 : -d4)) - zoom;
+
+ this._delta = 0;
+ this._startTime = null;
+
+ if (!delta) { return; }
+
+ if (map.options.scrollWheelZoom === 'center') {
+ map.setZoom(zoom + delta);
+ } else {
+ map.setZoomAround(this._lastMousePos, zoom + delta);
+ }
+ }
+});
+
+// @section Handlers
+// @property scrollWheelZoom: Handler
+// Scroll wheel zoom handler.
+L.Map.addInitHook('addHandler', 'scrollWheelZoom', L.Map.ScrollWheelZoom);
+
+
+
+/*
+ * Extends the event handling code with double tap support for mobile browsers.
+ */
+
+L.extend(L.DomEvent, {
+
+ _touchstart: L.Browser.msPointer ? 'MSPointerDown' : L.Browser.pointer ? 'pointerdown' : 'touchstart',
+ _touchend: L.Browser.msPointer ? 'MSPointerUp' : L.Browser.pointer ? 'pointerup' : 'touchend',
+
+ // inspired by Zepto touch code by Thomas Fuchs
+ addDoubleTapListener: function (obj, handler, id) {
+ var last, touch,
+ doubleTap = false,
+ delay = 250;
+
+ function onTouchStart(e) {
+ var count;
+
+ if (L.Browser.pointer) {
+ if ((!L.Browser.edge) || e.pointerType === 'mouse') { return; }
+ count = L.DomEvent._pointersCount;
+ } else {
+ count = e.touches.length;
+ }
+
+ if (count > 1) { return; }
+
+ var now = Date.now(),
+ delta = now - (last || now);
+
+ touch = e.touches ? e.touches[0] : e;
+ doubleTap = (delta > 0 && delta <= delay);
+ last = now;
+ }
+
+ function onTouchEnd(e) {
+ if (doubleTap && !touch.cancelBubble) {
+ if (L.Browser.pointer) {
+ if ((!L.Browser.edge) || e.pointerType === 'mouse') { return; }
+
+ // work around .type being readonly with MSPointer* events
+ var newTouch = {},
+ prop, i;
+
+ for (i in touch) {
+ prop = touch[i];
+ newTouch[i] = prop && prop.bind ? prop.bind(touch) : prop;
+ }
+ touch = newTouch;
+ }
+ touch.type = 'dblclick';
+ handler(touch);
+ last = null;
+ }
+ }
+
+ var pre = '_leaflet_',
+ touchstart = this._touchstart,
+ touchend = this._touchend;
+
+ obj[pre + touchstart + id] = onTouchStart;
+ obj[pre + touchend + id] = onTouchEnd;
+ obj[pre + 'dblclick' + id] = handler;
+
+ obj.addEventListener(touchstart, onTouchStart, false);
+ obj.addEventListener(touchend, onTouchEnd, false);
+
+ // On some platforms (notably, chrome<55 on win10 + touchscreen + mouse),
+ // the browser doesn't fire touchend/pointerup events but does fire
+ // native dblclicks. See #4127.
+ // Edge 14 also fires native dblclicks, but only for pointerType mouse, see #5180.
+ obj.addEventListener('dblclick', handler, false);
+
+ return this;
+ },
+
+ removeDoubleTapListener: function (obj, id) {
+ var pre = '_leaflet_',
+ touchstart = obj[pre + this._touchstart + id],
+ touchend = obj[pre + this._touchend + id],
+ dblclick = obj[pre + 'dblclick' + id];
+
+ obj.removeEventListener(this._touchstart, touchstart, false);
+ obj.removeEventListener(this._touchend, touchend, false);
+ if (!L.Browser.edge) {
+ obj.removeEventListener('dblclick', dblclick, false);
+ }
+
+ return this;
+ }
+});
+
+
+
+/*
+ * Extends L.DomEvent to provide touch support for Internet Explorer and Windows-based devices.
+ */
+
+L.extend(L.DomEvent, {
+
+ POINTER_DOWN: L.Browser.msPointer ? 'MSPointerDown' : 'pointerdown',
+ POINTER_MOVE: L.Browser.msPointer ? 'MSPointerMove' : 'pointermove',
+ POINTER_UP: L.Browser.msPointer ? 'MSPointerUp' : 'pointerup',
+ POINTER_CANCEL: L.Browser.msPointer ? 'MSPointerCancel' : 'pointercancel',
+ TAG_WHITE_LIST: ['INPUT', 'SELECT', 'OPTION'],
+
+ _pointers: {},
+ _pointersCount: 0,
+
+ // Provides a touch events wrapper for (ms)pointer events.
+ // ref http://www.w3.org/TR/pointerevents/ https://www.w3.org/Bugs/Public/show_bug.cgi?id=22890
+
+ addPointerListener: function (obj, type, handler, id) {
+
+ if (type === 'touchstart') {
+ this._addPointerStart(obj, handler, id);
+
+ } else if (type === 'touchmove') {
+ this._addPointerMove(obj, handler, id);
+
+ } else if (type === 'touchend') {
+ this._addPointerEnd(obj, handler, id);
+ }
+
+ return this;
+ },
+
+ removePointerListener: function (obj, type, id) {
+ var handler = obj['_leaflet_' + type + id];
+
+ if (type === 'touchstart') {
+ obj.removeEventListener(this.POINTER_DOWN, handler, false);
+
+ } else if (type === 'touchmove') {
+ obj.removeEventListener(this.POINTER_MOVE, handler, false);
+
+ } else if (type === 'touchend') {
+ obj.removeEventListener(this.POINTER_UP, handler, false);
+ obj.removeEventListener(this.POINTER_CANCEL, handler, false);
+ }
+
+ return this;
+ },
+
+ _addPointerStart: function (obj, handler, id) {
+ var onDown = L.bind(function (e) {
+ if (e.pointerType !== 'mouse' && e.MSPOINTER_TYPE_MOUSE && e.pointerType !== e.MSPOINTER_TYPE_MOUSE) {
+ // In IE11, some touch events needs to fire for form controls, or
+ // the controls will stop working. We keep a whitelist of tag names that
+ // need these events. For other target tags, we prevent default on the event.
+ if (this.TAG_WHITE_LIST.indexOf(e.target.tagName) < 0) {
+ L.DomEvent.preventDefault(e);
+ } else {
+ return;
+ }
+ }
+
+ this._handlePointer(e, handler);
+ }, this);
+
+ obj['_leaflet_touchstart' + id] = onDown;
+ obj.addEventListener(this.POINTER_DOWN, onDown, false);
+
+ // need to keep track of what pointers and how many are active to provide e.touches emulation
+ if (!this._pointerDocListener) {
+ var pointerUp = L.bind(this._globalPointerUp, this);
+
+ // we listen documentElement as any drags that end by moving the touch off the screen get fired there
+ document.documentElement.addEventListener(this.POINTER_DOWN, L.bind(this._globalPointerDown, this), true);
+ document.documentElement.addEventListener(this.POINTER_MOVE, L.bind(this._globalPointerMove, this), true);
+ document.documentElement.addEventListener(this.POINTER_UP, pointerUp, true);
+ document.documentElement.addEventListener(this.POINTER_CANCEL, pointerUp, true);
+
+ this._pointerDocListener = true;
+ }
+ },
+
+ _globalPointerDown: function (e) {
+ this._pointers[e.pointerId] = e;
+ this._pointersCount++;
+ },
+
+ _globalPointerMove: function (e) {
+ if (this._pointers[e.pointerId]) {
+ this._pointers[e.pointerId] = e;
+ }
+ },
+
+ _globalPointerUp: function (e) {
+ delete this._pointers[e.pointerId];
+ this._pointersCount--;
+ },
+
+ _handlePointer: function (e, handler) {
+ e.touches = [];
+ for (var i in this._pointers) {
+ e.touches.push(this._pointers[i]);
+ }
+ e.changedTouches = [e];
+
+ handler(e);
+ },
+
+ _addPointerMove: function (obj, handler, id) {
+ var onMove = L.bind(function (e) {
+ // don't fire touch moves when mouse isn't down
+ if ((e.pointerType === e.MSPOINTER_TYPE_MOUSE || e.pointerType === 'mouse') && e.buttons === 0) { return; }
+
+ this._handlePointer(e, handler);
+ }, this);
+
+ obj['_leaflet_touchmove' + id] = onMove;
+ obj.addEventListener(this.POINTER_MOVE, onMove, false);
+ },
+
+ _addPointerEnd: function (obj, handler, id) {
+ var onUp = L.bind(function (e) {
+ this._handlePointer(e, handler);
+ }, this);
+
+ obj['_leaflet_touchend' + id] = onUp;
+ obj.addEventListener(this.POINTER_UP, onUp, false);
+ obj.addEventListener(this.POINTER_CANCEL, onUp, false);
+ }
+});
+
+
+
+/*
+ * L.Handler.TouchZoom is used by L.Map to add pinch zoom on supported mobile browsers.
+ */
+
+// @namespace Map
+// @section Interaction Options
+L.Map.mergeOptions({
+ // @section Touch interaction options
+ // @option touchZoom: Boolean|String = *
+ // Whether the map can be zoomed by touch-dragging with two fingers. If
+ // passed `'center'`, it will zoom to the center of the view regardless of
+ // where the touch events (fingers) were. Enabled for touch-capable web
+ // browsers except for old Androids.
+ touchZoom: L.Browser.touch && !L.Browser.android23,
+
+ // @option bounceAtZoomLimits: Boolean = true
+ // Set it to false if you don't want the map to zoom beyond min/max zoom
+ // and then bounce back when pinch-zooming.
+ bounceAtZoomLimits: true
+});
+
+L.Map.TouchZoom = L.Handler.extend({
+ addHooks: function () {
+ L.DomUtil.addClass(this._map._container, 'leaflet-touch-zoom');
+ L.DomEvent.on(this._map._container, 'touchstart', this._onTouchStart, this);
+ },
+
+ removeHooks: function () {
+ L.DomUtil.removeClass(this._map._container, 'leaflet-touch-zoom');
+ L.DomEvent.off(this._map._container, 'touchstart', this._onTouchStart, this);
+ },
+
+ _onTouchStart: function (e) {
+ var map = this._map;
+ if (!e.touches || e.touches.length !== 2 || map._animatingZoom || this._zooming) { return; }
+
+ var p1 = map.mouseEventToContainerPoint(e.touches[0]),
+ p2 = map.mouseEventToContainerPoint(e.touches[1]);
+
+ this._centerPoint = map.getSize()._divideBy(2);
+ this._startLatLng = map.containerPointToLatLng(this._centerPoint);
+ if (map.options.touchZoom !== 'center') {
+ this._pinchStartLatLng = map.containerPointToLatLng(p1.add(p2)._divideBy(2));
+ }
+
+ this._startDist = p1.distanceTo(p2);
+ this._startZoom = map.getZoom();
+
+ this._moved = false;
+ this._zooming = true;
+
+ map._stop();
+
+ 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 || !this._zooming) { return; }
+
+ var map = this._map,
+ p1 = map.mouseEventToContainerPoint(e.touches[0]),
+ p2 = map.mouseEventToContainerPoint(e.touches[1]),
+ scale = p1.distanceTo(p2) / this._startDist;
+
+
+ this._zoom = map.getScaleZoom(scale, this._startZoom);
+
+ if (!map.options.bounceAtZoomLimits && (
+ (this._zoom < map.getMinZoom() && scale < 1) ||
+ (this._zoom > map.getMaxZoom() && scale > 1))) {
+ this._zoom = map._limitZoom(this._zoom);
+ }
+
+ if (map.options.touchZoom === 'center') {
+ this._center = this._startLatLng;
+ if (scale === 1) { return; }
+ } else {
+ // Get delta from pinch to center, so centerLatLng is delta applied to initial pinchLatLng
+ var delta = p1._add(p2)._divideBy(2)._subtract(this._centerPoint);
+ if (scale === 1 && delta.x === 0 && delta.y === 0) { return; }
+ this._center = map.unproject(map.project(this._pinchStartLatLng, this._zoom).subtract(delta), this._zoom);
+ }
+
+ if (!this._moved) {
+ map._moveStart(true);
+ this._moved = true;
+ }
+
+ L.Util.cancelAnimFrame(this._animRequest);
+
+ var moveFn = L.bind(map._move, map, this._center, this._zoom, {pinch: true, round: false});
+ this._animRequest = L.Util.requestAnimFrame(moveFn, this, true);
+
+ L.DomEvent.preventDefault(e);
+ },
+
+ _onTouchEnd: function () {
+ if (!this._moved || !this._zooming) {
+ this._zooming = false;
+ return;
+ }
+
+ this._zooming = false;
+ L.Util.cancelAnimFrame(this._animRequest);
+
+ L.DomEvent
+ .off(document, 'touchmove', this._onTouchMove)
+ .off(document, 'touchend', this._onTouchEnd);
+
+ // Pinch updates GridLayers' levels only when zoomSnap is off, so zoomSnap becomes noUpdate.
+ if (this._map.options.zoomAnimation) {
+ this._map._animateZoom(this._center, this._map._limitZoom(this._zoom), true, this._map.options.zoomSnap);
+ } else {
+ this._map._resetView(this._center, this._map._limitZoom(this._zoom));
+ }
+ }
+});
+
+// @section Handlers
+// @property touchZoom: Handler
+// Touch zoom handler.
+L.Map.addInitHook('addHandler', 'touchZoom', L.Map.TouchZoom);
+
+
+
+/*
+ * L.Map.Tap is used to enable mobile hacks like quick taps and long hold.
+ */
+
+// @namespace Map
+// @section Interaction Options
+L.Map.mergeOptions({
+ // @section Touch interaction options
+ // @option tap: Boolean = true
+ // Enables mobile hacks for supporting instant taps (fixing 200ms click
+ // delay on iOS/Android) and touch holds (fired as `contextmenu` events).
+ tap: true,
+
+ // @option tapTolerance: Number = 15
+ // The max number of pixels a user can shift his finger during touch
+ // for it to be considered a valid tap.
+ tapTolerance: 15
+});
+
+L.Map.Tap = L.Handler.extend({
+ addHooks: function () {
+ L.DomEvent.on(this._map._container, 'touchstart', this._onDown, this);
+ },
+
+ removeHooks: function () {
+ L.DomEvent.off(this._map._container, 'touchstart', this._onDown, this);
+ },
+
+ _onDown: function (e) {
+ if (!e.touches) { return; }
+
+ L.DomEvent.preventDefault(e);
+
+ this._fireClick = true;
+
+ // don't simulate click or track longpress if more than 1 touch
+ if (e.touches.length > 1) {
+ this._fireClick = false;
+ clearTimeout(this._holdTimeout);
+ return;
+ }
+
+ var first = e.touches[0],
+ el = first.target;
+
+ this._startPos = this._newPos = new L.Point(first.clientX, first.clientY);
+
+ // if touching a link, highlight it
+ if (el.tagName && el.tagName.toLowerCase() === 'a') {
+ L.DomUtil.addClass(el, 'leaflet-active');
+ }
+
+ // simulate long hold but setting a timeout
+ this._holdTimeout = setTimeout(L.bind(function () {
+ if (this._isTapValid()) {
+ this._fireClick = false;
+ this._onUp();
+ this._simulateEvent('contextmenu', first);
+ }
+ }, this), 1000);
+
+ this._simulateEvent('mousedown', first);
+
+ L.DomEvent.on(document, {
+ touchmove: this._onMove,
+ touchend: this._onUp
+ }, this);
+ },
+
+ _onUp: function (e) {
+ clearTimeout(this._holdTimeout);
+
+ L.DomEvent.off(document, {
+ touchmove: this._onMove,
+ touchend: this._onUp
+ }, this);
+
+ if (this._fireClick && e && e.changedTouches) {
+
+ var first = e.changedTouches[0],
+ el = first.target;
+
+ if (el && el.tagName && el.tagName.toLowerCase() === 'a') {
+ L.DomUtil.removeClass(el, 'leaflet-active');
+ }
+
+ this._simulateEvent('mouseup', first);
+
+ // simulate click if the touch didn't move too much
+ if (this._isTapValid()) {
+ this._simulateEvent('click', first);
+ }
+ }
+ },
+
+ _isTapValid: function () {
+ return this._newPos.distanceTo(this._startPos) <= this._map.options.tapTolerance;
+ },
+
+ _onMove: function (e) {
+ var first = e.touches[0];
+ this._newPos = new L.Point(first.clientX, first.clientY);
+ this._simulateEvent('mousemove', first);
+ },
+
+ _simulateEvent: function (type, e) {
+ var simulatedEvent = document.createEvent('MouseEvents');
+
+ simulatedEvent._simulated = true;
+ e.target._simulatedClick = true;
+
+ simulatedEvent.initMouseEvent(
+ type, true, true, window, 1,
+ e.screenX, e.screenY,
+ e.clientX, e.clientY,
+ false, false, false, false, 0, null);
+
+ e.target.dispatchEvent(simulatedEvent);
+ }
+});
+
+// @section Handlers
+// @property tap: Handler
+// Mobile touch hacks (quick tap and touch hold) handler.
+if (L.Browser.touch && !L.Browser.pointer) {
+ L.Map.addInitHook('addHandler', 'tap', L.Map.Tap);
+}
+
+
+
+/*
+ * L.Handler.BoxZoom is used to add shift-drag zoom interaction to the map
+ * (zoom to a selected bounding box), enabled by default.
+ */
+
+// @namespace Map
+// @section Interaction Options
+L.Map.mergeOptions({
+ // @option boxZoom: Boolean = true
+ // Whether the map can be zoomed to a rectangular area specified by
+ // dragging the mouse while pressing the shift key.
+ boxZoom: true
+});
+
+L.Map.BoxZoom = L.Handler.extend({
+ initialize: function (map) {
+ this._map = map;
+ this._container = map._container;
+ this._pane = map._panes.overlayPane;
+ },
+
+ addHooks: function () {
+ L.DomEvent.on(this._container, 'mousedown', this._onMouseDown, this);
+ },
+
+ removeHooks: function () {
+ L.DomEvent.off(this._container, 'mousedown', this._onMouseDown, this);
+ },
+
+ moved: function () {
+ return this._moved;
+ },
+
+ _resetState: function () {
+ this._moved = false;
+ },
+
+ _onMouseDown: function (e) {
+ if (!e.shiftKey || ((e.which !== 1) && (e.button !== 1))) { return false; }
+
+ this._resetState();
+
+ L.DomUtil.disableTextSelection();
+ L.DomUtil.disableImageDrag();
+
+ this._startPoint = this._map.mouseEventToContainerPoint(e);
+
+ L.DomEvent.on(document, {
+ contextmenu: L.DomEvent.stop,
+ mousemove: this._onMouseMove,
+ mouseup: this._onMouseUp,
+ keydown: this._onKeyDown
+ }, this);
+ },
+
+ _onMouseMove: function (e) {
+ if (!this._moved) {
+ this._moved = true;
+
+ this._box = L.DomUtil.create('div', 'leaflet-zoom-box', this._container);
+ L.DomUtil.addClass(this._container, 'leaflet-crosshair');
+
+ this._map.fire('boxzoomstart');
+ }
+
+ this._point = this._map.mouseEventToContainerPoint(e);
+
+ var bounds = new L.Bounds(this._point, this._startPoint),
+ size = bounds.getSize();
+
+ L.DomUtil.setPosition(this._box, bounds.min);
+
+ this._box.style.width = size.x + 'px';
+ this._box.style.height = size.y + 'px';
+ },
+
+ _finish: function () {
+ if (this._moved) {
+ L.DomUtil.remove(this._box);
+ L.DomUtil.removeClass(this._container, 'leaflet-crosshair');
+ }
+
+ L.DomUtil.enableTextSelection();
+ L.DomUtil.enableImageDrag();
+
+ L.DomEvent.off(document, {
+ contextmenu: L.DomEvent.stop,
+ mousemove: this._onMouseMove,
+ mouseup: this._onMouseUp,
+ keydown: this._onKeyDown
+ }, this);
+ },
+
+ _onMouseUp: function (e) {
+ if ((e.which !== 1) && (e.button !== 1)) { return; }
+
+ this._finish();
+
+ if (!this._moved) { return; }
+ // Postpone to next JS tick so internal click event handling
+ // still see it as "moved".
+ setTimeout(L.bind(this._resetState, this), 0);
+
+ var bounds = new L.LatLngBounds(
+ this._map.containerPointToLatLng(this._startPoint),
+ this._map.containerPointToLatLng(this._point));
+
+ this._map
+ .fitBounds(bounds)
+ .fire('boxzoomend', {boxZoomBounds: bounds});
+ },
+
+ _onKeyDown: function (e) {
+ if (e.keyCode === 27) {
+ this._finish();
+ }
+ }
+});
+
+// @section Handlers
+// @property boxZoom: Handler
+// Box (shift-drag with mouse) zoom handler.
+L.Map.addInitHook('addHandler', 'boxZoom', L.Map.BoxZoom);
+
+
+
+/*
+ * L.Map.Keyboard is handling keyboard interaction with the map, enabled by default.
+ */
+
+// @namespace Map
+// @section Keyboard Navigation Options
+L.Map.mergeOptions({
+ // @option keyboard: Boolean = true
+ // Makes the map focusable and allows users to navigate the map with keyboard
+ // arrows and `+`/`-` keys.
+ keyboard: true,
+
+ // @option keyboardPanDelta: Number = 80
+ // Amount of pixels to pan when pressing an arrow key.
+ keyboardPanDelta: 80
+});
+
+L.Map.Keyboard = L.Handler.extend({
+
+ keyCodes: {
+ left: [37],
+ right: [39],
+ down: [40],
+ up: [38],
+ zoomIn: [187, 107, 61, 171],
+ zoomOut: [189, 109, 54, 173]
+ },
+
+ initialize: function (map) {
+ this._map = map;
+
+ this._setPanDelta(map.options.keyboardPanDelta);
+ this._setZoomDelta(map.options.zoomDelta);
+ },
+
+ addHooks: function () {
+ var container = this._map._container;
+
+ // make the container focusable by tabbing
+ if (container.tabIndex <= 0) {
+ container.tabIndex = '0';
+ }
+
+ L.DomEvent.on(container, {
+ focus: this._onFocus,
+ blur: this._onBlur,
+ mousedown: this._onMouseDown
+ }, this);
+
+ this._map.on({
+ focus: this._addHooks,
+ blur: this._removeHooks
+ }, this);
+ },
+
+ removeHooks: function () {
+ this._removeHooks();
+
+ L.DomEvent.off(this._map._container, {
+ focus: this._onFocus,
+ blur: this._onBlur,
+ mousedown: this._onMouseDown
+ }, this);
+
+ this._map.off({
+ focus: this._addHooks,
+ blur: this._removeHooks
+ }, this);
+ },
+
+ _onMouseDown: function () {
+ if (this._focused) { return; }
+
+ var body = document.body,
+ docEl = document.documentElement,
+ top = body.scrollTop || docEl.scrollTop,
+ left = body.scrollLeft || docEl.scrollLeft;
+
+ this._map._container.focus();
+
+ window.scrollTo(left, top);
+ },
+
+ _onFocus: function () {
+ this._focused = true;
+ this._map.fire('focus');
+ },
+
+ _onBlur: function () {
+ this._focused = false;
+ this._map.fire('blur');
+ },
+
+ _setPanDelta: function (panDelta) {
+ var keys = this._panKeys = {},
+ codes = this.keyCodes,
+ i, len;
+
+ for (i = 0, len = codes.left.length; i < len; i++) {
+ keys[codes.left[i]] = [-1 * panDelta, 0];
+ }
+ for (i = 0, len = codes.right.length; i < len; i++) {
+ keys[codes.right[i]] = [panDelta, 0];
+ }
+ for (i = 0, len = codes.down.length; i < len; i++) {
+ keys[codes.down[i]] = [0, panDelta];
+ }
+ for (i = 0, len = codes.up.length; i < len; i++) {
+ keys[codes.up[i]] = [0, -1 * panDelta];
+ }
+ },
+
+ _setZoomDelta: function (zoomDelta) {
+ var keys = this._zoomKeys = {},
+ codes = this.keyCodes,
+ i, len;
+
+ for (i = 0, len = codes.zoomIn.length; i < len; i++) {
+ keys[codes.zoomIn[i]] = zoomDelta;
+ }
+ for (i = 0, len = codes.zoomOut.length; i < len; i++) {
+ keys[codes.zoomOut[i]] = -zoomDelta;
+ }
+ },
+
+ _addHooks: function () {
+ L.DomEvent.on(document, 'keydown', this._onKeyDown, this);
+ },
+
+ _removeHooks: function () {
+ L.DomEvent.off(document, 'keydown', this._onKeyDown, this);
+ },
+
+ _onKeyDown: function (e) {
+ if (e.altKey || e.ctrlKey || e.metaKey) { return; }
+
+ var key = e.keyCode,
+ map = this._map,
+ offset;
+
+ if (key in this._panKeys) {
+
+ if (map._panAnim && map._panAnim._inProgress) { return; }
+
+ offset = this._panKeys[key];
+ if (e.shiftKey) {
+ offset = L.point(offset).multiplyBy(3);
+ }
+
+ map.panBy(offset);
+
+ if (map.options.maxBounds) {
+ map.panInsideBounds(map.options.maxBounds);
+ }
+
+ } else if (key in this._zoomKeys) {
+ map.setZoom(map.getZoom() + (e.shiftKey ? 3 : 1) * this._zoomKeys[key]);
+
+ } else if (key === 27) {
+ map.closePopup();
+
+ } else {
+ return;
+ }
+
+ L.DomEvent.stop(e);
+ }
+});
+
+// @section Handlers
+// @section Handlers
+// @property keyboard: Handler
+// Keyboard navigation handler.
+L.Map.addInitHook('addHandler', 'keyboard', L.Map.Keyboard);
+
+
+
+/*
+ * L.Handler.MarkerDrag is used internally by L.Marker to make the markers draggable.
+ */
+
+
+/* @namespace Marker
+ * @section Interaction handlers
+ *
+ * Interaction handlers are properties of a marker instance that allow you to control interaction behavior in runtime, enabling or disabling certain features such as dragging (see `Handler` methods). Example:
+ *
+ * ```js
+ * marker.dragging.disable();
+ * ```
+ *
+ * @property dragging: Handler
+ * Marker dragging handler (by both mouse and touch).
+ */
+
+L.Handler.MarkerDrag = L.Handler.extend({
+ initialize: function (marker) {
+ this._marker = marker;
+ },
+
+ addHooks: function () {
+ var icon = this._marker._icon;
+
+ if (!this._draggable) {
+ this._draggable = new L.Draggable(icon, icon, true);
+ }
+
+ this._draggable.on({
+ dragstart: this._onDragStart,
+ drag: this._onDrag,
+ dragend: this._onDragEnd
+ }, this).enable();
+
+ L.DomUtil.addClass(icon, 'leaflet-marker-draggable');
+ },
+
+ removeHooks: function () {
+ this._draggable.off({
+ dragstart: this._onDragStart,
+ drag: this._onDrag,
+ dragend: this._onDragEnd
+ }, this).disable();
+
+ if (this._marker._icon) {
+ L.DomUtil.removeClass(this._marker._icon, 'leaflet-marker-draggable');
+ }
+ },
+
+ moved: function () {
+ return this._draggable && this._draggable._moved;
+ },
+
+ _onDragStart: function () {
+ // @section Dragging events
+ // @event dragstart: Event
+ // Fired when the user starts dragging the marker.
+
+ // @event movestart: Event
+ // Fired when the marker starts moving (because of dragging).
+
+ this._oldLatLng = this._marker.getLatLng();
+ this._marker
+ .closePopup()
+ .fire('movestart')
+ .fire('dragstart');
+ },
+
+ _onDrag: function (e) {
+ var marker = this._marker,
+ shadow = marker._shadow,
+ iconPos = L.DomUtil.getPosition(marker._icon),
+ latlng = marker._map.layerPointToLatLng(iconPos);
+
+ // update shadow position
+ if (shadow) {
+ L.DomUtil.setPosition(shadow, iconPos);
+ }
+
+ marker._latlng = latlng;
+ e.latlng = latlng;
+ e.oldLatLng = this._oldLatLng;
+
+ // @event drag: Event
+ // Fired repeatedly while the user drags the marker.
+ marker
+ .fire('move', e)
+ .fire('drag', e);
+ },
+
+ _onDragEnd: function (e) {
+ // @event dragend: DragEndEvent
+ // Fired when the user stops dragging the marker.
+
+ // @event moveend: Event
+ // Fired when the marker stops moving (because of dragging).
+ delete this._oldLatLng;
+ this._marker
+ .fire('moveend')
+ .fire('dragend', e);
+ }
+});
+
+
+
+/*
+ * @class Control
+ * @aka L.Control
+ * @inherits Class
+ *
+ * L.Control is a base class for implementing map controls. Handles positioning.
+ * All other controls extend from this class.
+ */
+
+L.Control = L.Class.extend({
+ // @section
+ // @aka Control options
+ options: {
+ // @option position: String = 'topright'
+ // The position of the control (one of the map corners). Possible values are `'topleft'`,
+ // `'topright'`, `'bottomleft'` or `'bottomright'`
+ position: 'topright'
+ },
+
+ initialize: function (options) {
+ L.setOptions(this, options);
+ },
+
+ /* @section
+ * Classes extending L.Control will inherit the following methods:
+ *
+ * @method getPosition: string
+ * Returns the position of the control.
+ */
+ getPosition: function () {
+ return this.options.position;
+ },
+
+ // @method setPosition(position: string): this
+ // Sets the position of the control.
+ setPosition: function (position) {
+ var map = this._map;
+
+ if (map) {
+ map.removeControl(this);
+ }
+
+ this.options.position = position;
+
+ if (map) {
+ map.addControl(this);
+ }
+
+ return this;
+ },
+
+ // @method getContainer: HTMLElement
+ // Returns the HTMLElement that contains the control.
+ getContainer: function () {
+ return this._container;
+ },
+
+ // @method addTo(map: Map): this
+ // Adds the control to the given map.
+ addTo: function (map) {
+ this.remove();
+ this._map = map;
+
+ var container = this._container = this.onAdd(map),
+ pos = this.getPosition(),
+ corner = map._controlCorners[pos];
+
+ L.DomUtil.addClass(container, 'leaflet-control');
+
+ if (pos.indexOf('bottom') !== -1) {
+ corner.insertBefore(container, corner.firstChild);
+ } else {
+ corner.appendChild(container);
+ }
+
+ return this;
+ },
+
+ // @method remove: this
+ // Removes the control from the map it is currently active on.
+ remove: function () {
+ if (!this._map) {
+ return this;
+ }
+
+ L.DomUtil.remove(this._container);
+
+ if (this.onRemove) {
+ this.onRemove(this._map);
+ }
+
+ this._map = null;
+
+ return this;
+ },
+
+ _refocusOnMap: function (e) {
+ // if map exists and event is not a keyboard event
+ if (this._map && e && e.screenX > 0 && e.screenY > 0) {
+ this._map.getContainer().focus();
+ }
+ }
+});
+
+L.control = function (options) {
+ return new L.Control(options);
+};
+
+/* @section Extension methods
+ * @uninheritable
+ *
+ * Every control should extend from `L.Control` and (re-)implement the following methods.
+ *
+ * @method onAdd(map: Map): HTMLElement
+ * Should return the container DOM element for the control and add listeners on relevant map events. Called on [`control.addTo(map)`](#control-addTo).
+ *
+ * @method onRemove(map: Map)
+ * Optional method. Should contain all clean up code that removes the listeners previously added in [`onAdd`](#control-onadd). Called on [`control.remove()`](#control-remove).
+ */
+
+/* @namespace Map
+ * @section Methods for Layers and Controls
+ */
+L.Map.include({
+ // @method addControl(control: Control): this
+ // Adds the given control to the map
+ addControl: function (control) {
+ control.addTo(this);
+ return this;
+ },
+
+ // @method removeControl(control: Control): this
+ // Removes the given control from the map
+ removeControl: function (control) {
+ control.remove();
+ return this;
+ },
+
+ _initControlPos: function () {
+ var corners = this._controlCorners = {},
+ l = 'leaflet-',
+ container = this._controlContainer =
+ L.DomUtil.create('div', l + 'control-container', this._container);
+
+ function createCorner(vSide, hSide) {
+ var className = l + vSide + ' ' + l + hSide;
+
+ corners[vSide + hSide] = L.DomUtil.create('div', className, container);
+ }
+
+ createCorner('top', 'left');
+ createCorner('top', 'right');
+ createCorner('bottom', 'left');
+ createCorner('bottom', 'right');
+ },
+
+ _clearControlPos: function () {
+ L.DomUtil.remove(this._controlContainer);