1L.Map.mergeOptions({ 2 doubleTapDragZoom: L.Browser.touch && !L.Browser.android23, 3 doubleTapDragZoomOptions: { 4 reverse: false, 5 }, 6}); 7 8var DoubleTapDragZoom = L.Handler.extend({ 9 addHooks: function () { 10 this._map.on('doubletapdragstart', this._onDoubleTapDragStart, this); 11 this._map.on('doubletapdrag', this._onDoubleTapDrag, this); 12 this._map.on('doubletapdragend', this._onDoubleTapDragEnd, this); 13 L.DomEvent.on(this._map._container, 'touchmove', this._onDragging, this); 14 }, 15 16 removeHooks: function () { 17 this._map.off('doubletapdragstart', this._onDoubleTapDragStart, this); 18 this._map.off('doubletapdrag', this._onDoubleTapDrag, this); 19 this._map.off('doubletapdragend', this._onDoubleTapDragEnd, this); 20 }, 21 22 _onDoubleTapDragStart: function (e) { 23 var map = this._map; 24 if (!e.touches || e.touches.length !== 1 || map._animatingZoom) { return; } 25 26 var p = map.mouseEventToContainerPoint(e.touches[0]); 27 this._startPointY = p.y; 28 this._startPoint = p; 29 30 this._centerPoint = map.getSize()._divideBy(2); 31 32 if (map.options.doubleTapDragZoom === 'center') { 33 this._startLatLng = map.containerPointToLatLng(this._centerPoint); 34 } else { 35 this._startLatLng = map.containerPointToLatLng(p); 36 } 37 38 this._startZoom = map.getZoom(); 39 40 map._stop(); 41 map._moveStart(true, false); 42 this._doubleTapDragging = true; 43 }, 44 45 _onDoubleTapDrag: function (e) { 46 if (!e.touches || e.touches.length !== 1) { return; } 47 48 var map = this._map; 49 var reverse = this._map.options.doubleTapDragZoomOptions.reverse; 50 var p = map.mouseEventToContainerPoint(e.touches[0]); 51 52 if (p.y <= 0) { 53 return; 54 } 55 56 var distance = reverse ? p.y - this._startPointY : this._startPointY - p.y; 57 58 var scale = Math.pow(Math.E, distance / 200); 59 60 if (scale === 1) { return; } 61 62 this._zoom = map.getScaleZoom(scale, this._startZoom); 63 64 if (map.options.doubleTapDragZoom === 'center') { 65 this._center = this._startLatLng; 66 } else { 67 var delta = 68 L.point(this._startPoint.x, p.y) 69 ._add(this._startPoint) 70 .divideBy(2) 71 ._subtract(this._centerPoint); 72 73 this._center = map.unproject(map.project(this._startLatLng, this._zoom).subtract(delta), this._zoom); 74 } 75 76 L.Util.cancelAnimFrame(this._animRequest); 77 78 var moveFn = L.Util.bind(map._move, map, this._center, this._zoom, {pinch: true, round: false}); 79 this._animRequest = L.Util.requestAnimFrame(moveFn, this, true); 80 }, 81 82 _onDoubleTapDragEnd: function (e) { 83 this._doubleTapDragging = false; 84 85 if (!this._center) { return; } 86 L.Util.cancelAnimFrame(this._animRequest); 87 88 // Pinch updates GridLayers' levels only when zoomSnap is off, so zoomSnap becomes noUpdate. 89 if (this._map.options.zoomAnimation) { 90 this._map._animateZoom(this._center, this._map._limitZoom(this._zoom), true, this._map.options.zoomSnap); 91 } else { 92 this._map._resetView(this._center, this._map._limitZoom(this._zoom)); 93 } 94 95 this._center = null; 96 }, 97 98 _onDragging: function (e) { 99 if (this._doubleTapDragging) { 100 L.DomEvent.preventDefault(e); 101 L.DomEvent.stopPropagation(e); 102 } 103 } 104}); 105 106L.Map.addInitHook('addHandler', 'doubleTapDragZoom', DoubleTapDragZoom);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.