acteng / atip

Active Travel Infrastructure Platform
https://acteng.github.io/atip/
Apache License 2.0
22 stars 4 forks source link

Refactor Map state to be more declaritive #344

Closed stuartlynn closed 1 year ago

stuartlynn commented 1 year ago

I wanted to propose a potential code refactor that might make dealing with the map a little more declarative and less imperative and decouple the map based code from the specifics of the application.

Basically what I think we can do is

There are a few advantages to this approach

dabreegster commented 1 year ago

Huge +1 to this. Let us know how we can help!

Do something similar for base map changes which should now be a little easier as we have the layer definitions stored explicitly in the store and can re-apply them after the basemap changes nukes the style

Brilliant idea, I love this approach! The alternative is making every single component listen for the appropriate map lifecycle event and try to re-create state. This would be so much simpler.

It gets us closer to how svelte-maplibre works

Do you think we should go for this intermediate refactor first, or attempt to cutover to svelte-maplibre directly? My inclination is the former, since we can iterate faster without needing to fix things upstream. But ultimately I'd like to use much of the same code in other Turing projects, so common libraries somewhere would be nice.

If it makes the refactor any easier, this ATIP codebase is logically 3 different tools at this point -- the scheme sketching bit, the browse page, and a critical issue entry page. The critical issue page and the homepage (used for the scheme sketching) are the simplest / most self-contained. The browse page is big (many layers) but conceptually pretty simple. And the sketch tool is the most complicated, because it's managing both previously drawn objects and letting you select one, hide it from that main drawing layer, and enable a tool to edit its geometry. The selection logic being tied to behavior in the sidebar is also complicated there.

dabreegster commented 1 year ago

I found an old branch where I tried to use svelte-maplibre here. I'll start a list of blockers/problems just to write 'em down somewhere, but please let me know if that's more helpful to stick in a new issue!

None of these were blockers/huge; I just haven't taken the time yet to work on upstream fixes

stuartlynn commented 1 year ago

Thanks for the link here. I am tempted to say that we should fork the svelte-maplibre module, point these projects to our forked copy, try and resolve these issues in our version, try to get those fixes accepted back in to the offical branch and then revert back to using that.

I think thats the proper way of doing things but I sympathise with wanting to go with the move faster approatch.

I might spend a day seeing if I can find fixes for the issues you proposed and if not we can do a more imediate refactor on our code?

Sound good?

stuartlynn commented 1 year ago

Also thats annoying about typescript in the svelte templates... I didn't realise that was a thing :-(

dabreegster commented 1 year ago

@dimfield to confirm, but PRs in svelte-maplibre have gone through very quickly. If we provide high-quality fixes to the things above (none of which are at all unique to us), I imagine we could fix a few things upstream first. As we migrate more things here to svelte-maplibre, I'm sure we'll uncover more things and can keep iterating.

From a refactoring perspective here, it might be nice to chunk it up and completely cutover some of the simpler pages first?

stuartlynn commented 1 year ago

Yeah that makes sense for sure... though I wonder if tackling the most compliceted page first might help us more quickly indentify if there are any massive gotachas we can't currently anticipate. Would be good to know about these before we go through the work of doing the simpler pages and then potentially find that we have to abandon svelte-maplibre.

Both have their merits :-)

dabreegster commented 1 year ago

https://github.com/acteng/atip/tree/svelte_maplibre_v2 starts to port to svelte-maplibre for the browse page. There are some small problems I'm hitting; will either file issues or send quick PRs to fix. But overall it's working fine, and the code doesn't change too much from how it was before. I do have ideas for more refactoring that this might unlock, though

dabreegster commented 1 year ago

We've now cutover to svelte-maplibre! I've filed #359 to track smaller bugfixes and improvements that this unblocks