[OpenLayers-Commits] r11773 - trunk/openlayers/lib/OpenLayers/Handler

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Mar 30 07:30:10 EDT 2011


Author: erilem
Date: 2011-03-30 04:30:07 -0700 (Wed, 30 Mar 2011)
New Revision: 11773

Modified:
   trunk/openlayers/lib/OpenLayers/Handler/Path.js
   trunk/openlayers/lib/OpenLayers/Handler/Point.js
Log:
some refactoring in the touch-specific code of draw handlers, r=sbrunner (closes #3208)

Modified: trunk/openlayers/lib/OpenLayers/Handler/Path.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Handler/Path.js	2011-03-30 09:57:41 UTC (rev 11772)
+++ trunk/openlayers/lib/OpenLayers/Handler/Path.js	2011-03-30 11:30:07 UTC (rev 11773)
@@ -45,6 +45,12 @@
     freehandToggle: 'shiftKey',
 
     /**
+     * Property: timerId
+     * {Integer} The timer used to test the double touch.
+     */
+    timerId: null,
+
+    /**
      * Constructor: OpenLayers.Handler.Path
      * Create a new path hander
      *
@@ -214,6 +220,38 @@
     },
 
     /**
+     * method: touchstart
+     * handle touchstart.
+     *
+     * parameters:
+     * evt - {event} the browser event
+     *
+     * returns:
+     * {boolean} allow event propagation
+     */
+    touchstart: function(evt) {
+        if (this.timerId &&
+            this.passesTolerance(this.lastTouchPx, evt.xy, this.dblclickTolerance)) {
+            // double-tap, finalize the geometry
+            this.lastTouchPx = evt.xy; // for up() to detect dblclick and do nothing
+            this.finishTouchGeometry();
+            window.clearTimeout(this.timerId);
+            this.timerId = null;
+            return false;
+        } else {
+            if (this.timerId) {
+                window.clearTimeout(this.timerId);
+                this.timerId = null;
+            }
+            this.timerId = window.setTimeout(
+                OpenLayers.Function.bind(function() {
+                    this.timerId = null;
+                }, this), 300);
+            return OpenLayers.Handler.Point.prototype.touchstart.call(this, evt);
+        }
+    },
+
+    /**
      * Method: mousedown
      * Handle mouse down.  Add a new point to the geometry and
      * render it. Return determines whether to propagate the event on the map.
@@ -295,7 +333,7 @@
         }
         this.stoppedDown = this.stopDown;
         this.mouseDown = false;
-        return !this.stopUp && !this.isDblclick;
+        return !this.stopUp;
     },
 
     /**

Modified: trunk/openlayers/lib/OpenLayers/Handler/Point.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Handler/Point.js	2011-03-30 09:57:41 UTC (rev 11772)
+++ trunk/openlayers/lib/OpenLayers/Handler/Point.js	2011-03-30 11:30:07 UTC (rev 11773)
@@ -120,26 +120,13 @@
     touch: false,
 
     /**
-     * Property: timerId
-     * {Integer} The timer used to test the double touch.
-     */
-    timerId: null,
-
-    /**
-     * Property: last
+     * Property: lastTouchPx
      * {<OpenLayers.Pixel>} The last pixel used to know the distance between
      * two touches (for double touch).
      */
-    last: null,
+    lastTouchPx: null,
 
     /**
-     * Property: dblclick
-     * {Boolean} The current event is a dblclick.
-     */
-    isDblclick: false,
-    
-    
-    /**
      * Constructor: OpenLayers.Handler.Point
      * Create a new point handler.
      *
@@ -281,6 +268,7 @@
         this.mouseDown = false;
         this.lastDown = null;
         this.lastUp = null;
+        this.lastTouchPx = null;
         this.callback(key, [this.geometryClone()]);
         if(cancel || !this.persist) {
             this.destroyFeature();
@@ -415,32 +403,8 @@
      */
     touchstart: function(evt) {
         this.touch = true;
-
-        var last = this.last;
-        this.last = evt.xy;
-
-        if (this.timerId &&
-            this.passesTolerance(last, evt.xy, this.dblclickTolerance)) {
-            this.isDblclick = true;
-            // a valid touch immediately adds a component and leaves us with a
-            // complete geometry
-            this.finishTouchGeometry();
-            window.clearTimeout(this.timerId);
-            this.timerId = null;
-            return false;
-        }
-        else {
-            if (this.timerId) {
-                window.clearTimeout(this.timerId);
-                this.timerId = null;
-            }
-            this.isDblclick = false;
-            this.timerId = window.setTimeout(
-                OpenLayers.Function.bind(function() {
-                    this.timerId = null;
-                }, this), 300);
-            return this.down(evt);
-        }
+        this.lastTouchPx = evt.xy;
+        return this.down(evt);
     },
 
     /**
@@ -471,7 +435,7 @@
      * {Boolean} Allow event propagation
      */
     touchmove: function(evt) {
-        this.last = evt.xy;
+        this.lastTouchPx = evt.xy;
         return this.move(evt);
     },
 
@@ -503,7 +467,7 @@
      * {Boolean} Allow event propagation
      */
     touchend: function(evt) {
-        evt.xy = this.last;
+        evt.xy = this.lastTouchPx;
         return this.up(evt);
     },
   



More information about the Commits mailing list