-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
535aa64
Start teasing apart the draw code's dependency on other parts of the
dabreegster 70179fd
Move draw logic that assigns new feature properties into config
dabreegster 521f332
Move some drawing-specific code into the appropriate directory
dabreegster f4f0e02
Make the draw tools deal with simpler types and almost entirely ignor…
dabreegster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import type { FeatureUnion } from "types"; | ||
import { | ||
newFeatureId, | ||
getArbitrarySchemeRef, | ||
gjSchemeCollection, | ||
} from "lib/draw/stores"; | ||
import type { FeatureWithAnyProps } from "lib/draw/types"; | ||
import type { Feature, LineString, Polygon, Point } from "geojson"; | ||
import { interventionName } from "lib/sidebar/scheme_data"; | ||
import { schema } from "stores"; | ||
import { get } from "svelte/store"; | ||
|
||
// The draw code should be agnostic to the feature properties that differ by | ||
// schema. Start centralizing the logic here, so it's easy for other users to | ||
// override. | ||
|
||
// TODO As an alternate idea, users could implement a custom Svelte store with methods for doing these things | ||
|
||
export let cfg = { | ||
interventionName: (f: FeatureWithAnyProps) => { | ||
return interventionName(f as FeatureUnion); | ||
}, | ||
|
||
newPointFeature: (f: Feature<Point>) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.update((gj) => { | ||
f.id = newFeatureId(gj); | ||
f.properties ||= {}; | ||
f.properties.scheme_reference = getArbitrarySchemeRef(gj); | ||
f.properties.intervention_type = "other"; | ||
// Typecast safe because we've established the invariants above | ||
gj.features.push(f as FeatureUnion); | ||
return gj; | ||
}); | ||
}, | ||
|
||
newPolygonFeature: (f: Feature<Polygon>) => { | ||
gjSchemeCollection.update((gj) => { | ||
f.id = newFeatureId(gj); | ||
f.properties ||= {}; | ||
f.properties.scheme_reference = getArbitrarySchemeRef(gj); | ||
f.properties.intervention_type = "area"; | ||
f.properties.is_coverage_polygon = false; | ||
// Typecast safe because we've established the invariants above | ||
gj.features.push(f as FeatureUnion); | ||
return gj; | ||
}); | ||
}, | ||
|
||
newLineStringFeature: (f: Feature<LineString>) => { | ||
gjSchemeCollection.update((gj) => { | ||
f.id = newFeatureId(gj); | ||
f.properties ||= {}; | ||
f.properties.scheme_reference = getArbitrarySchemeRef(gj); | ||
f.properties.intervention_type = "route"; | ||
if (f.properties.route_name) { | ||
if (get(schema) != "pipeline") { | ||
f.properties.name = f.properties.route_name; | ||
} | ||
delete f.properties.route_name; | ||
} | ||
// Typecast safe because we've established the invariants above | ||
gj.features.push(f as FeatureUnion); | ||
return gj; | ||
}); | ||
}, | ||
|
||
updateFeature: ( | ||
destination: FeatureWithAnyProps, | ||
source: FeatureWithAnyProps, | ||
) => { | ||
// Only copy route_name if the user hasn't set it. It's not simple to | ||
// distinguish the user manually editing the name from it being auto-filled | ||
// previously, so be safe and don't overwrite anything. The user can always | ||
// use the auto-fill button explicitly. | ||
if ( | ||
source.properties.route_name && | ||
!destination.properties.name && | ||
get(schema) != "pipeline" | ||
) { | ||
destination.properties.name = source.properties.route_name; | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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