Fix zoom anchor for touch zoom interaction
This commit is contained in:
@@ -4,6 +4,7 @@ goog.provide('ol.interaction.TouchZoom');
|
|||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.style');
|
goog.require('goog.style');
|
||||||
|
goog.require('ol.Coordinate');
|
||||||
goog.require('ol.View');
|
goog.require('ol.View');
|
||||||
goog.require('ol.ViewHint');
|
goog.require('ol.ViewHint');
|
||||||
goog.require('ol.interaction.Interaction');
|
goog.require('ol.interaction.Interaction');
|
||||||
@@ -25,6 +26,12 @@ ol.interaction.TouchZoom = function() {
|
|||||||
|
|
||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.Coordinate}
|
||||||
|
*/
|
||||||
|
this.anchor_ = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {number|undefined}
|
* @type {number|undefined}
|
||||||
@@ -73,12 +80,12 @@ ol.interaction.TouchZoom.prototype.handleTouchMove =
|
|||||||
var centroid = ol.interaction.Touch.centroid(this.targetTouches);
|
var centroid = ol.interaction.Touch.centroid(this.targetTouches);
|
||||||
centroid.x -= viewportPosition.x;
|
centroid.x -= viewportPosition.x;
|
||||||
centroid.y -= viewportPosition.y;
|
centroid.y -= viewportPosition.y;
|
||||||
var anchor = map.getCoordinateFromPixel(centroid);
|
this.anchor_ = map.getCoordinateFromPixel(centroid);
|
||||||
|
|
||||||
// scale, bypass the resolution constraint
|
// scale, bypass the resolution constraint
|
||||||
map.requestRenderFrame();
|
map.requestRenderFrame();
|
||||||
ol.interaction.Interaction.zoomWithoutConstraints(
|
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 not to zoom out/in if user was pinching in/out.
|
||||||
// Direction is > 0 if pinching out, and < 0 if pinching in.
|
// Direction is > 0 if pinching out, and < 0 if pinching in.
|
||||||
var direction = this.lastScaleDelta_ - 1;
|
var direction = this.lastScaleDelta_ - 1;
|
||||||
ol.interaction.Interaction.zoom(map, view, view.getResolution(), undefined,
|
ol.interaction.Interaction.zoom(map, view, view.getResolution(),
|
||||||
ol.interaction.TOUCHZOOM_ANIMATION_DURATION, direction);
|
this.anchor_, ol.interaction.TOUCHZOOM_ANIMATION_DURATION, direction);
|
||||||
view.setHint(ol.ViewHint.INTERACTING, -1);
|
view.setHint(ol.ViewHint.INTERACTING, -1);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@@ -113,6 +120,7 @@ ol.interaction.TouchZoom.prototype.handleTouchStart =
|
|||||||
if (this.targetTouches.length >= 2) {
|
if (this.targetTouches.length >= 2) {
|
||||||
var map = mapBrowserEvent.map;
|
var map = mapBrowserEvent.map;
|
||||||
var view = map.getView();
|
var view = map.getView();
|
||||||
|
this.anchor_ = null;
|
||||||
this.lastDistance_ = undefined;
|
this.lastDistance_ = undefined;
|
||||||
this.lastScaleDelta_ = 1;
|
this.lastScaleDelta_ = 1;
|
||||||
map.requestRenderFrame();
|
map.requestRenderFrame();
|
||||||
|
|||||||
Reference in New Issue
Block a user