gis-ops / routingjs

Library for consistent access to various vehicle routing APIs
https://gis-ops.github.io/routingjs/
MIT License
44 stars 4 forks source link

Add convenience methods to Directions/Matrix/Isochrone #2

Open chrstnbwnkl opened 1 year ago

chrstnbwnkl commented 1 year ago

As of now, I've adapted an approach similar to routingpy's when it comes to parsing the response and making the returned coordinates easily accessible. I think that in browsers, memory is more of a concern, so I propose to not parse the response by default and thereby ending up with a lot of duplicate data, but instead providing the parsing as a static method that can be optionally called:

v.directions(
    [
        [8.512516, 47.380742],
        [8.557835, 47.359467],
    ],
    "auto"
).then((d) => {
    L.GeoJSON(d.toFeatureCollection()).addTo(map)  // e.g. if you want to display the results in Leaflet
})

We could even attach more attributes to the features than the common ones we're making accessible in routingpy right now (distance and duration), depending on the router's response.

nilsnolde commented 1 year ago

I propose to not parse the response by default

Hm, how about the other way around? I mean, we could only keep the raw response if specifically requested (and default to false), but keep parsing? But I'm not really familiar how this package does it right now, we can talk about it in the next days.