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

paste geojson features #14

Merged
merged 1 commit into from
Sep 30, 2024
Merged

paste geojson features #14

merged 1 commit into from
Sep 30, 2024

Conversation

missinglink
Copy link
Collaborator

The GeoJSON Region Coverer is now much more tolerant of invalid/funky geometries, we might want to add an option to paste geojson:

Screenshot 2024-09-23 at 00 38 25 Screenshot 2024-09-23 at 00 35 33

@missinglink missinglink requested a review from bdon September 22, 2024 22:38
@missinglink
Copy link
Collaborator Author

There is a minor issue with this currently, if you paste geojson and then hit the up/down arrows on min/max cell it doesn't refresh like it does with drawing, unless you reload the json text area.

@@ -224,9 +224,12 @@ function App() {
const [maxCells, setMaxCells] = createSignal(200);
const [drawMode, setDrawMode] = createSignal("");
const [cellUnionText, setCellUnionText] = createSignal("");
Copy link
Owner

Choose a reason for hiding this comment

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

can we get away with a single textbox that detects if the input starts with { for GeoJSON?

@bdon
Copy link
Owner

bdon commented Sep 23, 2024

I think the GeoJSON needs to be loaded into terra-draw state so it is persistent, instead of just being parsed once when it is loaded from the text box.

@missinglink
Copy link
Collaborator Author

needs to be loaded into terra-draw state so it is persistent

hmm I just tried this and it's kinda tricky because terradraw attempts to validate the geometry:

Screenshot 2024-09-23 at 11 06 38
const feature = JSON.parse(jsonArea.value);
if (feature?.type !== "Feature") throw new Error("Invalid Feature");

feature.id = "ffaae8e0-cf4b-47f9-9cf2-4bcaa9826a2b";
feature.properties = { mode: "polygon" };

draw!.clear();
draw!.addFeatures([feature]);
computeCoveringForDraw();

It only seems to support a subset of the GeoJSON geometry types:

Screenshot 2024-09-23 at 11 13 43

@bdon
Copy link
Owner

bdon commented Sep 23, 2024

Can you normalize a MultiPolygon into a list of Polygon features, etc?

@missinglink
Copy link
Collaborator Author

Can you normalize a MultiPolygon into a list of Polygon features, etc

I tried this and it's difficult because terradraw still tries to validate the features according to the drawing mode, I couldn't get it to work.

So what I ended up doing is storing the features in another variable outside terradraw.

It works now, but feels kinda messy 🤷‍♂️

@missinglink missinglink force-pushed the geojson branch 2 times, most recently from f8eb032 to b5163f7 Compare September 24, 2024 21:44
@bdon bdon merged commit 82e7dd4 into main Sep 30, 2024
1 check passed
@bdon bdon deleted the geojson branch September 30, 2024 06:55
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.

2 participants