Add job queue full event.

This commit is contained in:
Aiosa 2024-06-01 15:02:31 +02:00
parent e0f442209b
commit cdb89ff5ad
2 changed files with 22 additions and 5 deletions

View File

@ -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 );
}
return false;
},
/**

View File

@ -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,
});
}
},
/**