Skip to content

Commit

Permalink
Merge pull request #350 from 2gis/fix/unwanted-inertia-movement
Browse files Browse the repository at this point in the history
fix unwanted inertia movement
  • Loading branch information
andymost committed May 17, 2016
2 parents 20b76ef + 6cf217d commit 9c84423
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions gulp/deps/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var deps = {
'DGCustomization/src/DGMap.js',
'DGCustomization/src/DGMap.BaseLayer.js',
'DGCustomization/src/DGMap.TilesCheck.js',
'DGCustomization/src/DGMap.Drag.js',
'DGCustomization/src/DGMarker.js'
],
less: {
Expand Down
40 changes: 40 additions & 0 deletions src/DGCustomization/src/DGMap.Drag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* This customization fixes unwanted inertia movement after sudden drag stops
* See https://github.com/Leaflet/Leaflet/pull/4048.
* If this PR ever gets merged, this file can be removed.
*/
var onDragEnd = DG.Map.Drag.prototype._onDragEnd;

DG.Map.Drag.include({
_rememberTimeAndPosition: function () {
var time = this._lastTime = +new Date(),
pos = this._lastPos = this._draggable._absPos || this._draggable._newPos;

this._positions.push(pos);
this._times.push(time);

// Remove all data points older than 50 ms
while (time - this._times[0] > 50) {
this._positions.shift();
this._times.shift();
}
},

_onDrag: function (e) {
if (this._map.options.inertia) {
this._rememberTimeAndPosition();
}

this._map
.fire('move', e)
.fire('drag', e);
},

_onDragEnd: function () {
if (this._map.options.inertia && !DG.Browser.touch) {
this._rememberTimeAndPosition();
}

onDragEnd.call(this);
}
});

0 comments on commit 9c84423

Please sign in to comment.