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:
@@ -44,6 +44,12 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
|||||||
*/
|
*/
|
||||||
freehandToggle: 'shiftKey',
|
freehandToggle: 'shiftKey',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: timerId
|
||||||
|
* {Integer} The timer used to test the double touch.
|
||||||
|
*/
|
||||||
|
timerId: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: OpenLayers.Handler.Path
|
* Constructor: OpenLayers.Handler.Path
|
||||||
* Create a new path hander
|
* Create a new path hander
|
||||||
@@ -213,6 +219,38 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
|||||||
return geometry;
|
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
|
* Method: mousedown
|
||||||
* Handle mouse down. Add a new point to the geometry and
|
* 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.stoppedDown = this.stopDown;
|
||||||
this.mouseDown = false;
|
this.mouseDown = false;
|
||||||
return !this.stopUp && !this.isDblclick;
|
return !this.stopUp;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -120,25 +120,12 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
touch: false,
|
touch: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property: timerId
|
* Property: lastTouchPx
|
||||||
* {Integer} The timer used to test the double touch.
|
|
||||||
*/
|
|
||||||
timerId: null,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Property: last
|
|
||||||
* {<OpenLayers.Pixel>} The last pixel used to know the distance between
|
* {<OpenLayers.Pixel>} The last pixel used to know the distance between
|
||||||
* two touches (for double touch).
|
* two touches (for double touch).
|
||||||
*/
|
*/
|
||||||
last: null,
|
lastTouchPx: null,
|
||||||
|
|
||||||
/**
|
|
||||||
* Property: dblclick
|
|
||||||
* {Boolean} The current event is a dblclick.
|
|
||||||
*/
|
|
||||||
isDblclick: false,
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: OpenLayers.Handler.Point
|
* Constructor: OpenLayers.Handler.Point
|
||||||
* Create a new point handler.
|
* Create a new point handler.
|
||||||
@@ -281,6 +268,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
this.mouseDown = false;
|
this.mouseDown = false;
|
||||||
this.lastDown = null;
|
this.lastDown = null;
|
||||||
this.lastUp = null;
|
this.lastUp = null;
|
||||||
|
this.lastTouchPx = null;
|
||||||
this.callback(key, [this.geometryClone()]);
|
this.callback(key, [this.geometryClone()]);
|
||||||
if(cancel || !this.persist) {
|
if(cancel || !this.persist) {
|
||||||
this.destroyFeature();
|
this.destroyFeature();
|
||||||
@@ -415,32 +403,8 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
*/
|
*/
|
||||||
touchstart: function(evt) {
|
touchstart: function(evt) {
|
||||||
this.touch = true;
|
this.touch = true;
|
||||||
|
this.lastTouchPx = evt.xy;
|
||||||
var last = this.last;
|
return this.down(evt);
|
||||||
this.last = evt.xy;
|
|
||||||
|
|
||||||
if (this.timerId &&
|
|
||||||
this.passesTolerance(last, evt.xy, this.dblclickTolerance)) {
|
|
||||||
this.isDblclick = true;
|
|
||||||
// a valid touch immediately adds a component and leaves us with a
|
|
||||||
// complete geometry
|
|
||||||
this.finishTouchGeometry();
|
|
||||||
window.clearTimeout(this.timerId);
|
|
||||||
this.timerId = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (this.timerId) {
|
|
||||||
window.clearTimeout(this.timerId);
|
|
||||||
this.timerId = null;
|
|
||||||
}
|
|
||||||
this.isDblclick = false;
|
|
||||||
this.timerId = window.setTimeout(
|
|
||||||
OpenLayers.Function.bind(function() {
|
|
||||||
this.timerId = null;
|
|
||||||
}, this), 300);
|
|
||||||
return this.down(evt);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -471,7 +435,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
* {Boolean} Allow event propagation
|
* {Boolean} Allow event propagation
|
||||||
*/
|
*/
|
||||||
touchmove: function(evt) {
|
touchmove: function(evt) {
|
||||||
this.last = evt.xy;
|
this.lastTouchPx = evt.xy;
|
||||||
return this.move(evt);
|
return this.move(evt);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -503,7 +467,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
* {Boolean} Allow event propagation
|
* {Boolean} Allow event propagation
|
||||||
*/
|
*/
|
||||||
touchend: function(evt) {
|
touchend: function(evt) {
|
||||||
evt.xy = this.last;
|
evt.xy = this.lastTouchPx;
|
||||||
return this.up(evt);
|
return this.up(evt);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user