Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear source tiles for removed/re-added layer #3655

Merged
merged 1 commit into from
Nov 21, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions js/style/style.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const assert = require('assert');
const Evented = require('../util/evented');
const StyleLayer = require('./style_layer');
const ImageSprite = require('./image_sprite');
Expand Down Expand Up @@ -252,7 +253,13 @@ class Style extends Evented {
this._updateWorkerLayers(updatedIds, removedIds);
}
for (const id in this._updatedSources) {
this._reloadSource(id);
const action = this._updatedSources[id];
assert(action === 'reload' || action === 'clear');
if (action === 'reload') {
this._reloadSource(id);
} else if (action === 'clear') {
this._clearSource(id);
}
}

this._applyClasses(classes, options);
Expand Down Expand Up @@ -362,7 +369,16 @@ class Style extends Evented {

this._layers[id] = layer;

delete this._removedLayers[id];
if (this._removedLayers[id]) {
// If, in the current batch, we have already removed this layer
// and we are now re-adding it, then we need to clear (rather
// than just reload) the underyling source's tiles.
// Otherwise, tiles marked 'reloading' will have buffers that are
// set up for the _previous_ version of this layer, confusing
// https://github.com/mapbox/mapbox-gl-js/issues/3633
delete this._removedLayers[id];
this._updatedSources[layer.source] = 'clear';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is going to introduce a flash in cases where remove/add was being used to re-order the layers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better than introducing corrupt buffers!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will these tiles still be marked as reloading within SourceCache? As it is defined now, reloading means that there is an asynchronous update underway and the tiles are still renderable.

Is there a need for another state that means there is an asynchronous update underway and the tiles are NOT renderable? Or is there a need to redefine reloading?

}
this._updateLayer(layer);

if (layer.type === 'symbol') {
Expand Down Expand Up @@ -393,8 +409,8 @@ class Style extends Evented {

if (layer.type === 'symbol') {
this._updatedSymbolOrder = true;
if (layer.source) {
this._updatedSources[layer.source] = true;
if (layer.source && !this._updatedSources[layer.source]) {
this._updatedSources[layer.source] = 'reload';
}
}
}
Expand Down Expand Up @@ -559,8 +575,8 @@ class Style extends Evented {

_updateLayer(layer) {
this._updatedLayers[layer.id] = true;
if (layer.source) {
this._updatedSources[layer.source] = true;
if (layer.source && !this._updatedSources[layer.source]) {
this._updatedSources[layer.source] = 'reload';
}
this._changed = true;
}
Expand Down Expand Up @@ -676,6 +692,10 @@ class Style extends Evented {
this.dispatcher.remove();
}

_clearSource(id) {
this.sourceCaches[id].clearTiles();
}

_reloadSource(id) {
this.sourceCaches[id].reload();
}
Expand Down