cj devin
cj devin

Reputation: 1375

How to destroy mapbox gl map instance

I am using "mapbox-gl": "^0.54.0". While initializing Mapboxgl instance no of web worker thread got created. please see the below image screenshot.

here is the sample code. gis-map.component.html

<div #container id="GisMapContainer">

</div>

gis-map.component.ts

import * as MapboxGl from 'mapbox-gl';

@Component({
  selector: 'gis-map',
  templateUrl: './gis-map.component.html',
  styleUrls: ['./gis-map.component.scss']
})
export class MapComponent implements OnInit, OnDestroy {

@ViewChild('container', {static: true}) mapContainer: ElementRef;

ngOnInit(){
let options={
container: this.mapContainer.nativeElement,
...
...
};
this.mapInstance = new MapboxGl.Map(options);
}

ngOnDestroy(){
this.mapInstance=null;
}

}

Now if i am destroying mapbox gl map instance on component destroy but these worker thread instance still exists.

Please give me suggestion it is possible to destroy Javascript vm web worker thread instance.

Thanks.

Upvotes: 5

Views: 9827

Answers (1)

Dolly
Dolly

Reputation: 2572

this.mapInstance=null; is Okay but it will not destroy and release all resources(Events.. etc..) associated with this map.

Use instance member of Mapbox-gl-js: https://docs.mapbox.com/mapbox-gl-js/api/map/#map#remove

Upvotes: 4

Related Questions