[OpenLayers-Commits] r11958 - in trunk/openlayers: lib/OpenLayers/Control tests/Control

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Mon May 9 03:37:02 EDT 2011


Author: ahocevar
Date: 2011-05-09 00:36:57 -0700 (Mon, 09 May 2011)
New Revision: 11958

Modified:
   trunk/openlayers/lib/OpenLayers/Control/TransformFeature.js
   trunk/openlayers/tests/Control/TransformFeature.html
Log:
do not reuse event objects to avoid incorrect event types. r=bartvde (closes #3280)

Modified: trunk/openlayers/lib/OpenLayers/Control/TransformFeature.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Control/TransformFeature.js	2011-05-09 07:16:39 UTC (rev 11957)
+++ trunk/openlayers/lib/OpenLayers/Control/TransformFeature.js	2011-05-09 07:36:57 UTC (rev 11958)
@@ -232,6 +232,9 @@
             this.dragControl.deactivate();
             deactivated = true;
         }
+        if (deactivated) {
+        	this.unsetFeature();
+        }
         return deactivated;
     },
     
@@ -265,13 +268,15 @@
             scale: 1,
             ratio: 1
         });
-        var evt = {feature: feature};
-        
+
         var oldRotation = this.rotation;
         var oldCenter = this.center;
         OpenLayers.Util.extend(this, initialParams);
 
-        if(this.events.triggerEvent("beforesetfeature", evt) === false) {
+        var cont = this.events.triggerEvent("beforesetfeature",
+            {feature: feature}
+        );
+        if (cont === false) {
             return;
         }
 
@@ -303,10 +308,26 @@
         
         delete this._setfeature;
 
-        this.events.triggerEvent("setfeature", evt);
+        this.events.triggerEvent("setfeature", {feature: feature});
     },
     
     /**
+     * APIMethod: unsetFeature
+     * Remove the transformation box off any feature.
+     * If the control is active, it will be deactivated first.
+     */
+    unsetFeature: function() {
+    	if (this.active) {
+    		this.deactivate();
+    	} else {
+	    	this.feature = null;
+	    	this.rotation = 0;
+	    	this.scale = 1;
+	    	this.ratio = 1;
+    	}
+    },
+    
+    /**
      * Method: createBox
      * Creates the box with all handles and transformation handles.
      */

Modified: trunk/openlayers/tests/Control/TransformFeature.html
===================================================================
--- trunk/openlayers/tests/Control/TransformFeature.html	2011-05-09 07:16:39 UTC (rev 11957)
+++ trunk/openlayers/tests/Control/TransformFeature.html	2011-05-09 07:36:57 UTC (rev 11958)
@@ -54,7 +54,7 @@
     }
     
     function test_setFeature(t) {
-        t.plan(4);
+        t.plan(6);
         var map = new OpenLayers.Map("map", {allOverlays: true});
         var layer = new OpenLayers.Layer.Vector();
         var feature = new OpenLayers.Feature.Vector(
@@ -64,8 +64,16 @@
         map.setCenter(new OpenLayers.LonLat(0, 0), 18);
         var control = new OpenLayers.Control.TransformFeature(layer);
         map.addControl(control);
+        var log = [];
+        control.events.on({
+            "beforesetfeature": function(e) { log.push(e); },
+            "setfeature": function(e) { log.push(e); }
+        });
         control.setFeature(feature);
         
+        t.eq(log[0].type, "beforesetfeature", "beforesetfeature event fired with correct event type");
+        t.eq(log[1].type, "setfeature", "setfeature event fired with correct event type");
+        
         t.ok(control.active, "control activated on setFeature");
         t.ok(feature.geometry.getBounds().equals(control.box.geometry.getBounds()), "box positioned correctly");
         t.geom_eq(control.handles[0].geometry, control.box.geometry.components[0], "handle positioned with box");



More information about the Commits mailing list