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

Start refactoring scheme sketcher code, before moving to a library #512

Merged
merged 4 commits into from
Jul 1, 2024

Conversation

dabreegster
Copy link
Contributor

I want to move the bulk of the scheme sketcher code into a new git repo, exposed as a Sveltekit library. The goal is to more easily use pieces of this from other projects, such as the inspectorate tools. It's not an easy refactor; the bulk of the core drawing logic is already in maplibre-draw-polygon and route-snapper, but the code here manages the toolbox, switches modes, manages the store with the GeoJSON features, etc.

Roughly the split of responsibility I picture is like this. The sketch library will handle lib/draw/ and parts of lib/sidebar -- giving people the mode switching logic, multi layer (scheme) management, sidebar controls, etc. What will remain in this repo (and have a new, much simpler variation in inspectorate tools) is per-schema forms, backfilling logic, etc. So the library shouldn't really care about feature properties beyond a few of the truly common ones.

This PR is a first step that makes lib/draw/ much more self-contained and starts teasing apart the types. I think even as a standalone refactor without doing the rest, it has some value. It's not complete -- the code still pulls in repo-wide map and userSetings stores, and I need to think through how to make the SchemeCollection type more generic. Assuming tests pass and there are no comments, I'll merge next time I work on this. A next step will probably be starting the new repo and discovering more tricky complications.

@@ -129,17 +126,7 @@
if (source.properties.waypoints) {
destination.properties.waypoints = source.properties.waypoints;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stuff staying here isn't domain specific; it comes from the route tool

return interventionName(f as FeatureUnion);
},

newPointFeature: (f: Feature<Point>) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The theme here is that these functions get a "mostly just geometry" object and then make it obey the invariants imposed by gjSchemeCollection. Some of the logic is common,but stuff like intervention_type and fiddling with route names is not.

| { mode: "set-image" }
| { mode: "streetview" };

// Properties are guaranteed to exist, but can be anything, so TS is mostly disabled
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed this to be more clear. By setting the properties this way, TS assumes any key can exist, with any type. (It's what we've been doing before; there's no change, just the name makes it more clear)

@robinlovelace-ate
Copy link
Contributor

This sounds great to me and should make it easier for others to use the very useful functionality, in UK and beyond!

@dabreegster dabreegster merged commit bc7949f into main Jul 1, 2024
2 checks passed
@dabreegster dabreegster deleted the ss_refactor branch July 1, 2024 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants