perliedman / leaflet-routing-machine

Control for routing in Leaflet
https://www.liedman.net/leaflet-routing-machine/
Other
1.08k stars 350 forks source link

How to export a route as GeoJSON #560

Closed erlangparasu closed 4 years ago

perliedman commented 4 years ago

It's not entirely clear what you want, given that you have just written a title, so I have to guess you want to export a route as GeoJSON.

You can achieve this by listening to the routeselected event on the control. When a route is selected, it will fire and the event's route property will contain the actual route. While there isn't a method to turn the route into GeoJSON, you can extract the route's coordinates from route.coordinates, it's an array of L.LatLng objects that you for example can turn into a LineString geometry. You can also access the waypoints, if you need to serialize them as well.

erlangparasu commented 4 years ago

thanks sir @perliedman :) :+1: