Reworking click and pinch handling to get better behavior on multi-touch devices. r=ahocevar +testing from others (closes #3133)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11695 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2011-03-11 01:53:26 +00:00
parent 3ce239208f
commit 5b7d530461
6 changed files with 488 additions and 184 deletions
+11 -11
View File
@@ -124,6 +124,7 @@ OpenLayers.Control.PinchZoom = OpenLayers.Class(OpenLayers.Control, {
*/
pinchStart: function(evt, pinchData) {
this.pinchOrigin = evt.xy;
this.currentCenter = evt.xy;
},
/**
@@ -170,21 +171,20 @@ OpenLayers.Control.PinchZoom = OpenLayers.Class(OpenLayers.Control, {
* of the pinch gesture. This give us the final scale of the pinch.
*/
pinchDone: function(evt, start, last) {
this.applyTransform("");
var zoom = this.map.getZoomForResolution(this.map.getResolution() / last.scale, true);
var resolution = this.map.getResolutionForZoom(zoom);
if (zoom !== this.map.getZoom() || !this.currentCenter.equals(this.pinchOrigin)) {
var resolution = this.map.getResolutionForZoom(zoom);
var location = this.map.getLonLatFromPixel(this.pinchOrigin);
var zoomPixel = this.currentCenter;
var size = this.map.getSize();
location.lon += resolution * ((size.w / 2) - zoomPixel.x);
location.lat -= resolution * ((size.h / 2) - zoomPixel.y);
var location = this.map.getLonLatFromPixel(this.pinchOrigin);
var zoomPixel = this.currentCenter;
var size = this.map.getSize();
this.map.setCenter(location, zoom);
location.lon += resolution * ((size.w / 2) - zoomPixel.x);
location.lat -= resolution * ((size.h / 2) - zoomPixel.y);
var style = this.map.layerContainerDiv.style;
style['-webkit-transform'] = "";
style['-moz-transform'] = "";
this.map.setCenter(location, zoom);
}
},
CLASS_NAME: "OpenLayers.Control.PinchZoom"
+13 -6
View File
@@ -44,6 +44,12 @@ OpenLayers.Control.TouchNavigation = OpenLayers.Class(OpenLayers.Control, {
*/
pinchZoomOptions: null,
/**
* APIProperty: clickHandlerOptions
* {Object} Options passed to the Click handler.
*/
clickHandlerOptions: null,
/**
* APIProperty: documentDrag
* {Boolean} Allow panning of the map by dragging outside map viewport.
@@ -121,13 +127,14 @@ OpenLayers.Control.TouchNavigation = OpenLayers.Class(OpenLayers.Control, {
*/
draw: function() {
var clickCallbacks = {
'click': this.defaultClick,
'dblclick': this.defaultDblClick
};
var clickOptions = {
'double': true,
'stopDouble': true
click: this.defaultClick,
dblclick: this.defaultDblClick
};
var clickOptions = OpenLayers.Util.extend({
"double": true,
stopDouble: true,
pixelTolerance: 2
}, this.clickHandlerOptions);
this.handlers.click = new OpenLayers.Handler.Click(
this, clickCallbacks, clickOptions
);