From 96ba0799621a2ad540d77cd2f36e05761cecb78a Mon Sep 17 00:00:00 2001 From: Sanaz Golbabaei <32684731+sgolbabaei@users.noreply.github.com> Date: Fri, 21 Feb 2020 15:07:59 -0800 Subject: [PATCH] Clearing the underlying source's tiles while removing a layer. (#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 --- src/source/tile.js | 2 ++ src/style/style.js | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/source/tile.js b/src/source/tile.js index d1d502cbf11..35aa5ea66cb 100644 --- a/src/source/tile.js +++ b/src/source/tile.js @@ -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'; diff --git a/src/style/style.js b/src/style/style.js index 27890d5dcde..d4f99622276 100644 --- a/src/style/style.js +++ b/src/style/style.js @@ -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();