Items added with addTiledImage are now added in correct sequence

This commit is contained in:
Ian Gilman 2014-11-18 15:45:03 -08:00
parent 7359dbe8ae
commit b7c78812c5

View File

@ -207,6 +207,7 @@ $.Viewer = function( options ) {
this._sequenceIndex = 0; this._sequenceIndex = 0;
this._firstOpen = true; this._firstOpen = true;
this._updateRequestId = null; this._updateRequestId = null;
this._loadQueue = [];
this.currentOverlays = []; this.currentOverlays = [];
//Inherit some behaviors and properties //Inherit some behaviors and properties
@ -1260,12 +1261,22 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
$.console.assert(options, "[Viewer.addTiledImage] options is required"); $.console.assert(options, "[Viewer.addTiledImage] options is required");
$.console.assert(options.tileSource, "[Viewer.addTiledImage] options.tileSource is required"); $.console.assert(options.tileSource, "[Viewer.addTiledImage] options.tileSource is required");
var _this = this, var _this = this;
tileSource = options.tileSource;
this._hideMessage(); this._hideMessage();
var myQueueItem = {
options: options
};
function raiseAddItemFailed( event ) { function raiseAddItemFailed( event ) {
for (var i = 0; i < _this._loadQueue; i++) {
if (_this._loadQueue[i] === myQueueItem) {
_this._loadQueue.splice(i, 1);
break;
}
}
/** /**
* Raised when an error occurs while adding a item. * Raised when an error occurs while adding a item.
* @event add-item-failed * @event add-item-failed
@ -1284,7 +1295,9 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
} }
} }
getTileSourceImplementation( this, tileSource, function( tileSource ) { this._loadQueue.push(myQueueItem);
getTileSourceImplementation( this, options.tileSource, function( tileSource ) {
if ( tileSource instanceof Array ) { if ( tileSource instanceof Array ) {
raiseAddItemFailed({ raiseAddItemFailed({
@ -1295,59 +1308,72 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
return; return;
} }
var tiledImage = new $.TiledImage({ myQueueItem.tileSource = tileSource;
viewer: _this,
source: tileSource,
viewport: _this.viewport,
drawer: _this.drawer,
tileCache: _this.tileCache,
imageLoader: _this.imageLoader,
x: options.x,
y: options.y,
width: options.width,
height: options.height,
imageLoaderLimit: _this.imageLoaderLimit,
minZoomImageRatio: _this.minZoomImageRatio,
wrapHorizontal: _this.wrapHorizontal,
wrapVertical: _this.wrapVertical,
immediateRender: _this.immediateRender,
blendTime: _this.blendTime,
alwaysBlend: _this.alwaysBlend,
minPixelRatio: _this.minPixelRatio,
debugMode: _this.debugMode,
debugGridColor: _this.debugGridColor
});
_this.world.addItem( tiledImage, { // add everybody at the front of the queue that's ready to go
index: options.index var queueItem, tiledImage, optionsClone;
}); while (_this._loadQueue.length) {
queueItem = _this._loadQueue[0];
if (!queueItem.tileSource) {
break;
}
if (_this.collectionMode) { _this._loadQueue.splice(0, 1);
_this.world.arrange({
rows: _this.collectionRows,
layout: _this.collectionLayout,
tileSize: _this.collectionTileSize,
tileMargin: _this.collectionTileMargin
});
}
if (_this.world.getItemCount() === 1 && !_this.preserveViewport) { tiledImage = new $.TiledImage({
_this.viewport.goHome(true); viewer: _this,
} source: queueItem.tileSource,
viewport: _this.viewport,
if (_this.navigator) { drawer: _this.drawer,
var optionsClone = $.extend({}, options, { tileCache: _this.tileCache,
originalTiledImage: tiledImage, imageLoader: _this.imageLoader,
tileSource: tileSource x: queueItem.options.x,
y: queueItem.options.y,
width: queueItem.options.width,
height: queueItem.options.height,
imageLoaderLimit: _this.imageLoaderLimit,
minZoomImageRatio: _this.minZoomImageRatio,
wrapHorizontal: _this.wrapHorizontal,
wrapVertical: _this.wrapVertical,
immediateRender: _this.immediateRender,
blendTime: _this.blendTime,
alwaysBlend: _this.alwaysBlend,
minPixelRatio: _this.minPixelRatio,
debugMode: _this.debugMode,
debugGridColor: _this.debugGridColor
}); });
_this.navigator.addTiledImage(optionsClone); _this.world.addItem( tiledImage, {
} index: queueItem.options.index
if (options.success) {
options.success({
item: tiledImage
}); });
if (_this.collectionMode) {
_this.world.arrange({
rows: _this.collectionRows,
layout: _this.collectionLayout,
tileSize: _this.collectionTileSize,
tileMargin: _this.collectionTileMargin
});
}
if (_this.world.getItemCount() === 1 && !_this.preserveViewport) {
_this.viewport.goHome(true);
}
if (_this.navigator) {
optionsClone = $.extend({}, queueItem.options, {
originalTiledImage: tiledImage,
tileSource: queueItem.tileSource
});
_this.navigator.addTiledImage(optionsClone);
}
if (queueItem.options.success) {
queueItem.options.success({
item: tiledImage
});
}
} }
}, function( event ) { }, function( event ) {
event.options = options; event.options = options;