Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions packages/deck.gl-geotiff/src/cog-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ export class COGLayer<
forwardReproject,
inverseReproject,
),
refinementStrategy: updateTileStateDefault,
});
}

Expand Down Expand Up @@ -476,3 +477,78 @@ function computeTileGeotransform(

return [a, b, xCoordOffset, d, e, yCoordOffset];
}

// bit masks
const TILE_STATE_VISITED = 1;
const TILE_STATE_VISIBLE = 2;

// For all the selected && pending tiles:
// - pick the closest ancestor as placeholder
// - if no ancestor is visible, pick the closest children as placeholder
function updateTileStateDefault(allTiles: Tile2DHeader[]) {
for (const tile of allTiles) {
tile.state = 0;
}
for (const tile of allTiles) {
if (tile.isSelected && !getPlaceholderInAncestors(tile)) {
getPlaceholderInChildren(tile);
}
}
for (const tile of allTiles) {
tile.isVisible = Boolean(tile.state! & TILE_STATE_VISIBLE);
}
}

// Until a selected tile and all its selected siblings are loaded, use the closest ancestor as placeholder
function updateTileStateReplace(allTiles: Tile2DHeader[]) {
for (const tile of allTiles) {
tile.state = 0;
}
for (const tile of allTiles) {
if (tile.isSelected) {
getPlaceholderInAncestors(tile);
}
}
// Always process parents first
const sortedTiles = Array.from(allTiles).sort((t1, t2) => t1.zoom - t2.zoom);
for (const tile of sortedTiles) {
tile.isVisible = Boolean(tile.state! & TILE_STATE_VISIBLE);

if (tile.children && (tile.isVisible || tile.state! & TILE_STATE_VISITED)) {
// If the tile is rendered, or if the tile has been explicitly hidden, hide all of its children
for (const child of tile.children) {
child.state = TILE_STATE_VISITED;
}
} else if (tile.isSelected) {
getPlaceholderInChildren(tile);
}
}
}

// Walk up the tree until we find one ancestor that is loaded. Returns true if successful.
function getPlaceholderInAncestors(startTile: Tile2DHeader) {
console.log("getPlaceholderInAncestors");
let tile: Tile2DHeader | null = startTile;
while (tile) {
console.log(" tile", tile.id, tile.isLoaded, Boolean(tile.content));
console.log("should set state", Boolean(tile.isLoaded || tile.content));
if (tile.isLoaded || tile.content) {
tile.state! |= TILE_STATE_VISIBLE;
return true;
}
tile = tile.parent;
console.log("parent tile", tile);
}
return false;
}

// Recursively set children as placeholder
function getPlaceholderInChildren(tile: Tile2DHeader) {
for (const child of tile.children) {
if (child.isLoaded || child.content) {
child.state |= TILE_STATE_VISIBLE;
} else {
getPlaceholderInChildren(child);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export class RasterTileset2D extends Tileset2D {
return `${index.x}-${index.y}-${index.z}`;
}

/** Get a list of all parents at one zoom level prior */
getAllNearestParentIndices(index: TileIndex): TileIndex[] {}

override getParentIndex(index: TileIndex): TileIndex {
if (index.z === 0) {
// Already at coarsest level
Expand Down
Loading