Here maps with Angular: 隐藏 UI 控件时出错

Here maps with Angular: error when hiding UI controls

我在 Angular 应用程序中使用了 HERE 地图。我已经关注了文档 to set it up

我想在地图上隐藏一些控件,主要是比例尺和缩放控件。但是,我收到 setEnabled is not a function 错误。

这是我的代码:

public ngAfterViewInit() {
  const defaultLayers = this.platform.createDefaultLayers();
  if (this.mapElement) {
  this.map = new H.Map(
    this.mapElement.nativeElement,
    defaultLayers.normal.map,
    {
      zoom: 10
    });

    this.ui = H.ui.UI.createDefault(this.map, defaultLayers, 'en-US');

    // This line throws a `setEnabled is not a function` error
    let scalebar = this.ui.getControl('scalebar').setEnabled(false);
  }
}

我正在做 what's written in the doc 所以我不明白为什么这行不通。有什么想法吗?

附加信息this.ui.getControl('scalebar') 并非未定义。而且我可以看到 setEnabled 方法不是原型的一部分。 (见截图)

如果您有以下行:

<link rel="stylesheet" type="text/css" href="http://js.api.here.com/v3/3.0/mapsjs-ui.css" />

在您的代码的头部,对其进行注释。 您将不会在地图上看到比例尺和缩放控件。 此行负责地图上的默认 UI 控件。

您可以使用以下代码行隐藏比例尺:

this.ui.getControl('scalebar').setVisibility(false)

旁注:

我在 API 参考中没有看到任何 setEnabled 方法,所以这可能是文档指南中的错字。

来源:H.ui.Control API reference