From f13691f60d0205a5b08abf42bb48b2c75ee05951 Mon Sep 17 00:00:00 2001 From: Larissa Smith Date: Wed, 19 Aug 2015 13:29:55 -0600 Subject: [PATCH] Added option in addTiledImage to replace tiledImage at index. --- src/viewer.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/viewer.js b/src/viewer.js index b0ee7757..7b482990 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1193,6 +1193,10 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, * named 'getTileUrl', it is treated as a custom TileSource. * @param {Number} [options.index] The index of the item. Added on top of * all other items if not specified. + * @param {Boolean} [options.replace=false] If true, the item at options.index will be + * removed and the new item is added in its place. options.tileSource will be + * interpreted and fetched if necessary before the old item is removed to avoid leaving + * a gap in the world. * @param {Number} [options.x=0] The X position for the image in viewport coordinates. * @param {Number} [options.y=0] The Y position for the image in viewport coordinates. * @param {Number} [options.width=1] The width for the image in viewport coordinates. @@ -1216,6 +1220,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, addTiledImage: function( options ) { $.console.assert(options, "[Viewer.addTiledImage] options is required"); $.console.assert(options.tileSource, "[Viewer.addTiledImage] options.tileSource is required"); + $.console.assert(!options.replace || (options.index > -1 && options.index < this.world.getItemCount()), + "[Viewer.addTiledImage] if options.replace is used, options.index must be a valid index in Viewer.world"); var _this = this; @@ -1283,6 +1289,10 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, _this._loadQueue.splice(0, 1); + if (queueItem.options.replace) { + _this.world.removeItem(_this.world.getItemAt(queueItem.options.index)); + } + tiledImage = new $.TiledImage({ viewer: _this, source: queueItem.tileSource,