[OpenLayers-Commits] r11559 - in sandbox/ahocevar/3072: lib/OpenLayers/Handler tests/Control tests/Handler

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Sun Feb 27 08:56:17 EST 2011


Author: ahocevar
Date: 2011-02-27 05:56:16 -0800 (Sun, 27 Feb 2011)
New Revision: 11559

Modified:
   sandbox/ahocevar/3072/lib/OpenLayers/Handler/Path.js
   sandbox/ahocevar/3072/lib/OpenLayers/Handler/Point.js
   sandbox/ahocevar/3072/tests/Control/Measure.html
   sandbox/ahocevar/3072/tests/Handler/Path.html
   sandbox/ahocevar/3072/tests/Handler/Point.html
   sandbox/ahocevar/3072/tests/Handler/Polygon.html
Log:
some doc improvements, and simplified the passesTolerance method

Modified: sandbox/ahocevar/3072/lib/OpenLayers/Handler/Path.js
===================================================================
--- sandbox/ahocevar/3072/lib/OpenLayers/Handler/Path.js	2011-02-27 13:08:51 UTC (rev 11558)
+++ sandbox/ahocevar/3072/lib/OpenLayers/Handler/Path.js	2011-02-27 13:56:16 UTC (rev 11559)
@@ -275,7 +275,7 @@
      */
     up: function (evt) {
         if (this.mouseDown && (!this.lastUp || !this.passesTolerance(
-                this.lastUp, evt.xy, this.dblclickPixelTolerance))) {
+                this.lastUp, evt.xy, this.dblclickTolerance))) {
             if(this.stoppedDown && this.freehandMode(evt)) {
                 this.removePoint();
                 this.finalize();

Modified: sandbox/ahocevar/3072/lib/OpenLayers/Handler/Point.js
===================================================================
--- sandbox/ahocevar/3072/lib/OpenLayers/Handler/Point.js	2011-02-27 13:08:51 UTC (rev 11558)
+++ sandbox/ahocevar/3072/lib/OpenLayers/Handler/Point.js	2011-02-27 13:56:16 UTC (rev 11559)
@@ -107,34 +107,34 @@
     pixelTolerance: 5,
 
     /**
-     * APIProperty: dblclickPixelTolerance
+     * APIProperty: dblclickTolerance
      * {Number} Maximum number of pixels between two touchend for an
      *     event to be considered a dblclick.  Default is 20.
      */
-    dblclickPixelTolerance: 20,
+    dblclickTolerance: 20,
 
     /**
      * Property: touch
-     * {Boolean} Privat, that indcate the support of touch events.
+     * {Boolean} Indcates the support of touch events.
      */
     touch: false,
 
     /**
      * Property: timerId
-     * {Integer} Privat, the timer used to test the double touch.
+     * {Integer} The timer used to test the double touch.
      */
     timerId: null,
 
     /**
      * Property: last
-     * {Pixel} Privat, the last pixel used to know the distance betweene
-     * two touch (for double touch).
+     * {<OpenLayers.Pixel>} The last pixel used to know the distance between
+     * two touches (for double touch).
      */
     last: null,
 
     /**
      * Property: dblclick
-     * {Pixel} Privat, the current event is a dblclick.
+     * {Boolean} The current event is a dblclick.
      */
     isDblclick: false,
     
@@ -419,7 +419,7 @@
         this.last = evt.xy;
 
         if (this.timerId &&
-                this.passesTolerance(last, evt.xy, this.dblclickPixelTolerance)) {
+                this.passesTolerance(last, evt.xy, this.dblclickTolerance)) {
             this.isDblclick = true;
             this.finishTouchGeometry();
             window.clearTimeout(this.timerId);
@@ -563,10 +563,12 @@
             return true;
         }
         // ignore double-clicks
-        if (this.lastUp && this.passesTolerance(this.lastUp, evt.xy, this.dblclickPixelTolerance)) {
+        if (this.lastUp && this.passesTolerance(this.lastUp, evt.xy,
+                                                    this.dblclickTolerance)) {
             return true;
         }
-        if (this.lastDown && this.passesTolerance(this.lastDown, evt.xy, this.pixelTolerance)) {
+        if (this.lastDown && this.passesTolerance(this.lastDown, evt.xy,
+                                                    this.pixelTolerance)) {
             if (this.touch) {
                 this.modifyFeature(evt.xy);
             }
@@ -598,32 +600,21 @@
 
     /**
      * 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,
-     *     the <clickPixelTolerance> will have no effect here (this method will always
-     *     return true).
+     * 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).
      */
-    passesTolerance: function(pixel1, pixel2, tollerate) {
+    passesTolerance: function(pixel1, pixel2, tolerance) {
         var passes = true;
 
-        // convert event into pixel
-        if (pixel1 != null && pixel1.xy) {
-            pixel1 = pixel1.xy;
-        }
-        if (pixel2 != null && pixel2.xy) {
-            pixel2 = pixel2.xy;
-        }
-
-        if (tollerate != null && pixel1 && pixel2) {
-            var dist = Math.sqrt(
-                Math.pow(pixel1.x - pixel2.x, 2) +
-                Math.pow(pixel1.y - pixel2.y, 2)
-            );
-            if (dist > tollerate) {
+        if (tolerance != null && pixel1 && pixel2) {
+            var dist = pixel1.distanceTo(pixel2);
+            if (dist > tolerance) {
                 passes = false;
             }
         }

Modified: sandbox/ahocevar/3072/tests/Control/Measure.html
===================================================================
--- sandbox/ahocevar/3072/tests/Control/Measure.html	2011-02-27 13:08:51 UTC (rev 11558)
+++ sandbox/ahocevar/3072/tests/Control/Measure.html	2011-02-27 13:56:16 UTC (rev 11559)
@@ -99,7 +99,7 @@
                 },
                 handlerOptions: {
                     pixelTolerance: 0,
-                    dblclickPixelTolerance: 0
+                    dblclickTolerance: 0
                 }
             }
         );
@@ -261,7 +261,7 @@
                 },
                 handlerOptions: {
                     pixelTolerance: 0,
-                    dblclickPixelTolerance: 0
+                    dblclickTolerance: 0
                 }
             }
         );

Modified: sandbox/ahocevar/3072/tests/Handler/Path.html
===================================================================
--- sandbox/ahocevar/3072/tests/Handler/Path.html	2011-02-27 13:08:51 UTC (rev 11558)
+++ sandbox/ahocevar/3072/tests/Handler/Path.html	2011-02-27 13:56:16 UTC (rev 11559)
@@ -148,7 +148,7 @@
         },
         {
             pixelTolerance: 0,
-            dblclickPixelTolerance: 0
+            dblclickTolerance: 0
         });
         control.handler = handler;
         map.addControl(control);
@@ -649,7 +649,7 @@
         var handler = new OpenLayers.Handler.Path(control, {},
         {
             pixelTolerance: 0,
-            dblclickPixelTolerance: 0
+            dblclickTolerance: 0
         });
         control.handler = handler;
         map.addControl(control);

Modified: sandbox/ahocevar/3072/tests/Handler/Point.html
===================================================================
--- sandbox/ahocevar/3072/tests/Handler/Point.html	2011-02-27 13:08:51 UTC (rev 11558)
+++ sandbox/ahocevar/3072/tests/Handler/Point.html	2011-02-27 13:56:16 UTC (rev 11559)
@@ -169,7 +169,7 @@
         },
         {
             pixelTolerance: 0,
-            dblclickPixelTolerance: 0
+            dblclickTolerance: 0
         });
         control.handler = handler;
         map.addControl(control);

