Repository navigation
fix(deck.gl-raster): pick parent tile by centre in RasterTileset2D.getParentIndex - #841
Conversation
…tParentIndex COGs whose overviews were sized by halving and rounding down (e.g. 1543 -> 771 px) have a decimation like 2.0013 between levels, well beyond TILE_EDGE_TOLERANCE. Flooring the child's top-left corner then picks the left/top neighbour, so best-available refinement draws the placeholder over the wrong tile and leaves a hole while the child loads. Map the child's centre instead. It is half a tile from any edge, so it covers both this and the rounded scale denominators from developmentseed#738 without a tolerance, and is unchanged for whole-number decimation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Base the rounded-overview fixture on a COG that is already in examples/cog-basic instead of an external file. Co-Authored-By: Claude Opus 5.5 <[email protected]>
When a level's last tile holds only a sliver of data, such as the one column of a 2049px level over a 1024px one, the tile's center lies past the parent level's edge, so getParentIndex returned a parent that doesn't exist. Clamp it to the parent level's last column and row, which hold that data. Test getParentIndex against the parent holding most of each tile's data, instead of restating the center formula, and cover the sliver case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Note This comment was written by Claude (Claude Code), not by @kylebarron. I pushed 80c1721 on top of this PR:
This affects most COGs, not only Umbra. GDAL's COG driver rounds overview sizes down: Before (left, main) and after (right, this PR). Each run zooms in one level while tile requests are held for 3 s, with the control panel hidden: naip-mosaic-side-by-side.mp4naip-mosaic: on main, the last tile column of a NAIP COG shows the bare basemap; with this PR, its parent stays as the placeholder. cog-basic-umbra-side-by-side.mp4cog-basic, Umbra COG with the debug overlay, zooming into the image's corner (5714 -> 11429 px level): on main, the corner tile The views before the zoom and after the tiles load are pixel-identical between main and this PR. Only the placeholders shown while loading change. 🤖 Written by Claude Code |
kylebarron
left a comment
There was a problem hiding this comment.
Thanks! This is a bug I've seen for a while but hadn't taken the time to track down
> [!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]>
* chore: upgrade deck.gl-raster to 0.10.0-beta.3 and drop patches 0.10.0-beta.3 ships the getParentIndex fix (developmentseed/deck.gl-raster#841) and Cylindrical Equal Area support (#791), so the deck.gl-raster, geotiff and proj patches are no longer needed. Drop the test that guarded our patch; upstream owns that logic now. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: migrate to the 0.10 COGLayer source API 0.10 dropped COGLayer/MultiCOGLayer's geotiff, sources, epsgResolver, onGeoTIFFLoad and onError props in favour of an opened `source`. We still passed the old props, so the layer never opened anything: no tiles, no fit-to-bounds, no error. Open the COGSource / MultiCOGSource ourselves in the load effect (keeping robustEpsgResolver and loadGeoTIFF's CORS workaround), check and fit the bounds there, and hand the layer the opened source. A source with invalid bounds is never set, so the extentValid gate is no longer needed. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: address review of the 0.10 source migration - Fit to bounds in an effect gated on the map's onLoad; maplibre-gl loads asynchronously, so mapRef could still be null when the source opened. - Restore the layers' onError so layer failures reach the error toast. - Run validateCog on every file of a multi-COG, like the single-file path. - Derive geotiff from source and share one auto-stats effect, so a stats failure in multi-COG mode logs a warning instead of an error toast. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Note
After merge, Claude (Claude Code) updated the Fix and Testing sections for @kylebarron to match the merged code, which includes the clamp from 80c1721. The rest is the original description.
Problem
While a tile loads,
best-availablerefinement draws its parent (the coarser tile covering the same area) as a placeholder. For some COGs,getParentIndexreturns the parent's neighbour instead. That tile is drawn somewhere else, so the loading tile's area goes blank until it arrives.before.mp4
after.mp4
This happens when a COG's overview sizes were rounded down. Each overview halves the level above, but an odd size can't be halved exactly. For example, the Umbra Port of Rotterdam COG in
cog-basicgoes 22859 → 11429 px. Every level still covers the same extent, so the decimation between levels is slightly above 2 (here 22859 / 11429 ≈ 2.00009).getParentIndexmaps a child to a parent withfloor(x / decimation + TILE_EDGE_TOLERANCE). With decimation slightly above 2, an evenxlands just under a whole number, and the floor picks the tile before the right one:The
1e-6tolerance from #750 (for #738) absorbs floating-point noise like2.000000000000004, but not an error of ~10⁻⁴. A COG is affected when twice an overview's size is less than the size of the level above. Umbra's2 × 11429 = 22858 < 22859is one example.Fix
Map the child tile's centre instead of its left/top edge:
Tile
xspans[x, x + 1)in child-tile units, sox + 0.5is its centre. Dividing bydecimationconverts that to parent-tile units, andfloorgives the parent containing the centre, which is the one covering most of the child. When decimation is a whole number, including 1:1 (Sentinel-2's last overview), the result is unchanged. The centre is half a tile from any edge, sogetParentIndexno longer needsTILE_EDGE_TOLERANCE.The clamp covers a level whose last tile holds only a sliver of data. With 512 px tiles, for example, the last tile of a 2049 px level holds one column of data, but its centre lies past the edge of the 1024 px level, so without the clamp
getParentIndexwould return a column that doesn't exist.Testing
New cases in
tests/raster-tileset/get-parent-index.test.ts, using the overview widths of the Umbra COG fromcog-basic(357 → 22859 px, 512 px tiles), fail onmain:The tests check every tile against the parent holding most of its data, for the Umbra widths and for a 2049 px COG whose last tile holds one column of data. With this change, all 259 tests in
packages/deck.gl-rasterpass, including the #750 tests.To see it in
cog-basic: pick Umbra Port of Rotterdam (rotated COG) and tick Debug overlay. Then zoom quickly from the fourz=1tiles into the right-hand side of the image (I recommend setting network throttle to "Fast 4G" in devtools). Onmain, part of the screen drops to bare basemap while tiles load. With this change, the coarse tile stays visible until the fine tiles arrive.🤖 Generated with Claude Code
🤖 Written by Claude Code