diff --git a/.jshintrc b/.jshintrc index c0b2083d9..6d62f983e 100644 --- a/.jshintrc +++ b/.jshintrc @@ -18,7 +18,7 @@ "eqnull": false, "evil": false, "expr": true, - "forin": true, + "forin": false, "immed": true, "latedef": true, "loopfunc": false, diff --git a/src/DGCustomization/src/DGCustomization.js b/src/DGCustomization/src/DGCustomization.js index ee652877e..26d04db95 100644 --- a/src/DGCustomization/src/DGCustomization.js +++ b/src/DGCustomization/src/DGCustomization.js @@ -160,3 +160,68 @@ DG.Map.addInitHook(function () { // Add some browser detection DG.Browser.safari51 = DG.Browser.safari && navigator.userAgent.indexOf('Version/5.1') !== -1; + +// Fix for https://github.com/2gis/mapsapi/issues/111 , remove on the next leaflet version +L.Draggable.include({ + _onMove: function (e) { + if (e.touches && e.touches.length > 1) { + this._moved = true; + return; + } + + var first = (e.touches && e.touches.length === 1 ? e.touches[0] : e), + newPoint = new L.Point(first.clientX, first.clientY), + offset = newPoint.subtract(this._startPoint); + + if (!offset.x && !offset.y) { return; } + if (L.Browser.touch && Math.abs(offset.x) + Math.abs(offset.y) < 3) { return; } + + L.DomEvent.preventDefault(e); + + if (!this._moved) { + this.fire('dragstart'); + + this._moved = true; + this._startPos = L.DomUtil.getPosition(this._element).subtract(offset); + + L.DomUtil.addClass(document.body, 'leaflet-dragging'); + + this._lastTarget = e.target || e.srcElement; + L.DomUtil.addClass(this._lastTarget, 'leaflet-drag-target'); + } + + this._newPos = this._startPos.add(offset); + this._moving = true; + + L.Util.cancelAnimFrame(this._animRequest); + this._animRequest = L.Util.requestAnimFrame(this._updatePosition, this, true, this._dragStartTarget); + }, + _onUp: function () { + L.DomUtil.removeClass(document.body, 'leaflet-dragging'); + + if (this._lastTarget) { + L.DomUtil.removeClass(this._lastTarget, 'leaflet-drag-target'); + this._lastTarget = null; + } + + for (var i in L.Draggable.MOVE) { + L.DomEvent + .off(document, L.Draggable.MOVE[i], this._onMove, this) + .off(document, L.Draggable.END[i], this._onUp, this); + } + + L.DomUtil.enableImageDrag(); + L.DomUtil.enableTextSelection(); + + if (this._moved && this._moving) { + // ensure drag is not fired after dragend + L.Util.cancelAnimFrame(this._animRequest); + + this.fire('dragend', { + distance: this._newPos.distanceTo(this._startPos) + }); + } + + this._moving = false; + } +});