make drag handler work with touch events, p=lotsofpeople, r=tschaub (closes #2995)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11189 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2011-02-21 15:07:55 +00:00
parent 7a1cb00fe4
commit 07160f5385
3 changed files with 201 additions and 86 deletions
+24 -3
View File
@@ -90,6 +90,20 @@ OpenLayers.Event = {
return event.target || event.srcElement;
},
/**
* Method: isSingleTouch
* Determine whether event was caused by a single touch
*
* Parameters:
* event - {Event}
*
* Returns:
* {Boolean}
*/
isSingleTouch: function(event) {
return event.touches && event.touches.length == 1;
},
/**
* Method: isLeftClick
* Determine whether event was caused by a left click.
@@ -369,7 +383,8 @@ OpenLayers.Events = OpenLayers.Class({
"mouseover", "mouseout",
"mousedown", "mouseup", "mousemove",
"click", "dblclick", "rightclick", "dblrightclick",
"resize", "focus", "blur"
"resize", "focus", "blur",
"touchstart", "touchmove", "touchend"
],
/**
@@ -846,10 +861,16 @@ OpenLayers.Events = OpenLayers.Class({
if (!this.element.offsets) {
this.element.offsets = OpenLayers.Util.pagePosition(this.element);
}
var clientX = evt.clientX;
var clientY = evt.clientY;
if (evt.touches && evt.touches.length > 0) {
clientX = evt.touches[0].clientX;
clientY = evt.touches[0].clientY;
}
return new OpenLayers.Pixel(
(evt.clientX + this.element.scrolls[0]) - this.element.offsets[0]
(clientX + this.element.scrolls[0]) - this.element.offsets[0]
- this.element.lefttop[0],
(evt.clientY + this.element.scrolls[1]) - this.element.offsets[1]
(clientY + this.element.scrolls[1]) - this.element.offsets[1]
- this.element.lefttop[1]
);
},