diff --git a/src/tiledimage.js b/src/tiledimage.js index 55b7e2f3..46f1e3e3 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -151,6 +151,10 @@ $.TiledImage.prototype = /** @lends OpenSeadragon.TiledImage.prototype */{ */ destroy: function() { this.reset(); + }, + + getWorldBounds: function() { + return new $.Rect( this._worldX, this._worldY, this._worldWidth, this._worldHeight ); } }; diff --git a/src/world.js b/src/world.js index a6f98e94..8eeb3141 100644 --- a/src/world.js +++ b/src/world.js @@ -146,24 +146,46 @@ $.World.prototype = /** @lends OpenSeadragon.World.prototype */{ }, resetTiles: function() { - for (var i = 0; i < this._items.length; i++ ) { + for ( var i = 0; i < this._items.length; i++ ) { this._items[i].reset(); } }, update: function() { - for (var i = 0; i < this._items.length; i++ ) { + for ( var i = 0; i < this._items.length; i++ ) { this._items[i].update(); } }, needsUpdate: function() { - for (var i = 0; i < this._items.length; i++ ) { - if (this._items[i].needsUpdate()) { + for ( var i = 0; i < this._items.length; i++ ) { + if ( this._items[i].needsUpdate() ) { return true; } } return false; + }, + + getHomeBounds: function() { + if ( !this._items.length ) { + return new $.Rect(0, 0, 1, 1); + } + + var bounds = this._items[0].getWorldBounds(); + var left = bounds.x; + var top = bounds.y; + var right = bounds.x + bounds.width; + var bottom = bounds.y + bounds.height; + var box; + for ( var i = 1; i < this._items.length; i++ ) { + box = this._items[i].getWorldBounds(); + left = Math.min( left, box.x ); + top = Math.min( top, box.y ); + right = Math.max( right, box.x + box.width ); + bottom = Math.max( bottom, box.y + box.height ); + } + + return new $.Rect( left, top, right - left, bottom - top ); } };