Skip to content

fix(deck.gl-geotiff): Select MosaicLayer sources whose bbox crosses the antimeridian - #752

Merged
kylebarron merged 4 commits into
mainfrom
kyle/mosaic-crossing-bbox
Oct 21, 2026
Merged

kylebarron merged 4 commits into
mainfrom
kyle/mosaic-crossing-bbox

Conversation

@kylebarron

@kylebarron kylebarron commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Note

This PR was written by Claude (Claude Code), not by @kylebarron.

Closes #749.

MosaicLayer never drew a source whose bbox crosses the antimeridian when the bbox is written with minX > 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:

  • unwrapBbox moves the east edge of a crossing bbox one world east, so [179, -20, -179, -17] becomes [179, -20, 181, -17]. That's the form getGeographicBounds already returns.
  • splitAtAntimeridian splits such bounds into two within [-180, 180].

buildSourceIndex indexes both halves and keeps a Uint32Array, boxToSource, that maps each box back to its source. The Flatbush and the mapping are stored together in layer state as a SourceIndex, which MosaicTileset2D reads through its existing getIndex closure. getTileIndices maps each hit back to its source before the Set that merges matches. searchBounds from #639 now splits the viewport's bounds with the same splitAtAntimeridian.

The rest of MosaicLayer handles such a bbox too:

  • The extent filter 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.
  • getTileMetadata gives deck.gl the unwrapped bbox (east edge 181 for -179), since deck.gl's request priority and picking cull check expect west < east.
  • The fetch priority uses the unwrapped bbox's center: [179, -20, -179, -17] is centered at 180°, not 0°.

The MosaicSource.bbox docstring now says a bbox may cross the antimeridian with minX > maxX, and dev-docs/world-copies.md says how it's indexed. Follow-up to #639.

Tests

The new MosaicTileset2D with a bbox across the antimeridian tests use real WebMercatorViewport and _GlobeViewport instances and a source with bbox [179, -20, -179, -17]. They check that the source is:

  • selected in Web Mercator with and without repeat, and on a globe, each centered at 179.9° and -179.9°
  • not selected with the view centered at 0°
  • kept for an extent over either half, and dropped for one elsewhere
  • given to deck.gl as {west: 179, south: -20, east: 181, north: -17}

A new MosaicLayer fetch priority test checks that the source gets priority 0.1 with the viewport at 179.9°.

Breaking either helper fails tests. If unwrapBbox doesn't unwrap, the 10 new tests that depend on it fail. If splitAtAntimeridian doesn'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 MosaicLayer of the antimeridian.tif fixture (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, getTileIndices takes 0.06 ms in a normal view, as on main. With every source in view and an extent set it takes 0.75 ms (main: 0.69 ms).

pnpm -r --filter="!docs" typecheck, the deck.gl-geotiff tests and biome check pass.

🤖 Written by Claude Code

…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]>
@github-actions github-actions Bot added the fix label Oct 21, 2026
Comment thread dev-docs/world-copies.md
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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

👍

/** Flatbush index of the sources' boxes. */
boxes: Flatbush;
/** For each box in `boxes`, the position of its source in `sources`. */
sourceOfBox: Uint32Array;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't really love the name sourceOfBox. Perhaps boxIndex?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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],
];
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

perhaps this should be generalized. Is there any other code that currently does this?

kylebarron and others added 3 commits October 20, 2026 22:46
`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]>

@kylebarron kylebarron left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

lgtm

@kylebarron
kylebarron merged commit 15834c2 into main Oct 21, 2026
4 checks passed
@kylebarron
kylebarron deleted the kyle/mosaic-crossing-bbox branch October 21, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MosaicLayer never selects a source whose bbox crosses the antimeridian

1 participant