diff --git a/src/components/Layer/index.js b/src/components/Layer/index.js index 9fe7ea7..05b222d 100644 --- a/src/components/Layer/index.js +++ b/src/components/Layer/index.js @@ -191,6 +191,8 @@ class Layer extends PureComponent { this._map.off(eventName, this._id, this[handlerName]); } }); + + this._map.removeLayer(this._id); } _onClick = (event: MapMouseEvent): void => { diff --git a/src/components/Source/index.js b/src/components/Source/index.js index 1a18c9f..796d56f 100644 --- a/src/components/Source/index.js +++ b/src/components/Source/index.js @@ -56,6 +56,16 @@ class Source extends PureComponent { } if (this._map.getSource(this.props.id)) { + const { id } = this.props; + const { layers } = this._map.getStyle(); + if (layers) { + layers.forEach((layer) => { + if (layer.source === id) { + this._map.removeLayer(layer.id); + } + }); + } + this._map.removeSource(this.props.id); } }