mirror of
https://github.com/openseadragon/openseadragon.git
synced 2025-01-19 17:21:50 +03:00
Fix resize handling.
This commit is contained in:
parent
14069a64e1
commit
1014d5767c
@ -2975,32 +2975,23 @@ function updateOnce( viewer ) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var containerSize;
|
|
||||||
if (viewer.autoResize) {
|
if (viewer.autoResize) {
|
||||||
containerSize = _getSafeElemSize( viewer.container );
|
var containerSize = _getSafeElemSize(viewer.container);
|
||||||
if ( !containerSize.equals( THIS[ viewer.hash ].prevContainerSize ) ) {
|
|
||||||
if ( viewer.preserveImageSizeOnResize ) {
|
|
||||||
var prevContainerSize = THIS[viewer.hash].prevContainerSize;
|
var prevContainerSize = THIS[viewer.hash].prevContainerSize;
|
||||||
var bounds = viewer.viewport.getBoundsNoRotate(true);
|
if (!containerSize.equals(prevContainerSize)) {
|
||||||
var deltaX = (containerSize.x - prevContainerSize.x);
|
var viewport = viewer.viewport;
|
||||||
var deltaY = (containerSize.y - prevContainerSize.y);
|
if (viewer.preserveImageSizeOnResize) {
|
||||||
var viewportDiff = viewer.viewport.deltaPointsFromPixels(
|
var resizeRatio = prevContainerSize.x / containerSize.x;
|
||||||
new $.Point(deltaX, deltaY), true);
|
var zoom = viewport.getZoom() * resizeRatio;
|
||||||
viewer.viewport.resize(
|
var center = viewport.getCenter();
|
||||||
new $.Point(containerSize.x, containerSize.y), false);
|
viewport.resize(containerSize, false);
|
||||||
|
viewport.zoomTo(zoom, null, true);
|
||||||
// Keep the center of the image in the center and just adjust the amount of image shown
|
viewport.panTo(center, true);
|
||||||
bounds.width += viewportDiff.x;
|
} else {
|
||||||
bounds.height += viewportDiff.y;
|
|
||||||
bounds.x -= (viewportDiff.x / 2);
|
|
||||||
bounds.y -= (viewportDiff.y / 2);
|
|
||||||
viewer.viewport.fitBoundsWithConstraints(bounds, true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// maintain image position
|
// maintain image position
|
||||||
var oldBounds = viewer.viewport.getBoundsNoRotate();
|
var oldBounds = viewport.getBounds();
|
||||||
var oldCenter = viewer.viewport.getCenter();
|
viewport.resize(containerSize, true);
|
||||||
resizeViewportAndRecenter(viewer, containerSize, oldBounds, oldCenter);
|
viewport.fitBoundsWithConstraints(oldBounds, true);
|
||||||
}
|
}
|
||||||
THIS[viewer.hash].prevContainerSize = containerSize;
|
THIS[viewer.hash].prevContainerSize = containerSize;
|
||||||
THIS[viewer.hash].forceRedraw = true;
|
THIS[viewer.hash].forceRedraw = true;
|
||||||
@ -3088,27 +3079,6 @@ function updateOnce( viewer ) {
|
|||||||
//viewer.profiler.endUpdate();
|
//viewer.profiler.endUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function resizes the viewport and recenters the image
|
|
||||||
// as it was before resizing.
|
|
||||||
// TODO: better adjust width and height. The new width and height
|
|
||||||
// should depend on the image dimensions and on the dimensions
|
|
||||||
// of the viewport before and after switching mode.
|
|
||||||
function resizeViewportAndRecenter( viewer, containerSize, oldBounds, oldCenter ) {
|
|
||||||
var viewport = viewer.viewport;
|
|
||||||
|
|
||||||
viewport.resize( containerSize, true );
|
|
||||||
|
|
||||||
var newBounds = new $.Rect(
|
|
||||||
oldCenter.x - ( oldBounds.width / 2.0 ),
|
|
||||||
oldCenter.y - ( oldBounds.height / 2.0 ),
|
|
||||||
oldBounds.width,
|
|
||||||
oldBounds.height
|
|
||||||
);
|
|
||||||
|
|
||||||
// let the viewport decide if the bounds are too big or too small
|
|
||||||
viewport.fitBoundsWithConstraints( newBounds, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawWorld( viewer ) {
|
function drawWorld( viewer ) {
|
||||||
viewer.imageLoader.clear();
|
viewer.imageLoader.clear();
|
||||||
viewer.drawer.clear();
|
viewer.drawer.clear();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user