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

fix uploadArea: geojson with no features leading page crash error solve #1367

Closed

Conversation

NSUWAL123
Copy link
Contributor

What type of PR is this? (check all applicable)

  • πŸ• Feature
  • πŸ› Bug Fix
  • πŸ“ Documentation
  • πŸ§‘β€πŸ’» Refactor
  • βœ… Test
  • πŸ€– Build or CI
  • ❓ Other (please specify)

Related Issue

Describe this PR

This PR solves the page crash problem whenever a geojson with empty features is uploaded.

Screenshots

image

Alternative Approaches Considered

Did you attempt any other approaches that are not documented in code?

Review Guide

Notes for the reviewer. How to test this change?

Checklist before requesting a review

[optional] What gif best describes this PR or how it makes you feel?

@github-actions github-actions bot added the frontend Related to frontend code label Mar 20, 2024
@NSUWAL123
Copy link
Contributor Author

NSUWAL123 commented Mar 20, 2024

@varun2948 , @spwoodcock
Although this PR solves the page crash problem. But there may be hundreds of cases where the geojson can be invalid which can lead to page crash.
for example: if a user uploads this as a geojson;
{"type": "FeatureCollection"}

Since the geojson is invalid it leads to page crash. Now how to handle each of the cases in a good way to avoid page crashes? Wrapping every function and code to a try-catch block in vectorLayer file or what?

Can you give some suggestions. Also, geojson-validator doesn't work in this case.

@spwoodcock
Copy link
Member

Thanks for the detailed feedback!

This PR may not work well, as geojson is not necessarily a FeatureCollection.

We need to support Polygon, MultiPolygon, (maybe) GeometryCollection and FeatureCollection.

Like you say, is there a way to simply try catch the loading of the geojson File via OpenLayers?

If the loading works, but the crs is invalid, keep the existing message.

If loading fails though, then display a different message like: GeoJSON file is invalid

@spwoodcock
Copy link
Member

I think you may need to find where the geojson data is included as a source for the vectorlayer and find the place where the try catch must be.

If the error isn't triggered until the layer is rendered, there may be other ways to catch this issue.

For example using .getSource().getGeometry() and if there is no geometry return an error.

The error should probably be bubbled up to the project creation page and a more informative toast error displayed from there

@NSUWAL123 NSUWAL123 closed this Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Related to frontend code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

page crash while uploading AOI with no feature during project creation
2 participants