Skip to content

Commit

Permalink
fix(Source): remove dependent layers on componentWillUnmount
Browse files Browse the repository at this point in the history
  • Loading branch information
stepankuzmin committed Apr 8, 2019
1 parent f9b54db commit 5abb0a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/Layer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ class Layer extends PureComponent<Props> {
this._map.off(eventName, this._id, this[handlerName]);
}
});

this._map.removeLayer(this._id);
}

_onClick = (event: MapMouseEvent): void => {
Expand Down
10 changes: 10 additions & 0 deletions src/components/Source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ class Source extends PureComponent<Props> {
}

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);
}
}
Expand Down

0 comments on commit 5abb0a4

Please sign in to comment.