From 4b395c72fa1a074236125edce7c34c2db5cfa2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sun, 14 Apr 2013 22:47:05 +0200 Subject: [PATCH 1/2] Fix zoom anchor for touch zoom interaction --- src/ol/interaction/touchzoominteraction.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ol/interaction/touchzoominteraction.js b/src/ol/interaction/touchzoominteraction.js index 4d378a7c80..8585bef32b 100644 --- a/src/ol/interaction/touchzoominteraction.js +++ b/src/ol/interaction/touchzoominteraction.js @@ -4,6 +4,7 @@ goog.provide('ol.interaction.TouchZoom'); goog.require('goog.asserts'); goog.require('goog.style'); +goog.require('ol.Coordinate'); goog.require('ol.View'); goog.require('ol.ViewHint'); goog.require('ol.interaction.Interaction'); @@ -25,6 +26,12 @@ ol.interaction.TouchZoom = function() { goog.base(this); + /** + * @private + * @type {ol.Coordinate} + */ + this.anchor_ = null; + /** * @private * @type {number|undefined} @@ -73,12 +80,12 @@ ol.interaction.TouchZoom.prototype.handleTouchMove = var centroid = ol.interaction.Touch.centroid(this.targetTouches); centroid.x -= viewportPosition.x; centroid.y -= viewportPosition.y; - var anchor = map.getCoordinateFromPixel(centroid); + this.anchor_ = map.getCoordinateFromPixel(centroid); // scale, bypass the resolution constraint map.requestRenderFrame(); ol.interaction.Interaction.zoomWithoutConstraints( - map, view, view.getResolution() * scaleDelta, anchor); + map, view, view.getResolution() * scaleDelta, this.anchor_); }; @@ -95,8 +102,8 @@ ol.interaction.TouchZoom.prototype.handleTouchEnd = // direction not to zoom out/in if user was pinching in/out. // Direction is > 0 if pinching out, and < 0 if pinching in. var direction = this.lastScaleDelta_ - 1; - ol.interaction.Interaction.zoom(map, view, view.getResolution(), undefined, - ol.interaction.TOUCHZOOM_ANIMATION_DURATION, direction); + ol.interaction.Interaction.zoom(map, view, view.getResolution(), + this.anchor_, ol.interaction.TOUCHZOOM_ANIMATION_DURATION, direction); view.setHint(ol.ViewHint.INTERACTING, -1); return false; } else { @@ -113,6 +120,7 @@ ol.interaction.TouchZoom.prototype.handleTouchStart = if (this.targetTouches.length >= 2) { var map = mapBrowserEvent.map; var view = map.getView(); + this.anchor_ = null; this.lastDistance_ = undefined; this.lastScaleDelta_ = 1; map.requestRenderFrame(); From 74feabb4c45d7f3043a71c29d92b4da616e2ae6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sun, 14 Apr 2013 22:47:52 +0200 Subject: [PATCH 2/2] Fix rotation anchor for touch rotate interation --- src/ol/interaction/touchrotateinteraction.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ol/interaction/touchrotateinteraction.js b/src/ol/interaction/touchrotateinteraction.js index 853dff1079..166ff7111e 100644 --- a/src/ol/interaction/touchrotateinteraction.js +++ b/src/ol/interaction/touchrotateinteraction.js @@ -4,6 +4,7 @@ goog.provide('ol.interaction.TouchRotate'); goog.require('goog.asserts'); goog.require('goog.style'); +goog.require('ol.Coordinate'); goog.require('ol.View'); goog.require('ol.ViewHint'); goog.require('ol.interaction.Interaction'); @@ -27,6 +28,12 @@ ol.interaction.TouchRotate = function(opt_threshold) { goog.base(this); + /** + * @private + * @type {ol.Coordinate} + */ + this.anchor_ = null; + /** * @private * @type {number|undefined} @@ -93,14 +100,14 @@ ol.interaction.TouchRotate.prototype.handleTouchMove = var centroid = ol.interaction.Touch.centroid(this.targetTouches); centroid.x -= viewportPosition.x; centroid.y -= viewportPosition.y; - var anchor = map.getCoordinateFromPixel(centroid); + this.anchor_ = map.getCoordinateFromPixel(centroid); // rotate if (this.rotating_) { var view = map.getView().getView2D(); map.requestRenderFrame(); ol.interaction.Interaction.rotateWithoutConstraints(map, view, - view.getRotation() + rotationDelta, anchor); + view.getRotation() + rotationDelta, this.anchor_); } }; @@ -115,7 +122,7 @@ ol.interaction.TouchRotate.prototype.handleTouchEnd = var view = map.getView().getView2D(); if (this.rotating_) { ol.interaction.Interaction.rotate( - map, view, view.getRotation(), undefined, + map, view, view.getRotation(), this.anchor_, ol.interaction.TOUCHROTATE_ANIMATION_DURATION); } view.setHint(ol.ViewHint.INTERACTING, -1); @@ -134,6 +141,7 @@ ol.interaction.TouchRotate.prototype.handleTouchStart = if (this.targetTouches.length >= 2) { var map = mapBrowserEvent.map; var view = map.getView(); + this.anchor_ = null; this.lastAngle_ = undefined; this.rotating_ = false; this.rotationDelta_ = 0.0;