0
votes

I am trying to work with the Mapbox Directions plugin. I have found no documentation for the various controls indicated in the example here:

https://www.mapbox.com/mapbox.js/example/v1.0.0/mapbox-directions/

The Inputs control doesn't work well at all so I'm using my own control and have got it to display the origin and destination markers, route highlight, and instructions using code similar to this:

        var loStartLatLng = L.latLng(53.5, -113.5);
        var loEndLatLng = L.latLng(53.5012, -113.5012);

        var loDirections = L.mapbox.directions({
            profile: 'mapbox.driving'
        });

        loDirections.setOrigin(loStartLatLng);
        loDirections.setDestination(loEndLatLng);
        loDirections.query();

        var loDirectionsLayer = L.mapbox.directions.layer(loDirections).addTo(moMap);
        var loDirectionsErrorsControl = L.mapbox.directions.errorsControl('divRouteErrors', loDirections);
        var loDirectionsRoutesControl = L.mapbox.directions.routesControl('divAlternateRoutes', loDirections);
        var loDirectionsInstructionsControl = L.mapbox.directions.instructionsControl('divRouteInstructions', loDirections);

I have not found documentation for any of the above controls. One thing I absolutely must be able to change is the instructions' units. It currently outputs in imperial/English/us units but I need to be able to toggle to metric for some customers. How can I do this?

Thanks in advance,

Tony

2

2 Answers

1
votes

The documentation for mapbox-directions.js can be found in the API.md file in the repo. Keep in mind that this plugin is very much still in development and changes often (it is pre-1.0).

You are right about unit control -- it was added after the release of 0.3.0 so it does not appear in the library in the CDN right now. One of the directions team developers just told me that there will be a new release of mapbox-directions.js tomorrow (yay!) and unit control will be included!

In terms of the inputs control, it doesn't take addresses/POIs, but lat/lon pairs. In the example, you have to click on the map to set a start location and then click on it again to set a destination location. The control will automatically populate with the lat/lon pairs and return a list of directions between them.

0
votes

Try: L.mapbox.directions({units: 'metric'}); I also couldn't find any documentation but looked at the repo and immediately found this push request from juni 13th.