Only manage the tile queue if it is not empty and improve comment

This commit is contained in:
Tom Payne
2013-04-08 12:14:33 +02:00
parent 6f49cb8abe
commit 01440b484b
+18 -7
View File
@@ -574,10 +574,21 @@ ol.Map.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
*/ */
ol.Map.prototype.handlePostRender = function() { ol.Map.prototype.handlePostRender = function() {
// Limit the number of tile loads if animating or interacting. var frameState = this.frameState_;
// Manage the tile queue
// Image loads are expensive and a limited resource, so try to use them
// efficiently:
// * When the view is static we allow a large number of parallel tile loads
// to complete the frame as quickly as possible.
// * When animating or interacting, image loads can cause janks, so we reduce
// the maximum number of loads per frame and limit the number of parallel
// tile loads to remain reactive to view changes and to reduce the chance of
// loading tiles that will quickly disappear from view.
var tileQueue = this.tileQueue_;
if (!tileQueue.isEmpty()) {
var maxTotalLoading = 16; var maxTotalLoading = 16;
var maxNewLoads = maxTotalLoading; var maxNewLoads = maxTotalLoading;
var frameState = this.frameState_;
if (!goog.isNull(frameState)) { if (!goog.isNull(frameState)) {
var hints = frameState.viewHints; var hints = frameState.viewHints;
if (hints[ol.ViewHint.ANIMATING] || hints[ol.ViewHint.INTERACTING]) { if (hints[ol.ViewHint.ANIMATING] || hints[ol.ViewHint.INTERACTING]) {
@@ -585,16 +596,16 @@ ol.Map.prototype.handlePostRender = function() {
maxNewLoads = 2; maxNewLoads = 2;
} }
} }
if (tileQueue.getTilesLoading() < maxTotalLoading) {
if (this.tileQueue_.getTilesLoading() < maxTotalLoading) { tileQueue.reprioritize(); // FIXME only call if view has changed
this.tileQueue_.reprioritize(); // FIXME only call if view has changed tileQueue.loadMoreTiles(maxTotalLoading, maxNewLoads);
this.tileQueue_.loadMoreTiles(maxTotalLoading, maxNewLoads); }
} }
var postRenderFunctions = this.postRenderFunctions_; var postRenderFunctions = this.postRenderFunctions_;
var i; var i;
for (i = 0; i < postRenderFunctions.length; ++i) { for (i = 0; i < postRenderFunctions.length; ++i) {
postRenderFunctions[i](this, this.frameState_); postRenderFunctions[i](this, frameState);
} }
postRenderFunctions.length = 0; postRenderFunctions.length = 0;
}; };