1

Goal: find the GeoJSON points in a web map that are closest to a directions route using turf.js.

I am using the Mapbox Directions plugin. I am following this example.

How do I work with the route that is the output of the directions request?

Is there are way to get the route line in GeoJSON format to perform typical Mapbox functions on it?

1

From the example you linked to, there is a directions layer on the map.

var directionsLayer = L.mapbox.directions.layer(directions)
.addTo(map);

The directions layer extends a leaflet LayerGroup, which from the leaflet documentation, has a function called toGeoJSON. So I would recommend trying something like:

var directions_geojson = directionsLayer.toGeoJSON();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.