Fix resize handling.

This commit is contained in:
Antoine Vandecreme 2016-05-12 19:23:09 -04:00
parent 14069a64e1
commit 1014d5767c

View File

@ -2975,35 +2975,26 @@ function updateOnce( viewer ) {
return; return;
} }
var containerSize; if (viewer.autoResize) {
if ( viewer.autoResize ) { var containerSize = _getSafeElemSize(viewer.container);
containerSize = _getSafeElemSize( viewer.container ); var prevContainerSize = THIS[viewer.hash].prevContainerSize;
if ( !containerSize.equals( THIS[ viewer.hash ].prevContainerSize ) ) { if (!containerSize.equals(prevContainerSize)) {
if ( viewer.preserveImageSizeOnResize ) { var viewport = viewer.viewport;
var prevContainerSize = THIS[ viewer.hash ].prevContainerSize; if (viewer.preserveImageSizeOnResize) {
var bounds = viewer.viewport.getBoundsNoRotate(true); var resizeRatio = prevContainerSize.x / containerSize.x;
var deltaX = (containerSize.x - prevContainerSize.x); var zoom = viewport.getZoom() * resizeRatio;
var deltaY = (containerSize.y - prevContainerSize.y); var center = viewport.getCenter();
var viewportDiff = viewer.viewport.deltaPointsFromPixels( viewport.resize(containerSize, false);
new $.Point(deltaX, deltaY), true); viewport.zoomTo(zoom, null, true);
viewer.viewport.resize( viewport.panTo(center, true);
new $.Point(containerSize.x, containerSize.y), false); } else {
// 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.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();