diff --git a/lib/OpenLayers/Control/DragFeature.js b/lib/OpenLayers/Control/DragFeature.js index 2f470370df..73643d9b70 100644 --- a/lib/OpenLayers/Control/DragFeature.js +++ b/lib/OpenLayers/Control/DragFeature.js @@ -24,6 +24,19 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, { */ geometryTypes: null, + /** + * APIProperty: onStart + * {Function} Define this function if you want to know when a drag starts. + * The function should expect to receive two arguments: the feature + * that is about to be dragged and the pixel location of the mouse. + * + * Parameters: + * feature - {OpenLayers.Feature.Vector} The feature that is about to be + * dragged. + * pixel - {OpenLayers.Pixel} The pixel location of the mouse. + */ + onStart: function(feature, pixel) {}, + /** * APIProperty: onDrag * {Function} Define this function if you want to know about each move of a @@ -154,6 +167,9 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, { // the return from the handlers is unimportant in this case this.dragHandler.deactivate(); this.featureHandler.deactivate(); + this.feature = null; + this.dragging = false; + this.lastPixel = null; return OpenLayers.Control.prototype.deactivate.apply(this, arguments); }, @@ -189,8 +205,8 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, { * pixel - {OpenLayers.Pixel} Location of the mouse event. */ downFeature: function(pixel) { - this.dragHandler.dragging = true; this.lastPixel = pixel; + this.onStart(this.feature, pixel); }, /** diff --git a/lib/OpenLayers/Handler/Drag.js b/lib/OpenLayers/Handler/Drag.js index 4257cd7dc7..d4d541be00 100644 --- a/lib/OpenLayers/Handler/Drag.js +++ b/lib/OpenLayers/Handler/Drag.js @@ -282,7 +282,10 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, { deactivate: function() { var deactivated = false; if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { + this.started = false; this.dragging = false; + this.start = null; + this.last = null; deactivated = true; } return deactivated; diff --git a/tests/Control/test_DragFeature.html b/tests/Control/test_DragFeature.html index 9884071c71..c5fd8bf8b0 100644 --- a/tests/Control/test_DragFeature.html +++ b/tests/Control/test_DragFeature.html @@ -109,14 +109,13 @@ } map.events.triggerEvent("mousemove"); - t.ok(!control.dragHandler.dragging, - "control is not dragging before the mousedown"); - // simulate a mousedown on a feature + control.onStart = function(feature, pixel) { + t.eq(feature, "foo", "onStart called with the correct feature"); + t.eq(pixel, "bar", "onStart called with the correct pixel"); + } map.events.triggerEvent("mousedown", {xy: "bar", which: 1}); - t.ok(control.dragHandler.dragging, - "drag is dragging after the mousedown"); t.eq(control.lastPixel, "bar", "mousedown sets the lastPixel correctly"); } diff --git a/tests/Handler/test_Drag.html b/tests/Handler/test_Drag.html index d5aaa4bfaf..6f7cc63781 100644 --- a/tests/Handler/test_Drag.html +++ b/tests/Handler/test_Drag.html @@ -306,7 +306,7 @@ } function test_Handler_Drag_deactivate(t) { - t.plan(3); + t.plan(6); var map = new OpenLayers.Map('map'); var control = new OpenLayers.Control(); map.addControl(control); @@ -320,8 +320,14 @@ deactivated = handler.deactivate(); t.ok(deactivated, "deactivate returns true if the handler was active already"); + t.ok(!handler.started, + "deactivate sets started to false"); t.ok(!handler.dragging, "deactivate sets dragging to false"); + t.ok(handler.start == null, + "deactivate sets start to null"); + t.ok(handler.last == null, + "deactivate sets start to null"); }