-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rendering Routes from JSON Data without OSRMv1 #707
Labels
Comments
Hey @beMimg, |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: