From ccb4ae9f8664d38e9e7939194430cdaf611fc703 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 20 Jul 2023 17:27:49 +0200 Subject: [PATCH] Fixed _updateViewport to come to a fullyLoaded state with n tiles. Improved _compareTiles --- src/tiledimage.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/tiledimage.js b/src/tiledimage.js index 59792431..e28ed224 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -1276,7 +1276,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag this._drawTiles(this.lastDrawn); // Load the new 'best' n tiles - if (bestTiles) { + if (bestTiles && bestTiles.length > 0) { bestTiles.forEach(function (tile) { if (tile && !tile.context2D) { this._loadTile(tile, currentTime); @@ -1930,20 +1930,20 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag return [tile]; } previousBest.push(tile); - previousBest.sort(function (a, b) { - if (a === null) { - return 1; - } - if (b === null) { - return -1; - } - if (a.visibility === b.visibility) { - return (a.squaredDistance - b.squaredDistance); - } else { - return (a.visibility - b.visibility); - } - }); if (previousBest.length > maxNTiles) { + previousBest.sort(function (a, b) { + if (a === null) { + return 1; + } + if (b === null) { + return -1; + } + if (a.visibility === b.visibility) { + return (a.squaredDistance - b.squaredDistance); + } else { + return (a.visibility - b.visibility); + } + }); previousBest.pop(); } return previousBest;