在 HERE Maps API 中获取 InvalidArgumentError for Javascript 3.1 升级

Getting InvalidArgumentError in HERE Maps API for Javascript 3.1 upgrade

在将 Javascript 的 HERE Maps API 升级到 3.1 版本时,我正在通过连接折线绘制多边形 我已将 H.geo.Strip 替换为 H.geo.LineString

var point = _this.map.screenToGeo(e.currentPointer.viewportX, e.currentPointer.viewportY);

var strip = new H.geo.LineString(_this.growingStrip.getLatLngAltArray().concat(point.lat, point.lng, point.alt));
_this.growingShape.setGeometry(strip);

也将 setStrip 替换为 setGeometry 但出现错误:

Uncaught InvalidArgumentError: H.map.Polygon#setGeometry (Argument #0 LINESTRING (-74.58221773042507 40.50631688766448,-74.5725439612637 40.50650019704824,-74.60575039389293 40.50943486497609))

根据 documentationH.map.Polygon.setGeometry 函数需要 H.geo.Polygon | H.geo.MultiPolygon,因此您需要创建 H.geo.Polygon,它将被更新,然后用作地图多边形的几何图形:

var growingLineString = new H.geo.LineString([0, 0, 0, 10, 10, 0, 10, 0, 0]),
    growingPolygon = new H.geo.Polygon(growingLineString),
    growingShape = new H.map.Polygon(growingPolygon);

map.getViewModel().setLookAtData({
  center:{lat: 0, lng:0}, 
  zoom: 5
});
map.addObject(growingShape);

map.addEventListener('tap', (e) => {
  var p = e.currentPointer,
      point = map.screenToGeo(p.viewportX, p.viewportY);

  growingLineString.pushPoint(point);
  growingPolygon.setExterior(growingLineString);

  growingShape.setGeometry(growingPolygon);
})

注意:您可以使用H.geo.LineString.pushPoint函数代替Array.concat。