give Layer.Vector a vertexremoved event, to be fired e.g. by the ModifyFeature control. r=bartvde (closes #3017)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11043 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2011-01-19 16:44:39 +00:00
parent edfbcb0a5e
commit c8982cb99a
3 changed files with 26 additions and 7 deletions

View File

@@ -608,6 +608,11 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
vertex.geometry.parent) {
// remove the vertex
vertex.geometry.parent.removeComponent(vertex.geometry);
this.layer.events.triggerEvent("vertexremoved", {
vertex: vertex.geometry,
feature: this.feature,
pixel: evt.xy
});
this.layer.drawFeature(this.feature, this.standalone ?
undefined :
this.selectControl.renderIntent);

View File

@@ -90,6 +90,12 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
* property referencing the vertex modified (always a point geometry),
* and a *pixel* property referencing the pixel location of the
* modification.
* vertexremoved - Triggered when a vertex within any feature geometry
* has been deleted. Listeners will receive an object with a
* *feature* property referencing the modified feature, a *vertex*
* property referencing the vertex modified (always a point geometry),
* and a *pixel* property referencing the pixel location of the
* removal.
* sketchstarted - Triggered when a feature sketch bound for this layer
* is started. Listeners will receive an object with a *feature*
* property referencing the new sketch feature and a *vertex* property
@@ -110,8 +116,8 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
"beforefeaturesremoved", "featureremoved", "featuresremoved",
"beforefeatureselected", "featureselected", "featureunselected",
"beforefeaturemodified", "featuremodified", "afterfeaturemodified",
"vertexmodified", "sketchstarted", "sketchmodified",
"sketchcomplete", "refresh"],
"vertexmodified", "vertexremoved", "sketchstarted",
"sketchmodified", "sketchcomplete", "refresh"],
/**
* APIProperty: isBaseLayer

View File

@@ -74,7 +74,7 @@
}
function test_handleKeypress(t) {
t.plan(11);
t.plan(14);
/**
* There are two things that we want to test here
@@ -108,9 +108,17 @@
"vertex deletion: removeComponent called on parent with proper geometry");
}
};
layer.events.on({"featuremodified": function(event) {
t.eq(event.feature.id, poly.id, "vertex deletion: featuremodifed triggered");
}});
layer.events.on({
"featuremodified": function(event) {
t.eq(event.feature.id, poly.id, "vertex deletion: featuremodifed triggered");
},
"vertexremoved": function(evt) {
layer.events.unregister("vertexremoved", this, arguments.callee);
t.eq(evt.feature.id, poly.id, "vertexremoved triggered with correct feature");
t.eq(evt.vertex.id, point.geometry.id, "vertexremoved triggered with correct vertex");
t.eq(evt.pixel, "foo", "vertexremoved triggered with correct pixel");
}
});
layer.drawFeature = function(feature) {
t.eq(feature.id, poly.id,
"vertex deletion: drawFeature called with the proper feature");
@@ -123,7 +131,7 @@
"vertex deletion: onModification called with the proper feature");
};
// run the above four tests twice
control.handleKeypress({keyCode:delKey});
control.handleKeypress({keyCode:delKey, xy: "foo"});
control.handleKeypress({keyCode:dKey});
t.eq(control.feature.state, OpenLayers.State.UPDATE, "feature state set to update");