You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m working with Leaflet Routing Machine and the OSRMv1 route, with the goal of optimizing HTTP requests to the OSRM server. To achieve this, I plan to embed OSRM data within the route data from the API, ensuring the frontend has all the necessary data and does not require a connection to the OSRM server. This approach will minimize duplicate requests and enable route rendering on the client side without further server interaction.
However, I’m facing challenges in transforming the OSRM response data into a format compatible with Leaflet Routing Machine. Here’s the current setup:
In the backend:
routingControl.on('routeselected', function (e) {
osrmDataToBeSent = JSON.stringify(e.route); // data sent to the client
});
According to this issue: #195
I understand that the JSON data received in the frontend, specifically the coordinates and waypoints properties, aren’t deserialized into an array of LatLng objects which will require a data transformation. The setAlternatives method expects setAlternatives(<IRoute[]> alternatives). As you can see here.
Frontend
I retrieve the data from localStorage which was fetched before, parse it, and transform it into an IRoute format:
Is setAlternatives the correct method? If not, what should I use to display pre-calculated routes?
Error with setAlternatives: Despite transforming data as required, I encounter errors. How can I resolve this?
Using Offline Data: Even if setAlternatives works, removing the router option from L.Routing.control defaults to the OSRM demo server, requiring an internet connection. How can I use offline data that has already been processed by an OSRM server?
Any help would be greatly appreciated. Thank you in advance!
The text was updated successfully, but these errors were encountered:
Hey @beMimg,
Apologies for the late reply, for some reason I didn't receive a notification for this issue. I'll have a look later and get back to you asap.
Yes, setAlternatives is still the way to go. It should be able to display the cached routes on a map without any requests
I think you're missing the waypointIndices or the inputWaypoints in your sample. One of those is needed to construct a PolyLine. If you cache those too (preferably the waypointIndices as they are smaller), it should work
Unfortunately, the only option I can see is implementing your custom router that has a cache in the middle between backend/OSRM and frontend. You can do this by extending the base OSRM implementation
Hello everyone, I hope you're having a great day!
I’m working with Leaflet Routing Machine and the OSRMv1 route, with the goal of optimizing HTTP requests to the OSRM server. To achieve this, I plan to embed OSRM data within the route data from the API, ensuring the frontend has all the necessary data and does not require a connection to the OSRM server. This approach will minimize duplicate requests and enable route rendering on the client side without further server interaction.
However, I’m facing challenges in transforming the OSRM response data into a format compatible with Leaflet Routing Machine. Here’s the current setup:
In the backend:
According to this issue: #195
I understand that the JSON data received in the frontend, specifically the coordinates and waypoints properties, aren’t deserialized into an array of LatLng objects which will require a data transformation. The setAlternatives method expects setAlternatives(<IRoute[]> alternatives). As you can see here.
Frontend
I retrieve the data from localStorage which was fetched before, parse it, and transform it into an IRoute format:
The resulting osrmDataTransformed looks like this (tried to make it smaller):
I want to create the routing using the data provided by my API, avoiding additional requests to the OSRM server. Here’s the routing control setup:
Issues and Questions:
Is setAlternatives the correct method? If not, what should I use to display pre-calculated routes?
Error with setAlternatives: Despite transforming data as required, I encounter errors. How can I resolve this?
Using Offline Data: Even if setAlternatives works, removing the router option from L.Routing.control defaults to the OSRM demo server, requiring an internet connection. How can I use offline data that has already been processed by an OSRM server?
Any help would be greatly appreciated. Thank you in advance!
The text was updated successfully, but these errors were encountered: