Back to Atlas map viewer
SOURCE / PINNED RELEASE

Made of little things.

Atlas map viewer

Release
1d2807e80b44…
Author-recorded commit
43810ed2b368…
License
LICENSE
Author’s source reference
nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-4757dbabc86

Archive hash verified: 8db6876d96c460ac…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

packages/renderer/src/cache-coverage.ts
import type { TileView } from "./tile-presentation";
export interface CachedTile {
  z: number;
  x: number;
  y: number;
  total: number;
  cached: number;
  /** null means the directory is not fully known, not that the tile is empty. */
  fraction: number | null;
}
/** Inspect only known descriptors. No directory or payload downloads. Empty
 * layers have no block, so they must not count as missing cache entries. */
export function cacheCoverage(
  view: TileView,
  has: (key: string) => boolean,
): CachedTile[] {
  if (!view.layers.length) return [];
  const n = 2 ** view.zoom;
  const [w, north, e, south] = view.bounds;
  const cells = new Map<string, CachedTile>();
  const xmin = Math.max(0, Math.floor(w * n)),
    xmax = Math.min(n - 1, Math.floor(e * n));
  const ymin = Math.max(0, Math.floor(north * n)),
    ymax = Math.min(n - 1, Math.floor(south * n));
  // Guard pathological cameras; normal views contain tens of cells.
  if ((xmax - xmin + 1) * (ymax - ymin + 1) > 16384) return [];
  for (let y = ymin; y <= ymax; y++)
    for (let x = xmin; x <= xmax; x++)
      cells.set(`${x}/${y}`, {
        z: view.zoom,
        x,
        y,
        total: 0,
        cached: 0,
        fraction: null,
      });
  for (const b of view.blocks) {
    if (b.z !== view.zoom) continue;
    const cell = cells.get(`${b.x}/${b.y}`);
    if (cell) {
      cell.total++;
      if (has(b.key)) cell.cached++;
    }
  }
  for (const cell of cells.values())
    cell.fraction = view.complete
      ? cell.total
        ? cell.cached / cell.total
        : 0
      : null;
  return [...cells.values()];
}