Start a maximum of two new tile downloads per frame

This commit is contained in:
Tom Payne
2013-04-04 23:33:18 +02:00
parent 9f689a0809
commit 71d1207201
2 changed files with 13 additions and 4 deletions

View File

@@ -77,6 +77,12 @@ ol.ENABLE_DOM = true;
ol.ENABLE_WEBGL = true; ol.ENABLE_WEBGL = true;
/**
* @define {number} Maximum new tile loads per frame.
*/
ol.MAXIMUM_NEW_TILE_LOADS_PER_FRAME = 2;
/** /**
* @enum {string} * @enum {string}
*/ */
@@ -556,7 +562,7 @@ ol.Map.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
*/ */
ol.Map.prototype.handlePostRender = function() { ol.Map.prototype.handlePostRender = function() {
this.tileQueue_.reprioritize(); // FIXME only call if needed this.tileQueue_.reprioritize(); // FIXME only call if needed
this.tileQueue_.loadMoreTiles(); this.tileQueue_.loadMoreTiles(ol.MAXIMUM_NEW_TILE_LOADS_PER_FRAME);
var postRenderFunctions = this.postRenderFunctions_; var postRenderFunctions = this.postRenderFunctions_;
var i; var i;

View File

@@ -74,15 +74,18 @@ ol.TileQueue.prototype.handleTileChange = function() {
/** /**
* FIXME empty description for jsdoc * @param {number} limit Maximum number of new tiles to load.
*/ */
ol.TileQueue.prototype.loadMoreTiles = function() { ol.TileQueue.prototype.loadMoreTiles = function(limit) {
var tile; var tile;
while (!this.isEmpty() && this.tilesLoading_ < this.maxTilesLoading_) { while (limit > 0 &&
!this.isEmpty() &&
this.tilesLoading_ < this.maxTilesLoading_) {
tile = /** @type {ol.Tile} */ (this.dequeue()[0]); tile = /** @type {ol.Tile} */ (this.dequeue()[0]);
goog.events.listenOnce(tile, goog.events.EventType.CHANGE, goog.events.listenOnce(tile, goog.events.EventType.CHANGE,
this.handleTileChange, false, this); this.handleTileChange, false, this);
tile.load(); tile.load();
++this.tilesLoading_; ++this.tilesLoading_;
--limit;
} }
}; };