Repository navigation
refactor(deck.gl-raster): handle every layer's source in RasterTileLayer - #805
Conversation
…eLayer COGLayer and MultiCOGLayer each handle their `source` prop with the same code, and ZarrLayer would add a third copy. RasterTileLayer now does it for any subclass that declares `source` and `onSourceLoad`: - It draws an opened `RasterSource` at once, and aborts any open in flight. - It opens other input in `loadMetadata`, through the subclass's `_openSource(input, signal)`, then calls `onSourceLoad`. - It keeps the source in `state.source`, and takes the tile grid from it. `_sourceState(source)` lets a subclass store more state with a source, such as a default render pipeline. If it throws, the layer draws nothing rather than the old source. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… source COGLayer and MultiCOGLayer drop their copies of the `source` handling, `clearState()` included, and implement RasterTileLayer's hooks: - COGLayer opens input with `COGSource.open`, and infers its default pipeline in `_sourceState`. - MultiCOGLayer opens a record with `MultiCOGSource.open`. Its `shouldLoadMetadata` still skips an empty record, which draws nothing. Their behavior doesn't change, and their existing tests pass as they were. A new test pins that an empty record replacing an opened source draws nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The spec records decisions 18 to 23: - Stage 4 lands as three PRs. - RasterTileLayer handles `source` (question 5, as built here). - Each layer declares its own `source` and `onSourceLoad` (question 6). - ZarrLayer takes one `source`, and its old props become `ZarrSource.open` options. - `selection` stays on ZarrLayer. - What `ZarrSource` holds, and where its projection helpers move. Stage 4's bullet becomes 4a, 4b and 4c, with 4c's plan. That plan includes unloading what deck.gl's `reloadAll` drops without calling `onTileUnload`. A new question 9 asks how to name ZarrSource's parsed metadata next to the raw `metadata` option. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… be drawn When `_sourceState` threw for an opened `source`, the error escaped `updateState`. deck.gl then skips `renderLayers`, so the layer kept its old inner TileLayer: the map showed the previous source, and kept fetching its tiles, until another prop changed. COGLayer has done this since 2a, for a COG its default pipeline can't draw. RasterTileLayer now reports the error through `onError` instead, with the prefix "Can't draw the source in <layer>", on both the opened and the shorthand path. `source: null` now means no source, like `undefined`. Before, the base opened it, and MultiCOGLayer threw from `updateState` and kept drawing its old source. A new test drives a real deck.gl LayerManager, since tests that call `renderLayers` directly can't see the stale sublayer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron
left a comment
There was a problem hiding this comment.
let's try to remove these casts with better typing
| * {@link COGSource.open}. | ||
| */ | ||
| protected override _openSource( | ||
| input: COGInput, |
There was a problem hiding this comment.
this input type can be derived from a type on the class probably?
There was a problem hiding this comment.
Note
This comment was written by Claude (Claude Code), not by @kylebarron.
Mostly, yes. In 97b827f the input type is a type argument of the class: COGLayer extends RasterTileLayer<DataT, COGLayerProps<DataT>, COGSource, COGInput>. The base declares _openSource(input: InputT, signal): Promise<SourceT>, so TypeScript checks this override against COGInput and COGSource.
The annotation itself has to stay, because TypeScript doesn't infer an overriding method's parameter types from the base class. Without it, tsc 7.0.2 reports TS7006: input implicitly has an any type.
🤖 Written by Claude Code
| * tiles over. | ||
| * | ||
| * Subclasses may supply this via state by overriding the protected | ||
| * Layers that take a `source` take the descriptor from it instead. Other |
There was a problem hiding this comment.
In the future this will be irrelevant because all layers will take a source, right?
There was a problem hiding this comment.
Note
This comment was written by Claude (Claude Code), not by @kylebarron.
For subclasses, yes. ZarrLayer is the last one that overrides _tilesetDescriptor(), and it moves onto source in 4b, so I'll drop the "Other subclasses" sentence there.
Direct use is the exception. The titiler-cog example passes a tilesetDescriptor built from a tile server's TileMatrixSet, with no RasterSource behind it. RasterTileLayer could take an opened RasterSource too: it already draws one, and the new SourceT parameter would type it. But a tile server would then need a small RasterSource of its own, so I'd decide that separately.
🤖 Written by Claude Code
There was a problem hiding this comment.
But a tile server would then need a small
RasterSourceof its own, so I'd decide that separately.
I think a ServerSource could make sense... But something to think about later
There was a problem hiding this comment.
Note
This comment was written by Claude (Claude Code), not by @kylebarron.
Agreed. I added it to the spec as question 10, marked for later (1f9c559).
🤖 Written by Claude Code
| */ | ||
| type SourceProps = { | ||
| /** An opened {@link RasterSource}, or input for the layer to open. */ | ||
| source?: unknown; |
There was a problem hiding this comment.
I'd like for the type of this to be better. Can we add a generic onto SourceProps?
There was a problem hiding this comment.
Note
This comment was written by Claude (Claude Code), not by @kylebarron.
Done in 97b827f. SourceProps<SourceT, InputT> types source as SourceT | InputT | null, and onSourceLoad as (source: SourceT) => void.
RasterTileLayertakesSourceTandInputTas type parameters. They default toneverfor layers without a source.- It adds
SourceProps<SourceT, InputT>to its props, sothis.props.sourceis typed in the base. _openSource,_sourceStateandstate.sourceuse the same types. COGLayer and MultiCOGLayer no longer redeclaresourcein their state.- Each layer still declares its own
sourceandonSourceLoad, to document its inputs. TypeScript intersects those declarations with these.
The three older as unknown as RasterTileLayerProps<DataT> casts stay. They read tilesetDescriptor, getTileData and renderTile, which subclasses redeclare with other signatures, such as COGLayer's getTileData(image, options); that's why those props live in ExtraProps. Removing those casts would mean retyping those props. I can open an issue for that if you want.
🤖 Written by Claude Code
|
|
||
| override updateState(params: UpdateParameters<this>): void { | ||
| super.updateState(params); | ||
| const { source } = params.props as SourceProps; |
There was a problem hiding this comment.
similarly I don't like this cast.
There was a problem hiding this comment.
Note
This comment was written by Claude (Claude Code), not by @kylebarron.
Removed in 97b827f: params.props.source is typed now.
- In the base, a private type guard,
_isOpened(source): source is SourceT, replacesinstanceof RasterSource.instanceofalone can't tell TypeScript that aRasterSourceis this layer'sSourceT. loadMetadatanow returns early unlesssourceis input, which narrows it toInputTfor_openSource.
🤖 Written by Claude Code
…t casts RasterTileLayer takes two more type parameters, `SourceT` and `InputT`. They are the opened source a subclass draws and the input it opens, such as COGLayer's `COGSource` and `COGInput`. `SourceProps<SourceT, InputT>` adds `source` and `onSourceLoad` to the layer's props with those types, so the base reads them without casts. `_openSource`, `_sourceState` and `state.source` take the same types. A private `_isOpened` type guard tells an opened source from input. `loadMetadata` returns early for anything that isn't input, which also narrows `source` to `InputT`. COGLayer and MultiCOGLayer pass their source and input types, and drop the `source` they declared in state. The test layers type their props the same way, which also removes the test's casts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Decision 19 gains the two type parameters that type a layer's `source`. Decision 20 now says RasterTileLayer adds `source` and `onSourceLoad` to every layer's props, while each layer still declares its own, to document its inputs. The Layers section's COGLayer sample shows the new type arguments. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| DataT, | ||
| COGLayerProps<DataT>, | ||
| COGSource, | ||
| COGInput |
There was a problem hiding this comment.
We're getting to have a lot of type parameters now:
- DataT: type of data transferred from
getTileDatatorenderTile - COGLayerProps: input props into the class
- COGSource: type of source (e.g. COG, MultiCOG, Zarr)
- COGInput: type of cog input...
It feels like a lot of type parameters?
Can we combine these at all and simplify them? Like COGLayerProps and COGInput seem perhaps overlapping?
There was a problem hiding this comment.
Note
This comment was written by Claude (Claude Code), not by @kylebarron.
Yes, they overlap: COGLayerProps already says source: COGSource | COGInput.
- What changed: in 853357d,
SourceTandInputTdefault to those two parts of thesourceprop. COGLayer and MultiCOGLayer pass two type arguments again,RasterTileLayer<DataT, COGLayerProps<DataT>>, as before this PR. A layer without asourcegetsnever. - Why they're still type parameters: with defaults derived from the props, the class body keeps working with plain types.
- Type tests (9048397): COGLayer's state holds a
COGSource, and itssourcerejects a number. DefaultingInputTtoanyornevermakes them fail.
The other two parameters stay:
DataTis the tile data apps can choose (COGLayer<DataT>).- The props type is what deck.gl's
CompositeLayertypesthis.propswith.COGLayerProps<DataT>repeatsDataTbecause itsgetTileDataandrenderTileuse it.
🤖 Written by Claude Code
| * tiles over. | ||
| * | ||
| * Subclasses may supply this via state by overriding the protected | ||
| * Layers that take a `source` take the descriptor from it instead. Other |
There was a problem hiding this comment.
But a tile server would then need a small
RasterSourceof its own, so I'd decide that separately.
I think a ServerSource could make sense... But something to think about later
…ce prop A layer's props already say what its `source` takes, such as COGLayer's `source: COGSource | COGInput`. `SourceT` and `InputT` now default to those two parts of the `source` prop in `ExtraProps`, so COGLayer and MultiCOGLayer pass two type arguments again: `RasterTileLayer<DataT, COGLayerProps<DataT>>`. A layer without a `source` gets `never`, as before. Type tests pin the derived types: COGLayer's state holds a `COGSource`, MultiCOGLayer's a `MultiCOGSource`, and a COGLayer subclass can't override `_openSource` with an input COGLayer's `source` doesn't take. The test layer in deck.gl-raster declares its `source` prop instead of passing type arguments. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The override test only checked COGLayer's own annotation of `_openSource`, so a derived input type of `any` passed it. A source of the wrong type is what such a type would let through. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Decision 19 says `SourceT` and `InputT` default to the two parts of a layer's `source` prop, and the Layers sample goes back to two type arguments. A new question 10 records the `ServerSource` idea for tile servers, for later. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`SourceOf` and `InputOf` hid two one-line definitions behind names. The defaults of `SourceT` and `InputT` now use `Extract` and `Exclude` directly, with a comment showing what each gives for COGLayer, and `SourcePropOf`'s doc explains its `keyof` check. The types don't change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Note
This PR was written by Claude (Claude Code), not by @kylebarron.
Stage 4a of the Sources design,
dev-docs/specs/2026-10-22-sources-design.md.RasterTileLayernow handles thesourceprop for every layer that takes one (question 5). COGLayer and MultiCOGLayer drop their copies of that code, and ZarrLayer won't need a third copy in 4b.A layer that takes a
sourcestill declares itssourceandonSourceLoadprops, which document its inputs (question 6). It also says how to open them:RasterTileLayerdoes the rest:SourceTandInputT, default to the two parts of the layer'ssourceprop, hereCOGSourceandCOGInput. They typesource,onSourceLoad,_openSource,_sourceStateandstate.source, so the base reads the props without casts, and a layer passes no extra type arguments.loadMetadatathrough_openSource. A result that arrives aftersourcechanged is dropped. OtherwiseonSourceLoadgets it, and the layer draws it.undefinedandnulldraw nothing.state.source, and the tile grid comes from it._sourceState(source)returns more state to keep with a source. COGLayer infers its default pipeline there. If it throws, the layer reports the error throughonErrorand draws nothing.Question 5's proposal had a second hook per layer,
isOpenedSource.instanceof RasterSourcereplaces it, since every source extendsRasterSource(decision 10). The hooks start with an underscore, like every other protected method in the repo.Behavior changes
Apart from these three changes, COGLayer and MultiCOGLayer behave as before.
updateState.renderLayers. The layer kept drawing the previous COG, and fetching its tiles, until another prop changed.onError, as "Can't draw the source in COGLayer: ...", and draws nothing.source: nulldraws nothing, likeundefined. Before, COGLayer and MultiCOGLayer reported an error for it.clearState()is gone from COGLayer and MultiCOGLayer. It was public, but undocumented.Spec
The spec records the stage 4 decisions, 18 to 23:
sourceandonSourceLoad.source.node,variable,metadataandepsgResolvermove toZarrSource.openoptions.selectionstays on the layer.ZarrSourceholds.The stage 4 entry now lists 4a, 4b and 4c. The 4c plan includes a texture leak to fix first: deck.gl's
Tileset2D.reloadAlldrops tiles without callingonTileUnload. Two new questions:metadataoption.ServerSourcefor tile servers, so that every layer takes asource. That one is for later.Tests
RasterTileLayer: 14 tests with a test layer.onSourceLoadgets the source.sourcereplaced is aborted, and its late result is dropped.nullsource draws nothing._sourceStateis stored, and its errors reachonError._openSourcerejects input.LayerManagerwith a stub device. It checks that the old source's sublayer goes away when_sourceStatethrows. Tests that callrenderLayersthemselves can't see that.onErrorinstead of a throw. Its other tests pass unchanged.nullsource.COGSource, and MultiCOGLayer's aMultiCOGSource.sourcetakes nothing else, such as a number.InputTtoanyornever, orSourceTtoRasterSource, fails them or the build.sourcechanges;_sourceState;_sourceState's errors again;nullsource.🤖 Written by Claude Code