-1

I am using this tutorial: https://docs.mapbox.com/help/tutorials/optimization-api/#getting-started and it allows a user to add points when they click on the map.

Does anyone know how to instead pass coordinates and then a route would be drawn?

mpora
  • 1,411
  • 5
  • 24
  • 65

1 Answers1

0

I had to modify the newDropoff() by passing coordinates

function newDropoff(coords) {
      // Store the clicked point as a new GeoJSON feature with
      // two properties: `orderTime` and `key`
      var pt = turf.point(
        [coords[0], coords[1]],
        {
          orderTime: Date.now(),
          key: Math.random()
        }
      );
      dropoffs.features.push(pt);
    }

and the looping through coordinates and calling newDropoff and updateDropoffs functions

 for (let i = 0; i < coords.length; i++) {
    newDropoff([coords[0], coords[1]]);
    updateDropoffs(dropoffs);
 }
mpora
  • 1,411
  • 5
  • 24
  • 65