From 1c14f5cc9430b060a152a92a40e2c43b938e7dd9 Mon Sep 17 00:00:00 2001 From: Grant Echols Date: Mon, 22 Jun 2015 13:26:24 -0600 Subject: [PATCH] Added code to handle the case where autoResize=false. In this mode the image size is preserved and the center is maintained. This may be considered changing the default behavior so I'd welcome a suggestion to add a configuration parameter to help preserve the default behavior. --- src/viewer.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/viewer.js b/src/viewer.js index 7143443d..26ac3aa2 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2835,6 +2835,28 @@ function updateOnce( viewer ) { THIS[ viewer.hash ].forceRedraw = true; } } + else { + var containerSize = _getSafeElemSize( viewer.container ); + if ( !containerSize.equals( THIS[ viewer.hash ].prevContainerSize ) ) { + var prevContainerSize = THIS[ viewer.hash ].prevContainerSize; + var bounds = viewer.viewport.getBounds(true); + var deltaX = (containerSize.x - prevContainerSize.x); + var deltaY = (containerSize.y - prevContainerSize.y); + var viewportDiff = viewer.viewport.deltaPointsFromPixels(new OpenSeadragon.Point(deltaX, deltaY), true); + viewer.viewport.resize(new OpenSeadragon.Point(containerSize.x, containerSize.y), false); + + // Keep the center of the image in the center and just adjust the amount of image shown + bounds.width += viewportDiff.x; + bounds.height += viewportDiff.y; + bounds.x -= (viewportDiff.x / 2); + bounds.y -= (viewportDiff.y / 2); + viewer.viewport.fitBounds(bounds, true); + viewer.forceRedraw(); + + THIS[ viewer.hash ].prevContainerSize = containerSize; + THIS[ viewer.hash ].forceRedraw = true; + } + } var viewportChange = viewer.viewport.update(); var animated = viewer.world.update() || viewportChange;