+});\r
+
+
+
+/*
+ L.Handler is a base class for handler classes that are used internally to inject
+ interaction features like dragging to classes like Map and Marker.
+*/
+
+// @class Handler
+// @aka L.Handler
+// Abstract class for map interaction handlers
+
+L.Handler = L.Class.extend({
+ initialize: function (map) {
+ this._map = map;
+ },
+
+ // @method enable(): this
+ // Enables the handler
+ enable: function () {
+ if (this._enabled) { return this; }
+
+ this._enabled = true;
+ this.addHooks();
+ return this;
+ },
+
+ // @method disable(): this
+ // Disables the handler
+ disable: function () {
+ if (!this._enabled) { return this; }
+
+ this._enabled = false;
+ this.removeHooks();
+ return this;
+ },
+
+ // @method enabled(): Boolean
+ // Returns `true` if the handler is enabled
+ enabled: function () {
+ return !!this._enabled;
+ }
+
+ // @section Extension methods
+ // Classes inheriting from `Handler` must implement the two following methods:
+ // @method addHooks()
+ // Called when the handler is enabled, should add event hooks.
+ // @method removeHooks()
+ // Called when the handler is disabled, should remove the event hooks added previously.
+});
+
+
+
+/*
+ * L.Handler.MapDrag is used to make the map draggable (with panning inertia), enabled by default.
+ */
+
+// @namespace Map
+// @section Interaction Options
+L.Map.mergeOptions({
+ // @option dragging: Boolean = true
+ // Whether the map be draggable with mouse/touch or not.
+ dragging: true,
+
+ // @section Panning Inertia Options
+ // @option inertia: Boolean = *
+ // If enabled, panning of the map will have an inertia effect where
+ // the map builds momentum while dragging and continues moving in
+ // the same direction for some time. Feels especially nice on touch
+ // devices. Enabled by default unless running on old Android devices.
+ inertia: !L.Browser.android23,
+
+ // @option inertiaDeceleration: Number = 3000
+ // The rate with which the inertial movement slows down, in pixels/second².
+ inertiaDeceleration: 3400, // px/s^2
+
+ // @option inertiaMaxSpeed: Number = Infinity
+ // Max speed of the inertial movement, in pixels/second.
+ inertiaMaxSpeed: Infinity, // px/s
+
+ // @option easeLinearity: Number = 0.2
+ easeLinearity: 0.2,
+
+ // TODO refactor, move to CRS
+ // @option worldCopyJump: Boolean = false
+ // With this option enabled, the map tracks when you pan to another "copy"
+ // of the world and seamlessly jumps to the original one so that all overlays
+ // like markers and vector layers are still visible.
+ worldCopyJump: false,
+
+ // @option maxBoundsViscosity: Number = 0.0
+ // If `maxBounds` is set, this option will control how solid the bounds
+ // are when dragging the map around. The default value of `0.0` allows the
+ // user to drag outside the bounds at normal speed, higher values will
+ // slow down map dragging outside bounds, and `1.0` makes the bounds fully
+ // solid, preventing the user from dragging outside the bounds.
+ maxBoundsViscosity: 0.0
+});
+
+L.Map.Drag = L.Handler.extend({
+ addHooks: function () {
+ if (!this._draggable) {
+ var map = this._map;
+
+ this._draggable = new L.Draggable(map._mapPane, map._container);
+
+ this._draggable.on({
+ down: this._onDown,
+ dragstart: this._onDragStart,
+ drag: this._onDrag,
+ dragend: this._onDragEnd
+ }, this);
+
+ this._draggable.on('predrag', this._onPreDragLimit, this);
+ if (map.options.worldCopyJump) {
+ this._draggable.on('predrag', this._onPreDragWrap, this);
+ map.on('zoomend', this._onZoomEnd, this);
+
+ map.whenReady(this._onZoomEnd, this);
+ }
+ }
+ L.DomUtil.addClass(this._map._container, 'leaflet-grab leaflet-touch-drag');
+ this._draggable.enable();
+ this._positions = [];
+ this._times = [];
+ },
+
+ removeHooks: function () {
+ L.DomUtil.removeClass(this._map._container, 'leaflet-grab');
+ L.DomUtil.removeClass(this._map._container, 'leaflet-touch-drag');
+ this._draggable.disable();
+ },
+
+ moved: function () {
+ return this._draggable && this._draggable._moved;
+ },
+
+ moving: function () {
+ return this._draggable && this._draggable._moving;
+ },
+
+ _onDown: function () {
+ this._map._stop();
+ },
+
+ _onDragStart: function () {
+ var map = this._map;
+
+ if (this._map.options.maxBounds && this._map.options.maxBoundsViscosity) {
+ var bounds = L.latLngBounds(this._map.options.maxBounds);
+
+ this._offsetLimit = L.bounds(
+ this._map.latLngToContainerPoint(bounds.getNorthWest()).multiplyBy(-1),
+ this._map.latLngToContainerPoint(bounds.getSouthEast()).multiplyBy(-1)
+ .add(this._map.getSize()));
+
+ this._viscosity = Math.min(1.0, Math.max(0.0, this._map.options.maxBoundsViscosity));
+ } else {
+ this._offsetLimit = null;
+ }
+
+ map
+ .fire('movestart')
+ .fire('dragstart');
+
+ if (map.options.inertia) {
+ this._positions = [];
+ this._times = [];
+ }
+ },
+
+ _onDrag: function (e) {
+ if (this._map.options.inertia) {
+ var time = this._lastTime = +new Date(),
+ pos = this._lastPos = this._draggable._absPos || this._draggable._newPos;
+
+ this._positions.push(pos);
+ this._times.push(time);
+
+ if (time - this._times[0] > 50) {
+ this._positions.shift();
+ this._times.shift();
+ }
+ }
+
+ this._map
+ .fire('move', e)
+ .fire('drag', e);
+ },
+
+ _onZoomEnd: function () {
+ var pxCenter = this._map.getSize().divideBy(2),
+ pxWorldCenter = this._map.latLngToLayerPoint([0, 0]);
+
+ this._initialWorldOffset = pxWorldCenter.subtract(pxCenter).x;
+ this._worldWidth = this._map.getPixelWorldBounds().getSize().x;
+ },
+
+ _viscousLimit: function (value, threshold) {
+ return value - (value - threshold) * this._viscosity;
+ },
+
+ _onPreDragLimit: function () {
+ if (!this._viscosity || !this._offsetLimit) { return; }
+
+ var offset = this._draggable._newPos.subtract(this._draggable._startPos);
+
+ var limit = this._offsetLimit;
+ if (offset.x < limit.min.x) { offset.x = this._viscousLimit(offset.x, limit.min.x); }
+ if (offset.y < limit.min.y) { offset.y = this._viscousLimit(offset.y, limit.min.y); }
+ if (offset.x > limit.max.x) { offset.x = this._viscousLimit(offset.x, limit.max.x); }
+ if (offset.y > limit.max.y) { offset.y = this._viscousLimit(offset.y, limit.max.y); }
+
+ this._draggable._newPos = this._draggable._startPos.add(offset);
+ },
+
+ _onPreDragWrap: function () {
+ // TODO refactor to be able to adjust map pane position after zoom
+ var worldWidth = this._worldWidth,
+ halfWidth = Math.round(worldWidth / 2),
+ dx = this._initialWorldOffset,
+ x = this._draggable._newPos.x,
+ newX1 = (x - halfWidth + dx) % worldWidth + halfWidth - dx,
+ newX2 = (x + halfWidth + dx) % worldWidth - halfWidth - dx,
+ newX = Math.abs(newX1 + dx) < Math.abs(newX2 + dx) ? newX1 : newX2;
+
+ this._draggable._absPos = this._draggable._newPos.clone();
+ this._draggable._newPos.x = newX;
+ },
+
+ _onDragEnd: function (e) {
+ var map = this._map,
+ options = map.options,
+
+ noInertia = !options.inertia || this._times.length < 2;
+
+ map.fire('dragend', e);
+
+ if (noInertia) {
+ map.fire('moveend');
+
+ } else {
+
+ var direction = this._lastPos.subtract(this._positions[0]),
+ duration = (this._lastTime - this._times[0]) / 1000,
+ ease = options.easeLinearity,
+
+ speedVector = direction.multiplyBy(ease / duration),
+ speed = speedVector.distanceTo([0, 0]),
+
+ limitedSpeed = Math.min(options.inertiaMaxSpeed, speed),
+ limitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed),
+
+ decelerationDuration = limitedSpeed / (options.inertiaDeceleration * ease),
+ offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();
+
+ if (!offset.x && !offset.y) {
+ map.fire('moveend');
+
+ } else {
+ offset = map._limitOffset(offset, map.options.maxBounds);
+
+ L.Util.requestAnimFrame(function () {
+ map.panBy(offset, {
+ duration: decelerationDuration,
+ easeLinearity: ease,
+ noMoveStart: true,
+ animate: true
+ });
+ });
+ }
+ }
+ }
+});
+
+// @section Handlers
+// @property dragging: Handler
+// Map dragging handler (by both mouse and touch).
+L.Map.addInitHook('addHandler', 'dragging', L.Map.Drag);
+
+
+
+/*
+ * L.Handler.DoubleClickZoom is used to handle double-click zoom on the map, enabled by default.
+ */
+
+// @namespace Map
+// @section Interaction Options
+
+L.Map.mergeOptions({
+ // @option doubleClickZoom: Boolean|String = true
+ // Whether the map can be zoomed in by double clicking on it and
+ // zoomed out by double clicking while holding shift. If passed
+ // `'center'`, double-click zoom will zoom to the center of the
+ // view regardless of where the mouse was.
+ doubleClickZoom: true
+});
+
+L.Map.DoubleClickZoom = L.Handler.extend({
+ addHooks: function () {
+ this._map.on('dblclick', this._onDoubleClick, this);
+ },
+
+ removeHooks: function () {
+ this._map.off('dblclick', this._onDoubleClick, this);
+ },
+
+ _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);
+
+
+
+/*\r
+ * Extends the event handling code with double tap support for mobile browsers.\r
+ */\r
+\r
+L.extend(L.DomEvent, {\r
+\r
+ _touchstart: L.Browser.msPointer ? 'MSPointerDown' : L.Browser.pointer ? 'pointerdown' : 'touchstart',\r
+ _touchend: L.Browser.msPointer ? 'MSPointerUp' : L.Browser.pointer ? 'pointerup' : 'touchend',\r
+\r
+ // inspired by Zepto touch code by Thomas Fuchs\r
+ addDoubleTapListener: function (obj, handler, id) {\r
+ var last, touch,\r
+ doubleTap = false,\r
+ delay = 250;\r
+\r
+ function onTouchStart(e) {\r
+ var count;\r
+\r
+ if (L.Browser.pointer) {\r
+ if ((!L.Browser.edge) || e.pointerType === 'mouse') { return; }\r
+ count = L.DomEvent._pointersCount;\r
+ } else {\r
+ count = e.touches.length;\r
+ }\r
+\r
+ if (count > 1) { return; }\r
+\r
+ var now = Date.now(),\r
+ delta = now - (last || now);\r
+\r
+ touch = e.touches ? e.touches[0] : e;\r
+ doubleTap = (delta > 0 && delta <= delay);\r
+ last = now;\r
+ }\r
+\r
+ function onTouchEnd(e) {\r
+ if (doubleTap && !touch.cancelBubble) {\r
+ if (L.Browser.pointer) {\r
+ if ((!L.Browser.edge) || e.pointerType === 'mouse') { return; }\r
+\r
+ // work around .type being readonly with MSPointer* events\r
+ var newTouch = {},\r
+ prop, i;\r
+\r
+ for (i in touch) {\r
+ prop = touch[i];\r
+ newTouch[i] = prop && prop.bind ? prop.bind(touch) : prop;\r
+ }\r
+ touch = newTouch;\r
+ }\r
+ touch.type = 'dblclick';\r
+ handler(touch);\r
+ last = null;\r
+ }\r
+ }\r
+\r
+ var pre = '_leaflet_',\r
+ touchstart = this._touchstart,\r
+ touchend = this._touchend;\r
+\r
+ obj[pre + touchstart + id] = onTouchStart;\r
+ obj[pre + touchend + id] = onTouchEnd;\r
+ obj[pre + 'dblclick' + id] = handler;\r
+\r
+ obj.addEventListener(touchstart, onTouchStart, false);\r
+ obj.addEventListener(touchend, onTouchEnd, false);\r
+\r
+ // On some platforms (notably, chrome<55 on win10 + touchscreen + mouse),\r
+ // the browser doesn't fire touchend/pointerup events but does fire\r
+ // native dblclicks. See #4127.\r
+ // Edge 14 also fires native dblclicks, but only for pointerType mouse, see #5180.\r
+ obj.addEventListener('dblclick', handler, false);\r
+\r
+ return this;\r
+ },\r
+\r
+ removeDoubleTapListener: function (obj, id) {\r
+ var pre = '_leaflet_',\r
+ touchstart = obj[pre + this._touchstart + id],\r
+ touchend = obj[pre + this._touchend + id],\r
+ dblclick = obj[pre + 'dblclick' + id];\r
+\r
+ obj.removeEventListener(this._touchstart, touchstart, false);\r
+ obj.removeEventListener(this._touchend, touchend, false);\r
+ if (!L.Browser.edge) {\r
+ obj.removeEventListener('dblclick', dblclick, false);\r
+ }\r
+\r
+ return this;\r
+ }\r
+});\r
+
+
+
+/*
+ * 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);
+