首页 > 解决方案 > HERE 映射 JS API 3.1 - Angular 中样式组“非冲突”的错误

问题描述

加载带有卫星基础层的 HERE 地图时,有时会出现此错误:

    Tangram [error]: Error for style group 'non-collision' for tile 13/16/15542/12554/15 Cannot read property 'retain' of undefined: TypeError: Cannot read property 'retain' of undefined
    at https://js.api.here.com/v3/3.1/mapsjs-core.js:377:259708
    at Array.forEach (<anonymous>)
    at https://js.api.here.com/v3/3.1/mapsjs-core.js:377:259679
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:4200/polyfills.js:3508:26)
    at Object.onInvoke (http://localhost:4200/vendor.js:64284:33)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:4200/polyfills.js:3507:52)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (http://localhost:4200/polyfills.js:3267:43)
    at http://localhost:4200/polyfills.js:4006:34
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:3540:31)
    at Object.onInvokeTask (http://localhost:4200/vendor.js:64275:33)

这可以防止瓷砖首先加载。它不会每次都发生。大约十分之三的页面加载。如果平移或切换到 defaultLayers.vector.normal.map 图层,它将开始正确加载切片。

我正在使用 Angular 7.2.15 和 HERE API 3.1。

我正在通过以下方式初始化地图:

const platform = new H.service.Platform({ apikey: apiKey });
const defaultLayers = platform.createDefaultLayers();

const map = new H.Map(
  elementRef.nativeElement, // elementRef:ElementRef from directive constructor
  defaultLayers.raster.satellite.map,
  {
    zoom: 15,
    center: {lat: 0, lng:0}
  }
);

const behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));

const ui = new H.ui.UI(map);
const zoomControl = new H.ui.ZoomControl();
ui.addControl('zoom', zoomControl);

如何在卫星视图中加载地图而不会引发此错误?

标签: angulartypescripthere-apitangram

解决方案


该行为的一个可能问题是在加载网页后加载了一些 HERE JS 库。尝试稍后在代码中添加卫星层是否有更好的响应。

// default map base layer 
var map = new H.Map(document.getElementById('mapContainer'),
  defaultLayers.vector.normal.map,{
  center: {lat:52.5160, lng:13.3779},
  zoom: 13
});
// set base layer later 
map.setBaseLayer(defaultLayers.raster.satellite.map);

推荐阅读