mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Knip, configured with the application, package exports, scripts, QA harnesses, workers, tools and tests as entry points, reports exports that no module imports. Each was checked by hand against string-based and namespace imports. - Symbols that are still used inside their own module lose only the `export` keyword (176 constants and helpers). - Unused re-exports are removed from barrel modules (flight, military, vessel, CCTV, directions, transit history, local ADS-B and street-level policy modules). - Declarations that nothing uses at all are deleted, among them AIS_WATCHDOG_STATUSES, applyFilter, isRadioCountryCode, compactText, DENSITY_STOPS, the unused CCTV endpoint constants, and the SDR band constants. - Default exports that nothing imports are removed. The ones in src/data/earthquakes.js, src/data/telegeographySubmarineCables.js, src/data/wind.js and src/data/bhoteKoshiLocator.js each constructed a layer instance at import time that nothing used; those instances are no longer created. Every export of a package.json entry stays, as does TOMTOM_CREDIT, which the traffic layer reads from the credits namespace it is given.
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
/** Decoded coverage tiles kept, and for how long. */
|
|
const TILE_CACHE_SIZE = 24;
|
|
const TILE_CACHE_TTL_MS = 10 * 60_000;
|
|
|
|
/** Least-recently-used map: reading an entry renews it. */
|
|
export function createLru(limit) {
|
|
const map = new Map();
|
|
return {
|
|
get(key) {
|
|
if (!map.has(key)) return undefined;
|
|
const value = map.get(key);
|
|
map.delete(key);
|
|
map.set(key, value);
|
|
return value;
|
|
},
|
|
set(key, value) {
|
|
map.delete(key);
|
|
map.set(key, value);
|
|
while (map.size > limit) map.delete(map.keys().next().value);
|
|
},
|
|
delete: (key) => map.delete(key),
|
|
clear: () => map.clear(),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Loaded (decoded) coverage tiles by `keyOf` (default `z/x/y`), at most `size`, each for
|
|
* `ttlMs`: a pan back, or a zoom across bands and back, neither fetches nor
|
|
* decodes them again. A load that fails is not kept.
|
|
*/
|
|
export function createTileCache({
|
|
load,
|
|
size = TILE_CACHE_SIZE,
|
|
ttlMs = TILE_CACHE_TTL_MS,
|
|
now = Date.now,
|
|
keyOf = (tile) => `${tile.z}/${tile.x}/${tile.y}`,
|
|
}) {
|
|
const kept = createLru(size);
|
|
return {
|
|
async get(tile, options) {
|
|
const key = keyOf(tile);
|
|
const entry = kept.get(key);
|
|
if (entry && now() - entry.at < ttlMs) return entry.tile;
|
|
const loaded = await load(tile, options);
|
|
kept.set(key, { at: now(), tile: loaded });
|
|
return loaded;
|
|
},
|
|
/** Forget every tile (the layer is off: its memory goes back). */
|
|
clear: () => kept.clear(),
|
|
};
|
|
}
|