Repository navigation
feat(deck.gl-geotiff): give renderSource the props MosaicLayer passes to sublayers - #789
Conversation
…cLayer sources
MosaicLayer didn't pass on the props a composite layer normally hands its
sublayers, so `opacity`, `pickable`, `parameters`, `modelMatrix`,
`extensions` and the rest had no effect on the layers its sources render.
Its inner TileLayer was built from a fixed set of props rather than
`getSubLayerProps()`, and its `renderSubLayers` called `renderSource`
without the props TileLayer hands it.
Build the inner TileLayer from `this.getSubLayerProps()`, as deck.gl's
TerrainLayer does, keeping its `mosaic-layer-${id}` id. Then clone each
layer `renderSource` returns with the inherited props it didn't set
itself, so a source can still set its own `opacity`. A layer's own props
are the ones passed to its constructor, since deck.gl keeps defaults on
the props prototype. The inherited keys are the ones `getSubLayerProps()`
returns, less the per-layer `id` and `updateTriggers`.
Also say why `MosaicTileset2DFactory` must be a new class on every
render: it is what makes the inner TileLayer pick up new `sources` and
re-render loaded sources with a new `renderSource`.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-props-refresh # Conflicts: # packages/deck.gl-geotiff/src/mosaic-layer/mosaic-layer.ts # packages/deck.gl-geotiff/tests/mosaic-layer.test.ts
… top of main Re-applies this PR's change to main's MosaicLayer, which stage 3 and #821 rewrote: the inner TileLayer is built from `getSubLayerProps()`, and each layer `renderSource` returns inherits the props it didn't set itself, such as `opacity`. `updateTriggers.all`, which `getSubLayerProps()` passes, no longer reaches the inner TileLayer, as in deck.gl's TerrainLayer: deck.gl's TileLayer would reload through `Tileset2D.reloadAll`, which leaks sources (#816). Co-Authored-By: Claude Opus 5.5 <[email protected]>
| const inheritedKeys = Object.keys(subLayerProps).filter( | ||
| (key) => key !== "id" && key !== "updateTriggers", | ||
| ); |
There was a problem hiding this comment.
Why do we have to override subLayerProps at all?
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
deck.gl doesn't pass a composite layer's props, such as opacity or extensions, to the layers it returns on its own. The composite has to pass this.getSubLayerProps() itself, and TerrainLayer does the same for its TileLayer (terrain-layer.ts#L363-L378). That's the first hop, MosaicLayer to its TileLayer.
The second object only adds what's MosaicLayer's own: the TileLayer's id, its tileset class and callbacks, and updateTriggers: {} to keep all out.
An item's layers are a second hop. TileLayer hands the inherited props on to renderSubLayers, but renderSource never sees them. So withInheritedProps copies them onto whatever renderSource returns, and inheritedKeys lists which props to copy.
🤖 Written by Claude Code
There was a problem hiding this comment.
Right, we need to pass down this.getSubLayerProps... I get that. But I don't see why we need these two lines on inheritedKeys
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
They're gone. e91e018 removed inheritedKeys and the cloning it fed. MosaicLayer now hands these props to renderSource as subLayerProps, and the app spreads them into its layers, so nothing has to list which props to copy. 006a657 adds a unique id for each item to those props.
🤖 Written by Claude Code
…ems each take Co-Authored-By: Claude Opus 5.5 <[email protected]>
| // An item's layers take them too, copied from the props TileLayer hands | ||
| // `renderSubLayers`. There, `id` is the tile's and `updateTriggers` are | ||
| // TileLayer's own, so an item's layers don't take those two. | ||
| const inheritedKeys = Object.keys(subLayerProps).filter( |
There was a problem hiding this comment.
oh, maybe this should be named like subGetTileDataProps?
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
Agreed that inheritedKeys doesn't say who inherits. But getTileData isn't involved: these keys are used in renderSubLayers, which copies those props onto the layers renderSource returns. A name with getTileData in it would point at the step that opens sources instead.
I'd name it after its target: itemLayerPropKeys, the keys of the props an item's layers inherit. It's also a list of keys, not of props. subLayerProps can stay, since it's deck.gl's own name (getSubLayerProps()).
Happy to rename it to that, or to whatever you prefer.
🤖 Written by Claude Code
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
Moot now: e91e018 removes inheritedKeys. What apps see is renderSource's subLayerProps option.
🤖 Written by Claude Code
| renderSubLayers: (props) => { | ||
| const { item, source } = props.data; | ||
| return renderSource(item, { source }); | ||
| const layers = renderSource(item, { source }); |
There was a problem hiding this comment.
Or, what if we passed props down into renderSource? as parameters that the user can then pass on if they'd like.
That's cleaner than us overriding any props automatically
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
I like that better. It's deck.gl's own pattern: TileLayer hands renderSubLayers its sublayer props, and deck.gl's docs example spreads them into the layer it returns, new BitmapLayer(props, {...}). It also removes the cloning, the nested-array flattening and the own-prop rule.
The shape I'd use:
renderSource: (item, { source, subLayerProps }) =>
new COGLayer({ ...subLayerProps, id: item.url, source }),- What
subLayerPropsholds: what MosaicLayer passes on, such asopacity,pickableandextensions, withoutidandupdateTriggers. Spreading it first never clobbers what the app sets after it. - Not everything TileLayer hands
renderSubLayers: that includes MosaicLayer's internalgetTileData, which would clash with COGLayer's own. - The cost: an app that doesn't spread it gets no inheritance, as with TileLayer. The docs example and naip-mosaic would spread it.
Shall I switch to that? The option could also be called just props.
🤖 Written by Claude Code
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
Done in e91e018. renderSource now gets subLayerProps, and MosaicLayer no longer clones the layers it returns. naip-mosaic spreads them and gains an opacity slider. In Chrome, moving it to 0.5 set all 120 of its COGLayers to opacity 0.5.
🤖 Written by Claude Code
Instead of MosaicLayer cloning each layer `renderSource` returns with the
props it inherits, `renderSource` gets them as `subLayerProps`, and the
app spreads them into the layers it returns, before their own props:
renderSource: (item, { source, subLayerProps }) =>
new COGLayer({ ...subLayerProps, id: item.url, source }),
This is how deck.gl's TileLayer hands `renderSubLayers` its props. It
drops the cloning, the nested-array flattening and the own-prop rule.
One destructuring now drops `id` and `updateTriggers` for both the inner
TileLayer and `renderSource`, so `updateTriggers.all` still never reaches
deck.gl's leaky `reloadAll`.
naip-mosaic spreads `subLayerProps` and gets an opacity slider, which
shows the mosaic's `opacity` reaching every item.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…erProps
`subLayerProps` now holds a unique `id` for each item,
`${mosaic id}-${item id}`, as deck.gl's TileLayer gives each tile's
sublayer one. `new COGLayer({ ...subLayerProps, source })` needs no id
of its own.
Its type now lists exactly what arrives: the `id`, and the 16 props
deck.gl passes from a composite layer to its sublayers. It no longer
offers every layer prop.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The bundled STAC features have no `id`, so MosaicLayer keyed its cache by each item's position, and since the previous commit, named each item's layer by it too. The image URL keys both now. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
> [!NOTE] > This PR was written by Claude (Claude Code), not by @kylebarron. Bumps `version` to `0.10.0-beta.3` in the root `package.json` and in every `packages/*/package.json`. The publish workflow publishes it under the `beta` dist-tag, so `latest` stays on 0.9.0. `CHANGELOG.md` gets a `v0.10.0-beta.3` section with GitHub's generated notes for the 17 PRs merged since v0.10.0-beta.2. ## Breaking change - #843: `MosaicLayer` no longer takes `maxCacheByteSize`. To bound an item's memory by bytes, set `maxCacheByteSize` on the layer that `renderSource` returns. ## Behavior changes - #839: a `MosaicLayer` item out of view keeps its opened source in the cache but drops its layers, which frees their textures. - #785: `parseGeoZarrMetadata` takes Y from the first entry of `spatial:dimensions` and X from the second, whatever their names, as v0.1 of the spatial convention says. Lists that aren't two entries long are rejected. - #841: `RasterTileset2D.getParentIndex` picks the parent tile that contains the child's centre. ## New APIs - #835: `parseVRT` in `@developmentseed/deck.gl-geotiff`, and `fromGDAL` in `@developmentseed/affine`. - #789: `renderSource` gets the props that `MosaicLayer` passes to its sublayers. ## Not included #838 (`ZarrSource` opens from a store with a `path`) and #837 (`DEFAULT_RANGE_READER` moves to `@developmentseed/deck.gl-raster`) are still open. Both are breaking. 🤖 Written by [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
…iggers.getSource changes (#848) > [!NOTE] > This PR was written by Claude (Claude Code), not by @kylebarron. `MosaicLayer` caches the source that `getSource` opens for each item. Until now, nothing opened those sources again. When something `getSource` reads changed, loaded items kept their old sources and only items loaded afterward used the new ones, so the mosaic could show a mix of both. Now a change to `updateTriggers.getSource` or `updateTriggers.all` opens every source again: ```ts new MosaicLayer({ data: items, getSource: (item, options) => COGSource.open(item.assets[band].href, options), updateTriggers: { getSource: band }, renderSource: (item, { source, subLayerProps }) => new COGLayer({ ...subLayerProps, source }), }); ``` - **How it works:** - MosaicLayer hands `updateTriggers.getSource` to its inner `TileLayer` as `updateTriggers.getTileData`, and `all` as `all`. When either changes, deck.gl's `TileLayer` calls the tileset's `reloadAll`, as it does upstream. - `MosaicTileset2D` overrides `reloadAll`. It unloads every source through `finalize` (#823), which also aborts the opens in flight. Then it makes the next update select the items in view again, and they open with the current `getSource`. Items out of view are opened when they come back. - **The old items stop drawing at once,** as #818's tiles do. - **A new `getSource` function alone opens nothing again,** as with deck.gl's accessors. - **deck.gl's own `reloadAll` is replaced** (#816): - It drops items out of view without unloading them, and keeps them in `tileset.tiles`. - It keeps drawing the items in view with their old sources until the new ones open, and never unloads the old ones. - The override stays until we adopt deck.gl v10's shared `Tileset2D` (#846). Its `reloadAll` unloads the tiles it drops, but still not the data a reload replaces. `renderSource` gets no trigger. Every render of MosaicLayer already draws the loaded items again with the current `renderSource`, and #844 tests that. RasterTileLayer still refetches through a count in its inner `TileLayer`'s id (#818). A follow-up moves it to the same override. ## Changes - **`MosaicLayer`** passes the two triggers to its inner `TileLayer`, and stores nothing. - **`MosaicTileset2D`** overrides `reloadAll`. - **Docs:** `getSource`'s docs say when and how to open the sources again. - **Spec:** decision 26 records this and the `renderSource` decision. The 4c entry points to it. ## Tests - **Runtime**, through deck.gl's `LayerManager`: - A change to `updateTriggers.getSource`, and to `updateTriggers.all`, opens every source again with the new `getSource`, and passes the old sources to `onSourceUnload`. - An unchanged trigger opens nothing again, even with a new `getSource` function. - The old items stop drawing at once, before the new sources open. - **`MosaicTileset2D`:** `reloadAll` unloads every item, and the next update selects the items in view again, even though the viewport hasn't changed. - **Replaced test:** #789 had a test that `all` doesn't open the sources again. `all` now opens them again, through the override instead of deck.gl's `reloadAll`. - **Mutation checks:** - Without the `setOptions` call in the override, 1 test fails. - Without the `getTileData` trigger, 2 tests fail. - Without the `all` trigger, 1 test fails. - Without the override, 4 tests fail. - **Everything else:** all 222 `deck.gl-geotiff` tests pass, as do the workspace typecheck and Biome. In Chrome, naip-mosaic still loads and pans with no errors. Closes #816 🤖 Written by [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Note
This PR was written by Claude (Claude Code), not by @kylebarron.
MosaicLayerdidn't hand its items' layers the props a composite layer normally passes to its sublayers. Soopacity,pickable,parameters,extensionsand the rest had no effect on them.Now
renderSourcegets them assubLayerProps, with a uniqueidfor each item. The app spreads them into the layers it returns, before their own props:This is how deck.gl's TileLayer hands
renderSubLayersits props, as in its docs example,new BitmapLayer(props, {...}). That includes a uniqueidfor each tile's sublayer. An app that doesn't spread them gets no inheritance.Changes
renderSource's options gainsubLayerProps:idfor each item,${mosaic id}-${item id};Its type lists exactly those 17 props. An item that returns several layers gives each its own
id.The inner
TileLayeris built from the same props.updateTriggers.all, as in deck.gl'sTerrainLayer. deck.gl'sTileLayerwould reload throughTileset2D.reloadAll, which leaks sources.naip-mosaic spreads
subLayerProps, and gains an opacity slider.id, so it now gives each item its image URL as one. Otherwise MosaicLayer keys its cache, and names each item's layer, by the item's position.Docs:
renderSourcedocumentssubLayerProps, and the class example and the spec spread it.MosaicTileset2DFactorymust be a new class on every render.Tests
opacityon aMosaicLayerreachesrenderSource, and the layers it returns.renderSourcegets a uniqueidfor each item, and noupdateTriggers.opacityreaches an item that's already loaded, without opening it again.updateTriggers.alldoesn't open the sources again through deck.gl's reload.renderSource's options have exactly the keyssourceandsubLayerProps.subLayerPropshas exactly the 17 props, and itsidis astring.subLayerPropsinto aCOGLayertypechecks, without anidof its own.subLayerPropsfails three of the four tests above.idfails three of them.updateTriggersin it fails theidandupdateTriggerstest and thealltest.naip-mosaic-layer-<image URL>.Closes #784
🤖 Written by Claude Code