diff --git a/src/layers/Layer.js b/src/layers/Layer.js index ed479c8f..a38f1074 100644 --- a/src/layers/Layer.js +++ b/src/layers/Layer.js @@ -79,17 +79,19 @@ class Layer extends Evented { this.onRemove() - layers.forEach(layer => { - if (mapgl.getLayer(layer.id)) { - mapgl.removeLayer(layer.id) - } - }) - - Object.keys(source).forEach(id => { - if (mapgl.getSource(id)) { - mapgl.removeSource(id) - } - }) + if (mapgl) { + layers.forEach(layer => { + if (mapgl.getLayer(layer.id)) { + mapgl.removeLayer(layer.id) + } + }) + + Object.keys(source).forEach(id => { + if (mapgl.getSource(id)) { + mapgl.removeSource(id) + } + }) + } if (onClick) { this.off('click', onClick) diff --git a/src/layers/VectorStyle.js b/src/layers/VectorStyle.js index 4473b419..8bba7df7 100644 --- a/src/layers/VectorStyle.js +++ b/src/layers/VectorStyle.js @@ -37,7 +37,9 @@ class VectorStyle extends Evented { // Remove vector style from map, reset to default map style async removeFrom() { const glyphs = this._map._glyphs - await this.toggleVectorStyle(false, mapStyle({ glyphs })) + if (this._map.getMapGL()) { + await this.toggleVectorStyle(false, mapStyle({ glyphs })) + } } // Set map style, resolves promise when map is ready for other layers