leaflet-routing-machine icon indicating copy to clipboard operation
leaflet-routing-machine copied to clipboard

Route rendering performance

Open Evaldas-B opened this issue 5 years ago • 4 comments

Depending on the route it can take quite a while to render the route even if the route is generated. For example route from Portugal to Estonia takes ~200ms to get rendered. Quite an extreme case but still this is a viable scenario.

It doesn't seem that OSRM server is the bottleneck here because the call to the server is only made once and visibility of the route is controlled using marker.options.route.addTo(map) marker.options.route.remove()

I feel that the ideal solution would be to render the route once and control its visibility with display: none or setting blank markers with route opacity set to 0.

The problem is that the only way to control the visibility of route and markers is with addTo(map) and remove(). As far as I am aware there is no other way to control this dynamically as mentioned in #584

Edit 1 Also, there is a warning: [Violation] 'load' handler took 178ms

Update 2 Ok, my bad. So the latency is caused due to communication between the frontend app and OSRM server. Every single time I use route.addTo(map) request is sent to OSRM server. I guess the solution here is to save the route in the database and pass it along with the main marker coordinates and when it is retrieved from database save it in marker variable for repeated use. Similar behavior is mentioned in #195

Am I missing something here?

I have gutted my Vue app made a simple example with pure js.

Evaldas-B avatar Aug 21 '20 21:08 Evaldas-B

Hi, I'm not really sure what the use case here is? Do you mean you switch the entire control on/off by adding and removing it, or when is the route recalculated?

perliedman avatar Sep 15 '20 12:09 perliedman

When mouse is over a marker the route should be displayed, when the mouse leaves the marker the route should be removed.

Evaldas-B avatar Sep 15 '20 14:09 Evaldas-B

Ok, sounds like something you would want to build a custom implementation for. You might want to use the L.Routing.Line class directly to do this instead of adding and removing the control. If you have an L.Routing.Line instance, adding it to or removing it from the map should be very quick.

perliedman avatar Sep 16 '20 18:09 perliedman

Yeah, that makes a lot of sense. So basically what I am doing is I am sending two points from my backend to OpenRouteService and saving the response(GeoJSON) and then passing it to frontend. I am using L.Routing.Line as you mentioned. It is a lot faster because OpenRouteService is only queried once.

Thank you for your response. I enjoyed using LeafletRoutingMachine. Great job.

Evaldas-B avatar Sep 16 '20 19:09 Evaldas-B