Modified: sandbox/ahocevar/3072/tests/Handler/Polygon.html
===================================================================
--- sandbox/ahocevar/3072/tests/Handler/Polygon.html	2011-02-27 13:08:51 UTC (rev 11558)
+++ sandbox/ahocevar/3072/tests/Handler/Polygon.html	2011-02-27 13:56:16 UTC (rev 11559)
@@ -145,7 +145,7 @@
         },
         {
             pixelTolerance: 0,
-            dblclickPixelTolerance: 0
+            dblclickTolerance: 0
         });
         control.handler = handler;
         map.addControl(control);
@@ -538,7 +538,7 @@
             {handlerOptions: {
                 holeModifier: "altKey",
                 pixelTolerance: 0,
-                dblclickPixelTolerance: 0
+                dblclickTolerance: 0
             }}
         );
         map.addControl(draw);
@@ -754,7 +754,7 @@
         var handler = new OpenLayers.Handler.Polygon(control,
             {done: function(g) { log.geometry = g; }},
             {stopDown: true, stopUp: true,
-            pixelTolerance: 0, dblclickPixelTolerance: 0}
+            pixelTolerance: 0, dblclickTolerance: 0}
         );
         control.handler = handler;
         map.addControl(control);
@@ -826,7 +826,7 @@
         var handler = new OpenLayers.Handler.Polygon(control,
             {done: function(g) { log.geometry = g; }},
             {stopDown: false, stopUp: false,
-            pixelTolerance: 0, dblclickPixelTolerance: 0}
+            pixelTolerance: 0, dblclickTolerance: 0}
         );
         control.handler = handler;
         map.addControl(control);



More information about the Commits mailing list