Here api Angular应用程序的Here map javascript api,打开Here map页面时发生内存泄漏
每次打开此处地图页时:Here api Angular应用程序的Here map javascript api,打开Here map页面时发生内存泄漏,here-api,Here Api,每次打开此处地图页时: this.router.navigate(['/car-section/here-map'], {replaceUrl: false}); html此处映射页面代码: <div #map class="map-container"> 获取内存泄漏,每次获取两个内存堆泄漏: 这并不奇怪,因为当您离开视图导航时,角度组件生命周期被破坏,当您导航到视图时(重新)创建,而此处贴图对象位于全局H对象上 我认为角度组件应该与OnDestroy接口,从而实现Ngond
this.router.navigate(['/car-section/here-map'], {replaceUrl: false});
html此处映射页面代码:
<div #map class="map-container">
获取内存泄漏,每次获取两个内存堆泄漏:
这并不奇怪,因为当您离开视图导航时,角度组件生命周期被破坏,当您导航到视图时(重新)创建,而此处贴图对象位于全局H对象上 我认为角度组件应该与OnDestroy接口,从而实现Ngondestory方法。在该方法中,应该处理已“强制”到映射的对象和处理程序。 通常,我们需要先处理事件处理程序,然后处理映射对象,然后处理映射本身。 例如,请参见上的dispose方法
export class HereMapComponent implements OnInit {
private platform: any;
private mapHere:any;
........
@ViewChild("map", {static: true}) public mapElement: ElementRef;
constructor() {
this.platform = new H.service.Platform({
'apikey': API_Key
});
}
......
public ngAfterViewInit() {
setTimeout(() => {
let defaultLayers = this.platform.createDefaultLayers();
this.mapHere = new H.Map(
this.mapElement.nativeElement,
defaultLayers.vector.normal.map, //3.1
// defaultLayers.normal.map, //3.0
{
zoom: 16,
center: this.center,
pixelRatio: window.devicePixelRatio || 1
}
);
}, 300);
}