Skip to content

Commit

Permalink
Clearing the underlying source's tiles while removing a layer. (mapbo…
Browse files Browse the repository at this point in the history
…x#9305)

* clearing the underlying source's tiles while removing a layer.

* Removing the clear command since this is computationally expensive and also causing a glitch on the map once the tiles are cleared.

* Changing the name of the function to hasLayer to be more specific regarding the function
  • Loading branch information
sgolbabaei authored and mike-unearth committed Mar 18, 2020
1 parent d88845c commit 96ba079
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/source/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ class Tile {
const vtLayers = this.latestFeatureIndex.loadVTLayers();

for (const id in this.buckets) {
if (!painter.style.hasLayer(id)) continue;

const bucket = this.buckets[id];
// Buckets are grouped by common source-layer
const sourceLayerId = bucket.layers[0]['sourceLayer'] || '_geojsonTileLayer';
Expand Down
11 changes: 11 additions & 0 deletions src/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,17 @@ class Style extends Evented {
return this._layers[id];
}

/**
* checks if a specific layer is present within the style.
*
* @param {string} id - id of the desired layer
* @returns {boolean} a boolean specifying if the given layer is present
*/
hasLayer(id: string): boolean {
const layerIds = Object.keys(this._layers);
return layerIds.includes(id, 0);
}

setLayerZoomRange(layerId: string, minzoom: ?number, maxzoom: ?number) {
this._checkLoaded();

Expand Down

0 comments on commit 96ba079

Please sign in to comment.