[OpenLayers-Commits] r11962 - in trunk/openlayers: lib/OpenLayers/Handler tests/Handler

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Mon May 9 05:34:22 EDT 2011


Author: erilem
Date: 2011-05-09 02:34:19 -0700 (Mon, 09 May 2011)
New Revision: 11962

Modified:
   trunk/openlayers/lib/OpenLayers/Handler/Path.js
   trunk/openlayers/lib/OpenLayers/Handler/Point.js
   trunk/openlayers/tests/Handler/Path.html
   trunk/openlayers/tests/Handler/Polygon.html
Log:
fix regression where drawing accurately is not possible anymore, r=jorix,bbinet (closes #3272)

Modified: trunk/openlayers/lib/OpenLayers/Handler/Path.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Handler/Path.js	2011-05-09 08:28:35 UTC (rev 11961)
+++ trunk/openlayers/lib/OpenLayers/Handler/Path.js	2011-05-09 09:34:19 UTC (rev 11962)
@@ -36,6 +36,14 @@
     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.
@@ -241,9 +249,9 @@
      */
     touchstart: function(evt) {
         if (this.timerId &&
-            this.passesTolerance(this.lastTouchPx, evt.xy, this.dblclickTolerance)) {
+            this.passesTolerance(this.lastTouchPx, evt.xy,
+                                 this.doubleTouchTolerance)) {
             // double-tap, finalize the geometry
-            this.lastTouchPx = evt.xy; // for up() to detect dblclick and do nothing
             this.finishGeometry();
             window.clearTimeout(this.timerId);
             this.timerId = null;
@@ -277,7 +285,9 @@
         if(this.freehandMode(evt)) {
             stopDown = true;
         }
-        if (!this.touch && (!this.lastDown || !this.passesTolerance(this.lastDown, evt.xy, this.pixelTolerance))) {
+        if (!this.touch && (!this.lastDown ||
+                            !this.passesTolerance(this.lastDown, evt.xy,
+                                                  this.pixelTolerance))) {
             this.modifyFeature(evt.xy, !!this.lastUp);
         }
         this.mouseDown = true;
@@ -323,13 +333,13 @@
      * {Boolean} Allow event propagation
      */
     up: function (evt) {
-        if (this.mouseDown && (!this.lastUp || !this.passesTolerance(
-                this.lastUp, evt.xy, this.dblclickTolerance))) {
+        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.passesTolerance(this.lastDown, evt.xy,
+                                         this.pixelTolerance)) {
                     if (this.touch) {
                         this.modifyFeature(evt.xy);
                     }

Modified: trunk/openlayers/lib/OpenLayers/Handler/Point.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Handler/Point.js	2011-05-09 08:28:35 UTC (rev 11961)
+++ trunk/openlayers/lib/OpenLayers/Handler/Point.js	2011-05-09 09:34:19 UTC (rev 11962)
@@ -107,13 +107,6 @@
     pixelTolerance: 5,
 
     /**
-     * APIProperty: dblclickTolerance
-     * {Number} Maximum number of pixels between two touchend for an
-     *     event to be considered a dblclick.  Default is 20.
-     */
-    dblclickTolerance: 20,
-
-    /**
      * Property: touch
      * {Boolean} Indcates the support of touch events.
      */
@@ -526,8 +519,7 @@
             return true;
         }
         // ignore double-clicks
-        if (this.lastUp && this.passesTolerance(this.lastUp, evt.xy,
-                                                this.dblclickTolerance)) {
+        if (this.lastUp && this.lastUp.equals(evt.xy)) {
             return true;
         }
         if (this.lastDown && this.passesTolerance(this.lastDown, evt.xy,
@@ -564,13 +556,9 @@
     /**
      * Method: passesTolerance
      * Determine whether the event is within the optional pixel tolerance.
-     * Note that the pixel tolerance check only works if mousedown events get
-     * to the listeners registered here.  If they are stopped by other
-     * elements, <pixelTolerance> and <dblclickTolerance> will have no effect
-     * here (this method will always return true).
      *
      * Returns:
-     * {Boolean} The click is within the pixel tolerance (if specified).
+     * {Boolean} The event is within the pixel tolerance (if specified).
      */
     passesTolerance: function(pixel1, pixel2, tolerance) {
         var passes = true;

Modified: trunk/openlayers/tests/Handler/Path.html
===================================================================
--- trunk/openlayers/tests/Handler/Path.html	2011-05-09 08:28:35 UTC (rev 11961)
+++ trunk/openlayers/tests/Handler/Path.html	2011-05-09 09:34:19 UTC (rev 11962)
@@ -179,8 +179,7 @@
             }
         },
         {
-            pixelTolerance: 0,
-            dblclickTolerance: 0
+            pixelTolerance: 0
         });
         control.handler = handler;
         map.addControl(control);
@@ -577,10 +576,10 @@
     // added here each a non-working sequence is found.
     //
 
-    // stopDown:true, stopUp:true
+    // stopDown:true, stopUp:true, pixelTolerance:1
     // a) click on (0, 0)
-    // b) mousedown on (0.5, 0.5)
-    // c) mouseup on (1, 1)
+    // b) mousedown on (1, 1)
+    // c) mouseup on (2, 2)
     // d) dblclick on (10, 10)
     function test_sequence1(t) {
         t.plan(1);
@@ -595,7 +594,7 @@
         var control = new OpenLayers.Control({});
         var handler = new OpenLayers.Handler.Path(control,
             {done: function(g) { log.geometry = g; }},
-            {stopDown: true, stopUp: true}
+            {stopDown: true, stopUp: true, pixelTolerance: 1}
         );
         control.handler = handler;
         map.addControl(control);
@@ -611,16 +610,16 @@
             {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)
+        // b) mousedown on (1, 1)
         handler.mousemove(
-            {type: "mousemove", xy: new OpenLayers.Pixel(0.5, 0.5)});
+            {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
         handler.mousedown(
-            {type: "mousedown", xy: new OpenLayers.Pixel(0.5, 0.5)});
-        // c) mouseup on (1, 1)
+            {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
+        // c) mouseup on (2, 2)
         handler.mousemove(
-            {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+            {type: "mousemove", xy: new OpenLayers.Pixel(2, 2)});
         handler.mouseup(
-            {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+            {type: "mouseup", xy: new OpenLayers.Pixel(2, 2)});
         // d) dblclick on (10, 10)
         handler.mousemove(
             {type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
@@ -637,10 +636,10 @@
             ]), "geometry is correct");
     }
 
-    // stopDown:false, stopUp:false
+    // stopDown:false, stopUp:false, pixelTolerance:1
     // a) click on (0, 0)
-    // b) mousedown on (0.5, 0.5)
-    // c) mouseup on (1, 1)
+    // b) mousedown on (1, 1)
+    // c) mouseup on (2, 2)
     // d) dblclick on (10, 10)
     function test_sequence2(t) {
         t.plan(1);
@@ -655,7 +654,7 @@
         var control = new OpenLayers.Control({});
         var handler = new OpenLayers.Handler.Path(control,
             {done: function(g) { log.geometry = g; }},
-            {stopDown: false, stopUp: false}
+            {stopDown: false, stopUp: false, pixelTolerance: 1}
         );
         control.handler = handler;
         map.addControl(control);
@@ -671,16 +670,16 @@
             {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)
+        // b) mousedown on (1, 1)
         handler.mousemove(
-            {type: "mousemove", xy: new OpenLayers.Pixel(0.5, 0.5)});
+            {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
         handler.mousedown(
-            {type: "mousedown", xy: new OpenLayers.Pixel(0.5, 0.5)});
-        // c) mouseup on (1, 1)
+            {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
+        // c) mouseup on (2, 2)
         handler.mousemove(
-            {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+            {type: "mousemove", xy: new OpenLayers.Pixel(2, 2)});
         handler.mouseup(
-            {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+            {type: "mouseup", xy: new OpenLayers.Pixel(2, 2)});
         // d) dblclick on (10, 10)
         handler.mousemove(
             {type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
@@ -714,8 +713,7 @@
         var control = new OpenLayers.Control({});
         var handler = new OpenLayers.Handler.Path(control, {},
         {
-            pixelTolerance: 0,
-            dblclickTolerance: 0
+            pixelTolerance: 0
         });
         control.handler = handler;
         map.addControl(control);
@@ -819,7 +817,7 @@
     // a) tap
     // c) doubletap
     function test_touch_sequence1(t) {
-        t.plan(17);
+        t.plan(19);
 
         // set up
 
@@ -841,7 +839,7 @@
                 log = {type: 'modify', geometry: g, feature: f};
             }
         }, {
-            dblclickTolerance: 2
+            doubleTouchTolerance: 2
         });
         control.handler = handler;
         map.addControl(control);
@@ -888,6 +886,10 @@
                 new OpenLayers.Geometry.Point(-149, 75),  // (1, 0)
                 new OpenLayers.Geometry.Point(-140, 65)   // (10, 10)
             ]), "[touchstart] final geometry is correct");
+        log = null;
+        ret = handler.touchend({});
+        t.ok(ret, '[touchend] event propagates');
+        t.eq(log, null, '[touchend] feature not finalized or modified');
 
         // tear down
 
@@ -898,7 +900,7 @@
     // b) tap-move
     // c) doubletap
     function test_touch_sequence2(t) {
-        t.plan(23);
+        t.plan(25);
 
         // set up
 
@@ -920,7 +922,7 @@
                 log = {type: 'modify', geometry: g, feature: f};
             }
         }, {
-            dblclickTolerance: 2
+            doubleTouchTolerance: 2
         });
         control.handler = handler;
         map.addControl(control);
@@ -979,6 +981,10 @@
                 new OpenLayers.Geometry.Point(-149, 75),  // (1, 0)
                 new OpenLayers.Geometry.Point(-140, 65)   // (10, 10)
             ]), "[touchstart] final geometry is correct");
+        log = null;
+        ret = handler.touchend({});
+        t.ok(ret, '[touchend] event propagates');
+        t.eq(log, null, '[touchend] feature not finalized or modified');
 
         // tear down
 

Modified: trunk/openlayers/tests/Handler/Polygon.html
===================================================================
--- trunk/openlayers/tests/Handler/Polygon.html	2011-05-09 08:28:35 UTC (rev 11961)
+++ trunk/openlayers/tests/Handler/Polygon.html	2011-05-09 09:34:19 UTC (rev 11962)
@@ -170,8 +170,7 @@
             }
         },
         {
-            pixelTolerance: 0,
-            dblclickTolerance: 0
+            pixelTolerance: 0
         });
         control.handler = handler;
         map.addControl(control);
@@ -563,8 +562,7 @@
             OpenLayers.Handler.Polygon,
             {handlerOptions: {
                 holeModifier: "altKey",
-                pixelTolerance: 0,
-                dblclickTolerance: 0
+                pixelTolerance: 0
             }}
         );
         map.addControl(draw);
@@ -780,7 +778,7 @@
         var handler = new OpenLayers.Handler.Polygon(control,
             {done: function(g) { log.geometry = g; }},
             {stopDown: true, stopUp: true,
-            pixelTolerance: 0, dblclickTolerance: 0}
+            pixelTolerance: 0}
         );
         control.handler = handler;
         map.addControl(control);
@@ -852,7 +850,7 @@
         var handler = new OpenLayers.Handler.Polygon(control,
             {done: function(g) { log.geometry = g; }},
             {stopDown: false, stopUp: false,
-            pixelTolerance: 0, dblclickTolerance: 0}
+            pixelTolerance: 0}
         );
         control.handler = handler;
         map.addControl(control);
