[OpenLayers-Commits] r11915 - in sandbox/elemoine/3272: lib/OpenLayers/Handler tests/Handler

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Apr 27 05:20:21 EDT 2011


Author: erilem
Date: 2011-04-27 02:20:20 -0700 (Wed, 27 Apr 2011)
New Revision: 11915

Modified:
   sandbox/elemoine/3272/lib/OpenLayers/Handler/Path.js
   sandbox/elemoine/3272/lib/OpenLayers/Handler/Point.js
   sandbox/elemoine/3272/tests/Handler/Path.html
   sandbox/elemoine/3272/tests/Handler/Polygon.html
Log:
touches at the same location shouldn't draw new points

Modified: sandbox/elemoine/3272/lib/OpenLayers/Handler/Path.js
===================================================================
--- sandbox/elemoine/3272/lib/OpenLayers/Handler/Path.js	2011-04-27 09:20:11 UTC (rev 11914)
+++ sandbox/elemoine/3272/lib/OpenLayers/Handler/Path.js	2011-04-27 09:20:20 UTC (rev 11915)
@@ -36,14 +36,6 @@
     maxVertices: null,
 
     /**
-     * Property: doubleTouchTolerance
-     * {Number} Maximum number of pixels between two touches for
-     *     the gesture to be considered a "finalize feature" action.
-     *     Default is 20.
-     */
-    doubleTouchTolerance: 20,
-
-    /**
      * Property: freehand
      * {Boolean} In freehand mode, the handler starts the path on mouse down,
      * adds a point for every mouse move, and finishes the path on mouse up.
@@ -68,6 +60,13 @@
     timerId: null,
 
     /**
+     * Property: acceptDblclick
+     * {Boolean} Indicate if we can finalize the feature on the next dblclick
+     * event.
+     */
+    acceptDblclick: false,
+
+    /**
      * Constructor: OpenLayers.Handler.Path
      * Create a new path hander
      *
@@ -250,7 +249,7 @@
     touchstart: function(evt) {
         if (this.timerId &&
             this.passesTolerance(this.lastTouchPx, evt.xy,
-                                 this.doubleTouchTolerance)) {
+                                 this.dblclickTolerance)) {
             // double-tap, finalize the geometry
             this.finishGeometry();
             window.clearTimeout(this.timerId);
@@ -294,6 +293,7 @@
         }
         this.mouseDown = true;
         this.lastDown = evt.xy;
+        this.acceptDblclick = false;
         this.stoppedDown = stopDown;
         return !stopDown;
     },
@@ -335,25 +335,33 @@
      * {Boolean} Allow event propagation
      */
     up: function (evt) {
-        if (this.mouseDown && (!this.lastUp || !this.lastUp.equals(evt.xy))) {
-            if(this.stoppedDown && this.freehandMode(evt)) {
-                this.removePoint();
-                this.finalize();
-            } else {
-                if (this.passesTolerance(this.lastDown, evt.xy,
-                                         this.pixelTolerance)) {
-                    if (this.touch) {
-                        this.modifyFeature(evt.xy);
+        if (this.mouseDown) {
+            var samePlace = this.lastUp &&
+                            this.passesTolerance(this.lastUp, evt.xy,
+                                                 this.dblclickTolerance);
+            if(!samePlace) {
+                if(this.stoppedDown && this.freehandMode(evt)) {
+                    this.removePoint();
+                    this.finalize();
+                } else {
+                    if (this.passesTolerance(this.lastDown, evt.xy,
+                                             this.pixelTolerance)) {
+                        if (this.touch) {
+                            this.modifyFeature(evt.xy);
+                        }
+                        if(this.lastUp == null && this.persist) {
+                            this.destroyPersistedFeature();
+                        }
+                        this.addPoint(evt.xy);
+                        this.lastUp = evt.xy;
+                        if(this.line.geometry.components.length ===
+                               this.maxVertices + 1) {
+                            this.finishGeometry();
+                        }
                     }
-                    if(this.lastUp == null && this.persist) {
-                        this.destroyPersistedFeature();
-                    }
-                    this.addPoint(evt.xy);
-                    this.lastUp = evt.xy;
-                    if(this.line.geometry.components.length === this.maxVertices + 1) {
-                        this.finishGeometry();
-                    }
                 }
+            } else {
+                this.acceptDblclick = true;
             }
         }
         this.stoppedDown = this.stopDown;
@@ -384,7 +392,13 @@
      */
     dblclick: function(evt) {
         if(!this.freehandMode(evt)) {
-            this.finishGeometry();
+            var accept = this.acceptDblclick ||
+                         (this.lastUp &&
+                          this.passesTolerance(this.lastUp, evt.xy,
+                                               this.dblclickTolerance));
+            if(accept) {
+                this.finishGeometry();
+            }
         }
         return false;
     },

Modified: sandbox/elemoine/3272/lib/OpenLayers/Handler/Point.js
===================================================================
--- sandbox/elemoine/3272/lib/OpenLayers/Handler/Point.js	2011-04-27 09:20:11 UTC (rev 11914)
+++ sandbox/elemoine/3272/lib/OpenLayers/Handler/Point.js	2011-04-27 09:20:20 UTC (rev 11915)
@@ -107,6 +107,15 @@
     pixelTolerance: 5,
 
     /**
+     * Property: dblclickTolerance
+     * {Number} Maximum distance in pixels between two clicks (or touches)
+     *     for these clicks to be considered on the same location. Used to
+     *     determine if the feature should be finalized. Default is 20 for
+     *     touch devices, and 0 for non-touch devices.
+     */
+    dblclickTolerance: "ontouchend" in document ? 20 : 0,
+
+    /**
      * Property: touch
      * {Boolean} Indcates the support of touch events.
      */
@@ -519,7 +528,8 @@
             return true;
         }
         // ignore double-clicks
-        if (this.lastUp && this.lastUp.equals(evt.xy)) {
+        if (this.lastUp && this.passesTolerance(this.lastUp, evt.xy,
+                                                this.dblclickTolerance)) {
             return true;
         }
         if (this.lastDown && this.passesTolerance(this.lastDown, evt.xy,

Modified: sandbox/elemoine/3272/tests/Handler/Path.html
===================================================================
--- sandbox/elemoine/3272/tests/Handler/Path.html	2011-04-27 09:20:11 UTC (rev 11914)
+++ sandbox/elemoine/3272/tests/Handler/Path.html	2011-04-27 09:20:20 UTC (rev 11915)
@@ -150,7 +150,7 @@
     }     
 
     function test_callbacks(t) {
-        t.plan(45);
+        t.plan(47);
         var map = new OpenLayers.Map("map", {
             resolutions: [1]
         });
@@ -271,11 +271,19 @@
         // mouse down
         handler.mousedown({type: "mousedown",
                            xy: new OpenLayers.Pixel(10, 10)});
-        t.eq(logs.length, 0, "[mousedown] called back");
+        t.eq(logs.length, 0, "[mousedown] not called back");
         // mouse up
         handler.mouseup({type: "mouseup",
                          xy: new OpenLayers.Pixel(10, 10)});
         t.eq(logs.length, 0, "[mouseup] not called back");
+        // mouse down
+        handler.mousedown({type: "mousedown",
+                           xy: new OpenLayers.Pixel(10, 10)});
+        t.eq(logs.length, 0, "[mousedown] not called back");
+        // mouse up
+        handler.mouseup({type: "mouseup",
+                         xy: new OpenLayers.Pixel(10, 10)});
+        t.eq(logs.length, 0, "[mouseup] not called back");
         // double click
         handler.dblclick({type: "dblclick",
                           xy: new OpenLayers.Pixel(10, 10)});
@@ -388,6 +396,14 @@
             {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
         handler.mousemove(
             {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
         handler.dblclick(
             {type: "dblclick", xy: new OpenLayers.Pixel(1, 1)});
         t.ok(feature1.layer == null, "a) feature1 destroyed");
@@ -402,6 +418,14 @@
             {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
         handler.mousemove(
             {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
         handler.dblclick(
             {type: "dblclick", xy: new OpenLayers.Pixel(1, 1)});
         t.ok(feature2.layer != null, "b) feature2 not destroyed");
@@ -415,6 +439,14 @@
             {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
         handler.mousemove(
             {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
         handler.dblclick(
             {type: "dblclick", xy: new OpenLayers.Pixel(1, 1)});
         t.ok(feature3.layer != null, "c) feature3 not destroyed");
@@ -627,6 +659,10 @@
             {type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
         handler.mouseup(
             {type: "mouseup", 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,
@@ -687,6 +723,10 @@
             {type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
         handler.mouseup(
             {type: "mouseup", 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,
@@ -793,6 +833,10 @@
             {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
         handler.mouseup(
             {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
         handler.dblclick(
             {type: "dblclick", xy: new OpenLayers.Pixel(1, 1)});
         t.geom_eq(log.geometry,
@@ -839,7 +883,7 @@
                 log = {type: 'modify', geometry: g, feature: f};
             }
         }, {
-            doubleTouchTolerance: 2
+            dblclickTolerance: 2
         });
         control.handler = handler;
         map.addControl(control);
@@ -918,7 +962,7 @@
                 log = {type: 'modify', geometry: g, feature: f};
             }
         }, {
-            doubleTouchTolerance: 2
+            dblclickTolerance: 2
         });
         control.handler = handler;
         map.addControl(control);

Modified: sandbox/elemoine/3272/tests/Handler/Polygon.html
===================================================================
--- sandbox/elemoine/3272/tests/Handler/Polygon.html	2011-04-27 09:20:11 UTC (rev 11914)
+++ sandbox/elemoine/3272/tests/Handler/Polygon.html	2011-04-27 09:20:20 UTC (rev 11915)
@@ -140,7 +140,7 @@
     }
 
     function test_callbacks(t) {
-        t.plan(45);
+        t.plan(47);
         var map = new OpenLayers.Map("map", {
             resolutions: [1]
         });
@@ -284,6 +284,14 @@
         handler.mouseup(
             {type: "mouseup", xy: new OpenLayers.Pixel(0, 10)});
         t.eq(logs.length, 0, "[mouseup] not called back");
+        // mouse down
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(0, 10)});
+        t.eq(logs.length, 0, "[mousedown] not called back");
+        // mouse up
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(0, 10)});
+        t.eq(logs.length, 0, "[mouseup] not called back");
         // dblclick
         handler.dblclick(
             {type: "dblclick", xy: new OpenLayers.Pixel(0, 10)});
@@ -404,6 +412,14 @@
             {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
         handler.mousemove(
             {type: "mousemove", xy: new OpenLayers.Pixel(2, 2)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(2, 2)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(2, 2)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(2, 2)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(2, 2)});
         handler.dblclick(
             {type: "dblclick", xy: new OpenLayers.Pixel(2, 2)});
         t.ok(feature1.layer == null, "a) feature1 destroyed");
@@ -424,6 +440,14 @@
             {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
         handler.mousemove(
             {type: "mousemove", xy: new OpenLayers.Pixel(2, 2)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(2, 2)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(2, 2)});
+        handler.mousedown(
+            {type: "mousedown", xy: new OpenLayers.Pixel(2, 2)});
+        handler.mouseup(
+            {type: "mouseup", xy: new OpenLayers.Pixel(2, 2)});
         handler.dblclick(
             {type: "dblclick", xy: new OpenLayers.Pixel(2, 2)});
         t.ok(feature2.layer != null, "b) feature2 not destroyed");
@@ -599,6 +623,8 @@
         event = {xy: new OpenLayers.Pixel(-9, 1)};
         trigger("mousedown", event);
         trigger("mouseup", event);
+        trigger("mousedown", event);
+        trigger("mouseup", event);
         trigger("dblclick", event);
         
         // make assertions
@@ -632,6 +658,8 @@
         event = {xy: new OpenLayers.Pixel(-6, 3), altKey: true};
         trigger("mousedown", event);
         trigger("mouseup", event);
+        trigger("mousedown", event);
+        trigger("mouseup", event);
         trigger("dblclick", event);
         
         // make assertions
@@ -666,6 +694,8 @@
         event = {xy: new OpenLayers.Pixel(-2, -2)};
         trigger("mousedown", event);
         trigger("mouseup", event);
+        trigger("mousedown", event);
+        trigger("mouseup", event);
         trigger("dblclick", event);
         
         // make assertions
@@ -704,6 +734,8 @@
         event = {xy: new OpenLayers.Pixel(-1, 1), altKey: true};
         trigger("mousedown", event);
         trigger("mouseup", event);
+        trigger("mousedown", event);
+        trigger("mouseup", event);
         trigger("dblclick", event);
         
         // make assertions
@@ -818,6 +850,10 @@
             {type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
         handler.mouseup(
             {type: "mouseup", 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,
@@ -890,6 +926,10 @@
             {type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
         handler.mouseup(
             {type: "mouseup", 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,
@@ -928,7 +968,7 @@
                 log = {type: 'modify', geometry: g, feature: f};
             }
         }, {
-            doubleTouchTolerance: 2
+            dblclickTolerance: 2
         });
         control.handler = handler;
         map.addControl(control);
@@ -1025,7 +1065,7 @@
                 log = {type: 'modify', geometry: g, feature: f};
             }
         }, {
-            doubleTouchTolerance: 2
+            dblclickTolerance: 2
         });
         control.handler = handler;
         map.addControl(control);



More information about the Commits mailing list