Skip to content

feat: antimeridian support - #673

Closed
willjnz wants to merge 21 commits into
developmentseed:kyle/antimeridian-crossingfrom
willjnz:willjnz/antimeridian-crossing-fixes
Closed

willjnz wants to merge 21 commits into
developmentseed:kyle/antimeridian-crossingfrom
willjnz:willjnz/antimeridian-crossing-fixes

Conversation

@willjnz

@willjnz willjnz commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Expanding upon #576. Fixes #171. This PR doesn't stick to the vertical cut limitation. Inspired by #269.

The problem: the map's x runs from −180° to +180° and repeats every 360°. proj4 always gives
back a point inside that range, so an image that crosses 180° gets its east half put on the
far side of the map, and its triangles stretch across the whole world.

The problem looked like this (visualising 1 antimeridian-crossing, and 1 non-crossing COG from EPGS:3832): bad am before

Key steps to solve this problem:

  1. Unwrap the mesh: packages/raster-reproject/src/delatin.ts (new wrapX option).
    Every new corner gets moved by whole map-widths to sit next to where it should be:
    • a corner added while refining goes next to where its parent triangle already
      guessed it would be (snapToCopy);
    • the 4 starting corners have no parent, so each one is reached by walking from the
      corner before it in short steps, snapping as it goes (unwrapAlong).
      The result is one unbroken mesh, but part of it now sits past ±180°.
  2. Clip the mesh: packages/deck.gl-raster/src/clip-mesh-to-world.ts (new), called
    from raster-layer.ts. It cuts the mesh at 180° and moves the overhanging piece back by
    one map-width, so each piece sits on the normal map and the two meet at the seam.
    This means that the data is only shown within 1 world copy.
  3. Plumbing so tiles get found and drawn:
    • raster-tile-traversal.ts / raster-tileset-2d.ts: when looking for tiles, also
      search one map-width left and right. Tile bounding boxes are unwrapped the same way.
      This replaces the old vertical-cut approach (antimeridian-cut.ts is deleted).
    • layer-utils.ts: debug tile outlines are unwrapped along their edges.
    • The mosaic layer and multi-COG layer do the same unwrapping for their source
      bounding boxes and searches.
Test case Screenshot
EPSG:4326 (geographic) Screenshot 2026-10-01 at 8 55 34 pm
EPSG:4326 (rotated) Screenshot 2026-10-01 at 8 54 53 pm
360° wide (not AM-crossing). Important test because common heuristics will falsely flag very wide images as being AM-crossing, when they don't. Screenshot 2026-10-01 at 8 54 44 pm
EPSG:3832 (projected) Screenshot 2026-10-01 at 8 55 21 pm
UTM Zone 60 (curved in native, straight/slanted in 3857) Screenshot 2026-10-01 at 8 55 05 pm

Test data: https://github.com/willjnz/geotiff-test-data/tree/antimeridian-testing

MosaicLayer support this (tested for 3832 only):
Screenshot 2026-10-01 at 9 13 17 pm

willjnz and others added 14 commits September 29, 2026 09:44
…lify render-gray; fix stale-index crash in MosaicTileset2D
…r ramp

Drop WhiteIsZero (color inversion, not needed for this example) and
the texture-format-inference indirection (hardcode the known r16unorm
format). Swap in BlackIsZero, which still does the required single-band
-> RGB broadcast so the image doesn't render red-tinted, but leaves
values un-inverted: dark = low, bright = high.
@willjnz
willjnz marked this pull request as ready for review October 1, 2026 06:11
@willjnz willjnz changed the title Willjnz/antimeridian crossing test/fixes feat: antimeridian support Oct 1, 2026
@github-actions github-actions Bot added the feat label Oct 1, 2026
@willjnz
willjnz marked this pull request as draft October 1, 2026 06:44
@willjnz
willjnz marked this pull request as ready for review October 1, 2026 08:19
@willjnz
willjnz marked this pull request as draft October 1, 2026 08:29
@willjnz
willjnz marked this pull request as ready for review October 1, 2026 12:03
@willjnz

willjnz commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

@mdsumner this is my antimeridian PR

@kylebarron

