Skip to content

Commit

Permalink
Restore "raster-fade-duration" functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Wojciechowski committed Nov 3, 2016
1 parent e3711c2 commit 4647c8c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
7 changes: 5 additions & 2 deletions js/render/draw_raster.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ 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']);

const program = painter.useProgram('raster');
gl.uniformMatrix4fv(program.u_matrix, false, posMatrix);

Expand All @@ -47,7 +49,7 @@ function drawRasterTile(painter, sourceCache, layer, coord) {
gl.uniform3fv(program.u_spin_weights, spinWeights(layer.paint['raster-hue-rotate']));

const parentTile = tile.sourceCache && tile.sourceCache.findLoadedParent(coord, 0, {}),
opacities = getOpacities(tile, parentTile, layer, painter.transform, painter.style.rasterFadeDuration);
opacities = getOpacities(tile, parentTile, layer, painter.transform);

let parentScaleBy, parentTL;

Expand Down Expand Up @@ -103,8 +105,9 @@ function saturationFactor(saturation) {
-saturation;
}

function getOpacities(tile, parentTile, layer, transform, fadeDuration) {
function getOpacities(tile, parentTile, layer, transform) {
const opacities = [1, 0];
const fadeDuration = layer.paint['raster-fade-duration'];

if (tile.sourceCache && fadeDuration > 0) {
const now = Date.now();
Expand Down
1 change: 0 additions & 1 deletion js/source/image_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ class ImageSource extends Evented {
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
this.map.animationLoop.set(this.tile.timeAdded + this.map.style.rasterFadeDuration - Date.now());

} else if (image instanceof window.HTMLVideoElement) {
gl.bindTexture(gl.TEXTURE_2D, this.tile.texture);
Expand Down
2 changes: 0 additions & 2 deletions js/source/raster_tile_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ class RasterTileSource extends Evented {
}
gl.generateMipmap(gl.TEXTURE_2D);

this.map.animationLoop.set(this.map.style.rasterFadeDuration);

tile.state = 'loaded';

callback(null);
Expand Down
6 changes: 3 additions & 3 deletions js/source/source_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SourceCache extends Evented {
if (this._sourceLoaded && event.dataType === 'source') {
this.reload();
if (this.transform) {
this.update(this.transform, this.map && this.map.style.rasterFadeDuration);
this.update(this.transform);
}
}
});
Expand Down Expand Up @@ -278,7 +278,7 @@ class SourceCache extends Evented {
* are inside the viewport.
* @private
*/
update(transform, fadeDuration) {
update(transform) {
if (!this._sourceLoaded) { return; }
let i;
let coord;
Expand Down Expand Up @@ -339,7 +339,7 @@ class SourceCache extends Evented {
const id = ids[k];
coord = TileCoord.fromID(id);
tile = this._tiles[id];
if (tile && tile.timeAdded > now - (fadeDuration || 0)) {
if (tile && tile.animationLoopEndTime <= 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
8 changes: 8 additions & 0 deletions js/source/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ 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);
}

/**
* Given a data object with a 'buffers' property, load it into
* this tile's elementGroups and buffers properties and set loaded
Expand Down
1 change: 0 additions & 1 deletion js/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ class Style extends Evented {

this._updateZoomHistory(z);

this.rasterFadeDuration = 300;
for (const layerId in this._layers) {
const layer = this._layers[layerId];

Expand Down

0 comments on commit 4647c8c

Please sign in to comment.