add distance to dragend event data, close #2158, ref #872

This commit is contained in:
Vladimir Agafonkin 2013-11-06 21:17:35 +02:00
parent ad65b5a77f
commit ddbb01c3da
4 changed files with 8 additions and 5 deletions

View File

@ -17,6 +17,7 @@ An in-progress version being developed on the `master` branch.
* Made `Map` `setView` `zoom` argument optional. [#2056](https://github.com/Leaflet/Leaflet/issues/2056)
* Added `maxZoom` option to `Map` `fitBounds`. [#2101](https://github.com/Leaflet/Leaflet/issues/2101)
* Added `Map` `bounceAtZoomLimits` option that makes the map bounce when you pinch-zoom past limits (it worked like this before, but now you can disable this) (by [@trevorpowell](https://github.com/trevorpowell)). [#1864](https://github.com/Leaflet/Leaflet/issues/1864) [#2072](https://github.com/Leaflet/Leaflet/pull/2072)
* Added `distance` property to `Map` and `Marker` `dragend` events. [#2158](https://github.com/Leaflet/Leaflet/issues/2158) [#872](https://github.com/Leaflet/Leaflet/issues/872)
* Added optional support for center-oriented scroll and double-click zoom (by [@jfirebaugh](https://github.com/jfirebaugh)). [#1939](https://github.com/Leaflet/Leaflet/issues/1939)
* Added `timestamp` to `Map` `locationfound` event. [#584](https://github.com/Leaflet/Leaflet/pull/584)
* Added CSS classes to draggable markers for easier customization (by [@snkashis](https://github.com/snkashis)). [#1902](https://github.com/Leaflet/Leaflet/issues/1902) [#1916](https://github.com/Leaflet/Leaflet/issues/1916)

View File

@ -127,7 +127,9 @@ L.Draggable = L.Class.extend({
// ensure drag is not fired after dragend
L.Util.cancelAnimFrame(this._animRequest);
this.fire('dragend');
this.fire('dragend', {
distance: this._newPos.distanceTo(this._startPos)
});
}
this._moving = false;

View File

@ -61,10 +61,10 @@ L.Handler.MarkerDrag = L.Handler.extend({
.fire('drag');
},
_onDragEnd: function () {
_onDragEnd: function (e) {
this._marker
.fire('moveend')
.fire('dragend');
.fire('dragend', e);
L.DomUtil.removeClass(this._marker._icon, 'leaflet-marker-dragging');
}
});

View File

@ -104,14 +104,14 @@ L.Map.Drag = L.Handler.extend({
this._draggable._newPos.x = newX;
},
_onDragEnd: function () {
_onDragEnd: function (e) {
var map = this._map,
options = map.options,
delay = +new Date() - this._lastTime,
noInertia = !options.inertia || delay > options.inertiaThreshold || !this._positions[0];
map.fire('dragend');
map.fire('dragend', e);
if (noInertia) {
map.fire('moveend');