Avoid coordinates when generating a route using Mapbox Direction API

I may be rough-guessing here, but looking through Mapbox API it does not have any options to avoid while generating routes, therefore you need to implement some route-selection logic on client-side.

Basically you need to have an algorithm which gets a set of points to avoid and checks if your Route geometry GeoJSON or Polyline are within some threshold range from given points. If it is - discard the route (or lower route priority).

Of course it may fail to find a route if all routes provided by Mapbox are discarded - Mapbox does not know about your restrictions, therefore using weight for routes could be one option of solving this.

These posts might give you some hints:

  • Is it possible to determine if a GeoJSON point is inside a GeoJSON polygon using JavasScript
  • How to check if a Latitude/Longitude point is on the GRoute in Google Maps API