some refactoring in the touch-specific code of draw handlers, r=sbrunner (closes #3208)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11773 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2011-03-30 11:30:07 +00:00
parent cafe9661c4
commit 147e5bba1a
2 changed files with 46 additions and 44 deletions

View File

@@ -44,6 +44,12 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
*/
freehandToggle: 'shiftKey',
/**
* Property: timerId
* {Integer} The timer used to test the double touch.
*/
timerId: null,
/**
* Constructor: OpenLayers.Handler.Path
* Create a new path hander
@@ -213,6 +219,38 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
return geometry;
},
/**
* 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
@@ -295,7 +333,7 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
}
this.stoppedDown = this.stopDown;
this.mouseDown = false;
return !this.stopUp && !this.isDblclick;
return !this.stopUp;
},
/**