Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapping to roads #1

Open
dabreegster opened this issue Nov 17, 2022 · 5 comments
Open

Snapping to roads #1

dabreegster opened this issue Nov 17, 2022 · 5 comments

Comments

@dabreegster
Copy link

Hi! I just watched your FOSS4G talk and wow, releasing this library couldn't have come at a better time for me. I've been working on a tool to quickly sketch line-strings that snap to some kind of network. Right now my approach hacks on top of mapbox-gl-draw, and every time I peek into its codebase to figure out how a proper integration would work, I'm daunted by the complexity (and not inspired by the backlog of PRs the repo is accumulating). I'd love to explore building on top of terra-draw instead (and reap the benefits of Leaflet support too!)

You can try the tool so far here. After it loads, click the button on the right. If you're curious about the implementation, see https://github.com/acteng/atip/tree/main/route-snapper. I'm new to modern web dev (and sticking to vanilla JS so far). Most of the logic is happening in a Rust layer right now, compiled to WASM. That's mostly due to convenience for me (it's a very familiar language) -- the code is simple enough to write in JS or TS for sure, and the speed is probably fine. The routing itself works off a static network loaded once from a file, so it's bound to a fixed area. When that area gets large enough, contraction hierarchies or a similar graph preprocessing technique might be worth trying instead of A*. And in that case, I'd lean heavily towards just building something like https://github.com/easbar/fast_paths/ to WASM.

I have more ideas about snapping based on arbitrary data preprocessed from OSM, like drawing areas that can snap to the edge of roads or waterways. There's a whole space of techniques for getting the idea to work outside of a fixed area too... I'll probably be exploring tiling and dynamically generating the networks soon. (The latter idea would be something like an Overpass query to extract OSM data wherever the viewport is, then piping through a Rust library to turn into the right kind of network).

Anyway, I'll keep a close eye on this repo as it evolves. From a quick skim, I'd be way more comfortable making a proper integration with this than mapbox-gl-draw. Let me know if you have any plans around snapping that might be relevant!

@JamesLMilner
Copy link
Owner

Hey @dabreegster thanks for your interest and feedback! It seems like a great use case for terra-draw. The LineString mode does have some builtin basic snapping functionality which can be turned on by setting snapping: true in the mode constructor.

To snap to some other layer, you may need a custom mode or two but I don't think it's an unreasonable amount of work. Terra Draw has the concept of 'render modes' which are essentially layers that can be rendered to the map, but don't explicitly have a way of adding new geometries to them via drawing. In theory you could create a render mode with no styling if you wanted an invisible layer to snap to via another custom linestring layer. There may be some complexities/performance problems with the amount of data but if it's not being rendered this may not be a limiting problem.

I am looking to implement some documentation around writing custom modes that would probably make this process easier - hopefully I can get round to that soon!

@dabreegster
Copy link
Author

I'm tracking this in dabreegster/route_snapper#17. Haven't forgotten it, but not time yet to try it out. I am separately considering moving one of my active projects, https://github.com/acteng/atip, to terra-draw, and if that happens, I'll definitely prioritize this

@howllian27
Copy link

Hi @JamesLMilner I was wondering if you have any updates on whether you intend on incorporating a route snap mode into terra-draw any time soon. Was thinking it's a great use case for terra-draw and I'll love to hear whether you have any plans on doing so!

@JamesLMilner
Copy link
Owner

Hey @howllian27 - At the moment there are no plans to support this directly in Terra Draw, but I may look and see if the route snapping mode created for https://github.com/JamesLMilner/terra-draw-route-snap-mode could be turned into it's own package for others to use. Hope this helps!

@dabreegster
Copy link
Author

Just mentioning that the prototype mentioned in the first comments here is a proper NPM package now, https://github.com/dabreegster/route_snapper/. The "new route" tool at https://acteng.github.io/atip/pipeline/scheme.html?authority=TA_North+Lincolnshire is a better demo than the one linked from NPM. Gluing to Terra Draw as a frontend could still be a nice idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants