0

While upgrading HERE Maps API for Javascript to 3.1 version within this I am drawing polygon by connecting polylines I have replaced H.geo.Strip with 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);

Also replaced setStrip with setGeometry but getting error:

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

mona0295
  • 3
  • 3
  • I guess you are referring to HERE Maps API for Javascript 3.1. If so, please check the migration guide, maybe there's something useful there for you https://developer.here.com/documentation/maps/3.1.20.0/dev_guide/topics/migration.html – psxls Feb 15 '21 at 23:32
  • @psxls I am refering the same – mona0295 Feb 16 '21 at 08:32

1 Answers1

0

As per the documentation, H.map.Polygon.setGeometry function requires H.geo.Polygon | H.geo.MultiPolygon, therefore you need to create H.geo.Polygon which will be updated and then used as geometry for map 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);
})

Note: you can use H.geo.LineString.pushPoint function instead of Array.concat.

Tomas
  • 1,849
  • 1
  • 13
  • 13