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

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Feb 16 03:17:09 EST 2011


Author: erilem
Date: 2011-02-16 00:17:09 -0800 (Wed, 16 Feb 2011)
New Revision: 11120

Modified:
   sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js
   sandbox/elemoine/draw-feature/tests/Handler/Path.html
   sandbox/elemoine/draw-feature/tests/Handler/Polygon.html
Log:
when stopDown is true make sure the behavior is as close as possible as what we have currently

Modified: sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js
===================================================================
--- sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js	2011-02-16 00:34:16 UTC (rev 11119)
+++ sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js	2011-02-16 08:17:09 UTC (rev 11120)
@@ -45,11 +45,11 @@
     freehandToggle: 'shiftKey',
 
     /**
-     * Property: freehandMouseDown
-     * {Boolean} The mouse is down, and freehand was active when mousedown
-     *     occurred.
+     * Property: stoppedDown
+     * {Boolean} Indicate whether the last mousedown stopped the event
+     * propagation.
      */
-    freehandMouseDown: false,
+    stoppedDown: null,
 
     /**
      * Constructor: OpenLayers.Handler.Path
@@ -232,8 +232,8 @@
      */
     mousedown: function(evt) {
         // consecutive mousedowns at the same location are
-        // ignored, this occurs when finalizing the line on
-        // dlbclick
+        // ignored (occurs when finalizing the line on
+        // double-click)
         if (this.lastDown && this.lastDown.equals(evt.xy)) {
             return false;
         }
@@ -241,9 +241,10 @@
         this.lastDown = evt.xy;
         this.modifyFeature(evt.xy, !!this.lastUp);
         if (this.freehandMode(evt)) {
-            this.freehandMouseDown = true;
+            this.stoppedDown = true;
             return false;
         } else {
+            this.stoppedDown = this.stopDown;
             return !this.stopDown;
         }
     },
