From 8bdc55bd6324a5a046088d57dd82ed1cb9662641 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Wed, 5 Nov 2014 15:57:44 -0800 Subject: [PATCH] Fixed fitVertically and fitHorizontally --- src/viewport.js | 51 +++++--------------------------- test/demo/collections/index.html | 1 + test/demo/collections/main.js | 2 +- 3 files changed, 10 insertions(+), 44 deletions(-) diff --git a/src/viewport.js b/src/viewport.js index abb4e641..1f07ebbe 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -178,15 +178,6 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{ this.contentAspectX = this.contentSize.x / this.contentSize.y; this.contentAspectY = this.contentSize.y / this.contentSize.x; - // TODO: seems like fitWidthBounds and fitHeightBounds should be thin slices - // across the appropriate axis, centered in the image, rather than what we have - // here. - this.fitWidthBounds = new $.Rect(this.homeBounds.x, this.homeBounds.y, - this.homeBounds.width, this.homeBounds.width); - - this.fitHeightBounds = new $.Rect(this.homeBounds.x, this.homeBounds.y, - this.homeBounds.height, this.homeBounds.height); - if( this.viewer ){ /** * Raised when the viewer's content size or home bounds are reset @@ -631,53 +622,27 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{ }, /** - * @function + * Zooms so the image just fills the viewer vertically. * @param {Boolean} immediately * @return {OpenSeadragon.Viewport} Chainable. */ fitVertically: function( immediately ) { - var center = this.getCenter(); + var box = new $.Rect(this.homeBounds.x + (this.homeBounds.width / 2), this.homeBounds.y, + 0, this.homeBounds.height); - if ( this.wrapHorizontal ) { - center.x = ( 1 + ( center.x % 1 ) ) % 1; - this.centerSpringX.resetTo( center.x ); - this.centerSpringX.update(); - } - - if ( this.wrapVertical ) { - center.y = ( - this.contentAspectY + ( center.y % this.contentAspectY ) - ) % this.contentAspectY; - this.centerSpringY.resetTo( center.y ); - this.centerSpringY.update(); - } - - return this.fitBounds( this.fitHeightBounds, immediately ); + return this.fitBounds( box, immediately ); }, /** - * @function + * Zooms so the image just fills the viewer horizontally. * @param {Boolean} immediately * @return {OpenSeadragon.Viewport} Chainable. */ fitHorizontally: function( immediately ) { - var center = this.getCenter(); + var box = new $.Rect(this.homeBounds.x, this.homeBounds.y + (this.homeBounds.height / 2), + this.homeBounds.width, 0); - if ( this.wrapHorizontal ) { - center.x = ( - this.contentAspectX + ( center.x % this.contentAspectX ) - ) % this.contentAspectX; - this.centerSpringX.resetTo( center.x ); - this.centerSpringX.update(); - } - - if ( this.wrapVertical ) { - center.y = ( 1 + ( center.y % 1 ) ) % 1; - this.centerSpringY.resetTo( center.y ); - this.centerSpringY.update(); - } - - return this.fitBounds( this.fitWidthBounds, immediately ); + return this.fitBounds( box, immediately ); }, diff --git a/test/demo/collections/index.html b/test/demo/collections/index.html index fc1766cc..b6aca4a1 100644 --- a/test/demo/collections/index.html +++ b/test/demo/collections/index.html @@ -12,6 +12,7 @@ .openseadragon1 { width: 100%; height: 100%; + margin: 0; } .openseadragon-overlay { diff --git a/test/demo/collections/main.js b/test/demo/collections/main.js index 0e3ab824..af83c343 100644 --- a/test/demo/collections/main.js +++ b/test/demo/collections/main.js @@ -86,7 +86,7 @@ } // this.crossTest3(); - this.crossTest2(); + this.basicTest(); }, // ----------