plugins
plugins copied to clipboard
Google-maps Polyline, add new point after polyline is added to map
trafficstars
Hello! I know how to add Polylines, works great.
However, after I do map.addPolyline({eg:etc});
I want to add more points to that same polyline afterwards.
Am I required to remove the Polyline and then add it back in or?
On the Polyline returned there is a getter/setter which returns or takes an array of points this can use to add the new points. I'll keep this open as I plan to add a method to push/add a single point rather than update all the points.
E.g:
When adding the initial Polyline,
this.surveyLine = {
points: [],
};
this.surveyLine.points.push({
lat: this.currentLocation.latitude,
lng: this.currentLocation.longitude,
});
this.surveyLine.visible = true;
this.surveyLine.geodesic = true;
this.surveyLine.width = 7;
// get the outcome of adding polyline and store
let surveyLine = this.mapView.addPolyline(this.surveyLine);
this.surveyLine = surveyLine;
Then inside some form of location watch or somewhere that you want to keep pinging new points to
// get the latest points
let points = this.surveyLine.points;
// Push to the array
points.push({
lat: this.currentLocation.latitude,
lng: this.currentLocation.longitude,
});
// set the array to the original Polyline
this.surveyLine.points = points;
```