0

So i was creating a polyline to use it in another place but after creating the instance the polyline is getting al mixed up its may be due to linestring or what?

var points = [
      { lat: 52.5309825, lng: 13.3845921 },
      { lat: 52.5311923, lng: 13.3853495 }];

var linestring = new H.geo.LineString();
points.forEach(function(point) {
  linestring.pushPoint(point);
});

// Initialize a polyline with the linestring:
var routeLine = new H.map.Polyline(linestring);```

[![if i give multiple polyline inputs the previous one is geting attached][1]][1]

Image of mixed output polylines:
  [1]: https://i.stack.imgur.com/jPrHq.png
Harsha
  • 74
  • 1
  • 10
  • 1
    What exactly is getting mixed up? I tried your code and map rendered correct polyline: https://prnt.sc/qc0r2m – Tomas Dec 17 '19 at 12:23
  • i tried to create an instance of polyline and used the instance in another place but linestring is not taking new instance – Harsha Dec 17 '19 at 12:33
  • Can you share also the code how you use the instance of polyline in another place? – Tomas Dec 17 '19 at 13:29

2 Answers2

1

I think what you're looking for is setGeometry method on H.map.Polyline object. Here is a sample code which creates Polyline with one LineString and then updates Polyline's geometry with second LineString after 2 seconds:

var points1 = [
      { lat: 52.5309825, lng: 13.3845921 },
      { lat: 52.5311923, lng: 13.3853495 }];
var points2 = [
      { lat:52.532015,lng:13.385634 },
      { lat:52.531441,lng:13.386225 }];
var linestring1 = new H.geo.LineString();
var linestring2 = new H.geo.LineString();

points1.forEach(function(point) {
  linestring1.pushPoint(point);
});

var routeLine = new H.map.Polyline(linestring1);

// update polyline's geometry 
setTimeout(function() {
  routeLine.setGeometry(linestring2);
}, 2000);
Tomas
  • 1,849
  • 1
  • 13
  • 13
0

So, i have created a lineString instance and a polyline instance.when i want to overwrite this polyline i have used another new lineString instance with the previous polyline instance. this made to get new routing every time i enter two different places

Harsha
  • 74
  • 1
  • 10