From 1fd37af4a10e318e13c2688b7ff3402584beea9a Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Tue, 19 Mar 2019 11:16:28 -0700 Subject: [PATCH] Brought changes over from https://github.com/paaddyy/openseadragon and cleaned up whitespace --- src/imageloader.js | 25 +++++++++++++++++++++++-- src/openseadragon.js | 4 +++- src/viewer.js | 4 +++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/imageloader.js b/src/imageloader.js index 14eb576b..2a4dc6f3 100644 --- a/src/imageloader.js +++ b/src/imageloader.js @@ -46,12 +46,14 @@ * @param {Function} [options.callback] - Called once image has been downloaded. * @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.tries] - Actual number of the current try. */ function ImageJob (options) { $.extend(true, this, { timeout: $.DEFAULT_SETTINGS.timeout, - jobId: null + jobId: null, + tries: 0 }, options); /** @@ -70,6 +72,8 @@ ImageJob.prototype = { * @method */ start: function(){ + this.tries++; + var self = this; var selfAbort = this.abort; @@ -180,6 +184,7 @@ $.ImageLoader = function(options) { jobLimit: $.DEFAULT_SETTINGS.imageLoaderLimit, timeout: $.DEFAULT_SETTINGS.timeout, jobQueue: [], + failedTiles: [], jobsInProgress: 0 }, 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 * @private * @param loader - ImageLoader used to start job. @@ -252,6 +258,10 @@ $.ImageLoader.prototype = { * @param callback - Called once cleanup is finished. */ function completeJob(loader, job, callback) { + if (job.errorMsg != '' && job.image === null && job.tries < 1 + loader.tileRetryMax) { + loader.failedTiles.push(job); + } + var nextJob; loader.jobsInProgress--; @@ -262,6 +272,17 @@ function completeJob(loader, job, callback) { 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); } diff --git a/src/openseadragon.js b/src/openseadragon.js index fd3fe809..d5f9c012 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -1156,7 +1156,9 @@ function OpenSeadragon( options ){ imageLoaderLimit: 0, maxImageCacheCount: 200, 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 prefixUrl: "/images/", diff --git a/src/viewer.js b/src/viewer.js index 51b22756..b1f5f071 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -377,7 +377,9 @@ $.Viewer = function( options ) { // Create the image loader this.imageLoader = new $.ImageLoader({ jobLimit: this.imageLoaderLimit, - timeout: options.timeout + timeout: options.timeout, + tileRetryMax: this.tileRetryMax, + tileRetryDelay: this.tileRetryDelay }); // Create the tile cache