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
This commit is contained in:
Christophe Avenel 2022-05-12 10:45:47 +02:00 committed by GitHub
parent 165aaebd4c
commit f1865c3878
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 ) {