fix Don't let the browser to zoom or select the map on feature selection, r=erilem (closes #3212)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11829 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -56,6 +56,13 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
|
||||
* {<OpenLayers.Pixel>} The location of the last mouseup.
|
||||
*/
|
||||
up: null,
|
||||
|
||||
/**
|
||||
* Property: touch
|
||||
* {Boolean} When a touchstart event is fired, touch will be true and all
|
||||
* mouse related listeners will do nothing.
|
||||
*/
|
||||
touch: false,
|
||||
|
||||
/**
|
||||
* Property: clickTolerance
|
||||
@@ -129,9 +136,33 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
|
||||
* {Boolean} Let the event propagate.
|
||||
*/
|
||||
touchstart: function(evt) {
|
||||
if(!this.touch) {
|
||||
this.touch = true;
|
||||
this.map.events.un({
|
||||
mousedown: this.mousedown,
|
||||
mouseup: this.mouseup,
|
||||
mousemove: this.mousemove,
|
||||
click: this.click,
|
||||
dblclick: this.dblclick,
|
||||
scope: this
|
||||
});
|
||||
}
|
||||
return this.mousedown(evt);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: touchmove
|
||||
* Handle touchmove events. We just prevent the browser default behavior,
|
||||
* for Android Webkit not to select text when moving the finger after
|
||||
* selecting a feature.
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Event}
|
||||
*/
|
||||
touchmove: function(evt) {
|
||||
OpenLayers.Event.stop(evt);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: mousedown
|
||||
* Handle mouse down. Stop propagation if a feature is targeted by this
|
||||
@@ -251,6 +282,11 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
|
||||
this.lastFeature = null;
|
||||
}
|
||||
if(this.feature) {
|
||||
if(evt.type === "touchstart") {
|
||||
// stop the event to prevent Android Webkit from
|
||||
// "flashing" the map div
|
||||
OpenLayers.Event.stop(evt);
|
||||
}
|
||||
var inNew = (this.feature != this.lastFeature);
|
||||
if(this.geometryTypeMatches(this.feature)) {
|
||||
// in to a feature
|
||||
@@ -349,6 +385,7 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
|
||||
this.lastFeature = null;
|
||||
this.down = null;
|
||||
this.up = null;
|
||||
this.touch = false;
|
||||
this.map.events.un({
|
||||
"removelayer": this.handleMapEvents,
|
||||
"changelayer": this.handleMapEvents,
|
||||
|
||||
@@ -59,6 +59,12 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
||||
*/
|
||||
timerId: null,
|
||||
|
||||
/**
|
||||
* Propery: stopTouchEnd
|
||||
* {Boolean} Stop event propagation of the next touch up.
|
||||
*/
|
||||
stopTouchEnd: false,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Handler.Path
|
||||
* Create a new path hander
|
||||
@@ -244,6 +250,8 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
||||
// double-tap, finalize the geometry
|
||||
this.lastTouchPx = evt.xy; // for up() to detect dblclick and do nothing
|
||||
this.finishGeometry();
|
||||
this.stopTouchEnd = true;
|
||||
OpenLayers.Event.stop(evt);
|
||||
window.clearTimeout(this.timerId);
|
||||
this.timerId = null;
|
||||
return false;
|
||||
@@ -259,6 +267,27 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
||||
return OpenLayers.Handler.Point.prototype.touchstart.call(this, evt);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: touchend
|
||||
* Handle touchend.
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Event} The browser event
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} Allow event propagation
|
||||
*/
|
||||
touchend: function(evt) {
|
||||
evt.xy = this.lastTouchPx;
|
||||
if (this.stopTouchEnd) {
|
||||
// don't zoom on the page at feature end
|
||||
OpenLayers.Event.stop(evt);
|
||||
this.stopTouchEnd = false;
|
||||
return false;
|
||||
}
|
||||
return this.up(evt);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: mousedown
|
||||
@@ -330,6 +359,8 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
||||
} else {
|
||||
if (this.passesTolerance(this.lastDown, evt.xy, this.pixelTolerance)) {
|
||||
if (this.touch) {
|
||||
// don't allow the browser to zoom
|
||||
OpenLayers.Event.stop(evt);
|
||||
this.modifyFeature(evt.xy);
|
||||
}
|
||||
if(this.lastUp == null && this.persist) {
|
||||
@@ -370,6 +401,9 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
||||
* {Boolean} Allow event propagation
|
||||
*/
|
||||
dblclick: function(evt) {
|
||||
if (this.touch) {
|
||||
return;
|
||||
}
|
||||
if(!this.freehandMode(evt)) {
|
||||
this.finishGeometry();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user