From 1f51c14e7ef4e52b8397abf988343cf95346f243 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Thu, 8 Jun 2017 15:32:36 +0200 Subject: [PATCH] Do not stop the render loop when all wanted tiles are aborted --- src/ol/tilequeue.js | 13 +++++++++++-- test/spec/ol/tilequeue.test.js | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/ol/tilequeue.js b/src/ol/tilequeue.js index 5750d0086b..14bb075e90 100644 --- a/src/ol/tilequeue.js +++ b/src/ol/tilequeue.js @@ -106,16 +106,25 @@ ol.TileQueue.prototype.handleTileChange = function(event) { */ ol.TileQueue.prototype.loadMoreTiles = function(maxTotalLoading, maxNewLoads) { var newLoads = 0; - var tile, tileKey; + var abortedTiles = false; + var state, tile, tileKey; while (this.tilesLoading_ < maxTotalLoading && newLoads < maxNewLoads && this.getCount() > 0) { tile = /** @type {ol.Tile} */ (this.dequeue()[0]); tileKey = tile.getKey(); - if (tile.getState() === ol.TileState.IDLE && !(tileKey in this.tilesLoadingKeys_)) { + state = tile.getState(); + if (state === ol.TileState.ABORT) { + abortedTiles = true; + } else if (state === ol.TileState.IDLE && !(tileKey in this.tilesLoadingKeys_)) { this.tilesLoadingKeys_[tileKey] = true; ++this.tilesLoading_; ++newLoads; tile.load(); } } + if (newLoads === 0 && abortedTiles) { + // Do not stop the render loop when all wanted tiles were aborted due to + // a small, saturated tile cache. + this.tileChangeCallback_(); + } }; diff --git a/test/spec/ol/tilequeue.test.js b/test/spec/ol/tilequeue.test.js index 87c40ed956..802e44cc76 100644 --- a/test/spec/ol/tilequeue.test.js +++ b/test/spec/ol/tilequeue.test.js @@ -86,6 +86,20 @@ describe('ol.TileQueue', function() { }); + it('calls #tileChangeCallback_ when all wanted tiles are aborted', function() { + var tileChangeCallback = sinon.spy(); + var queue = new ol.TileQueue(noop, tileChangeCallback); + var numTiles = 20; + for (var i = 0; i < numTiles; ++i) { + var tile = createImageTile(); + tile.state = ol.TileState.ABORT; + queue.enqueue([tile]); + } + var maxLoading = numTiles / 2; + queue.loadMoreTiles(maxLoading, maxLoading); + expect(tileChangeCallback.callCount).to.be(1); + }); + }); describe('heapify', function() {