Validate collection bboxes on create/edit and tolerate them on view#79
Open
alukach wants to merge 2 commits into
Open
Validate collection bboxes on create/edit and tolerate them on view#79alukach wants to merge 2 commits into
alukach wants to merge 2 commits into
Conversation
A collection or item whose bbox sits at the Web Mercator singularity (latitude ±90°, e.g. [-90, 90, -90, 90]) made fitBounds produce NaN center coordinates and an out-of-range tile request (.../22/1048576/0.png), crashing the map. Add a shared sanitizeBbox helper that drops non-finite corners and clamps lon/lat to ±180 / ±85.0511°, and call it from both CollectionMap and ItemMap before fitBounds. Also cap fitBounds at maxZoom and guard it in try/catch so a zero-area extent can't zoom absurdly or take down the app. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The schema-driven form validation only knew each bbox corner was a number, so geographically invalid or degenerate extents (out-of-range coords, south>north, zero-area boxes like [-90, 90, -90, 90]) could be saved and later crash the map. Add a shared inspectBbox/summarizeBboxIssues util ($utils/bbox) encoding the geographic rules: lon in [-180,180], lat in [-90,90], south<north, and non-zero area on both axes (west<east is NOT required so antimeridian-crossing bboxes stay valid). The collection EditForm now folds per-corner bbox errors into the Formik validation (keyed at spatial.<i>.<corner> so they render inline and block submit), and the collection detail page shows a non-blocking warning listing the problems when a stored extent is invalid. Unit-tested in bbox.test.ts. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What & why
A collection or item whose spatial extent is invalid or degenerate could be saved through the form and then crash the map when viewed. The triggering example was a bbox of
[-90, 90, -90, 90]— a zero-area point sitting at the Web Mercator singularity (latitude 90°), which madefitBoundsproduce NaN coordinates and request an out-of-range tile (.../22/1048576/0.png).This PR adds validation on both sides: block bad bboxes when creating/editing, and tolerate + warn about them when viewing.
Changes
Viewing (defensive)
sanitizeBbox/MERCATOR_MAX_LATincomponents/Map/bounds.ts: drops non-finite corners and clamps lon/lat to ±180 / ±85.0511°.CollectionMapandItemMaprun the bbox through it beforefitBounds, cap atmaxZoom, and guard the call intry/catchso a still-degenerate extent can't take down the app.Creating / editing (blocking)
$utils/bbox(inspectBbox/summarizeBboxIssues) encoding the geographic rules:[-90, 90, -90, 90]case)min === maxlongitude is degenerate.CollectionForm/EditForm.tsxfolds per-corner bbox errors into Formik validation, keyed atspatial.<i>.<corner>so they render inline on the offending input and block submit.Viewing (warning)
CollectionDetailshows a non-blocking banner listing the problems when a stored extent is invalid.Tests
bbox.test.ts— 13 unit tests covering ranges, ordering, zero-area, antimeridian, 3D (6-value) bboxes, and string coercion. Full client suite green (19 tests).Manual check
[-90, 90, -90, 90]in the new-collection form → inline errors block submit and the view scrolls to the invalid field.🤖 Generated with Claude Code