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))
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.