Check if map style is loaded before removing source or layer (#1123)

This commit is contained in:
Jonas Witt 2020-06-04 20:52:58 +02:00 committed by GitHub
parent 120f55efe3
commit 1d79ad61e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -104,7 +104,7 @@ export default class Layer<Props: LayerProps> extends PureComponent<Props> {
const map = this._map;
if (map) {
map.off('styledata', this._updateLayer);
if (map.style) {
if (map.style && map.style._loaded) {
map.removeLayer(this.id);
}
}

View File

@ -58,9 +58,11 @@ export default class Source<Props: SourceProps> extends PureComponent<Props> {
const map = this._map;
if (map) {
map.off('styledata', this._updateSource);
if (map.style) {
requestAnimationFrame(() => map.removeSource(this.id));
}
requestAnimationFrame(() => {
if (map.style && map.style._loaded) {
map.removeSource(this.id);
}
});
}
}