dabreegster / route_snapper

Draw routes in MapLibre snapped to a street network using client-side routing
https://dabreegster.github.io/route_snapper
Apache License 2.0
138 stars 9 forks source link

Question: Draw route between two coordinates without UI #59

Open danielbeeke opened 2 months ago

danielbeeke commented 2 months ago

Should I import the WASM directly for this use case? or is there some method that would do this already?

dabreegster commented 2 months ago

You could use https://github.com/dabreegster/route_snapper/blob/bdb5e99e2b3db51518a9122fc17ea56b009cdb71/route-snapper-ts/src/index.ts#L219 in the TS library, then read out routeToolGj there. This is from the newer TS library that's on NPM, but sadly undocumented.

Or to avoid the maplibre dependencies entirely, just go through the WASM API, adding two snapped waypoints.

If your goal is to just calculate routes from OSM data in JS, using this project might be a heavyweight option, but it does work.