Repository navigation
fix(deck.gl-geotiff): Select MosaicLayer sources whose bbox crosses the antimeridian - #752
Merged
Merged
Conversation
…he antimeridian A bbox across the antimeridian, written with minX > maxX as GeoJSON and STAC do, was an inverted box to Flatbush, so MosaicLayer only selected the source when nearly the whole world was in view. It's now indexed as two boxes, one on each side, with a box -> source mapping kept with the index. The rest of MosaicLayer handles such a bbox too: the `extent` check tests both halves, `getTileMetadata` gives deck.gl an east edge one world east (deck.gl expects west < east), and the fetch priority centers the bbox on the antimeridian instead of the prime meridian. Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron
commented
Oct 21, 2026
Comment on lines
+114
to
+116
| A source whose bbox crosses the antimeridian, written with `minX > maxX` as in | ||
| GeoJSON and STAC, is indexed as two boxes, one on each side of it. | ||
|
|
| /** Flatbush index of the sources' boxes. */ | ||
| boxes: Flatbush; | ||
| /** For each box in `boxes`, the position of its source in `sources`. */ | ||
| sourceOfBox: Uint32Array; |
Member
Author
There was a problem hiding this comment.
I don't really love the name sourceOfBox. Perhaps boxIndex?
Member
Author
There was a problem hiding this comment.
Though then we're overloading the term index as both spatial index and index within an array
Comment on lines
+203
to
+217
| /** | ||
| * Split a bbox across the antimeridian, written with `minX > maxX`, into one | ||
| * box on each side. Any other bbox is returned as it is. | ||
| */ | ||
| function splitAtAntimeridian(bbox: Bounds): Bounds[] { | ||
| const [minX, minY, maxX, maxY] = bbox; | ||
| if (minX <= maxX) { | ||
| return [bbox]; | ||
| } | ||
| return [ | ||
| [minX, minY, 180, maxY], | ||
| [-180, minY, maxX, maxY], | ||
| ]; | ||
| } | ||
|
|
Member
Author
There was a problem hiding this comment.
perhaps this should be generalized. Is there any other code that currently does this?
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`unwrapBbox` moves the east edge of a bbox across the antimeridian one world east, so `getTileMetadata`, the fetch priority, the index and the `extent` check all use one helper instead of repeating the expression. `splitAtAntimeridian` now takes such unwrapped bounds, so `searchBounds` reuses it to split the viewport's bounds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y bboxes The `extent` check runs for each matched source on every call, and copying and splitting every bbox made it 0.42 ms slower than main with 10,000 sources in view. Only a bbox across the antimeridian is split now, which leaves it within 0.06 ms of main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Note
This PR was written by Claude (Claude Code), not by @kylebarron.
Closes #749.
MosaicLayernever drew a source whose bbox crosses the antimeridian when the bbox is written withminX > maxX, as GeoJSON (RFC 7946 §5.2) and STAC write it. Flatbush treats such a bbox as an inverted box, so it only matched a search that covered nearly every longitude.Fix: two helpers in
mosaic-tileset-2d.ts:unwrapBboxmoves the east edge of a crossing bbox one world east, so[179, -20, -179, -17]becomes[179, -20, 181, -17]. That's the formgetGeographicBoundsalready returns.splitAtAntimeridiansplits such bounds into two within [-180, 180].buildSourceIndexindexes both halves and keeps aUint32Array,boxToSource, that maps each box back to its source. The Flatbush and the mapping are stored together in layer state as aSourceIndex, whichMosaicTileset2Dreads through its existinggetIndexclosure.getTileIndicesmaps each hit back to its source before theSetthat merges matches.searchBoundsfrom #639 now splits the viewport's bounds with the samesplitAtAntimeridian.The rest of
MosaicLayerhandles such a bbox too:extentfilter keeps the source if either half overlaps the extent. An ordinary bbox is tested without splitting, since this runs for each matched source on every call.getTileMetadatagives deck.gl the unwrapped bbox (east edge 181 for -179), since deck.gl's request priority and picking cull check expect west < east.[179, -20, -179, -17]is centered at 180°, not 0°.The
MosaicSource.bboxdocstring now says a bbox may cross the antimeridian withminX > maxX, anddev-docs/world-copies.mdsays how it's indexed. Follow-up to #639.Tests
The new
MosaicTileset2D with a bbox across the antimeridiantests use realWebMercatorViewportand_GlobeViewportinstances and a source with bbox[179, -20, -179, -17]. They check that the source is:repeat, and on a globe, each centered at 179.9° and -179.9°extentover either half, and dropped for one elsewhere{west: 179, south: -20, east: 181, north: -17}A new
MosaicLayer fetch prioritytest checks that the source gets priority 0.1 with the viewport at 179.9°.Breaking either helper fails tests. If
unwrapBboxdoesn't unwrap, the 10 new tests that depend on it fail. IfsplitAtAntimeridiandoesn't split, 8 tests fail, including #639's tests for sources on both sides of the antimeridian.In Chrome, through MapLibre with an interleaved deck.gl overlay, a
MosaicLayerof theantimeridian.tiffixture (bbox[156, -18, -162, 24]) centered at 180° now draws across the antimeridian in Mercator and on the globe. On main it isn't selected in either. On the globe, main can still draw it right after the page loads, until the first pan.With 10,000 sources,
getTileIndicestakes 0.06 ms in a normal view, as on main. With every source in view and anextentset it takes 0.75 ms (main: 0.69 ms).pnpm -r --filter="!docs" typecheck, the deck.gl-geotiff tests andbiome checkpass.🤖 Written by Claude Code