making ModifyFeature control in standalone mode trigger the beforefeaturemodified event. r=bartvde (closes #3009

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11146 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2011-02-18 15:25:41 +00:00
parent d6695cff67
commit b30d35c615
2 changed files with 16 additions and 8 deletions

View File

@@ -351,18 +351,23 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
}, },
/** /**
* Method: selectFeature * APIMethod: selectFeature
* Called when the select feature control selects a feature. * Select a feature for modification in standalone mode. In non-standalone
* mode, this method is called when the select feature control selects a
* feature. Register a listener to the beforefeaturemodified event and
* return false to prevent feature modification.
* *
* Parameters: * Parameters:
* feature - {<OpenLayers.Feature.Vector>} the selected feature. * feature - {<OpenLayers.Feature.Vector>} the selected feature.
*/ */
selectFeature: function(feature) { selectFeature: function(feature) {
if (!this.standalone || this.beforeSelectFeature(feature) !== false) {
this.feature = feature; this.feature = feature;
this.modified = false; this.modified = false;
this.resetVertices(); this.resetVertices();
this.dragControl.activate(); this.dragControl.activate();
this.onModificationStart(this.feature); this.onModificationStart(this.feature);
}
}, },
/** /**

View File

@@ -648,7 +648,7 @@
function test_standalone(t) { function test_standalone(t) {
t.plan(17); t.plan(18);
var map = new OpenLayers.Map("map"); var map = new OpenLayers.Map("map");
var layer = new OpenLayers.Layer.Vector(); var layer = new OpenLayers.Layer.Vector();
@@ -673,6 +673,7 @@
var log = []; var log = [];
layer.events.on({ layer.events.on({
beforefeaturemodified: function(evt) { beforefeaturemodified: function(evt) {
layer.events.unregister("beforefeaturemodified", this, arguments.callee);
log.push(evt); log.push(evt);
}, },
featuremodified: function(evt) { featuremodified: function(evt) {
@@ -690,7 +691,9 @@
// manually select feature for editing // manually select feature for editing
control.selectFeature(f1); control.selectFeature(f1);
t.eq(log.length, 1, "[select f1] beforefeaturemodified triggered");
t.ok(control.feature === f1, "[select f1] control.feature set to f1"); t.ok(control.feature === f1, "[select f1] control.feature set to f1");
log = []
// manually unselect feature for editing // manually unselect feature for editing
control.unselectFeature(f1); control.unselectFeature(f1);