[OpenLayers-Commits] r11368 - in
sandbox/crschmidt/pan-tap/lib/OpenLayers: Control Handler
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Wed Feb 23 13:27:47 EST 2011
Author: crschmidt
Date: 2011-02-23 10:27:46 -0800 (Wed, 23 Feb 2011)
New Revision: 11368
Modified:
sandbox/crschmidt/pan-tap/lib/OpenLayers/Control/Navigation.js
sandbox/crschmidt/pan-tap/lib/OpenLayers/Control/TouchNavigation.js
sandbox/crschmidt/pan-tap/lib/OpenLayers/Handler/Click.js
Log:
Support tap-to-pan in Navigation controls. Still includes
alerts to inform whether tap is being set to true or false
on the click handler.
Modified: sandbox/crschmidt/pan-tap/lib/OpenLayers/Control/Navigation.js
===================================================================
--- sandbox/crschmidt/pan-tap/lib/OpenLayers/Control/Navigation.js 2011-02-23 18:17:13 UTC (rev 11367)
+++ sandbox/crschmidt/pan-tap/lib/OpenLayers/Control/Navigation.js 2011-02-23 18:27:46 UTC (rev 11368)
@@ -162,7 +162,8 @@
this.map.viewPortDiv.oncontextmenu = OpenLayers.Function.False;
}
- var clickCallbacks = {
+ var clickCallbacks = {
+ 'click': this.handleClick,
'dblclick': this.defaultDblClick,
'dblrightclick': this.defaultDblRightClick
};
@@ -189,6 +190,11 @@
this.mouseWheelOptions );
},
+ handleClick: function(evt) {
+ if (this.handlers.click.tap) {
+ map.panTo(map.getLonLatFromPixel(evt.xy));
+ }
+ },
/**
* Method: defaultDblClick
*
Modified: sandbox/crschmidt/pan-tap/lib/OpenLayers/Control/TouchNavigation.js
===================================================================
--- sandbox/crschmidt/pan-tap/lib/OpenLayers/Control/TouchNavigation.js 2011-02-23 18:17:13 UTC (rev 11367)
+++ sandbox/crschmidt/pan-tap/lib/OpenLayers/Control/TouchNavigation.js 2011-02-23 18:27:46 UTC (rev 11368)
@@ -130,6 +130,8 @@
defaultClick: function (evt) {
if(evt.lastTouches && evt.lastTouches.length == 2) {
this.map.zoomOut();
+ } else if (this.handlers.click.tap) {
+ this.map.panTo(map.getLonLatFromViewPortPx(evt.xy));
}
},
Modified: sandbox/crschmidt/pan-tap/lib/OpenLayers/Handler/Click.js
===================================================================
--- sandbox/crschmidt/pan-tap/lib/OpenLayers/Handler/Click.js 2011-02-23 18:17:13 UTC (rev 11367)
+++ sandbox/crschmidt/pan-tap/lib/OpenLayers/Handler/Click.js 2011-02-23 18:27:46 UTC (rev 11368)
@@ -102,7 +102,22 @@
*/
touch: false,
+ /**
+ * Property: tap
+ * Are we on a device which supports 'taps', but is not touch?
+ */
+ tap: undefined,
+
/**
+ * Property: tapTolerance
+ * How long from mousemove->mousedown->mouseup in order to decide
+ * that it must be a tap? Setting this to anything larger than
+ * 50ms may result in setting tap true on the handler even
+ * on non-mobile browsers with fast move+down+up event chains.
+ */
+ tapTolerance: 50,
+
+ /**
* Property: rightclickTimerId
* {Number} The id of the right mouse timeout waiting to clear the
* <delayedEvent>.
@@ -128,25 +143,38 @@
initialize: function(control, callbacks, options) {
OpenLayers.Handler.prototype.initialize.apply(this, arguments);
// optionally register for mouseup and mousedown
- if(this.pixelTolerance != null) {
- this.mousedown = function(evt) {
- this.down = evt;
- return true;
- };
- }
},
+ mouseover: function(evt) {
+ this.firstMouseOver = evt.xy;
+ this.unregister("mouseover", this.mouseover);
+ },
+
/**
* Method: mousedown
- * Handle mousedown. Only registered as a listener if pixelTolerance is
- * a non-zero value at construction.
+ * Handle mousedown.
*
* Returns:
* {Boolean} Continue propagating this event.
*/
- mousedown: null,
+ mousedown: function(evt) {
+ if (this.pixelTolerance != null) {
+ this.down = evt;
+ }
+ this.lastDown = new Date().getTime();
+ return true;
+ },
/**
+ * Method: mousemove
+ * Handle mousemove. This is simply used to record
+ *
+ */
+ mousemove: function(evt) {
+ this.lastMove = new Date().getTime();
+ },
+
+ /**
* Method: touchstart
* Handle touchstart.
*
@@ -168,6 +196,7 @@
* {Boolean} Continue propagating this event.
*/
mouseup: function (evt) {
+ this.lastUp = new Date().getTime();
var propagate = true;
// Collect right mouse clicks from the mouseup
@@ -286,11 +315,35 @@
* {Boolean} Continue propagating this event.
*/
click: function(evt) {
+ if (this.tap === undefined) {
+ if (this.touch === true) {
+ this.tap = false;
+
+ // Opera on Symbian, FF on Maemo: first mouseover and click happen at the
+ // same location.
+ } else if (this.firstMouseOver && this.firstMouseOver.equals(evt.xy)) {
+ this.tap = true;
+ alert('tap true');
+
+ // IE on WP7 (and possibly others) -- move->down->up all happen at almost
+ // exactly the same time (within tapTolerance) means this was a tap. Setting
+ // the tapTolerance too high can cause this to also be triggered on
+ // desktop browsers.
+ } else if (this.lastMove < this.lastDown && this.lastDown < this.lastUp && ((this.lastUp - this.lastMove) < this.tapTolerance)) {
+ this.tap = true;
+ alert('tap true');
+ } else {
+ this.tap = false;
+ alert('tap false');
+ }
+ }
+
// Sencha Touch emulates click events, see ticket 3079 for more info
if (this.touch === true && evt.type === "click") {
return !this.stopSingle;
}
- if(this.passesTolerance(evt)) {
+
+ if (this.passesTolerance(evt)) {
if(this.timerId != null) {
// already received a click
if(evt.lastTouches) {
More information about the Commits
mailing list