From 7078826be173b158b0a9aaacf41919aba3f85266 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Mon, 1 Dec 2014 16:29:21 -0800 Subject: [PATCH 1/2] Auto-resize now works for multi-image --- src/viewer.js | 8 +++----- test/demo/collections/index.html | 4 ++++ test/demo/collections/main.js | 6 ++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index e05bbba8..971eb9d7 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2735,11 +2735,9 @@ function resizeViewportAndRecenter( viewer, containerSize, oldBounds, oldCenter // We try to remove blanks as much as possible var worldBounds = viewer.world.getHomeBounds(); - var aspectRatio = worldBounds.width / worldBounds.height; - var imageHeight = 1 / aspectRatio; - var newWidth = oldBounds.width <= 1 ? oldBounds.width : 1; - var newHeight = oldBounds.height <= imageHeight ? - oldBounds.height : imageHeight; + var newWidth = oldBounds.width <= worldBounds.width ? oldBounds.width : worldBounds.width; + var newHeight = oldBounds.height <= worldBounds.height ? + oldBounds.height : worldBounds.height; var newBounds = new $.Rect( oldCenter.x - ( newWidth / 2.0 ), diff --git a/test/demo/collections/index.html b/test/demo/collections/index.html index b6aca4a1..46b4e7f2 100644 --- a/test/demo/collections/index.html +++ b/test/demo/collections/index.html @@ -15,6 +15,10 @@ margin: 0; } + .openseadragon1.small { + width: 50%; + } + .openseadragon-overlay { background-color: rgba(255, 0, 0, 0.3); } diff --git a/test/demo/collections/main.js b/test/demo/collections/main.js index b2c7eeb8..01f7229d 100644 --- a/test/demo/collections/main.js +++ b/test/demo/collections/main.js @@ -116,6 +116,12 @@ } }, + // ---------- + toggle: function() { + var $el = $(this.viewer.element); + $el.toggleClass('small'); + }, + // ---------- basicTest: function() { var self = this; From 211127b87bb818d40649188353cf22b47bfe5b83 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Wed, 3 Dec 2014 11:13:06 -0800 Subject: [PATCH 2/2] Fixed window resize for navigator with multi-image --- src/navigator.js | 17 ++--------------- test/demo/collections/main.js | 2 +- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/navigator.js b/src/navigator.js index df4b637a..512d4671 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -272,23 +272,10 @@ $.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, /* (this.container.clientWidth === 0 ? 1 : this.container.clientWidth), (this.container.clientHeight === 0 ? 1 : this.container.clientHeight) ); + if ( !containerSize.equals( this.oldContainerSize ) ) { - var oldBounds = this.viewport.getBounds(); - var oldCenter = this.viewport.getCenter(); this.viewport.resize( containerSize, true ); - var worldBounds = this.world.getHomeBounds(); - var aspectRatio = worldBounds.width / worldBounds.height; - var imageHeight = 1 / aspectRatio; - var newWidth = oldBounds.width <= 1 ? oldBounds.width : 1; - var newHeight = oldBounds.height <= imageHeight ? - oldBounds.height : imageHeight; - var newBounds = new $.Rect( - oldCenter.x - ( newWidth / 2.0 ), - oldCenter.y - ( newHeight / 2.0 ), - newWidth, - newHeight - ); - this.viewport.fitBounds( newBounds, true ); + this.viewport.goHome(true); this.oldContainerSize = containerSize; this.drawer.update(); } diff --git a/test/demo/collections/main.js b/test/demo/collections/main.js index 01f7229d..d18710a2 100644 --- a/test/demo/collections/main.js +++ b/test/demo/collections/main.js @@ -9,7 +9,7 @@ var testInitialOpen = true; var testOverlays = false; var testMargins = false; - var testNavigator = false; + var testNavigator = true; var margins; var config = {