@@ -908,7 +906,7 @@
     // b) tap
     // c) doubletap
     function test_touch_sequence1(t) {
-        t.plan(24);
+        t.plan(26);
 
         // set up
 
@@ -930,7 +928,7 @@
                 log = {type: 'modify', geometry: g, feature: f};
             }
         }, {
-            dblclickTolerance: 2
+            doubleTouchTolerance: 2
         });
         control.handler = handler;
         map.addControl(control);
@@ -994,6 +992,10 @@
                     new OpenLayers.Geometry.Point(-140, 65)  // (10, 10)
                 ])
             ]), "[touchstart] geometry is correct");
+        log = null;
+        ret = handler.touchend({});
+        t.ok(ret, '[touchend] event propagates');
+        t.eq(log, null, '[touchend] feature not finalized or modified');
 
         // tear down
 
@@ -1005,7 +1007,7 @@
     // c) tap
     // d) doubletap
     function test_touch_sequence2(t) {
-        t.plan(30);
+        t.plan(32);
 
         // set up
 
@@ -1027,7 +1029,7 @@
                 log = {type: 'modify', geometry: g, feature: f};
             }
         }, {
-            dblclickTolerance: 2
+            doubleTouchTolerance: 2
         });
         control.handler = handler;
         map.addControl(control);
@@ -1103,6 +1105,10 @@
                     new OpenLayers.Geometry.Point(-140, 65)  // (10, 10)
                 ])
             ]), "[touchstart] geometry is correct");
+        log = null;
+        ret = handler.touchend({});
+        t.ok(ret, '[touchend] event propagates');
+        t.eq(log, null, '[touchend] feature not finalized or modified');
 
         // tear down
 



More information about the Commits mailing list