Do not stop the render loop when all wanted tiles are aborted

This commit is contained in:
Andreas Hocevar
2017-06-08 15:32:36 +02:00
parent dee3ebdc54
commit 1f51c14e7e
2 changed files with 25 additions and 2 deletions
+11 -2
View File
@@ -106,16 +106,25 @@ ol.TileQueue.prototype.handleTileChange = function(event) {
*/ */
ol.TileQueue.prototype.loadMoreTiles = function(maxTotalLoading, maxNewLoads) { ol.TileQueue.prototype.loadMoreTiles = function(maxTotalLoading, maxNewLoads) {
var newLoads = 0; var newLoads = 0;
var tile, tileKey; var abortedTiles = false;
var state, tile, tileKey;
while (this.tilesLoading_ < maxTotalLoading && newLoads < maxNewLoads && while (this.tilesLoading_ < maxTotalLoading && newLoads < maxNewLoads &&
this.getCount() > 0) { this.getCount() > 0) {
tile = /** @type {ol.Tile} */ (this.dequeue()[0]); tile = /** @type {ol.Tile} */ (this.dequeue()[0]);
tileKey = tile.getKey(); 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.tilesLoadingKeys_[tileKey] = true;
++this.tilesLoading_; ++this.tilesLoading_;
++newLoads; ++newLoads;
tile.load(); 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_();
}
}; };
+14
View File
@@ -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() { describe('heapify', function() {