[OpenLayers-Commits] r11146 - in trunk/openlayers:
lib/OpenLayers/Control tests/Control
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Fri Feb 18 10:25:41 EST 2011
Author: ahocevar
Date: 2011-02-18 07:25:41 -0800 (Fri, 18 Feb 2011)
New Revision: 11146
Modified:
trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js
trunk/openlayers/tests/Control/ModifyFeature.html
Log:
making ModifyFeature control in standalone mode trigger the beforefeaturemodified event. r=bartvde (closes #3009
Modified: trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js 2011-02-18 15:22:12 UTC (rev 11145)
+++ trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js 2011-02-18 15:25:41 UTC (rev 11146)
@@ -351,18 +351,23 @@
},
/**
- * 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 - {<OpenLayers.Feature.Vector>} 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);
+ }
},
/**
Modified: trunk/openlayers/tests/Control/ModifyFeature.html
===================================================================
--- trunk/openlayers/tests/Control/ModifyFeature.html 2011-02-18 15:22:12 UTC (rev 11145)
+++ trunk/openlayers/tests/Control/ModifyFeature.html 2011-02-18 15:25:41 UTC (rev 11146)
@@ -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);
More information about the Commits
mailing list