From 4643851da9719cce366249c8878b4d354ddfec20 Mon Sep 17 00:00:00 2001 From: Larissa Smith Date: Fri, 25 Sep 2015 09:57:35 -0600 Subject: [PATCH] Optimized adding large numbers of items to the world. --- src/viewer.js | 32 +++++++++++++++++++++++--------- src/world.js | 7 ++++++- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 215f14f8..3d9ebeb8 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1250,6 +1250,10 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, } } + if (_this._loadQueue.length === 0) { + refreshWorld(myQueueItem); + } + /** * Raised when an error occurs while adding a item. * @event add-item-failed @@ -1268,6 +1272,19 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, } } + function refreshWorld(theItem) { + if (_this.collectionMode) { + _this.world.arrange({ + immediately: theItem.options.collectionImmediately, + rows: _this.collectionRows, + columns: _this.collectionColumns, + layout: _this.collectionLayout, + tileSize: _this.collectionTileSize, + tileMargin: _this.collectionTileMargin + }); + } + } + this._loadQueue.push(myQueueItem); getTileSourceImplementation( this, options.tileSource, function( tileSource ) { @@ -1328,19 +1345,16 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, debugMode: _this.debugMode }); + if (_this.collectionMode) { + _this.world.setAutoRefigureSizes(false); + } _this.world.addItem( tiledImage, { index: queueItem.options.index }); - if (_this.collectionMode) { - _this.world.arrange({ - immediately: queueItem.options.collectionImmediately, - rows: _this.collectionRows, - columns: _this.collectionColumns, - layout: _this.collectionLayout, - tileSize: _this.collectionTileSize, - tileMargin: _this.collectionTileMargin - }); + if (_this._loadQueue.length === 0) { + //this restores the autoRefigureSizes flag to true. + refreshWorld(queueItem); } if (_this.world.getItemCount() === 1 && !_this.preserveViewport) { diff --git a/src/world.js b/src/world.js index 0c0502aa..5597f0f8 100644 --- a/src/world.js +++ b/src/world.js @@ -85,7 +85,12 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W this._items.push( item ); } - this._figureSizes(); + if (this._autoRefigureSizes) { + this._figureSizes(); + } else { + this._needsSizesFigured = true; + } + this._needsDraw = true; item.addHandler('bounds-change', this._delegatedFigureSizes);