I have a loop where I add lat/long points to polygonLines array
var polygonlines = [];
for (var k = 0; k < lines.length; k++) {
var start = [Number(lines[k].start.lat), Number(lines[k].start.lng)];
var end = [Number(lines[k].end.lat), Number(lines[k].end.lng)];
polygonlines.push(new L.Geodesic([[start, end]], geodesicOptions));
}
I need to get the array of polygonlines into a turf.polygon, I can get from a JSON data of coordinates to turf.polygon easily
var turfPolygon = turf.polygon([[
json.data.features[0].geometry.coordinates
]], ...
how can I get from my polygonlines array to JSON data coordinates? Or can I create polygonlines as json data and push the lines onto it in the loop? How do I add items to json coordinates I have never used json data before?
Or is there a better way?
Thank you very much
Edit: I want to be able to put the polygonlines into the json... possibly like this. All the examples have hard coded values, but my values will change through user interaction.
var geojsonPolygon =
{
"type": "geojson",
"data":
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [polygonlines]
}
}
}
I've never used json object before so not sure how to copy an array into the coordinates part.
Then use turf booleanIntersect which requires a "GeoJSON Feature or Geometry"
So don't use Geodesic for the lat/long point, this will do
var start = [vol.lines[k].start.lng, vol.lines[k].start.lat];
polygonlines.push(start);
then
var geojsonPolygon =
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [polygonlines]
}
var turfpolygon = turf.polygon(geojsonPolygon.geometry.coordinates);
var result = turf.booleanIntersects(line, turfpolygon);
This will match poly1 in this example that is really helpful https://codesandbox.io/s/ripkk