Compute number of new tiles to load exactly

This commit is contained in:
Tom Payne
2013-04-07 19:12:35 +02:00
parent 5b133d40d9
commit 60a913aef3

View File

@@ -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;
}
};