Hi, I'm new to Java Script and ReactJS, and I'm currently working on a project to enhance my skills. One of the tasks in this project involves rendering polygonal points on a map using the google-maps-react
library.
However, I encountered an issue with the format of the coordinates required by the library for plotting polygons. The data format that I have is different from what is expected by the library:
[
[
[-47.7027099655629, -22.26485424139211],
[-47.70271526762656, -22.26487408404245],
[-47.70272860122938, -22.26486817968162],
[-47.70275769033151, -22.26485486960603],
[-47.7027803963492, -22.26483968832534],
[-47.7027099655629, -22.26485424139211]
]
], [
[
[-47.70336262481528, -22.26561084941619],
[-47.70336542334331, -22.26561213882109],
[-47.70336596593334, -22.26561211173161],
[-47.7033695288571, -22.2656092720629],
[-47.70337969579747, -22.26560034650085],
[-47.70336262481528, -22.26561084941619]
]
]
I'm looking for a JavaScript function or method that can help me transform my coordinate array into the correct format expected by the google-maps-react
library. The desired output should look like this:
const coords = {
coords: [
[
{ lat: -47.7027099655629, lng: -22.26485424139211 },
{ lat: -47.70271526762656, lng: -22.26487408404245 },
{ lat: -47.70275769033151, lng: -22.26485486960603 },
{ lat: -47.7027803963492, lng: -22.26483968832534 },
{ lat: -47.7027099655629, lng: -22.26485424139211 },
],
[
{ lat: -47.70336262481528, lng: -22.26561084941619 },
{ lat: -47.70336542334331, lng: -22.26561213882109 },
{ lat: -47.70336596593334, lng: -22.26561211173161 },
{ lat: -47.70337969579747, lng: -22.26560034650085 },
{ lat: -47.70336262481528, lng: -22.26561084941619 },
],
],
};
With almost eight thousand lines of data, manually converting each coordinate is not feasible. So, I am seeking a solution to automate this process.
You can find the original data file I am attempting to use here:
Thank you for your help!