ngx-leaflet
ngx-leaflet copied to clipboard
Map container is being reused by another instance
ngOnDestroy(): void {
if (this.map) {
this.map.remove();
}
}
results me into an error:
Map container is being reused by another instance
The same thing happens to me and I am not able to solve it
Had the same issue...
The problem came from my own component ngOnDestroy
calling remove()
on the map instance. The directive does it already so it's no use and breaks the following test in the leaflet source, since after the 1st remove, this._containerId
is undefined
:
if (this._containerId !== this._container._leaflet_id) {
throw new Error('Map container is being reused by another instance');
}
Just get rid of your own this.map.remove()
in your ngOnDestroy
.