Skip to content

Commit

Permalink
DragFeature control should trigger afterfeaturemodified, r=crschmidt (c…
Browse files Browse the repository at this point in the history
…loses #3277)
  • Loading branch information
Bart van den Eijnden committed Sep 23, 2011
1 parent 807b0ea commit a46489d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
28 changes: 24 additions & 4 deletions lib/OpenLayers/Control/DragFeature.js
Expand Up @@ -26,10 +26,14 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {
* send a list of strings corresponding to the geometry class names.
*/
geometryTypes: null,

/**
* APIProperty: onStart
* {Function} Define this function if you want to know when a drag starts.
* {Function} *Deprecated*. Register for "beforefeaturemodified" instead.
* The "beforefeaturemodified" event is triggered on the layer before
* any modification begins.
*
* 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.
*
Expand All @@ -42,7 +46,11 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {

/**
* APIProperty: onDrag
* {Function} Define this function if you want to know about each move of a
* {Function} *Deprecated*. Register for "featuremodified" instead.
* The "featuremodified" event is triggered on the layer with each
* feature modification.
*
* Define this function if you want to know about each move of a
* feature. The function should expect to receive two arguments: the
* feature that is being dragged and the pixel location of the mouse.
*
Expand All @@ -54,7 +62,11 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {

/**
* APIProperty: onComplete
* {Function} Define this function if you want to know when a feature is
* {Function} *Deprecated*. Register for "afterfeaturemodified" instead.
* The "afterfeaturemodified" event is triggered on the layer after
* a feature has been modified.
*
* Define this function if you want to know when a feature is
* done dragging. The function should expect to receive two arguments:
* the feature that is being dragged and the pixel location of the
* mouse.
Expand Down Expand Up @@ -273,6 +285,9 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {
downFeature: function(pixel) {
this.lastPixel = pixel;
this.onStart(this.feature, pixel);
return this.layer.events.triggerEvent(
"beforefeaturemodified", {feature: this.feature}
);
},

/**
Expand All @@ -290,6 +305,8 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {
this.layer.drawFeature(this.feature);
this.lastPixel = pixel;
this.onDrag(this.feature, pixel);
this.layer.events.triggerEvent("featuremodified",
{feature: this.feature});
},

/**
Expand All @@ -315,6 +332,9 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {
*/
doneDragging: function(pixel) {
this.onComplete(this.feature, pixel);
this.layer.events.triggerEvent("afterfeaturemodified", {
feature: this.feature
});
},

/**
Expand Down
11 changes: 9 additions & 2 deletions tests/Control/DragFeature.html
Expand Up @@ -168,9 +168,13 @@
}

function test_Control_DragFeature_move(t) {
t.plan(3);
t.plan(5);
var map = new OpenLayers.Map("map");
var layer = new OpenLayers.Layer.Vector();
layer.events.on({
'beforefeaturemodified': function(evt) { t.ok(true, "beforefeaturemodified is triggered on the layer"); },
'featuremodified': function(evt) { t.ok(true, "featuremodified is triggered on the layer"); }
});
map.addLayer(layer);
var control = new OpenLayers.Control.DragFeature(layer);
map.addControl(control);
Expand Down Expand Up @@ -257,10 +261,13 @@
}

function test_Control_DragFeature_done(t) {
t.plan(2);
t.plan(3);
var map = new OpenLayers.Map("map");
var layer = new OpenLayers.Layer.Vector();
map.addLayer(layer);
layer.events.on({
'afterfeaturemodified': function(evt) { t.ok(true, "afterfeaturemodified is triggered on the layer"); }
});
var control = new OpenLayers.Control.DragFeature(layer);
map.addControl(control);

Expand Down

0 comments on commit a46489d

Please sign in to comment.