From 86c105beaa0881be8160bc93bdf7108e4901bee1 Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 10 Dec 2022 06:57:53 -0500 Subject: [PATCH] bugfix in getCenter during zoom animation --- src/viewport.js | 5 +++-- test/demo/fitboundswithconstraints.html | 27 +++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/viewport.js b/src/viewport.js index cbb71429..a0e5a6f1 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -483,7 +483,7 @@ $.Viewport.prototype = { ); newZoomPixel = this._pixelFromPoint(this.zoomPoint, bounds); - deltaZoomPixels = newZoomPixel.minus( oldZoomPixel ); + deltaZoomPixels = newZoomPixel.minus( oldZoomPixel ).rotate(-this.getRotation(true)); deltaZoomPoints = deltaZoomPixels.divide( this._containerInnerSize.x * zoom ); return centerTarget.plus( deltaZoomPoints ); @@ -578,7 +578,7 @@ $.Viewport.prototype = { } var constraintApplied = xConstrained || yConstrained; - var newViewportBounds = constraintApplied ? this.viewerElementToViewportRectangle(newBounds) : bounds.clone(); + var newViewportBounds = constraintApplied ? this.viewerElementToViewportRectangle(newBounds, false) : bounds.clone(); newViewportBounds.xConstrained = xConstrained; newViewportBounds.yConstrained = yConstrained; newViewportBounds.constraintApplied = constraintApplied; @@ -811,6 +811,7 @@ $.Viewport.prototype = { constrainedBounds; bounds = this.getBounds(current); + // bounds = this.getBoundsNoRotate(current); constrainedBounds = this._applyBoundaryConstraints(bounds); diff --git a/test/demo/fitboundswithconstraints.html b/test/demo/fitboundswithconstraints.html index d91c52e5..5851a424 100644 --- a/test/demo/fitboundswithconstraints.html +++ b/test/demo/fitboundswithconstraints.html @@ -81,8 +81,9 @@ setTimeout(() => viewport.applyConstraints(), 1000); tileSources: "../data/testpattern.dzi", minZoomImageRatio: 0, maxZoomPixelRatio: 10, - visibilityRatio:1.0, + visibilityRatio:1, constrainDuringPan:true, + // showNavigationControl:false, }); viewer.addHandler("open", function(event) { @@ -147,7 +148,29 @@ setTimeout(() => viewport.applyConstraints(), 1000); }); }) - viewer.viewport.zoomTo(0.5, null, true); + viewer.viewport.zoomTo(1/2, null, true); + + // viewer.viewport.panBy(new OpenSeadragon.Point(0.5, 0.5).minus(viewer.viewport.pointFromPixel(new OpenSeadragon.Point(0, 0)))) + // setTimeout(()=>viewer.viewport.contentCoords(),1500); + // // setTimeout(()=>{ + // // viewer.viewport.rotateBy(-90, new OpenSeadragon.Point(0.5, 0.5)); + // // console.log('Rotated by -90') + // // viewer.viewport.contentCoords(); + // // setTimeout(()=>{ + // // console.log('After rotation'); + // // viewer.viewport.contentCoords(); + // // },1500); + // // }, 2000) + + // setTimeout(()=>{ + // viewer.viewport.zoomBy(2, new OpenSeadragon.Point(0.5, 0.5)); + // console.log('Zoomed by 2') + // viewer.viewport.contentCoords(); + // setTimeout(()=>{ + // console.log('After zoom'); + // viewer.viewport.contentCoords(); + // },1500); + // }, 4500) }); $('.method').on('click',function(){