Merge main into german/i18n-plurals-context

The catalogs conflicted only on neighbouring lines: no key changed on both
sides, so they are merged key by key in main's order. Main removed the rail
timeline, the other user of plain "Latest", so that entry is pruned and the
News test no longer checks the timeline's wording.
This commit is contained in:
German Khokhlov committed 2026-11-16 16:58:37 +04:00
commit 49409ba8f1
1502 files changed
+180715 -47887

No files matched your search

+218 -123
View File
@@ -1,4 +1,3 @@
import * as Cesium from 'cesium';
import {
decodeXml,
kmzImageResolver,
@@ -15,6 +14,9 @@ import {
tn,
} from '../../i18n/index.js';
import { createHorizonCull } from '../streetLevel/view.js';
import { fromDegrees } from '../../geo/ellipsoid.js';
import { hexColor } from '../../render/color.js';
import { drawOf, findFrame } from '../../render/rendererOf.js';
import { readGhostMapsKml } from './kml.js';
import {
fieldLabel,
@@ -25,6 +27,7 @@ import {
parseDescriptionFields,
wrapCardText,
} from './records.js';
import { inputFor as defaultInputFor } from '../../input/dispatcher.js';
export * from './catalog.js';
export * from './records.js';
export { readGhostMapsKml } from './kml.js';
@@ -128,10 +131,34 @@ function markerImage(color) {
return url;
}
const cesiumColor = (rgba, fallback, alpha) =>
const drawColor = (rgba, fallback, alpha) =>
rgba
? new Cesium.Color(rgba[0], rgba[1], rgba[2], alpha ?? rgba[3])
: Cesium.Color.fromCssColorString(fallback).withAlpha(alpha ?? 1);
? [rgba[0], rgba[1], rgba[2], alpha ?? rgba[3]]
: hexColor(fallback, alpha ?? 1);
/** The size a marker image draws at, before its scale: the product marker. */
const MARKER_SIZE = [20, 20];
/**
* An image's own size in pixels, as an icon drew it unsized; null when it
* cannot be read here (no DOM, or the image does not decode).
*/
async function imageSizeOf(url) {
if (typeof globalThis.Image !== 'function' || !url) return null;
try {
const image = new globalThis.Image();
image.src = url;
await image.decode();
return image.naturalWidth > 0 && image.naturalHeight > 0
? [image.naturalWidth, image.naturalHeight]
: null;
} catch {
return null;
}
}
/** Each layer's draw sets have ids of their own. */
let instances = 0;
function anchorOf(geometry) {
if (geometry.type === 'point') return geometry.position;
@@ -154,9 +181,8 @@ function anchorOf(geometry) {
export function createGhostMapsLayer({
source,
overlayHost = null,
screenSpaceEventHandlerFactory = null,
inputFor = defaultInputFor,
picking = null,
pointer = null,
openExternal = null,
storage = defaultStorage(),
now = () => Date.now(),
@@ -170,7 +196,7 @@ export function createGhostMapsLayer({
let _unsubscribe = null;
let _stream = 'closed';
let _queue = Promise.resolve();
let _clickHandler = null;
let _clickSubscription = null;
let _rowListener = null;
let _selectedKey = null;
let _selectedCardId = null;
@@ -179,7 +205,7 @@ export function createGhostMapsLayer({
let _selection = readStoredSelection(storage);
let _ageDays = readStoredAge(storage);
let _expiryTimer = null;
/** productId → {version, dataSource, urls, features: Map<index, record>, pins} */
/** productId → {version, ageDays, sets, urls, features: Map<index, record>, pins} */
const _loaded = new Map();
/** productId → in-flight version */
const _loading = new Map();
@@ -187,7 +213,11 @@ export function createGhostMapsLayer({
const _failed = new Map();
const notifyRow = () => _rowListener?.();
const render = () => _viewer?.scene?.requestRender?.();
const render = () =>
_viewer && findFrame(_viewer)?.requestRender?.('ghostmaps');
/** This layer's draw sets' ids start with this; one set per edition. */
const setBase = `${GHOSTMAPS_LAYER_ID}:${++instances}`;
let editions = 0;
// Pins skip the depth test, and with Google 3D tiles the globe is hidden,
// so nothing else stops far-side pins drawing through the planet.
const _horizon = createHorizonCull({
@@ -195,10 +225,18 @@ export function createGhostMapsLayer({
items: function* () {
for (const item of _loaded.values()) yield* item.pins;
},
onChange: render,
// Pins the cull turned are written to their editions' icon sets.
onChange: (changed) => {
const bySet = new Map();
for (const pin of changed) {
if (!bySet.has(pin.set)) bySet.set(pin.set, []);
bySet.get(pin.set).push(pin.item);
}
for (const [set, items] of bySet) set?.upsert(items);
render();
},
});
const canSelect = () =>
overlayHost && screenSpaceEventHandlerFactory && picking;
const canSelect = () => overlayHost && inputFor && picking;
function wanted(product) {
return _selection ? _selection.has(product.id) : product.defaultOn;
@@ -212,21 +250,22 @@ export function createGhostMapsLayer({
const item = _loaded.get(id);
if (!item) return;
_loaded.delete(id);
_viewer?.dataSources?.remove(item.dataSource, true);
disposeSets(item.sets);
item.urls.forEach((url) => URL.revokeObjectURL(url));
if (!keepSelection && _selectedKey?.startsWith(`${id}:`)) clearSelection();
}
// Remove expired entities, rather than hiding them: horizon culling must
// never make an old pin visible again. Map keys keep surviving picks stable.
// Remove expired placemarks' items, rather than hiding them: horizon
// culling must never make an old pin visible again. Map keys keep
// surviving picks stable.
function expireEvents() {
const at = now();
let changed = false;
for (const [productId, item] of _loaded) {
for (const [index, feature] of item.features) {
if (!isGhostMapsEventExpired(feature.dateMs, at, _ageDays)) continue;
for (const entity of feature.entities)
item.dataSource.entities.remove(entity);
for (const [kind, ids] of Object.entries(feature.itemIds))
if (ids.length) item.sets?.[kind]?.remove(ids);
item.features.delete(index);
if (_selectedKey === `${productId}:${index}`) clearSelection();
changed = true;
@@ -239,7 +278,56 @@ export function createGhostMapsLayer({
}
}
/** Build one product's data source off-scene, then swap it in. */
function disposeSets(sets) {
if (!sets) return;
for (const set of Object.values(sets)) set.dispose();
}
/**
* Draw a loaded edition in sets of its own, beside any edition drawing
* now. One that cannot be drawn draws nothing and lets its images go.
*/
function mount(next) {
const base = `${setBase}:${++editions}`;
const sets = {};
try {
// Inside the try: a viewer with no renderer bound draws nothing and
// still lets the edition's images go.
const draw = drawOf(_viewer);
sets.shapes = draw.shapes({ id: `${base}:shapes`, clampTo: 'both' });
sets.lines = draw.lines({ id: `${base}:lines`, clampTo: 'both' });
sets.icons = draw.icons({ id: `${base}:icons`, clampTo: 'both' });
sets.shapes.set(next.items.shapes);
sets.lines.set(next.items.lines);
sets.icons.set(next.items.icons);
} catch (error) {
disposeSets(sets);
next.urls.forEach((url) => URL.revokeObjectURL(url));
throw error;
}
for (const pin of next.pins) pin.set = sets.icons;
next.sets = sets;
}
/** The placemark a hit on one of this layer's items is, or null. */
function hitKey(hit) {
if (
!hit?.set?.startsWith(`${setBase}:`) ||
!hit.id?.startsWith(PICK_PREFIX)
)
return null;
const [productId, index] = hit.id.slice(PICK_PREFIX.length).split(':');
const loaded = _loaded.get(productId);
// Only the drawing edition's sets: a retiring one may still pick.
const current = loaded?.sets
? Object.values(loaded.sets).some((set) => set?.id === hit.set)
: false;
return current && loaded.features.has(Number(index))
? `${productId}:${index}`
: null;
}
/** Build one product's draw items off-scene, then swap them in. */
async function load(product, signal) {
const ageDays = _ageDays;
const bytes = await source.getFile(product.id, product.version, { signal });
@@ -268,107 +356,125 @@ export function createGhostMapsLayer({
entries.clear();
signal.throwIfAborted();
const color = PRODUCT_COLORS[product.id] || ACCENT;
const dataSource = new Cesium.CustomDataSource(
`${GHOSTMAPS_LAYER_ID}:${product.id}`,
);
const icons = [];
const lines = [];
const shapes = [];
const features = new Map();
const pins = [];
const at = now();
dataSource.entities.suspendEvents();
// Each distinct icon's own size, read once: icons draw at it, scaled.
const sizes = new Map();
const marker = markerImage(color);
for (const feature of parsed.features)
for (const geometry of feature.geometries)
if (geometry.type === 'point') {
const image = feature.style.icon || marker;
if (image && !sizes.has(image))
sizes.set(
image,
image === marker ? MARKER_SIZE : imageSizeOf(image),
);
}
for (const [image, size] of sizes) sizes.set(image, await size);
signal.throwIfAborted();
parsed.features.forEach((feature, index) => {
const dateMs = ghostMapsEventDate(feature.description);
if (isGhostMapsEventExpired(dateMs, at, ageDays)) return;
const key = `${product.id}:${index}`;
const { style } = feature;
const entities = [];
// The items each placemark draws, by set, for expiry to take off.
const itemIds = { icons: [], lines: [], shapes: [] };
feature.geometries.forEach((geometry, part) => {
const id = `${PICK_PREFIX}${key}:${part}`;
if (geometry.type === 'point') {
const position = Cesium.Cartesian3.fromDegrees(
...geometry.position,
);
const entity = dataSource.entities.add({
const position = fromDegrees(...geometry.position);
const image = style.icon || marker;
// An image that cannot be drawn shows nothing, as before.
if (!image) return;
const item = {
id,
position,
billboard: {
image: style.icon || markerImage(color),
scale: Math.min(
1.5,
Math.max(0.35, (style.iconScale ?? 1) * 0.7),
),
color:
style.icon && style.iconColor
? cesiumColor(style.iconColor)
: undefined,
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
verticalOrigin: Cesium.VerticalOrigin.CENTER,
// Ground-clamped icons would sink into terrain and 3D tiles; the
// horizon cull hides the far side instead (see `_horizon`).
disableDepthTestDistance: Number.POSITIVE_INFINITY,
},
});
entities.push(entity);
pos: position,
image,
size: sizes.get(image) ?? MARKER_SIZE,
scale: Math.min(
1.5,
Math.max(0.35, (style.iconScale ?? 1) * 0.7),
),
...(style.icon && style.iconColor
? { color: style.iconColor }
: {}),
height: 'clampGround',
anchor: 'center',
// Ground-clamped icons would sink into terrain and 3D tiles; the
// horizon cull hides the far side instead (see `_horizon`).
disableDepthTest: Number.POSITIVE_INFINITY,
};
const slot = icons.push(item) - 1;
itemIds.icons.push(id);
// What the horizon cull turns: the icon as it draws now, in its
// edition's icon set once mounted.
pins.push({
index,
position,
set: null,
get item() {
return icons[slot];
},
get show() {
return entity.show;
return icons[slot].show !== false;
},
set show(value) {
entity.show = value;
icons[slot] = { ...icons[slot], show: value };
},
});
} else if (geometry.type === 'line') {
entities.push(
dataSource.entities.add({
id,
polyline: {
positions: Cesium.Cartesian3.fromDegreesArray(
geometry.positions.flat(),
),
width: Math.min(8, Math.max(1.5, style.lineWidth ?? 2)),
material: cesiumColor(style.lineColor, color),
clampToGround: true,
},
}),
);
itemIds.lines.push(id);
lines.push({
id,
positions: geometry.positions.map(([lon, lat]) =>
fromDegrees(lon, lat),
),
widthPx: Math.min(8, Math.max(1.5, style.lineWidth ?? 2)),
mode: 'draped',
style: {
kind: 'solid',
color: drawColor(style.lineColor, color),
},
});
} else {
const ring = (points) =>
Cesium.Cartesian3.fromDegreesArray(points.flat());
entities.push(
dataSource.entities.add({
id,
polygon: {
hierarchy: new Cesium.PolygonHierarchy(
ring(geometry.outer),
geometry.holes.map(
(hole) => new Cesium.PolygonHierarchy(ring(hole)),
const ring = (points) => points.map(([lon, lat]) => ({ lon, lat }));
itemIds.shapes.push(id);
shapes.push({
id,
geometry: {
kind: 'polygon',
rings: [ring(geometry.outer), ...geometry.holes.map(ring)],
},
// An unfilled polygon is still there to click, as before.
fill:
style.fill === false
? [0, 0, 0, 0]
: drawColor(
style.polyColor,
color,
style.polyColor ? undefined : 0.25,
),
),
material:
style.fill === false
? Cesium.Color.TRANSPARENT
: cesiumColor(
style.polyColor,
color,
style.polyColor ? undefined : 0.25,
),
classificationType: Cesium.ClassificationType.BOTH,
},
}),
);
height: 'clampGround',
});
if (style.outline !== false) itemIds.lines.push(`${id}:outline`);
if (style.outline !== false)
entities.push(
dataSource.entities.add({
id: `${id}:outline`,
polyline: {
positions: ring([...geometry.outer, geometry.outer[0]]),
width: Math.min(6, Math.max(1.5, style.lineWidth ?? 2)),
material: cesiumColor(style.lineColor, color),
clampToGround: true,
},
}),
);
lines.push({
id: `${id}:outline`,
positions: [...geometry.outer, geometry.outer[0]].map(
([lon, lat]) => fromDegrees(lon, lat),
),
widthPx: Math.min(6, Math.max(1.5, style.lineWidth ?? 2)),
mode: 'draped',
style: {
kind: 'solid',
color: drawColor(style.lineColor, color),
},
});
}
});
features.set(index, {
@@ -376,15 +482,15 @@ export function createGhostMapsLayer({
folder: feature.folder,
description: feature.description,
dateMs,
entities,
itemIds,
anchor: anchorOf(feature.geometries[0]),
});
});
dataSource.entities.resumeEvents();
return {
version: product.version,
ageDays,
dataSource,
items: { icons, lines, shapes },
sets: null,
urls,
features,
pins,
@@ -421,8 +527,8 @@ export function createGhostMapsLayer({
return;
}
// Cull before the first frame so far-side pins never flash.
_horizon.update(next.pins);
await _viewer.dataSources.add(next.dataSource);
_horizon.update(next.pins, { quiet: true });
mount(next);
// The new edition is on the globe before the old one leaves. The card
// stays only if its index still holds the same report: the server
// may answer a pinned version with newer bytes.
@@ -565,7 +671,7 @@ export function createGhostMapsLayer({
// when its marker turns behind the planet.
stateless: true,
horizonCull: true,
position: Cesium.Cartesian3.fromDegrees(...feature.anchor),
position: fromDegrees(...feature.anchor),
};
if (card.interactive) {
const link = _selectedLink;
@@ -593,37 +699,25 @@ export function createGhostMapsLayer({
overlayHost?.setEntries(GHOSTMAPS_OVERLAY_SOURCE_ID, [], CARD_HOST_OPTIONS);
}
function pickedKey(picked) {
const pickId = picking.resolvePickId(picked);
if (typeof pickId !== 'string' || !pickId.startsWith(PICK_PREFIX))
return null;
const [productId, index] = pickId.slice(PICK_PREFIX.length).split(':');
return _loaded.get(productId)?.features.has(Number(index))
? `${productId}:${index}`
: null;
}
function installClickHandler() {
if (!canSelect() || _clickHandler || !_viewer) return;
if (!canSelect() || _clickSubscription || !_viewer) return;
picking.registerPickOwner?.(
GHOSTMAPS_LAYER_ID,
(pickedId) =>
typeof pickedId === 'string' && pickedId.startsWith(PICK_PREFIX),
);
_clickHandler = screenSpaceEventHandlerFactory(_viewer);
_clickHandler.setInputAction((click) => {
if (pointer && !pointer.isPointerFree()) return;
_clickSubscription = inputFor(_viewer).onClick((event) => {
const cardHit = overlayHost.hitTest?.(
click.position?.x,
click.position?.y,
event.screenPosition?.x,
event.screenPosition?.y,
{ sourceId: GHOSTMAPS_OVERLAY_SOURCE_ID },
);
if (cardHit && cardHit.entryId === _selectedCardId) {
if (_selectedLink && openExternal) openExternal(_selectedLink);
return;
}
const picked = _viewer.scene.pick(click.position);
const key = picked ? pickedKey(picked) : null;
const picked = event.topHit;
const key = picked ? hitKey(event.drawHit) : null;
if (key) {
_selectedKey = key;
publishCard();
@@ -639,12 +733,12 @@ export function createGhostMapsLayer({
clearSelection();
render();
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
});
}
function removeClickHandler() {
_clickHandler?.destroy();
_clickHandler = null;
_clickSubscription?.();
_clickSubscription = null;
picking?.unregisterPickOwner?.(GHOSTMAPS_LAYER_ID);
}
@@ -673,7 +767,8 @@ export function createGhostMapsLayer({
_lifetime = new AbortController();
if (_expiryTimer === null)
_expiryTimer = setInterval(expireEvents, 60_000);
for (const item of _loaded.values()) item.dataSource.show = true;
for (const item of _loaded.values())
for (const set of Object.values(item.sets ?? {})) set.show = true;
installClickHandler();
if (!_unsubscribe && typeof source.subscribe === 'function')
_unsubscribe = source.subscribe(
+97 -64
View File
@@ -1,8 +1,8 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import * as Cesium from 'cesium';
import { setLocale } from '../../i18n/index.js';
import { createGhostMapsLayer } from './index.js';
import { bindFakeDraw } from '../../testSupport/fakeDrawPort.mjs';
import { GHOSTMAPS_PRODUCTS, GHOSTMAPS_LATEST_DROP } from './catalog.js';
function element(localName, children = [], value = '', attributes = {}) {
@@ -119,18 +119,48 @@ function fixture(
});
t.mock.method(URL, 'revokeObjectURL', (url) => revoked.push(url));
t.mock.method(console, 'warn', () => {});
const mounted = new Set();
const viewer = {
scene: { requestRender() {} },
dataSources: {
async add(dataSource) {
mounted.add(dataSource);
return dataSource;
},
remove(dataSource) {
return mounted.delete(dataSource);
const viewer = {};
// An input port and a query port: a click picks what `click(id)` names.
const listeners = new Set();
let picked = null;
const { draw, unbind } = bindFakeDraw(viewer, {
input: {
on(type, cb) {
if (type !== 'click') return () => {};
listeners.add(cb);
return () => listeners.delete(cb);
},
},
query: { pick: () => picked },
});
t.after(unbind);
// Every live item, by id, with the id of the set drawing it.
const items = () =>
new Map(
[...draw.sets.values()]
.filter((set) => !set.disposed)
.flatMap((set) => [...set.items.keys()].map((id) => [id, set.spec.id])),
);
const liveSets = () => [...draw.sets.values()].filter((set) => !set.disposed);
const click = (id) => {
const set = items().get(id);
picked = set ? { set, id } : null;
for (const cb of [...listeners])
cb({
position: { x: 0, y: 0 },
button: 0,
modifiers: { shift: false, ctrl: false, alt: false },
});
};
// The editions drawn: each draws in sets of its own.
const mounted = {
get size() {
return new Set(
[...draw.sets.values()]
.filter((set) => !set.disposed)
.map((set) => set.spec.id.split(':').slice(0, 3).join(':')),
).size;
},
};
const layer = createGhostMapsLayer({
storage: null,
@@ -151,7 +181,18 @@ function fixture(
layer.init(viewer);
layer.enable();
t.after(() => layer.destroy());
return { layer, viewer, mounted, created, revoked };
return {
layer,
viewer,
draw,
unbind,
mounted,
created,
revoked,
items,
liveSets,
click,
};
}
test('cancelling a file read does not allocate packed-image URLs', async (t) => {
@@ -174,9 +215,9 @@ test('cancellation during parsing releases every packed-image URL', async (t) =>
assert.equal(mounted.size, 0);
});
test('entity construction failure releases parsed image URLs', async (t) => {
const { layer, viewer, mounted, created, revoked } = fixture(t);
t.mock.method(Cesium.EntityCollection.prototype, 'add', () => {
test('a draw failure releases parsed image URLs', async (t) => {
const { layer, viewer, draw, mounted, created, revoked } = fixture(t);
t.mock.method(draw, 'icons', () => {
throw new Error('fixture entity failure');
});
await layer.update(viewer);
@@ -186,13 +227,34 @@ test('entity construction failure releases parsed image URLs', async (t) => {
assert.equal(layer.getStats().error, 'fixture entity failure');
});
test('a viewer with no renderer bound releases parsed image URLs', async (t) => {
const { layer, viewer, unbind, mounted, created, revoked } = fixture(t);
unbind();
await layer.update(viewer);
assert.equal(created.length, 1);
assert.deepEqual(revoked, created);
assert.equal(mounted.size, 0);
assert.ok(layer.getStats().error);
});
test('successful load keeps icons until the product is disabled', async (t) => {
const { layer, viewer, mounted, created, revoked } = fixture(t);
const { layer, viewer, draw, mounted, created, revoked } = fixture(t);
await layer.update(viewer);
assert.equal(created.length, 1);
assert.equal(revoked.length, 0);
assert.equal(mounted.size, 1);
assert.equal(layer.getStats().count, 1);
const pins = [...draw.sets.values()].find(
(set) => !set.disposed && set.kind === 'icons',
);
const [pin] = pins.items.values();
assert.equal(pin.id, 'ghostmaps:cip:0:0');
assert.equal(pin.image, 'blob:local-0');
assert.equal(pin.height, 'clampGround');
assert.equal(pins.spec.clampTo, 'both');
assert.equal(pin.disableDepthTest, Infinity);
assert.equal(pin.scale, 0.7);
assert.deepEqual(pin.size, [20, 20], 'unread in Node: the marker size');
layer.disable();
assert.deepEqual(revoked, created);
assert.equal(mounted.size, 0);
@@ -393,7 +455,7 @@ test('age filtering and All markers apply to every conflict-map product, includi
});
test('default products filter old event dates while keeping recent, future and undated markers', async (t) => {
const { layer, viewer, mounted } = fixture(t, {
const { layer, viewer, items } = fixture(t, {
now: () => Date.UTC(2026, 10, 3, 12),
reports: [
dated('Old event', '10/20/2026'),
@@ -427,21 +489,17 @@ test('default products filter old event dates while keeping recent, future and u
],
);
assert.equal(layer.getStats().count, 7);
assert.equal([...mounted][0].entities.values.length, 7);
assert.equal(items().size, 7);
// Filtering cannot shift pick ids onto a different report.
assert.ok([...mounted][0].entities.getById('ghostmaps:cip:1:0'));
assert.equal(
[...mounted][0].entities.getById('ghostmaps:cip:0:0'),
undefined,
);
assert.ok(items().has('ghostmaps:cip:1:0'));
assert.equal(items().has('ghostmaps:cip:0:0'), false);
});
test('unchanged cached products age out on the timer, clear selected cards and keep surviving picks', async (t) => {
t.mock.timers.enable({ apis: ['setInterval'] });
let at = Date.UTC(2026, 10, 3, 12);
let click;
const cards = [];
const { layer, viewer, mounted } = fixture(t, {
const { layer, viewer, mounted, items, liveSets, click } = fixture(t, {
now: () => at,
reports: [
dated('Expiring', '10/27/2026 12:00:00 PM'),
@@ -449,31 +507,23 @@ test('unchanged cached products age out on the timer, clear selected cards and k
],
controls: {
overlayHost: { setEntries: (_id, entries) => cards.push(entries) },
screenSpaceEventHandlerFactory: () => ({
setInputAction: (fn) => {
click = fn;
},
destroy() {},
}),
picking: { resolvePickId: (picked) => picked },
},
});
await layer.update(viewer);
const ds = [...mounted][0];
viewer.scene.pick = () => 'ghostmaps:cip:0:0';
click({ position: { x: 0, y: 0 } });
const sets = liveSets();
click('ghostmaps:cip:0:0');
assert.equal(cards.at(-1).length, 1);
at += 60_000;
t.mock.timers.tick(60_000);
assert.equal(layer.getStats().count, 1);
assert.equal(ds.entities.values.length, 1);
assert.equal(ds.entities.getById('ghostmaps:cip:0:0'), undefined);
assert.ok(ds.entities.getById('ghostmaps:cip:1:0'));
assert.equal(items().size, 1);
assert.equal(items().has('ghostmaps:cip:0:0'), false);
assert.ok(items().has('ghostmaps:cip:1:0'));
assert.deepEqual(cards.at(-1), []);
await layer.update(viewer);
assert.equal([...mounted][0], ds, 'same-version KMZ is not reloaded');
viewer.scene.pick = () => 'ghostmaps:cip:1:0';
click({ position: { x: 0, y: 0 } });
assert.deepEqual(liveSets(), sets, 'same-version KMZ is not reloaded');
click('ghostmaps:cip:1:0');
assert.match(cards.at(-1)[0].title, /Surviving/);
layer.disable();
at += 14 * 86400_000;
@@ -495,7 +545,7 @@ test('expiry removes every geometry and polygon outline belonging to an old repo
]),
]),
]);
const { layer, viewer, mounted } = fixture(t, {
const { layer, viewer, items } = fixture(t, {
now: () => at,
reports: [
{
@@ -509,11 +559,10 @@ test('expiry removes every geometry and polygon outline belonging to an old repo
],
});
await layer.update(viewer);
const ds = [...mounted][0];
assert.equal(ds.entities.values.length, 4);
assert.equal(items().size, 4);
at += 60_000;
t.mock.timers.tick(60_000);
assert.equal(ds.entities.values.length, 0);
assert.equal(items().size, 0);
assert.equal(layer.getStats().count, 0);
});
@@ -548,27 +597,19 @@ test('two quick clicks, 1d then 7d, restore the report', async (t) => {
});
test('narrowing the window keeps the open card of a surviving marker', async (t) => {
let click;
const cards = [];
const { layer, viewer } = fixture(t, {
const { layer, viewer, click } = fixture(t, {
now: () => Date.UTC(2026, 10, 3, 12),
reports: [dated('Recent', '11/2/2026'), dated('Older', '10/20/2026')],
controls: {
overlayHost: { setEntries: (_id, entries) => cards.push(entries) },
screenSpaceEventHandlerFactory: () => ({
setInputAction: (fn) => {
click = fn;
},
destroy() {},
}),
picking: { resolvePickId: (picked) => picked },
},
});
await layer.update(viewer);
await ageChip(layer, 30).onClick();
assert.equal(layer.getStats().count, 2);
viewer.scene.pick = () => 'ghostmaps:cip:0:0';
click({ position: { x: 0, y: 0 } });
click('ghostmaps:cip:0:0');
assert.equal(cards.at(-1).length, 1);
await ageChip(layer, 3).onClick();
assert.equal(layer.getStats().count, 1);
@@ -590,26 +631,18 @@ test('a report dated yesterday is shown by 1d one hour into today (UTC)', async
});
test('a widened reload that returns a different report at the selected index closes its card', async (t) => {
let click;
const cards = [];
const reports = [dated('Recent', '11/2/2026'), dated('Older', '10/20/2026')];
const { layer, viewer } = fixture(t, {
const { layer, viewer, click } = fixture(t, {
now: () => Date.UTC(2026, 10, 3, 12),
reports,
controls: {
overlayHost: { setEntries: (_id, entries) => cards.push(entries) },
screenSpaceEventHandlerFactory: () => ({
setInputAction: (fn) => {
click = fn;
},
destroy() {},
}),
picking: { resolvePickId: (picked) => picked },
},
});
await layer.update(viewer);
viewer.scene.pick = () => 'ghostmaps:cip:0:0';
click({ position: { x: 0, y: 0 } });
click('ghostmaps:cip:0:0');
assert.equal(cards.at(-1).length, 1);
// The server answers the pinned version with a newer edition's bytes.
reports[0] = dated('Replacement', '11/2/2026');