Files
gods-eye-view/server/providers/mapillary/trim.js
T
German KhokhlovandClaude Fable 5.1 e214129e45 refactor(street-level): drop hover, legend and byte-budget cache; flatten the provider directory
- No pointer cursor over coverage lines (no other layer has one); a click
  test replaces the hover tests.
- No legend: one source, one colour.
- The on-globe credit lives in index.js; credits.js is gone.
- Billboard glyphs are SVG data URLs with the same geometry, so tests need
  no canvas stub.
- The tile cache keeps the 120 most recently used tiles, same 24 h TTL,
  instead of a byte budget; listTileLayers was test-only.
- providers/mapillary/ is flattened into the layer and its policy merged
  into one policy.js; the source's method list is a literal in the catalog.
- One fakeCesiumViewer for the layer tests.
- The fixture gate keeps the steps the unit tests do not cover: coverage and
  credit, a rejected key, line -> cone -> photo, close, a keyless page.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-10-08 19:17:45 +04:00

44 lines
1.4 KiB
JavaScript

import { PbfReader, PbfWriter } from 'pbf';
/** Field number of `layers` in a Mapbox Vector Tile, and of `name` in a layer. */
const TILE_LAYER_FIELD = 3;
const LAYER_NAME_FIELD = 1;
/** Read a layer's name without touching its features. */
function layerName(layerBytes) {
const pbf = new PbfReader(layerBytes);
let name = '';
pbf.readFields((tag, _result, reader) => {
if (tag !== LAYER_NAME_FIELD) return;
name = reader.readString();
reader.pos = reader.length; // the name is all we need
}, null);
return name;
}
/**
* Drop whole layers from a vector tile without decoding kept layers, so a
* 12 MB tile trims in milliseconds. Returns the input when nothing was dropped.
* @param {Buffer|Uint8Array} bytes
* @param {Iterable<string>} dropNames
*/
export function stripTileLayers(bytes, dropNames) {
const drop = new Set(dropNames || []);
if (!bytes?.length || !drop.size) return bytes;
const reader = new PbfReader(bytes);
const writer = new PbfWriter();
let dropped = false;
reader.readFields((tag, _result, pbf) => {
if (tag !== TILE_LAYER_FIELD) return;
const end = pbf.readVarint() + pbf.pos;
const layerBytes = bytes.subarray(pbf.pos, end);
pbf.pos = end;
if (drop.has(layerName(layerBytes))) {
dropped = true;
return;
}
writer.writeBytesField(TILE_LAYER_FIELD, layerBytes);
}, null);
return dropped ? Buffer.from(writer.finish()) : bytes;
}