From 60a913aef349c03d7a8f8473e3f1c972a47cb14f Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 7 Apr 2013 19:12:35 +0200 Subject: [PATCH] Compute number of new tiles to load exactly --- src/ol/tilequeue.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/ol/tilequeue.js b/src/ol/tilequeue.js index a2989b3f42..37265f7008 100644 --- a/src/ol/tilequeue.js +++ b/src/ol/tilequeue.js @@ -80,15 +80,16 @@ ol.TileQueue.prototype.handleTileChange = function() { * @param {number} maxNewLoads Maximum number of new tiles to load. */ ol.TileQueue.prototype.loadMoreTiles = function(maxTotalLoading, maxNewLoads) { - var tile; - while (maxNewLoads > 0 && - !this.isEmpty() && - this.tilesLoading_ < maxTotalLoading) { - tile = /** @type {ol.Tile} */ (this.dequeue()[0]); - goog.events.listenOnce(tile, goog.events.EventType.CHANGE, - this.handleTileChange, false, this); - tile.load(); - ++this.tilesLoading_; - --maxNewLoads; + var newLoads = Math.min( + maxTotalLoading - this.getTilesLoading(), maxNewLoads, this.getCount()); + if (newLoads > 0) { + var i, tile; + for (i = 0; i < newLoads; ++i) { + tile = /** @type {ol.Tile} */ (this.dequeue()[0]); + goog.events.listenOnce(tile, goog.events.EventType.CHANGE, + this.handleTileChange, false, this); + tile.load(); + } + this.tilesLoading_ += newLoads; } };