Copy link
Copy Markdown
Member

Thanks, this and particularly #703 is useful to see.

I'm currently deliberating in #708 whether, instead of calculating reprojection error in the source CRS, we should instead calculate reprojection error in the viewing CRS. This would simplify some of the antimeridian handling because it wouldn't matter if the inverse projection was either undefined or mapped to a different world copy as the input points.

kylebarron added a commit that referenced this pull request Oct 14, 2026
…711)

We originally drafted this PR in
#708, then I
decided I wanted to move forward with it, and this PR is the careful
implementation I did, step by step with claude.

Previously, we used _input space_ to compute the error metric for when
to stop mesh refinement. We used input space because gdalwarp's linear
approximator also uses input space, and we wanted to be as similar to
gdalwarp as possible.

But that has some problems. Foremost, it requires you to have a
projection function where the inverse projection is defined and valid.

This means that only projections that are `1:1` bijective are supported.
This leads to problems with the antimeridian (where +- 180 deg longitude
both map to the antimeridian), with mapping lat/lon to polar
stereographic (where the lines of +-90 deg latitude map to a single
point) and with efficient globe reprojections.

Instead, we're implementing the first step to switching to _output
pixel_ error computations. In all of my inspections I can't see any
perceptible difference visually, and claude created some statistics
arguing that it's more effective for the same number of triangles.

This requires a few more forward projections (we compute the local
jacobian / aka local partial derivatives at the center of the input
image) in order to find the screen pixel size of one pixel. But it
doesn't require _any_ inverse projections, which makes it a much more
reliable reprojection approach.

This PR makes the output-pixel error mode experimental and opt-in. A
follow-up PR will make it the default. Perhaps we'll remove input-pixel
error mode altogether for the next release.

----


> [!NOTE]
> This PR was written by Claude (Claude Code) on behalf of @kylebarron,
not by @kylebarron.

`RasterReprojector` refines its mesh until every test point's error is
below `maxError`. Until now that error was measured in input pixels: the
GPU's drawn position is mapped back through the inverse projection and
compared with the test point, as gdalwarp's `-et` does. This adds an
experimental `_errorSpace: "output"` mode that measures in output pixels
instead: the distance on the map between where a test point belongs and
where the GPU draws it, divided by one input pixel's size on the map.
The default stays `"input"`, which builds the same meshes as before.

Output mode only needs the forward projection. Input mode needs to
invert the projection, which fails where the projection is N:1 rather
than 1:1: at the pole of a polar map, where a whole row of a lat/lon
tile meets at one point, and along the antimeridian. A 512 px EPSG:4326
tile reaching 90°N, projected to EPSG:3413, never converges in input
mode; output mode meshes it with 3,439 triangles in 20 ms.

## Changes

