From 71d12072010adba6deb9e1befa4222f02b10f27a Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 4 Apr 2013 23:33:18 +0200 Subject: [PATCH 1/2] Start a maximum of two new tile downloads per frame --- src/ol/map.js | 8 +++++++- src/ol/tilequeue.js | 9 ++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ol/map.js b/src/ol/map.js index c616c64669..ca1d36b2e3 100644 --- a/src/ol/map.js +++ b/src/ol/map.js @@ -77,6 +77,12 @@ ol.ENABLE_DOM = true; ol.ENABLE_WEBGL = true; +/** + * @define {number} Maximum new tile loads per frame. + */ +ol.MAXIMUM_NEW_TILE_LOADS_PER_FRAME = 2; + + /** * @enum {string} */ @@ -556,7 +562,7 @@ ol.Map.prototype.handleMapBrowserEvent = function(mapBrowserEvent) { */ ol.Map.prototype.handlePostRender = function() { 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 i; diff --git a/src/ol/tilequeue.js b/src/ol/tilequeue.js index 4d21f2ef44..43c25f85cb 100644 --- a/src/ol/tilequeue.js +++ b/src/ol/tilequeue.js @@ -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; - while (!this.isEmpty() && this.tilesLoading_ < this.maxTilesLoading_) { + while (limit > 0 && + !this.isEmpty() && + this.tilesLoading_ < this.maxTilesLoading_) { tile = /** @type {ol.Tile} */ (this.dequeue()[0]); goog.events.listenOnce(tile, goog.events.EventType.CHANGE, this.handleTileChange, false, this); tile.load(); ++this.tilesLoading_; + --limit; } }; From 0e12d16c37965620bd2f3d03899d2ffe1ab8b0af Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 4 Apr 2013 23:49:21 +0200 Subject: [PATCH 2/2] Move configuration of maximum tiles loading into map.js --- src/ol/map.js | 10 +++++++++- src/ol/tilequeue.js | 7 +++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ol/map.js b/src/ol/map.js index ca1d36b2e3..9508938a21 100644 --- a/src/ol/map.js +++ b/src/ol/map.js @@ -77,6 +77,12 @@ ol.ENABLE_DOM = true; ol.ENABLE_WEBGL = true; +/** + * @define {number} Maximum number of simultaneously loading tiles. + */ +ol.MAXIMUM_TILES_LOADING = 8; + + /** * @define {number} Maximum new tile loads per frame. */ @@ -279,7 +285,9 @@ ol.Map = function(mapOptions) { * @private * @type {ol.TileQueue} */ - this.tileQueue_ = new ol.TileQueue(goog.bind(this.getTilePriority, this), + this.tileQueue_ = new ol.TileQueue( + ol.MAXIMUM_TILES_LOADING, + goog.bind(this.getTilePriority, this), goog.bind(this.handleTileChange_, this)); goog.events.listen(this, ol.Object.getChangedEventType(ol.MapProperty.VIEW), diff --git a/src/ol/tilequeue.js b/src/ol/tilequeue.js index 43c25f85cb..94274ca6d7 100644 --- a/src/ol/tilequeue.js +++ b/src/ol/tilequeue.js @@ -18,12 +18,15 @@ ol.TilePriorityFunction; /** * @constructor * @extends {ol.structs.PriorityQueue} + * @param {number} maxTilesLoading Maximum number of simultaneously loading + * tiles. * @param {ol.TilePriorityFunction} tilePriorityFunction * Tile priority function. * @param {Function} tileChangeCallback * Function called on each tile change event. */ -ol.TileQueue = function(tilePriorityFunction, tileChangeCallback) { +ol.TileQueue = + function(maxTilesLoading, tilePriorityFunction, tileChangeCallback) { goog.base( this, @@ -52,7 +55,7 @@ ol.TileQueue = function(tilePriorityFunction, tileChangeCallback) { * @private * @type {number} */ - this.maxTilesLoading_ = 8; + this.maxTilesLoading_ = maxTilesLoading; /** * @private