Skip to content

Commit

Permalink
fix: make sure map is present before removing layers and source (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
turban authored Feb 7, 2022
1 parent d742735 commit 58c6cd1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
24 changes: 13 additions & 11 deletions src/layers/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/layers/VectorStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 58c6cd1

Please sign in to comment.