Skip to content

Commit

Permalink
Ensure animation loop stops after raster tiles fade in (#3764)
Browse files Browse the repository at this point in the history
* Ensure animation loop stops after raster tiles fade in

* Fix unit tests
  • Loading branch information
Lucas Wojciechowski committed Dec 13, 2016
1 parent 44d9c42 commit 1d762f6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion js/render/draw_raster.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function drawRasterTile(painter, sourceCache, layer, coord) {
const tile = sourceCache.getTile(coord);
const posMatrix = painter.transform.calculatePosMatrix(coord, sourceCache.getSource().maxzoom);

tile.setAnimationLoop(painter.style.animationLoop, layer.paint['raster-fade-duration']);
tile.registerFadeDuration(painter.style.animationLoop, layer.paint['raster-fade-duration']);

const program = painter.useProgram('raster');
gl.uniformMatrix4fv(program.u_matrix, false, posMatrix);
Expand Down
2 changes: 1 addition & 1 deletion js/source/source_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class SourceCache extends Evented {
const id = ids[k];
coord = TileCoord.fromID(id);
tile = this._tiles[id];
if (tile && tile.animationLoopEndTime >= Date.now()) {
if (tile && tile.fadeEndTime >= Date.now()) {
// This tile is still fading in. Find tiles to cross-fade with it.
if (this.findLoadedChildren(coord, maxCoveringZoom, retain)) {
retain[id] = true;
Expand Down
13 changes: 7 additions & 6 deletions js/source/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ class Tile {
this.state = 'loading';
}

setAnimationLoop(animationLoop, t) {
this.animationLoopEndTime = t + Date.now();
if (this.animationLoopId !== undefined) {
animationLoop.cancel(this.animationLoopId);
}
this.animationLoopId = animationLoop.set(t);
registerFadeDuration(animationLoop, duration) {
const fadeEndTime = duration + this.timeAdded;
if (fadeEndTime < Date.now()) return;
if (this.fadeEndTime && fadeEndTime < this.fadeEndTime) return;

this.fadeEndTime = fadeEndTime;
animationLoop.set(this.fadeEndTime - Date.now());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/js/source/source_cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ test('SourceCache#update', (t) => {
loadTile: function(tile, callback) {
tile.timeAdded = Infinity;
tile.state = 'loaded';
tile.setAnimationLoop(animationLoop, 100);
tile.registerFadeDuration(animationLoop, 100);
callback();
}
});
Expand Down Expand Up @@ -419,7 +419,7 @@ test('SourceCache#update', (t) => {
loadTile: function(tile, callback) {
tile.timeAdded = Infinity;
tile.state = 'loaded';
tile.setAnimationLoop(animationLoop, 100);
tile.registerFadeDuration(animationLoop, 100);
callback();
}
});
Expand Down

0 comments on commit 1d762f6

Please sign in to comment.