Do not load tiles while interacting

Especially on mobile devices, loading just a single tile can
cause major janks. During animations, it is fine to just skip
frames. But during user interaction (e.g. dragging), a more
instant visual feedback is desirable.
This commit is contained in:
ahocevar
2014-02-13 13:30:55 +01:00
parent 4d0d2500a2
commit 877e881a52
+12 -9
View File
@@ -816,25 +816,28 @@ ol.Map.prototype.handlePostRender = function() {
// efficiently: // efficiently:
// * When the view is static we allow a large number of parallel tile loads // * When the view is static we allow a large number of parallel tile loads
// to complete the frame as quickly as possible. // to complete the frame as quickly as possible.
// * When animating or interacting, image loads can cause janks, so we reduce // * Image loads can cause janks. So when animating, we reduce the maximum
// the maximum number of loads per frame and limit the number of parallel // number of loads per frame and limit the number of parallel tile loads to
// tile loads to remain reactive to view changes and to reduce the chance of // remain reactive to view changes and to reduce the chance of loading
// loading tiles that will quickly disappear from view. // tiles that will quickly disappear from view. When interacting, we do not
// load any tiles at all.
var tileQueue = this.tileQueue_; var tileQueue = this.tileQueue_;
if (!tileQueue.isEmpty()) { if (!tileQueue.isEmpty()) {
var maxTotalLoading = 16; var maxTotalLoading = 16;
var maxNewLoads = maxTotalLoading; var maxNewLoads = maxTotalLoading;
var tileSourceCount = 0; var wantedTileSourcesCount = 0;
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]) {
maxTotalLoading = 8; maxTotalLoading = 8;
maxNewLoads = 2; maxNewLoads = 2;
} }
tileSourceCount = goog.object.getCount(frameState.wantedTiles); if (!hints[ol.ViewHint.INTERACTING]) {
wantedTileSourcesCount = goog.object.getCount(frameState.wantedTiles);
}
} }
maxTotalLoading *= tileSourceCount; maxTotalLoading *= wantedTileSourcesCount;
maxNewLoads *= tileSourceCount; maxNewLoads *= wantedTileSourcesCount;
if (tileQueue.getTilesLoading() < maxTotalLoading) { if (tileQueue.getTilesLoading() < maxTotalLoading) {
tileQueue.reprioritize(); // FIXME only call if view has changed tileQueue.reprioritize(); // FIXME only call if view has changed
tileQueue.loadMoreTiles(maxTotalLoading, maxNewLoads); tileQueue.loadMoreTiles(maxTotalLoading, maxNewLoads);