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. * @param {number} maxNewLoads Maximum number of new tiles to load.
*/ */
ol.TileQueue.prototype.loadMoreTiles = function(maxTotalLoading, maxNewLoads) { ol.TileQueue.prototype.loadMoreTiles = function(maxTotalLoading, maxNewLoads) {
var tile; var newLoads = Math.min(
while (maxNewLoads > 0 && maxTotalLoading - this.getTilesLoading(), maxNewLoads, this.getCount());
!this.isEmpty() && if (newLoads > 0) {
this.tilesLoading_ < maxTotalLoading) { var i, tile;
tile = /** @type {ol.Tile} */ (this.dequeue()[0]); for (i = 0; i < newLoads; ++i) {
goog.events.listenOnce(tile, goog.events.EventType.CHANGE, tile = /** @type {ol.Tile} */ (this.dequeue()[0]);
this.handleTileChange, false, this); goog.events.listenOnce(tile, goog.events.EventType.CHANGE,
tile.load(); this.handleTileChange, false, this);
++this.tilesLoading_; tile.load();
--maxNewLoads; }
this.tilesLoading_ += newLoads;
} }
}; };