[OpenLayers-Commits] r11084 - in sandbox/elemoine/draw-feature: lib/OpenLayers/Handler tests/Handler

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Thu Feb 10 05:46:18 EST 2011


Author: erilem
Date: 2011-02-10 02:46:17 -0800 (Thu, 10 Feb 2011)
New Revision: 11084

Modified:
   sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js
   sandbox/elemoine/draw-feature/tests/Handler/Path.html
Log:
make persist work for the path handler

Modified: sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js
===================================================================
--- sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js	2011-02-10 10:46:08 UTC (rev 11083)
+++ sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js	2011-02-10 10:46:17 UTC (rev 11084)
@@ -91,9 +91,6 @@
         );
         this.callback("create", [this.point.geometry, this.getSketch()]);
         this.point.geometry.clearBounds();
-        if(this.persist) {
-            this.destroyFeature();
-        }
         this.layer.addFeatures([this.line, this.point], {silent: true});
     },
         
@@ -107,6 +104,17 @@
     },
 
     /**
+     * Method: destroyPersistedFeature
+     * Destroy the persisted feature.
+     */
+    destroyPersistedFeature: function() {
+        var layer = this.layer;
+        if(layer && layer.features.length > 2) {
+            this.layer.features[0].destroy();
+        }
+    },
+
+    /**
      * Method: removePoint
      * Destroy the temporary point.
      */
@@ -274,6 +282,9 @@
                 this.finalize();
             } else {
                 if(this.lastDown.equals(evt.xy)) {
+                    if(this.lastUp == null && this.persist) {
+                        this.destroyPersistedFeature();
+                    }
                     this.addPoint(evt.xy);
                     this.lastUp = evt.xy;
                 }

Modified: sandbox/elemoine/draw-feature/tests/Handler/Path.html
===================================================================
--- sandbox/elemoine/draw-feature/tests/Handler/Path.html	2011-02-10 10:46:08 UTC (rev 11083)
+++ sandbox/elemoine/draw-feature/tests/Handler/Path.html	2011-02-10 10:46:17 UTC (rev 11084)
@@ -257,6 +257,62 @@
         map.destroy();
     }        
 
+    function test_persist(t) {
+        t.plan(3);
+        var map = new OpenLayers.Map("map", {
+            resolutions: [1]
+        });
+        var layer = new OpenLayers.Layer.Vector("foo", {
+            maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+            isBaseLayer: true
+        });
+        map.addLayer(layer);
+        var control = new OpenLayers.Control({});
+        var handler = new OpenLayers.Handler.Path(control, {});
+        control.handler = handler;
+        map.addControl(control);
+        map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+        handler.activate();
+
+        handler.persist = false;
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+        handler.dblclick(
+            {type: "dblclick", xy: new OpenLayers.Pixel(1, 1)});
+        t.eq(handler.layer.features.length, 2,
+             "feature destroyed on dblclick when persist is false");
+
+        handler.persist = true;
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+        handler.dblclick(
+            {type: "dblclick", xy: new OpenLayers.Pixel(1, 1)});
+        var feature = handler.layer.features[0];
+        t.eq(handler.layer.features.length, 3,
+             "feature not destroyed on dblclick when persist is true");
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+        handler.dblclick(
+            {type: "dblclick", xy: new OpenLayers.Pixel(1, 1)});
+        t.ok(handler.layer.features[0] !== feature,
+             "persisted feature destroyed on next dblclick");
+
+        map.destroy();
+    }
+
     function test_Handler_Path_destroy(t) {
         t.plan(6);
         var map = new OpenLayers.Map('map');



More information about the Commits mailing list