Brought changes over from https://github.com/paaddyy/openseadragon and cleaned up whitespace

This commit is contained in:
Ian Gilman 2019-03-19 11:16:28 -07:00
parent 01408a4744
commit 1fd37af4a1
3 changed files with 29 additions and 4 deletions

View File

@ -46,12 +46,14 @@
* @param {Function} [options.callback] - Called once image has been downloaded. * @param {Function} [options.callback] - Called once image has been downloaded.
* @param {Function} [options.abort] - Called when this image job is aborted. * @param {Function} [options.abort] - Called when this image job is aborted.
* @param {Number} [options.timeout] - The max number of milliseconds that this image job may take to complete. * @param {Number} [options.timeout] - The max number of milliseconds that this image job may take to complete.
* @param {Number} [options.tries] - Actual number of the current try.
*/ */
function ImageJob (options) { function ImageJob (options) {
$.extend(true, this, { $.extend(true, this, {
timeout: $.DEFAULT_SETTINGS.timeout, timeout: $.DEFAULT_SETTINGS.timeout,
jobId: null jobId: null,
tries: 0
}, options); }, options);
/** /**
@ -70,6 +72,8 @@ ImageJob.prototype = {
* @method * @method
*/ */
start: function(){ start: function(){
this.tries++;
var self = this; var self = this;
var selfAbort = this.abort; var selfAbort = this.abort;
@ -180,6 +184,7 @@ $.ImageLoader = function(options) {
jobLimit: $.DEFAULT_SETTINGS.imageLoaderLimit, jobLimit: $.DEFAULT_SETTINGS.imageLoaderLimit,
timeout: $.DEFAULT_SETTINGS.timeout, timeout: $.DEFAULT_SETTINGS.timeout,
jobQueue: [], jobQueue: [],
failedTiles: [],
jobsInProgress: 0 jobsInProgress: 0
}, options); }, options);
@ -244,7 +249,8 @@ $.ImageLoader.prototype = {
}; };
/** /**
* Cleans up ImageJob once completed. * Cleans up ImageJob once completed. Restarts job after 2.5 seconds
* if it failed loading but max three times.
* @method * @method
* @private * @private
* @param loader - ImageLoader used to start job. * @param loader - ImageLoader used to start job.
@ -252,6 +258,10 @@ $.ImageLoader.prototype = {
* @param callback - Called once cleanup is finished. * @param callback - Called once cleanup is finished.
*/ */
function completeJob(loader, job, callback) { function completeJob(loader, job, callback) {
if (job.errorMsg != '' && job.image === null && job.tries < 1 + loader.tileRetryMax) {
loader.failedTiles.push(job);
}
var nextJob; var nextJob;
loader.jobsInProgress--; loader.jobsInProgress--;
@ -262,6 +272,17 @@ function completeJob(loader, job, callback) {
loader.jobsInProgress++; loader.jobsInProgress++;
} }
if (loader.tileRetryMax > 0 && loader.jobQueue.length === 0) {
//SAME AS ABOVE => REFACTOR
if ((!loader.jobLimit || loader.jobsInProgress < loader.jobLimit) && loader.failedTiles.length > 0) {
nextJob = loader.failedTiles.shift();
setTimeout(function () {
nextJob.start();
}, loader.tileRetryDelay);
loader.jobsInProgress++;
}
}
callback(job.image, job.errorMsg, job.request); callback(job.image, job.errorMsg, job.request);
} }

View File

@ -1157,6 +1157,8 @@ function OpenSeadragon( options ){
maxImageCacheCount: 200, maxImageCacheCount: 200,
timeout: 30000, timeout: 30000,
useCanvas: true, // Use canvas element for drawing if available useCanvas: true, // Use canvas element for drawing if available
tileRetryMax: 0,
tileRetryDelay: 2500,
//INTERFACE RESOURCE SETTINGS //INTERFACE RESOURCE SETTINGS
prefixUrl: "/images/", prefixUrl: "/images/",

View File

@ -377,7 +377,9 @@ $.Viewer = function( options ) {
// Create the image loader // Create the image loader
this.imageLoader = new $.ImageLoader({ this.imageLoader = new $.ImageLoader({
jobLimit: this.imageLoaderLimit, jobLimit: this.imageLoaderLimit,
timeout: options.timeout timeout: options.timeout,
tileRetryMax: this.tileRetryMax,
tileRetryDelay: this.tileRetryDelay
}); });
// Create the tile cache // Create the tile cache