- **`@developmentseed/raster-reproject`:** `new RasterReprojector(fns,
w, h, { _errorSpace: "output" })`.
- The unit, one output pixel, is measured once per mesh at the center of
the seed: √|det J| from half-pixel steps, the side of a square with the
pixel's area on the map
([code](https://github.com/developmentseed/deck.gl-raster/blob/d148b94fe14f8db56a2fbf1f0de49d4e75f4f65e/packages/raster-reproject/src/delatin.ts#L570-L619)).
Unlike the geometric mean of the pixel's two sides, it doesn't overstate
sheared pixels.
- Output mode never calls the inverse functions
([code](https://github.com/developmentseed/deck.gl-raster/blob/d148b94fe14f8db56a2fbf1f0de49d4e75f4f65e/packages/raster-reproject/src/delatin.ts#L422-L428)),
and each split reuses its test point's projected position for the new
vertex.
- **`@developmentseed/deck.gl-raster`:**
- `RasterLayer` and `RasterTileLayer` get an `@internal` `_errorSpace`
prop, so `COGLayer`, `ZarrLayer` and `MultiCOGLayer` do too. Changing it
rebuilds meshes from the tiles already loaded.
- If a mesh can't be built, `RasterLayer` now draws nothing and reports
the error through `raiseError`
([code](https://github.com/developmentseed/deck.gl-raster/blob/d148b94fe14f8db56a2fbf1f0de49d4e75f4f65e/packages/deck.gl-raster/src/raster-layer.ts#L262-L280)).
Before, the error escaped `updateState` and the layer kept drawing its
old mesh.
- **Examples:** land-cover and custom-projection get a "Mesh error
measured" select (input or output pixels) under "Debug overlay". In
output mode, custom-projection skips its `meshXScale` column stretch,
which only exists to make input-pixel error track error on the map.
- **`tests/compare-error-spaces.test.ts`:** an on-demand comparison of
both modes (`COMPARE_ERROR_SPACES=1`), skipped in normal test runs.
- **Spec:**
[`dev-docs/specs/2026-10-13-output-pixel-error-design.md`](https://github.com/developmentseed/deck.gl-raster/blob/d148b94fe14f8db56a2fbf1f0de49d4e75f4f65e/dev-docs/specs/2026-10-13-output-pixel-error-design.md).

## Comparison

Triangles at the default tolerance of 0.125 px. In parentheses: each
mesh's worst error in the other mode's unit.

| Case | Input mode | Output mode |
|---|---|---|
| NLCD, Albers → Web Mercator | 5,288 (0.158 output px) | 4,726 (0.145
input px) |
| NAIP in UTM 18N, LINZ in NZTM | same mesh | same mesh |
| MODIS, sinusoidal → Web Mercator | 2,382 (0.188) | 2,848 (0.139) |
| EPSG:4326 60–85°N tile → Web Mercator | 2,394 (0.536) | 5,598 (0.124)
|
| EPSG:4326 67.5–89.9°N tile → EPSG:3413 | 11,880 (0.177) | 3,426 (15.4)
|
| EPSG:4326 30–85°N band → EPSG:3413 | 33,810 (0.205) | 33,004 (0.953) |

- **Where input pixels grow on the map**, input mode misses its
tolerance on screen. That happens at high latitudes in Web Mercator, and
with MODIS, whose sinusoidal pixels are sheared. On the 60–85°N tile
it's 4× over; output mode adds the triangles that takes.
- **Where they shrink**, toward a polar map's pole, input mode spends
3.5× the triangles on detail smaller than an output pixel.
- **Projection calls:** per triangle, both modes make about as many;
output mode's are all forward.

## Follow-ups

- **Output mode only.** Make it the only mode, before or after the next
release. That can also delete the custom-projection example's input-mode
workarounds: `meshXScale`, the 89.5° pole cut, and
`tileInverseReproject`'s longitude unwrap.
- **The reprojection explainer** gets a metric toggle and an Arctic
scenario, previewed in #708.
- **#710:** pass these props to tiles through `updateTriggers`.
- **#566 (globe) and #673 (antimeridian)** build on output mode.

🤖 Written by [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
mdsumner added a commit to mdsumner/sidebyside that referenced this pull request Oct 14, 2026
- dep / dep4326 presets: a VRT (gearbox/data/) over the Pacific Landsat
  GeoMAD test tiles from developmentseed/deck.gl-raster#673, twelve
  EPSG:3832 tiles with one column across 180 degrees. Deployed with the
  page; a local fixture with the same layout is in test/.
- Display menu grouped (this source, Greenwich-centred, Pacific-centred,
  polar, any), with Pacific-centred Plate Carree, Mercator (3832), Equal
  Earth (8859), Robinson and Mollweide. Extents come from the projection.
- "ask above": files or chunks one screen tile may read before the page
  asks; always on screen, not a policy, carried in view links.
- README and guide updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LWy6Gu3HQdEfPo6Za5Yd3R
kylebarron added a commit that referenced this pull request Oct 16, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

`MosaicLayer` accepts `extent` and passes it to its inner `TileLayer`,
which hands it to `MosaicTileset2D`. But `MosaicTileset2D` overrides
`getTileIndices` and never reads `this.opts.extent`, so the prop does
nothing. Every source whose bbox meets the viewport is still fetched,
rendered and reported by `onViewportLoad`, with no warning. It has been
this way since `MosaicLayer` was added in #184.

#684 makes the same fix for `RasterTileset2D`, the repo's only other
`Tileset2D` subclass, and its description lists `MosaicTileset2D` as not
changed there. Ref #684

## Reproduction

```ts
new MosaicLayer({
  id: "mosaic",
  sources: [
    { bbox: [0, 0, 10, 10] }, // A
    { bbox: [20, 0, 30, 10] }, // B
    { bbox: [40, 0, 50, 10] }, // C
  ],
  extent: [15, -5, 35, 5], // overlaps only B
  getSource: async (source) => {
    console.log("fetching", source.bbox);
  },
  renderSource: () => null,
});
```

In a viewport that shows all three sources (longitude 25, latitude 5,
zoom 3, 512×512), `main` fetches all three. I ran a version of this with
named sources and an `onViewportLoad` callback through deck.gl's
`LayerManager` in vitest (no GPU device, public API only), logging what
`getSource` fetched and what `onViewportLoad` reported:

```
main     extent=[15,-5,35,5]: fetched=["A","B","C"] onViewportLoad=["A","B","C"]
this PR  extent=[15,-5,35,5]: fetched=["B"] onViewportLoad=["B"]
```

On `main`, changing `extent` on later renders (none, then
`[15,-5,35,5]`, then `[5,-5,25,5]`, then none) never changes the
selection. With this PR, `onViewportLoad` reports `["A","B","C"]`,
`["B"]`, `["A","B"]`, then `["A","B","C"]`.

## Fix

- `MosaicTileset2D.getTileIndices` keeps its zoom gate and its Flatbush
search of the viewport, then drops the hits whose bbox doesn't overlap
`extent`. It reads `this.opts.extent` on every call, because `TileLayer`
updates it through `setOptions`. The filter runs before the hits are
mapped, so a source's default tile id is still its position in
`sources`.
- It uses the same rule as deck.gl's `TileLayer` (`OSMNode.update`'s
`insideBounds`) and #684. The overlap is strict, so a source that only
touches the extent at an edge or a corner is skipped. Each source is
tested against the whole extent, not against the part of it in view, so
a source that is on screen and overlaps the extent off-screen still
loads (it is drawn in full).
- `extent` is no longer picked from `TileLayerProps`. `MosaicLayerProps`
now declares it with TSDoc, which covers:
  - the format: WGS84 `[minLng, minLat, maxLng, maxLat]`
- that an overlapping source is drawn in full, so to limit what it
loads, pass the same `extent` to the layers `renderSource` returns
- that unlike deck.gl's `TileLayer`, it doesn't keep sources loading
below `minZoom`

## Tests

There's a new `MosaicTileset2D extent` block in
`tests/mosaic-tileset-2d.test.ts`. Its tests check that the tileset:

- selects only the sources that overlap an asymmetric extent
- keeps array-position ids when the extent skips an earlier source
- skips sources that only touch the extent, at an east/west edge and at
a north edge
- keeps a visible source whose overlap with the extent is off-screen,
and skips an on-screen source that misses the extent
- applies an extent changed through `setOptions` on the next call

Red/green: with only `mosaic-tileset-2d.ts` and `mosaic-layer.ts`
reverted to `main`, all 5 new tests fail (`Tests 5 failed | 6 passed
(11)`). With this PR, `Tests 11 passed (11)`. I also tried these wrong
versions of the fix, and each one fails at least one test:

- inclusive comparisons, on both axes or on y alone
- the extent read with its axes swapped
- searching viewport ∩ extent instead of testing each source
- the extent captured once in the constructor
- ids numbered after filtering

Checks:

- `pnpm --filter @developmentseed/deck.gl-geotiff test`: `Test Files 7
passed (7)`, `Tests 38 passed (38)`.
- `pnpm --filter @developmentseed/deck.gl-geotiff typecheck` passes
under TypeScript 6.0.3. I haven't run it under TypeScript 7 (#685); CI
will.
- `pnpm exec biome ci .`: `Checked 385 files ... No fixes applied.`

## Open questions and judgment calls

- **Merge after #684?** The TSDoc tells users to pass `extent` to the
layers `renderSource` returns. That only limits what a `COGLayer` loads
once #684 makes `RasterTileset2D` read `extent`. If this PR lands first,
that sentence is ahead of the code until #684 does.
- **`minZoom`.** I kept the existing zoom gate, so setting `extent` does
not keep sources loading below `minZoom`, unlike in deck.gl's
`TileLayer`. #684 makes the same choice.
- **A `MosaicLayer`-level test?** This PR doesn't change how
`MosaicLayer` forwards `extent`, and no test covers that forwarding yet.
A test that `renderTileLayer(...)` passes `extent` to the inner
`TileLayer` needs no `LayerManager`. Turning the end-to-end reproduction
above into a test would make it the repo's first `LayerManager` test.
Without a device, deck.gl swallows `updateState` errors there, so it
could only assert positive outcomes.
- **#639 and #673** rewrite the same lines of `getTileIndices`, so
whichever lands second needs a manual merge. In #673 the check moves
into its per-source loop, as a `continue` when `extent` is set and
`!overlaps(source.bbox, extent)`, after the `source === undefined`
guard. In #639 it stays a `.filter` on `[...matched]` before the `.map`.
Since #673 shifts antimeridian-crossing bboxes so that `maxX > 180`,
should the check also test each bbox shifted by ±360? Otherwise a source
stored as `[178, -10, 182, 10]` misses an extent like `[-179, -10, -175,
10]`. An extent that itself crosses the antimeridian isn't supported, as
in deck.gl.

## Related bug, not fixed here

`MosaicLayer`'s `getSources` closure (`() => this.props.sources`) stays
bound to the first layer instance. `TileLayer` creates the tileset once,
and deck.gl moves `state` to each new layer instance but leaves the old
instance's `props` as they were. So after the first render, the tileset
pairs the rebuilt spatial index with the first `sources` array. In the
same `LayerManager` setup, with no `extent` (`main` gives the same
results):

```
# sources grow after the first render
sources=["A"]: fetched=["A"] onViewportLoad=["A"]
sources=["A","B","C"]: fetched=[] onViewportLoad=null
# sources shrink after the first render
sources=["A","B","C"]: fetched=["A","B","C"] onViewportLoad=["A","B","C"]
sources=["C"]: fetched=[] onViewportLoad=["A"]
```

So filtering `sources` yourself is not a reliable substitute for
`extent` once the layer has rendered. #673 switches the closure to
`this.state.sources`, which would fix this; it probably deserves its own
issue. The new filter assumes, like the existing `.map`, that every
index hit has a matching entry in `sources`, so it doesn't make this
worse.

🤖 Written by [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
kylebarron added a commit that referenced this pull request Oct 20, 2026
The problem was that `sources` was read statically. So when `sources`
changed, the existing `MosaicLayer` instance would never see an updated
`sources`.

----


> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

After its first render, `MosaicLayer` ignored changes to `sources`. Its
tileset searched the latest spatial index but looked up the hits in the
first render's `sources` array:

- **Added sources:** they never loaded, and deck.gl reported `update of
TileLayer({id: 'mosaic-layer-<id>'}): Cannot read properties of
undefined (reading 'id')`. A layer that started with `sources: []` never
loaded the sources passed to it later.
- **Removed sources:** they stayed selected. Going from `[A, B, C]` to
`[C]` selected A.
- **Replaced sources:** replacing every source kept the old ones. Going
from `[A, B]` to `[P, Q]` kept A and B selected and never fetched P or
Q.

[usgs-topo](https://github.com/kylebarron/usgs-topo) passes a new
`sources` array as the map moves. It showed missing maps after a pan,
and drew nothing after a jump to another area.

**Cause:** `TileLayer` creates its tileset only once, so the
`getSources` and `getIndex` closures that `MosaicLayer` hands it stay
bound to the first `MosaicLayer` instance. Apps create a new layer
instance on every render. deck.gl hands the new instance the old
instance's `state` object, but each instance has its own `props`. So
`getIndex` (`this.state.index`) returned the latest index, while
`getSources` (`this.props.sources`) returned the first instance's array.

**Fix:** `MosaicLayer` now keeps `sources` in state next to the index
built from them, and `getSources` reads `this.state.sources`. The
comment above the closures used to say that deck.gl reuses the layer
instance across prop updates. It now explains why both closures read
`this.state`.

#673 included the same fix but was closed without merging. #688's
description documented this bug under "Related bug, not fixed here".

### Not covered

Sources without an `id` still go wrong when one is removed or replaced.
- Their tile id defaults to their position in `sources`, and deck.gl's
`Tileset2D` reuses the cached tile with that id. So a source that moves
into a removed source's position shows the removed source's tile.
- `[A, B, C]` to `[C]` still shows A, and `[A, B]` to `[P, Q]` keeps A
and B and never fetches P or Q.
- The `sources` docs say shifted sources re-fetch, but they don't.

Sources with an `id` aren't affected. This needs a separate fix.

### Tests

The existing tests in `mosaic-layer.test.ts` call the lifecycle methods
on one bare layer instance, so they couldn't catch this. The new
`MosaicLayer sources across layer instances` block renders through
deck.gl's `LayerManager` with a new `MosaicLayer` for each update.
- It passes a stub device, because deck.gl ignores errors thrown in
`updateState` when there's no device. `renderSource` returns `null`, so
nothing draws.
- Each test checks what `onViewportLoad` last reported and that
`onError` wasn't called. The tests that add sources also check which
ones `getSource` fetched.

The tests:
- `loads sources added after the first render`: `[A]` to `[A, B, C]`
- `loads sources passed after an empty first render`: `[]` to `[A, B]`
- `drops sources removed after the first render`: `[A, B, C]` to `[C]`
- `loads the new sources when every source is replaced`: `[A, B]` to
`[P, Q]`

Without the change to `mosaic-layer.ts`, all four fail (`Tests 4 failed
| 7 passed (11)`):
- The first two get the `reading 'id'` error.
- The third sees `onViewportLoad` report A instead of C.
- The fourth never fetches P or Q.

With the change they pass, and so do `pnpm build`, `pnpm -r
--filter="!docs" typecheck`, `pnpm test`, `pnpm publint` and `biome ci
.`.

🤖 Written by [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
kylebarron added a commit to willjnz/deck.gl-raster that referenced this pull request Oct 21, 2026
…tseed#716)

Antimeridian handling has been a requested feature for a long time. It
took a little while but I'm happy with where we're ending up,
architecturally.

For one, we no longer split the mesh in two, like one of my previous
attempts did.

And our switch to using an error metric in _output space_ rather than in
_input space_
(developmentseed#711) makes it a
lot simpler to compute the reprojection mesh.

Here's an example of rendering across the antimeridian of a Sentinel 2
TCI image in Fiji:

<img width="701" height="697" alt="image"
src="https://github.com/user-attachments/assets/6d363374-659f-4fb0-b6ff-ff5f606cbbef"
/>


<img width="605" height="655" alt="image"
src="https://github.com/user-attachments/assets/febc8475-8d7e-44ea-8d1a-b430f78681f0"
/>
<img width="911" height="958" alt="image"
src="https://github.com/user-attachments/assets/805af185-9879-4f23-bcdf-fc8b37347e35"
/>



----


> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

An image that crosses the antimeridian now renders in Web Mercator as
one mesh, straight across 180°, when mesh error is measured in output
pixels (`_errorSpace: "output"`). Before, its mesh never converged and
was drawn the long way around the world.

**Why it broke.** proj4 returns x inside one copy of the world. So a
tile that crosses 180° has its west corners near +180° and its east
corners near -180°, and its triangles span the whole world. The GPU then
draws points near the seam in the middle of the world, and refinement
piles up along the seam until it hits the iteration cap. The same wrap
made a crossing tile's bounding box span the world, so the tile was
selected everywhere. It also sent the tile's debug outline the long way
around, and made `getGeographicBounds` span the world, so the examples'
fly-to zoomed out to the far side of it.

An image that stops just short of 180° can cross it too, when its edge
tiles are fetched as full blocks, as `MultiCOGLayer` does: the blocks'
padding runs past 180° though the image doesn't. developmentseed#366's Digital Earth
Pacific COG, in EPSG:3832, ends at 179.97°E, and its 512 px edge blocks
reach 180.07°E.

**The approach.** The forward projection is made continuous across the
wrap before the mesh is built, and the finished mesh is cut at the
world's edge. The reprojector stays planar: it knows nothing about world
copies, Web Mercator or longitudes. `RasterLayer` is told only that its
output x wraps with some period, and `RasterTileLayer`, which knows it
draws in Web Mercator's common space, passes the period. This replaces
developmentseed#714, which unwrapped inside the reprojector and gave the same meshes.

**What changes.**

- **`@developmentseed/proj`** gets `nearestCopy`, which moves a value by
whole periods next to a reference, and `unwrapAlong`, which unwraps a
value at the end of a path by walking along it.
- **`@developmentseed/deck.gl-raster`**
- `RasterLayer` gets an `@internal` `_wrapX` prop: the period of the
output's x axis. With it, `RasterLayer` lifts the image's forward
projection. It unwraps the image's corners by walking to each from the
image's center, then moves each projected x to the copy nearest the
bilinear blend of the corners at that pixel. The unchanged reprojector
meshes the result, and `RasterLayer` cuts the mesh at the world's edge,
moving each part back into the world (Sutherland-Hodgman, with UVs
interpolated along cut edges). `_wrapX` requires `_errorSpace:
"output"`, which never calls the inverse projection; that is what made
this hard in input mode (developmentseed#673). The debug overlay outlines the mesh as
drawn.
- `RasterTileLayer` sets the period, 512, in its Web Mercator branch,
and passes it as `_wrapX` in output mode. Input mode and the globe are
unchanged.
- Tile selection: a tile's reference points are unwrapped from its
center, so a crossing tile's box hugs it. The part past the world's edge
is also tested one world over, so either part alone in view selects the
tile, with or without `repeat`, and it is no longer selected from across
the world. A box half a world wide or more covers the whole world, which
handles tiles around a pole. This also fixes a bug where a polar grid's
root tile was culled near the antimeridian and no tile was selected.
Tile selection changes in input mode too.
- The debug tile outline goes the short way across the antimeridian, and
its label sits in the world copy nearest 0°.
- **`@developmentseed/deck.gl-geotiff`**: `getGeographicBounds` bounds
an image across the antimeridian the short way. West is in [-180°,
180°), and east may run past 180°, as MapLibre's `fitBounds` accepts.
- **`cog-basic`**, in development, serves the five antimeridian fixtures
from `fixtures/geotiff-test-data` and lists them as sources. Picking one
switches to output pixels and draws the antimeridian.
- **Spec:**
[`dev-docs/specs/2026-10-14-antimeridian-unwrap-design.md`](https://github.com/developmentseed/deck.gl-raster/blob/1fde6b45c33c6193796b9e6500e422b665321828/dev-docs/specs/2026-10-14-antimeridian-unwrap-design.md)
replaces the 2026-05-27 cut-in-two spec, now marked superseded.

**Tests.** The main requirement is that a crossing image is never drawn
the long way around. The tests check that the unwrapped mesh is under
half a world wide and crosses exactly one world edge, that no drawn
triangle is wider than half a world, and that the drawn mesh lies inside
the world, with a part at each edge. They run on synthetic images, and
on every tile of every level of the five antimeridian fixtures, through
the tileset and `RasterLayer` that `COGLayer` builds. The fixtures are
EPSG:4326, rotated, UTM 60N (where the seam is curved), EPSG:3832, and
180°W to 180°E, and each is selected with the view on the seam and on
either side of it, with and without `repeat`. A crossing image meshes
exactly like the same image moved off the seam, and an image that
doesn't cross is unchanged. An EPSG:3832 edge block whose padding
crosses 180° meshes the short way, a polar grid (NSIDC's EPSG:3413
extent) is selected at every longitude, and an EPSG:3031 tile with the
pole at a corner is drawn as it would be without wrapping.

**Not changed here:**

- Input mode, the default, still can't draw a crossing image. A
follow-up PR makes output pixels the only mode in the layers.
- `MultiCOGLayer` meshes the full block of an edge tile, including the
zero-filled padding past the image. In output mode, padding that crosses
180° is drawn just east of -180°, unless the render pipeline hides
zeros.
- The Web Mercator clamp seed takes the nominal tile's latitudes, not
the data's, and the debug outline draws the nominal tile. These existing
bugs show on the tiny fixtures.
- Views in other projections: `RasterTileLayer` draws every view but the
globe in Web Mercator's common space.
- developmentseed#713 (tiles centered on the equator never converge), developmentseed#715 (geographic
bounds of rotated images are too small), and `MosaicLayer` and
`MultiCOGLayer` source bounds across 180° (developmentseed#639).
- Tiles that contain a pole have no continuous unwrap.

Closes developmentseed#171
Closes developmentseed#366
Closes developmentseed#269
Closes developmentseed#374
Closes developmentseed#576
Closes developmentseed#673
Closes developmentseed#714

🤖 Written by [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
kylebarron added a commit that referenced this pull request Oct 22, 2026
<img width="2452" height="1283" alt="image"
src="https://github.com/user-attachments/assets/1bb97dd6-112c-468b-8809-f76f4f6e602b"
/>
<img width="2121" height="1241" alt="image"
src="https://github.com/user-attachments/assets/07cc4b99-ebf9-463d-9cbd-a596b58c8555"
/>


> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Adds `examples/explainers/antimeridian-explainer`, a step-by-step
animation of how deck.gl-raster meshes an image that crosses the
antimeridian (±180°). It replaces #703, which explained #673's design,
with the mechanism on `main` today (#716 and #721).

The explainer follows `antimeridian_UTM_60N.tif` from geotiff-test-data:
42 x 42 pixels of 20 km in UTM zone 60N, over the Aleutian Islands. It
reads the file live from GitHub at a pinned commit. The maps draw
Natural Earth's 1:50m land (public domain) under the meshes, also read
live. In the close-up, the coastlines go over the image too, so the
Aleutians show through it. If the land can't be read, the maps fall back
to a plain graticule. There are nine steps:

1. **An image across 180°**: the image as stored, with the 180° meridian
through it, and where it belongs on the map: at both edges.
2. **Two triangles**: the reprojector starts from two triangles.
3. **Project the corners**: proj4 returns every point in one copy of the
world, so both triangles stretch across it.
4. **Refining can't fix it**: a time-lapse of the reprojector refining
that projection. It stops at its cap, 20,001 triangles, still 616 output
pixels off.
5. **Walk to the corners**: `unwrapAlong`'s walk from the image's
center. Each sample is numbered, and shown where proj4 puts it, in a
whole-world strip, and where it moves to, in a close-up of the seam.
6. **Snap every point**: the reprojector projects four check points in
each triangle, 320 times in all for this image, and the layer snaps
every one to the copy nearest the blend of the unwrapped corners. A
probe, the explainer's own, sweeps the image to show it: proj4's answer
jumps a world at 180°, while the snapped point moves smoothly.
7. **Mesh as usual**: the library's refinement of the snapped
projection, replayed split by split. It finishes in 40 triangles.
8. **Cut at the world's edge**: `clipMeshToWorld` cuts the 10 triangles
that cross -180° and moves the overhang one world over.
9. **On the map**: the world copies put the two parts back together at
the seam.

Steps 3, 5, 6 and 8 play in beats. Each press of Next plays one beat, so
the image panel and the map panels can be followed one at a time.

Every corner, sample, snapped point, split and cut comes from the
functions `RasterLayer` calls, called in its order:

- `makeUnwrappedReprojectionFns`, which uses `unwrapAlong` and
`nearestCopy`;
- `RasterReprojector`, with output-pixel error;
- `clipMeshToWorld`.

`makeUnwrappedReprojectionFns`, `clipMeshToWorld` and
`rescaleEPSG3857ToCommonSpace` aren't exported from
`@developmentseed/deck.gl-raster`, and its export map blocks deep
imports. The explainer reaches them through a private alias in its own
`vite.config.ts` and `tsconfig.json`, pointing at the built `dist/`. The
package's exports don't change.

Also included:

- a card in the Explainers section of the docs examples page;
- the design spec,
`dev-docs/specs/2026-10-21-antimeridian-explainer-design.md`.

As with the other explainers, the code is LLM-generated and unreviewed
(see its README).

Closes #703

🤖 Written by [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

2 participants