最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to destroy mapbox gl map instance - Stack Overflow

programmeradmin4浏览0评论

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

here is the sample code. gis-mapponent.html

<div #container id="GisMapContainer">

</div>

gis-mapponent.ts

import * as MapboxGl from 'mapbox-gl';

@Component({
  selector: 'gis-map',
  templateUrl: './gis-mapponent.html',
  styleUrls: ['./gis-mapponent.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 ponent destroy but these worker thread instance still exists.

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

Thanks.

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

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

<div #container id="GisMapContainer">

</div>

gis-map.ponent.ts

import * as MapboxGl from 'mapbox-gl';

@Component({
  selector: 'gis-map',
  templateUrl: './gis-map.ponent.html',
  styleUrls: ['./gis-map.ponent.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 ponent destroy but these worker thread instance still exists.

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

Thanks.

Share Improve this question edited Jul 15, 2020 at 16:22 cj devin asked Jun 18, 2020 at 10:23 cj devincj devin 1,3754 gold badges17 silver badges58 bronze badges 1
  • instead of setting map instance null,using remove() method this.mapInstance.remove() it's working fine.. github – cj devin Commented Jul 15, 2020 at 16:23
Add a ment  | 

1 Answer 1

Reset to default 4

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./mapbox-gl-js/api/map/#map#remove

发布评论

评论列表(0)

  1. 暂无评论