@@ -260,16 +261,14 @@
      * {Boolean} Allow event propagation
      */
     mousemove: function (evt) {
-        if(this.freehandMouseDown && this.freehandMode(evt)) {
+        if(this.stoppedDown && this.freehandMode(evt)) {
             if(this.persist) {
                 this.destroyPersistedFeature();
             }
             this.addPoint(evt.xy);
             return false;
         }
-        // if the mouse is down and if freehand was active when
-        // the mousedown occurred we move the feature here
-        if(!this.mouseDown || this.freehandMouseDown) {
+        if(!this.mouseDown || this.stoppedDown) {
             this.modifyFeature(evt.xy, !!this.lastUp);
         }
         return true;
@@ -287,19 +286,16 @@
      * {Boolean} Allow event propagation
      */
     mouseup: function (evt) {
-        // consecutive mouseups at the same location must not
-        // cause adding new points to the line
+        // consecutive mouseups at the same location are ignored
         if (this.lastUp && this.lastUp.equals(evt.xy)) {
             return false;
         }
         if(this.mouseDown) {
-            if(this.freehandMouseDown && this.freehandMode(evt)) {
+            if(this.stoppedDown && this.freehandMode(evt)) {
                 this.removePoint();
                 this.finalize();
             } else {
-                // we add a point if freehand was active when the mousedown
-                // occurred
-                if(this.lastDown.equals(evt.xy) || this.freehandMouseDown) {
+                if(this.lastDown.equals(evt.xy) || this.stoppedDown) {
                     var first = this.lastUp == null;
                     if(first && this.persist) {
                         this.destroyPersistedFeature();
@@ -309,7 +305,6 @@
                 }
             }
             this.mouseDown = false;
-            this.freehandMouseDown = false;
             return !this.stopUp;
         }
         return true;

Modified: sandbox/elemoine/draw-feature/tests/Handler/Path.html
===================================================================
--- sandbox/elemoine/draw-feature/tests/Handler/Path.html	2011-02-16 00:34:16 UTC (rev 11119)
+++ sandbox/elemoine/draw-feature/tests/Handler/Path.html	2011-02-16 08:17:09 UTC (rev 11120)
@@ -466,6 +466,117 @@
         map.destroy();
     }
 
+    function test_stopDown_true(t) {
+        t.plan(1);
+        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,
+            {done: function(g) { log.geometry = g; }},
+            {stopDown: true, stopUp: true}
+        );
+        control.handler = handler;
+        map.addControl(control);
+        map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+        handler.activate();
+        log = {};
+
+        // a) click on (0, 0)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+        // b) mousedown on (0.5, 0.5)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(0.5, 0.5)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(0.5, 0.5)});
+        // c) mouseup on (1, 1)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+        // d) dblclick on (10, 10)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
+        handler.dblclick(
+            {type: "dblclick", xy: new OpenLayers.Pixel(10, 10)});
+        t.geom_eq(log.geometry,
+            new OpenLayers.Geometry.LineString([
+                new OpenLayers.Geometry.Point(-150, 75), // (0, 0)
+                new OpenLayers.Geometry.Point(-149, 74), // (1, 1)
+                new OpenLayers.Geometry.Point(-140, 65)  // (10, 10)
+            ]), "geometry is correct");
+    }
+
+    function test_stopDown_false(t) {
+        t.plan(1);
+        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,
+            {done: function(g) { log.geometry = g; }},
+            {stopDown: false, stopUp: false}
+        );
+        control.handler = handler;
+        map.addControl(control);
+        map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+        handler.activate();
+        log = {};
+
+        // a) click on (0, 0)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+        // b) mousedown on (0.5, 0.5)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(0.5, 0.5)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(0.5, 0.5)});
+        // c) mouseup on (1, 1)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+        // d) dblclick on (10, 10)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
+        handler.dblclick(
+            {type: "dblclick", xy: new OpenLayers.Pixel(10, 10)});
+        t.geom_eq(log.geometry,
+            new OpenLayers.Geometry.LineString([
+                new OpenLayers.Geometry.Point(-150, 75), // (0, 0)
+                new OpenLayers.Geometry.Point(-140, 65)  // (10, 10)
+            ]), "geometry is correct");
+    }
+
     function test_Handler_Path_destroy(t) {
         t.plan(6);
         var map = new OpenLayers.Map('map');

Modified: sandbox/elemoine/draw-feature/tests/Handler/Polygon.html
===================================================================
--- sandbox/elemoine/draw-feature/tests/Handler/Polygon.html	2011-02-16 00:34:16 UTC (rev 11119)
+++ sandbox/elemoine/draw-feature/tests/Handler/Polygon.html	2011-02-16 08:17:09 UTC (rev 11120)
@@ -678,7 +678,138 @@
         map.destroy();
     }        
 
+    function test_stopDown_true(t) {
+        t.plan(1);
+        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.Polygon(control,
+            {done: function(g) { log.geometry = g; }},
+            {stopDown: true, stopUp: true}
+        );
+        control.handler = handler;
+        map.addControl(control);
+        map.setCenter(new OpenLayers.LonLat(0, 0), 0);
 
+        handler.activate();
+        log = {};
+
+        // a) click on (0, 0)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+        // b) mousedown on (0.5, 0.5)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(0.5, 0.5)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(0.5, 0.5)});
+        // c) mouseup on (1, 1)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+        // d) click on (0, 10)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(0, 10)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(0, 10)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(0, 10)});
+        // e) dblclick on (10, 10)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
+        handler.dblclick(
+            {type: "dblclick", xy: new OpenLayers.Pixel(10, 10)});
+        t.geom_eq(log.geometry,
+            new OpenLayers.Geometry.Polygon([
+                new OpenLayers.Geometry.LinearRing([
+                    new OpenLayers.Geometry.Point(-150, 75), // (0, 0)
+                    new OpenLayers.Geometry.Point(-149, 74), // (1, 1)
+                    new OpenLayers.Geometry.Point(-150, 65), // (0, 10)
+                    new OpenLayers.Geometry.Point(-140, 65)  // (10, 10)
+                ])
+            ]), "geometry is correct");
+    }
+
+    function test_stopDown_false(t) {
+        t.plan(1);
+        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.Polygon(control,
+            {done: function(g) { log.geometry = g; }},
+            {stopDown: false, stopUp: false}
+        );
+        control.handler = handler;
+        map.addControl(control);
+        map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+        handler.activate();
+        log = {};
+
+        // a) click on (0, 0)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+        // b) mousedown on (0.5, 0.5)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(0.5, 0.5)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(0.5, 0.5)});
+        // c) mouseup on (1, 1)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+        // d) click on (0, 10)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(0, 10)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(0, 10)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(0, 10)});
+        // e) dblclick on (10, 10)
+        handler.mousemove(
+            {type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
+        handler.dblclick(
+            {type: "dblclick", xy: new OpenLayers.Pixel(10, 10)});
+        console.log(log.geometry);
+        t.geom_eq(log.geometry,
+            new OpenLayers.Geometry.Polygon([
+                new OpenLayers.Geometry.LinearRing([
+                    new OpenLayers.Geometry.Point(-150, 75), // (0, 0)
+                    new OpenLayers.Geometry.Point(-150, 65), // (0, 10)
+                    new OpenLayers.Geometry.Point(-140, 65)  // (10, 10)
+                ])
+            ]), "geometry is correct");
+    }
+
     function test_Handler_Polygon_destroy(t) {
         t.plan(8);
         var map = new OpenLayers.Map('map');
@@ -719,4 +850,3 @@
 <body>
     <div id="map" style="width: 300px; height: 150px;"/>
 </body>
-</html>



More information about the Commits mailing list