[OpenLayers-Commits] r11628 -
sandbox/tschaub/click/lib/OpenLayers/Handler
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Sun Mar 6 19:19:17 EST 2011
Author: tschaub
Date: 2011-03-06 16:19:16 -0800 (Sun, 06 Mar 2011)
New Revision: 11628
Modified:
sandbox/tschaub/click/lib/OpenLayers/Handler/Click.js
Log:
The click handler should use the provided pixel tolerance for each touch before determining whether a sequence of touches constitutes a click.
Modified: sandbox/tschaub/click/lib/OpenLayers/Handler/Click.js
===================================================================
--- sandbox/tschaub/click/lib/OpenLayers/Handler/Click.js 2011-03-07 00:18:14 UTC (rev 11627)
+++ sandbox/tschaub/click/lib/OpenLayers/Handler/Click.js 2011-03-07 00:19:16 UTC (rev 11628)
@@ -392,10 +392,39 @@
var passes = true;
if (this.pixelTolerance != null && this.down && this.down.xy) {
passes = this.pixelTolerance >= this.down.xy.distanceTo(evt.xy);
+ // for touch environments, we also enforce that all touches
+ // start and end within the given tolerance to be considered a click
+ if (passes && this.touch &&
+ this.down.touches.length === this.last.touches.length) {
+ // the touchend event doesn't come with touches, so we check
+ // down and last
+ for (var i=0, ii=this.down.touches.length; i<ii; ++i) {
+ if (this.getTouchDistance(
+ this.down.touches[i],
+ this.last.touches[i]
+ ) > this.pixelTolerance) {
+ passes = false;
+ break;
+ }
+ }
+ }
}
return passes;
},
+ /**
+ * Method: getTouchDistance
+ *
+ * Returns:
+ * {Boolean} The pixel displacement between two touches.
+ */
+ getTouchDistance: function(from, to) {
+ return Math.sqrt(
+ Math.pow(from.clientX - to.clientX, 2) +
+ Math.pow(from.clientY - to.clientY, 2)
+ );
+ },
+
/**
* Method: passesDblclickTolerance
* Determine whether the event is within the optional double-cick pixel
More information about the Commits
mailing list