From f1865c3878e199425720a1df6936ee249a45bd7c Mon Sep 17 00:00:00 2001 From: Christophe Avenel Date: Thu, 12 May 2022 10:45:47 +0200 Subject: [PATCH] Fix wrong center point on touch zoom When doing pinch to zoom, we need to do pan first and then zoom, so that the center point is correct. Otherwise, the pan will computed on the unzoomed coordinates, giving an impression of zooming toward the center --- src/viewer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index ab779142..d33a4a26 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -3289,9 +3289,6 @@ function onCanvasPinch( event ) { if ( gestureSettings.pinchToZoom && (!canvasPinchEventArgs.preventDefaultPanAction || !canvasPinchEventArgs.preventDefaultZoomAction) ) { centerPt = this.viewport.pointFromPixel( event.center, true ); - if ( !canvasPinchEventArgs.preventDefaultZoomAction ) { - this.viewport.zoomBy( event.distance / event.lastDistance, centerPt, true ); - } if ( gestureSettings.zoomToRefPoint && !canvasPinchEventArgs.preventDefaultPanAction ) { lastCenterPt = this.viewport.pointFromPixel( event.lastCenter, true ); panByPt = lastCenterPt.minus( centerPt ); @@ -3303,6 +3300,9 @@ function onCanvasPinch( event ) { } this.viewport.panBy(panByPt, true); } + if ( !canvasPinchEventArgs.preventDefaultZoomAction ) { + this.viewport.zoomBy( event.distance / event.lastDistance, centerPt, true ); + } this.viewport.applyConstraints(); } if ( gestureSettings.pinchRotate && !canvasPinchEventArgs.preventDefaultRotateAction ) {