diff --git a/src/imageloader.js b/src/imageloader.js index 87b79079..9d04ed2b 100644 --- a/src/imageloader.js +++ b/src/imageloader.js @@ -198,6 +198,7 @@ $.ImageLoader.prototype = { * requests. * @param {Function} [options.callback] - Called once image has been downloaded. * @param {Function} [options.abort] - Called when this image job is aborted. + * @returns {boolean} true if job was immediatelly started, false if queued */ addJob: function(options) { if (!options.source) { @@ -229,10 +230,10 @@ $.ImageLoader.prototype = { if ( !this.jobLimit || this.jobsInProgress < this.jobLimit ) { newJob.start(); this.jobsInProgress++; + return true; } - else { - this.jobQueue.push( newJob ); - } + this.jobQueue.push( newJob ); + return false; }, /** diff --git a/src/tiledimage.js b/src/tiledimage.js index bd3db706..4d0aa7de 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -2042,7 +2042,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag var _this = this; tile.loading = true; tile.tiledImage = this; - this._imageLoader.addJob({ + if (!this._imageLoader.addJob({ src: tile.getUrl(), tile: tile, source: this.source, @@ -2057,7 +2057,23 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag abort: function() { tile.loading = false; } - }); + })) { + /** + * Triggered if tile load job was added to a full queue. + * This allows to react upon e.g. network not being able to serve the tiles fast enough. + * @event job-queue-full + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {OpenSeadragon.Tile} tile - The tile that failed to load. + * @property {OpenSeadragon.TiledImage} tiledImage - The tiled image the tile belongs to. + * @property {number} time - The time in milliseconds when the tile load began. + */ + this.viewer.raiseEvent("job-queue-full", { + tile: tile, + tiledImage: this, + time: time, + }); + } }, /**