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
135 stars 9 forks source link

Separate backend and frontend more #4

Open dabreegster opened 1 year ago

dabreegster commented 1 year ago

The graph and actual routing is dirt simple. I don't want to get into the business of adding tons of options here, instead encourage people to build their own graphs + cost functions however they want. Also, not tied to the local-WASM approach either -- hitting a remote server for requests is fine too. The frontend JS logic should be totally independent from the backend.

dabreegster commented 1 year ago

@chriswhong raised the idea of using vector tiles, which're already loaded, to do this. I haven't worked with the MVT format much before, but from a glance, things like roads are encoded as polylines, and so share a point when they meet at an intersection. So there is enough to make the basic graph structure needed.

Some possible steps to explore this:

1) Figure out the API to read all vector tiles currently in view 2) Scrape the road polylines from that 3) Decide on an encoding scheme and pass to the WASM RouteSnapper

More about the third... right now the Rust code takes a bincoded version of this graph here. I'm not sure this encoding is standard, but we could switch to / also handle anything serde supports. JSON might be the simplest and maybe performant enough.

carlosrziegler commented 1 year ago

Maybe you can use t-rex to do it: https://t-rex.tileserver.ch/ Here is more examples to implement MVT: https://github.com/mapbox/awesome-vector-tiles

dabreegster commented 1 year ago

t-rex could maybe help if we go down the route of trying to tile the graph files (#7). I'll have a look through the MVT libraries. If MapLibre is loading tiles covering the viewport already and there are line-strings in there, it should be possible to turn them into a graph on-the-fly

dschep commented 1 year ago

As I mentioned on reddit, I would be happy with client side graph generation from a GeoJSON file. For the purposes of this project, that might serve as a good MVP for client-side graph generation 🙂

dabreegster commented 1 year ago

As I mentioned on reddit, I would be happy with client side graph generation from a GeoJSON file. For the purposes of this project, that might serve as a good MVP for client-side graph generation

Maybe something like a static method RouteSnapper.geojsonToGraph(geojson) would be useful? The input would just be a bunch of line-strings, already split at intersections (like a graph) or should that be something the helper function does?

dabreegster commented 1 year ago

Also if the area you want to cover is fixed, for perf reasons it's probably best to do this conversion once and just load the binary graph file. So maybe this is instead a command-line tool that takes a .geojson file.

dschep commented 1 year ago

It would be useful, but yeah. you're right, might as well just run the conversion. Hopefully I'll have time to try it out soon 🤞

dabreegster commented 1 week ago

Just following up if the PRs weren't clear, importing GeoJSON was done in #49. See https://github.com/dabreegster/route_snapper/blob/main/user_guide.md#from-custom-geojson-files