Skip to content

feat(deck.gl-geotiff)!: take MosaicLayer's items as data, and pass their sources as source - #804

Merged
kylebarron merged 5 commits into
mainfrom
kyle/mosaic-sources
Oct 26, 2026
Merged

kylebarron merged 5 commits into
mainfrom
kyle/mosaic-sources

Conversation

@kylebarron

Copy link
Copy Markdown
Member

Note

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

Stage 3 of the Sources design, dev-docs/specs/2026-10-22-sources-design.md: MosaicLayer takes its items as deck.gl's data, and passes each item's opened source to its callbacks as source. In MosaicLayer, a "source" now always means an opened source, such as a COGSource, and an "item" means an entry of the mosaic (question 7).

new MosaicLayer<Item, COGSource>({
  id: "naip",
  // Items with a unique `id`, a `bbox` and a `url`. Or a STAC search URL, with
  // `dataTransform: (fc: any) => fc.features`
  data: items,
  getSource: (item, { signal, concurrencyLimiter, getPriority }) =>
    COGSource.open(item.url, { signal, concurrencyLimiter, getPriority }),
  renderSource: (item, { source, signal }) =>
    new COGLayer({ id: item.url, source, signal }),
});
  • Items are deck.gl's data.
    • data can be an array, a promise, or a URL that deck.gl loads, so a STAC search needs no fetch code of its own.
    • dataTransform, dataComparator and onDataLoad work as in other deck.gl layers, and isLoaded waits for data to load.
    • The layer rebuilds its spatial index whenever deck.gl reports dataChanged.
  • The callbacks get the opened source as source:
    • renderSource(item, { source, signal });
    • onSourceLoad(item, { source }) and onSourceUnload(item, { source });
    • onViewportLoad's entries are { item, source }.
  • Types:
    • MosaicSource is now MosaicItem, and the type parameters are ItemT and SourceT.
    • SourceT stays unconstrained, so a mosaic of plain images, such as one drawn with BitmapLayer, still works.
  • Docs:
    • MosaicLayer's class doc shows getSource opening a COGSource.
    • getSource's concurrencyLimiter points to COGSource.open.
    • The docs now say each item needs a unique id unless the list only grows by appending. With the default id, its position, a new item at a cached position draws as the old one, as on main. The old docs said such items re-fetch.
    • They also say when deck.gl actually aborts getSource's signal: when the layer is removed, or, for an item out of view, when more than maxRequests opens are in flight. It doesn't abort as soon as the item leaves view.

Example caches

naip-mosaic is the only example that uses MosaicLayer, and it moves to the new props.

It keeps its own cache of opened sources, with MosaicLayer's cache turned off (maxCacheSize: 0), because MosaicLayer's cache would hold much more than sources:

  • deck.gl's TileLayer keeps the sublayer of every cached item alive.
  • A COGLayer out of view keeps all its tiles.

