I am making a request to a service in which the following information is returned:
{
"orden": 0,
"idlinea": 1,
"idtrayecto": 1,
"utmy": 4824500,
"utmx": 281405
},
{
"orden": 1,
"idlinea": 1,
"idtrayecto": 1,
"utmy": 4824470,
"utmx": 281416
},
{
"orden": 2,
"idlinea": 1,
"idtrayecto": 2,
"utmy": 4824481,
"utmx": 281495
},
{
"orden": 3,
"idlinea": 1,
"idtrayecto": 2,
"utmy": 4824487,
"utmx": 281540
}
...
And this is increasing until all the lines with their respective routes are finished.
I would like to group the content, such that for line 1, path 1, I get the entire group of coordinates. And so on.
At the moment I have obtained the unique values of the lines and the paths like this:
let distinctValues = []
let infoRoute = {
line: null,
journey: null,
coordinates: []
}
data.forEach((route) => {
if (route.idlinea != infoRoute.line || route.idtrayecto != infoRoute.journey) {
infoRoute.line = route.idlinea;
infoRoute.journey = route.idtrayecto;
distinctValues.push([infoRoute.line, infoRoute.journey])
}
});
With this I get: [[1,1], [1,2], [1,3], [2,1]...]
You could try a hashmap where the name of the array value is made up of lineid and pathid.
To get any route it is only necessary to call
mapped[idruta + '.' + idtrayecto]
.