[OpenLayers-Commits] r11082 - 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:01 EST 2011


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

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

Modified: sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Point.js
===================================================================
--- sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Point.js	2011-02-10 10:45:49 UTC (rev 11081)
+++ sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Point.js	2011-02-10 10:46:01 UTC (rev 11082)
@@ -159,9 +159,6 @@
         );
         this.callback("create", [this.point.geometry, this.point]);
         this.point.geometry.clearBounds();
-        if(this.persist) {
-            this.destroyFeature();
-        }
         this.layer.addFeatures([this.point], {silent: true});
     },
 
@@ -198,6 +195,17 @@
     },
 
     /**
+     * Method: destroyPersistedFeature
+     * Destroy the persisted feature.
+     */
+    destroyPersistedFeature: function() {
+        var layer = this.layer;
+        if(layer && layer.features.length > 1) {
+            this.layer.features[0].destroy();
+        }
+    },
+
+    /**
      * Method: finalize
      * Finish the geometry and call the "done" callback.
      *
@@ -366,6 +374,9 @@
             return true;
         }
         if(this.lastDown && this.lastDown.equals(evt.xy)) {
+            if(this.persist) {
+                this.destroyPersistedFeature();
+            }
             this.lastUp = evt.xy;
             this.finalize();
             return !this.stopUp;

Modified: sandbox/elemoine/draw-feature/tests/Handler/Point.html
===================================================================
--- sandbox/elemoine/draw-feature/tests/Handler/Point.html	2011-02-10 10:45:49 UTC (rev 11081)
+++ sandbox/elemoine/draw-feature/tests/Handler/Point.html	2011-02-10 10:46:01 UTC (rev 11082)
@@ -239,7 +239,52 @@
         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 logs = [], log;
+        var handler = new OpenLayers.Handler.Point(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)});
+        t.eq(handler.layer.features.length, 1,
+             "feature destroyed on mouseup when persist is false");
+
+        handler.persist = true;
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(1, 0)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(1, 0)});
+        t.eq(handler.layer.features.length, 2,
+             "feature not destroyed on mouseup when persist is true");
+        var feature = handler.layer.features[0];
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(2, 0)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(2, 0)});
+        t.ok(handler.layer.features[0] !== feature,
+             "persisted feature destroyed on next mouseup");
+
+        map.destroy();
+    }
+
+
     function test_Handler_Point_deactivation(t) {
         t.plan(5);
         var log = [];



More information about the Commits mailing list