bluehalo / ngx-leaflet

Core Leaflet package for Angular.io
MIT License
774 stars 126 forks source link

Map container is being reused by another instance #352

Open neverlose-lv opened 1 year ago

neverlose-lv commented 1 year ago
  ngOnDestroy(): void {
    if (this.map) {
      this.map.remove();
    }
  }

results me into an error:

Map container is being reused by another instance
epazs commented 1 year ago

The same thing happens to me and I am not able to solve it

vvandens commented 1 year ago

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.