Skip to content

Commit

Permalink
Prune unused layers from the CrossTileSymbolIndex.
Browse files Browse the repository at this point in the history
Fixes issue #5995 (index leaked removed layers)
  • Loading branch information
ChrisLoer committed Jan 18, 2018
1 parent 94f775a commit 3688d83
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ class Style extends Evented {
const layerBucketsChanged = this.crossTileSymbolIndex.addLayer(styleLayer, layerTiles[styleLayer.source]);
symbolBucketsChanged = symbolBucketsChanged || layerBucketsChanged;
}
this.crossTileSymbolIndex.pruneUnusedLayers(this._order);

// Anything that changes our "in progress" layer and tile indices requires us
// to start over. When we start over, we do a full placement instead of incremental
Expand Down
12 changes: 12 additions & 0 deletions src/symbol/cross_tile_symbol_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,18 @@ class CrossTileSymbolIndex {

return symbolBucketsChanged;
}

pruneUnusedLayers(usedLayers: Array<string>) {
const usedLayerMap = {};
usedLayers.forEach((usedLayer) => {
usedLayerMap[usedLayer] = true;
});
for (const layerId in this.layerIndexes) {
if (!usedLayerMap[layerId]) {
delete this.layerIndexes[layerId];
}
}
}
}

module.exports = CrossTileSymbolIndex;
23 changes: 23 additions & 0 deletions test/unit/symbol/cross_tile_symbol_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,26 @@ test('CrossTileSymbolIndex.addLayer', (t) => {

t.end();
});

test('CrossTileSymbolIndex.pruneUnusedLayers', (t) => {
const index = new CrossTileSymbolIndex();

const tileID = new OverscaledTileID(6, 0, 6, 8, 8);
const instances = [
makeSymbolInstance(1000, 1000, ""), // A
makeSymbolInstance(1000, 1000, "") // B
];
const tile = makeTile(tileID, instances);

// assigns new ids
index.addLayer(styleLayer, [tile]);
t.equal(instances[0].crossTileID, 1);
t.equal(instances[1].crossTileID, 2);
t.ok(index.layerIndexes[styleLayer.id]);

// remove styleLayer
index.pruneUnusedLayers([]);
t.notOk(index.layerIndexes[styleLayer.id]);

t.end();
});

0 comments on commit 3688d83

Please sign in to comment.