From b30d35c61505fcfd235561e69c447c01180c16c9 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Fri, 18 Feb 2011 15:25:41 +0000 Subject: [PATCH] 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 --- lib/OpenLayers/Control/ModifyFeature.js | 19 ++++++++++++------- tests/Control/ModifyFeature.html | 5 ++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/OpenLayers/Control/ModifyFeature.js b/lib/OpenLayers/Control/ModifyFeature.js index 40976db6f0..59298627f4 100644 --- a/lib/OpenLayers/Control/ModifyFeature.js +++ b/lib/OpenLayers/Control/ModifyFeature.js @@ -351,18 +351,23 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, { }, /** - * Method: selectFeature - * Called when the select feature control selects a feature. + * APIMethod: selectFeature + * 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: * feature - {} the selected feature. */ selectFeature: function(feature) { - this.feature = feature; - this.modified = false; - this.resetVertices(); - this.dragControl.activate(); - this.onModificationStart(this.feature); + if (!this.standalone || this.beforeSelectFeature(feature) !== false) { + this.feature = feature; + this.modified = false; + this.resetVertices(); + this.dragControl.activate(); + this.onModificationStart(this.feature); + } }, /** diff --git a/tests/Control/ModifyFeature.html b/tests/Control/ModifyFeature.html index 2344cbbbc5..e8b49f35aa 100644 --- a/tests/Control/ModifyFeature.html +++ b/tests/Control/ModifyFeature.html @@ -648,7 +648,7 @@ function test_standalone(t) { - t.plan(17); + t.plan(18); var map = new OpenLayers.Map("map"); var layer = new OpenLayers.Layer.Vector(); @@ -673,6 +673,7 @@ var log = []; layer.events.on({ beforefeaturemodified: function(evt) { + layer.events.unregister("beforefeaturemodified", this, arguments.callee); log.push(evt); }, featuremodified: function(evt) { @@ -690,7 +691,9 @@ // manually select feature for editing control.selectFeature(f1); + t.eq(log.length, 1, "[select f1] beforefeaturemodified triggered"); t.ok(control.feature === f1, "[select f1] control.feature set to f1"); + log = [] // manually unselect feature for editing control.unselectFeature(f1);