So each cached item would hold its COGLayer and its GPU textures, not just its source. A later PR can make MosaicLayer keep only sources (the spec's option B).

While looking into this, I found that maxCacheByteSize leaves MosaicLayer's cache unbounded, filed as #803.

vermont-cog-comparison's cache stays too: it's the app keeping the sources it switches between.

The spec records these decisions as 15 to 17.

Migration

MosaicLayer's sources becomes data, and MosaicSource becomes MosaicItem.

// Before
new MosaicLayer({ sources: items, renderSource: (source, { data }) => ... });

// After
new MosaicLayer({ data: items, renderSource: (item, { source }) => ... });

The callbacks' data field becomes source. onViewportLoad's entries change from { source, data } to { item, source }, so entry.source now holds the opened source, where it used to hold the item:

// Before
onViewportLoad: (entries) => entries.map(({ source, data }) => ...),

// After
onViewportLoad: (entries) => entries.map(({ item, source }) => ...),

TypeScript catches most of this, but not all of it:

  • Caught: sources and MosaicSource are rejected.
  • Missed: code that still reads entry.source as the item. With SourceT left at its default any, as in new MosaicLayer<MyItem>(...), entry.source.bbox still compiles and is undefined at runtime. Check every onViewportLoad, onSourceLoad and onSourceUnload.
  • In JavaScript: sources and the callbacks' { data } are ignored without a warning. The mosaic draws nothing, and data reads as undefined.

Tests

  • data:
    • Items load from an array, from a promise, and from a URL with dataTransform. In the URL test, the layer's fetch prop stands in for the network.
    • A promise that resolves after newer data doesn't replace it, even when the app then renders that newer data again. Without deck.gl's latest-wins guard, this test fails.
    • A new array updates the mosaic. An item pushed onto the array in place isn't picked up, and the docs say in-place changes aren't supported.
    • data: null draws nothing, without an error.
  • Sources:
    • renderSource and onSourceLoad get each item's opened source.
    • onViewportLoad reports each item with its source.
    • onSourceUnload gets an evicted item's source.
  • Existing tests:
    • The spatial index tests and the tests across layer instances now go through data.
    • The tileset tests use the new names.
  • Type tests pin the type of data, the source that renderSource and onViewportLoad get, and the removed sources.
  • Mutation checks: each of these makes a test fail:
    • rebuilding the index only on the first update;
    • dropping source from renderSource, onViewportLoad or onSourceUnload.
  • In Chrome:
    • naip-mosaic loads its 112 items in view.
    • False Color and NDVI redraw.
    • Panning loads the new items.

🤖 Written by Claude Code

kylebarron and others added 5 commits October 26, 2026 14:32
MosaicSource becomes MosaicItem, so that "source" can mean the source
opened for an item. The tileset's spatial index and the layer's state
call them items too, and the tileset's doc no longer claims it rebuilds
the index itself.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eir sources as source

MosaicLayer's items move from `sources` to deck.gl's `data` prop, so they
can be an array, a promise, or a URL with `dataTransform`, such as a STAC
search. The layer rebuilds its index whenever deck.gl reports `dataChanged`.

Its callbacks get the source `getSource` opened for an item as `source`:
`renderSource(item, { source, signal })`, `onSourceLoad(item, { source })`
and `onSourceUnload(item, { source })`. `onViewportLoad`'s entries become
`{ item, source }`. The type parameters become `ItemT` and `SourceT`.

naip-mosaic moves to the new props.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The spec records three decisions:
- MosaicLayer's items are `data` (decision 15).
- naip-mosaic keeps its own source cache, and why (decision 16).
- The `maxCacheByteSize` bug (#803, decision 17).

naip-mosaic's comments explain its cache, and dev-docs/world-copies.md
calls mosaic items "items".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test rendered plain newer data right after the older promise
resolved, before deck.gl could apply it, so it passed even without
deck.gl's latest-wins guard. It now lets the older promise land, then
renders the same newer data again. Without the guard, that render
fetches the older items, and the test fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Items need a unique id unless the list only grows: with the default
  positional id, a new item at a cached position draws as the old one.
  The docs said shifted items re-fetch.
- getSource's signal aborts when deck.gl cancels the open (the layer is
  removed, or too many opens are in flight for items out of view), not
  whenever an item leaves view. The spec said the same.
- Changing the data array in place isn't supported, and dataComparator
  can't see such a change.
- The dataTransform examples now compile.

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

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.

the changes in this file are all just renames 👍

@kylebarron
kylebarron merged commit 48141bb into main Oct 26, 2026
3 checks passed
@kylebarron
kylebarron deleted the kyle/mosaic-sources branch October 26, 2026 20:58
kylebarron added a commit that referenced this pull request Oct 30, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Bumps `version` to `0.10.0-beta.1` in the root `package.json` and in
every `packages/*/package.json`, ready for the first 0.10 beta. The
publish workflow sees `beta` in the version and publishes to npm under
the `beta` dist-tag, so `latest` stays on 0.9.0.

`CHANGELOG.md` gets a `v0.10.0-beta.1` section listing the 19 PRs merged
since v0.9.0.

## Publish `@developmentseed/range-reader` by hand before tagging

`@developmentseed/range-reader` (#806) isn't on npm yet, and
`@developmentseed/geotiff` and `@developmentseed/deck.gl-geotiff` depend
on it. The publish workflow can't create it: it publishes only through
trusted publishing (OIDC), and npm can add a trusted publisher only to a
package that [already
exists](https://docs.npmjs.com/cli/v11/commands/npm-trust). Pushing the
tag first would fail at `range-reader`. `pnpm publish --recursive` stops
at the first failure, so packages published before it in the run would
be out, and the rest, including `geotiff` and `deck.gl-geotiff`, would
not.

Once this is merged, from an up-to-date `main`:

1. Publish it once, as a public package under the `beta` tag. Its
`prepublishOnly` script builds it first.
   ```sh
   cd packages/range-reader
   pnpm publish --tag beta --access public --no-git-checks
   ```
2. Give it the same trusted publisher as the other packages (workflow
`release.yml`, environment `release`), in its settings on npmjs.com or
with:
   ```sh
npm trust github @developmentseed/range-reader --file release.yml --repo
developmentseed/deck.gl-raster --env release --allow-publish
   ```
3. Tag the merge commit `v0.10.0-beta.1` and push the tag. The workflow
skips `range-reader`, since that version is already on npm, and
publishes the other ten packages.

## Breaking changes

- #799: `COGLayer` takes a single `source`: an opened `COGSource`, or
any input of `COGSource.open`. `geotiff` becomes `source`,
`onGeoTIFFLoad` becomes `onSourceLoad`, and `epsgResolver` and
`concurrencyLimiter` move to `COGSource.open`.
- #801: `MultiCOGLayer` does the same with `MultiCOGSource`. `sources: {
red: { url } }` becomes `source: { red: url }`, `MultiCOGSourceConfig`
is removed, and files that don't share a CRS and an extent are rejected.
- #804: `MosaicLayer`'s `sources` becomes deck.gl's `data`, and
`MosaicSource` becomes `MosaicItem`. The callbacks get the item's opened
source as `source`, and `onViewportLoad`'s entries are `{ item, source
}`.
- #821: `renderSource` gets only `{ source }`, without `signal`.
- #812: `ZarrLayer` takes a `ZarrSource`, or a zarrita group or array,
as `source`. `node`, `variable`, `metadata` and `epsgResolver` are
removed (`metadata` becomes `ZarrSource.open`'s `geoZarrMetadata`), and
the type parameters are now `ZarrLayer<DataT, Dtype, Store>`.
- #807: `GeoTIFF.fromUrl` no longer takes `chunkSize` or `cacheSize`.
They're `RangeReader` options now (`minMetadataReadBytes`,
`cache.metadataBytes`).

Two behavior changes aren't marked breaking:

- #809: COG tile reads are coalesced by default, and `COGLayer` and
`MultiCOGLayer` default to `maxRequests: 256` and `debounceTime: 50`.
- #818: changing `updateTriggers.getTileData`, or ZarrLayer's
`selection`, fetches tiles again, and the old tiles are removed at once.

🤖 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant