diff --git a/src/viewer.js b/src/viewer.js index 2f1684de..2f5f697e 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -608,6 +608,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, if (successes) { if (_this._firstOpen || !_this.preserveViewport) { _this.viewport.goHome( true ); + _this.viewport.update(); } _this._firstOpen = false; diff --git a/src/viewport.js b/src/viewport.js index 1f07ebbe..167e0eca 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -953,7 +953,10 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{ //they passed a point instead of individual components return this.viewportToImageCoordinates( viewerX.x, viewerX.y ); } - return new $.Point( viewerX * this.contentSize.x, viewerY * this.contentSize.y * this.contentAspectX ); + + var scale = this.homeBounds.width; + return new $.Point((viewerX - this.homeBounds.x) * (this.contentSize.x / scale), + (viewerY - this.homeBounds.y) * ((this.contentSize.y * this.contentAspectX) / scale)); }, /** @@ -971,7 +974,10 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{ //they passed a point instead of individual components return this.imageToViewportCoordinates( imageX.x, imageX.y ); } - return new $.Point( imageX / this.contentSize.x, imageY / this.contentSize.y / this.contentAspectX ); + + var scale = this.homeBounds.width; + return new $.Point(this.homeBounds.x + ((imageX / this.contentSize.x) * scale), + this.homeBounds.y + ((imageY / this.contentSize.y / this.contentAspectX) * scale)); }, /** @@ -1003,13 +1009,13 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{ imageX, imageY ); coordB = this.imageToViewportCoordinates( - pixelWidth, pixelHeight + imageX + pixelWidth, imageY + pixelHeight ); return new $.Rect( coordA.x, coordA.y, - coordB.x, - coordB.y + coordB.x - coordA.x, + coordB.y - coordA.y ); }, @@ -1039,12 +1045,12 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{ ); } coordA = this.viewportToImageCoordinates( viewerX, viewerY ); - coordB = this.viewportToImageCoordinates( pointWidth, pointHeight ); + coordB = this.viewportToImageCoordinates(viewerX + pointWidth, viewerY + pointHeight); return new $.Rect( coordA.x, coordA.y, - coordB.x, - coordB.y + coordB.x - coordA.x, + coordB.y - coordA.y ); }, @@ -1148,7 +1154,8 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{ viewportToImageZoom: function( viewportZoom ) { var imageWidth = this.viewer.source.dimensions.x; var containerWidth = this._containerInnerSize.x; - var viewportToImageZoomRatio = containerWidth / imageWidth; + var scale = this.homeBounds.width; + var viewportToImageZoomRatio = (containerWidth / imageWidth) * scale; return viewportZoom * viewportToImageZoomRatio; }, @@ -1166,7 +1173,8 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{ imageToViewportZoom: function( imageZoom ) { var imageWidth = this.viewer.source.dimensions.x; var containerWidth = this._containerInnerSize.x; - var viewportToImageZoomRatio = imageWidth / containerWidth; + var scale = this.homeBounds.width; + var viewportToImageZoomRatio = (imageWidth / containerWidth) / scale; return imageZoom * viewportToImageZoomRatio; } }; diff --git a/test/demo/collections/main.js b/test/demo/collections/main.js index 669d4fdb..b2c7eeb8 100644 --- a/test/demo/collections/main.js +++ b/test/demo/collections/main.js @@ -7,7 +7,7 @@ var self = this; var testInitialOpen = true; - var testOverlays = true; + var testOverlays = false; var testMargins = false; var testNavigator = false; var margins; @@ -34,6 +34,12 @@ if (testInitialOpen) { config.tileSources = [ + { + tileSource: "../../data/testpattern.dzi", + x: 4, + y: 2, + width: 2 + }, { tileSource: "../../data/tall.dzi", x: 1.5,