mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
fix(earthquakes): address review follow-ups on click arbitration
A drifting touch tap or a cockpit-mode tap on a fire, quake or vessel card
beside an aircraft did nothing: the cards deferred to the aircraft, whose
click handler ignores such taps. Pick owners can now declare the clicks
they ignore (registerPickOwner(..., { declinesClick })); flights and
military decline a drag or a cockpit tap and CCTV declines any click that
is not clean, so a card over them keeps that tap.
Also from review:
- the selected quake's contour rings sit on the ground the disc is draped
on, re-read through the heights service while they paint;
- a label's fly-to frames the whole disc for large quakes;
- a quake that ages out of the feed clears its selection as evicted;
- id-less quakes are named by their content, not their row;
- the Bhote Koshi trigger-record callout opens its source on a click, as
its keyboard action does, and yields like the other cards;
- the card's place line is cut to 48 characters, its link hint shows only
with an opener, and its accessible name carries depth, place and time; a
link-less card's click and keyboard action fly to the quake;
- camera trace comparison scales its tolerance with the value and wraps
heading and roll.
This commit is contained in:
1 parent
fde5f95b45
commit
7312280817
33 files changed
+702
-76
No files matched your search
@@ -5,6 +5,7 @@ import { viewshedColors, cameraHue } from '../../data/cctvViewshed.js';
|
||||
import { CCTV_OVERLAY_SOURCE_ID } from '../../data/cctvCards.js';
|
||||
import { GIZMO_ID_PREFIX } from '../../data/cctvGizmo.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { isTrackingClickGesture } from '../../data/trackingClickGesture.js';
|
||||
import {
|
||||
GROUND_PRIOR_INIT_WAIT_MS,
|
||||
CALIBRATION_RANGE_FLOOR_M,
|
||||
@@ -509,19 +510,26 @@ export function createLifecycle({
|
||||
layerState._lastUpdate = Date.now();
|
||||
// Pick-ownership (H2): camera icons use the camera id directly;
|
||||
// coverage polyline entities use `cctv-<cameraId>-<role>` entity ids.
|
||||
registerPickOwner('cctv', (pickedId) => {
|
||||
if (layerState._recordById.has(pickedId)) return true;
|
||||
if (
|
||||
typeof pickedId === 'string' &&
|
||||
pickedId.startsWith(GIZMO_ID_PREFIX)
|
||||
)
|
||||
return true;
|
||||
const coverage =
|
||||
/^cctv-(.+)-(?:ray-tl|ray-tr|ray-br|ray-bl|cap|plane|plane-label)$/.exec(
|
||||
pickedId,
|
||||
);
|
||||
return Boolean(coverage && layerState._recordById.has(coverage[1]));
|
||||
});
|
||||
registerPickOwner(
|
||||
'cctv',
|
||||
(pickedId) => {
|
||||
if (layerState._recordById.has(pickedId)) return true;
|
||||
if (
|
||||
typeof pickedId === 'string' &&
|
||||
pickedId.startsWith(GIZMO_ID_PREFIX)
|
||||
)
|
||||
return true;
|
||||
const coverage =
|
||||
/^cctv-(.+)-(?:ray-tl|ray-tr|ray-br|ray-bl|cap|plane|plane-label)$/.exec(
|
||||
pickedId,
|
||||
);
|
||||
return Boolean(coverage && layerState._recordById.has(coverage[1]));
|
||||
},
|
||||
// The world click handler takes only clean clicks (see
|
||||
// `bindCctvWorldClickGesture`), so a card over a camera keeps any
|
||||
// other tap.
|
||||
{ declinesClick: (click) => !isTrackingClickGesture(click?.gesture) },
|
||||
);
|
||||
if (!layerState._activeCameraId && layerState._records.length) {
|
||||
layerState._activeCameraId = parts.navigation.openingCameraId();
|
||||
layerState._autoHopSuspended = false;
|
||||
|
||||
@@ -136,8 +136,8 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
};
|
||||
const services = {
|
||||
sprites: {},
|
||||
focus: {},
|
||||
render: {},
|
||||
focus: { onFocusTargetAppear: () => noop },
|
||||
render: { releaseContinuousRender: noop },
|
||||
picking,
|
||||
activation: { activateCctvCameraFromWorldClick: (id) => actions.push(id) },
|
||||
};
|
||||
@@ -152,6 +152,7 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
picking.unregisterPickOwner('test-trails');
|
||||
picking.unregisterPickOwner('test-planes');
|
||||
picking.unregisterPickOwner('test-tracking');
|
||||
picking.unregisterPickOwner('test-exact');
|
||||
picking.unregisterCardBackground('area-fixture');
|
||||
});
|
||||
await lifecycle.methods.init(viewer);
|
||||
@@ -214,6 +215,13 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
// A coarse tap whose touch contact is an aircraft (a layer that acts on
|
||||
// nearby contacts) is the aircraft's, even under a live CCTV card.
|
||||
const previousMatch = globalThis.matchMedia;
|
||||
const restoreMatch = () => {
|
||||
if (previousMatch) globalThis.matchMedia = previousMatch;
|
||||
else delete globalThis.matchMedia;
|
||||
};
|
||||
// Restored below for the fine-pointer clicks that follow; here too, so a
|
||||
// failing assertion cannot leave the coarse pointer for later tests.
|
||||
t.after(restoreMatch);
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
picking.registerPickOwner('test-planes', (id) => id === 'plane:1', {
|
||||
expanded: true,
|
||||
@@ -230,8 +238,7 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
drilled = [];
|
||||
click(null, [ownCard], ['cam-1']);
|
||||
picking.unregisterPickOwner('test-planes');
|
||||
if (previousMatch) globalThis.matchMedia = previousMatch;
|
||||
else delete globalThis.matchMedia;
|
||||
restoreMatch();
|
||||
// The live card reads the owners that acted when the click resolved, so it
|
||||
// yields to the aircraft even though tracking made it passive meanwhile.
|
||||
picking.registerPickOwner('test-tracking', (id) => id === 'plane:9', {
|
||||
@@ -253,4 +260,28 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
[foreignCard, ownCard],
|
||||
['cam-1'],
|
||||
);
|
||||
// CCTV takes only clean clicks, so for a long press or a drag its cameras
|
||||
// act for nobody: a card painted over one keeps that tap.
|
||||
// Enable's own work is beside the point here: only its registration.
|
||||
Object.assign(parts.cards, {
|
||||
refreshAmbientCards: noop,
|
||||
startCardFrameLoop: noop,
|
||||
});
|
||||
parts.frames = { refreshProjectionImage: noop };
|
||||
Object.assign(parts.geometryQueue, { startGeometryLoadQueue: noop });
|
||||
parts.navigation = { openingCameraId: () => 'cam-1' };
|
||||
Object.assign(parts.projection, {
|
||||
ensureProjectionRuntime: noop,
|
||||
startProjectionLoop: noop,
|
||||
});
|
||||
state._cctvOverlayHost.setVisible ??= noop;
|
||||
lifecycle.methods.enable();
|
||||
t.after(() => picking.unregisterPickOwner('cctv'));
|
||||
const acted = (gesture) =>
|
||||
picking.isActedOnByOtherLayer('earthquakes', 'cam-1', {
|
||||
click: { gesture },
|
||||
});
|
||||
assert.equal(acted({ travelPx: 0, durationMs: 80 }), true, 'a clean click');
|
||||
assert.equal(acted({ travelPx: 0, durationMs: 900 }), false, 'a long press');
|
||||
assert.equal(acted({ travelPx: 20, durationMs: 80 }), false, 'a drag');
|
||||
});
|
||||
@@ -35,6 +35,8 @@ export const EARTHQUAKES_LAYER_ID = 'earthquakes';
|
||||
export const EARTHQUAKE_CARD_SOURCE_ID = 'earthquake-card';
|
||||
/** A disc's item id is this prefix and the event's stable id. */
|
||||
const PICK_PREFIX = 'earthquake:';
|
||||
/** Fly-to range per metre of disc radius: 220 km frames an M6 (64 km). */
|
||||
const EARTHQUAKE_FOCUS_RANGE_PER_RADIUS = 3.5;
|
||||
/** The selected quake's flat fill, faint under the painted gradient. */
|
||||
const SELECTED_DISC_ALPHA = 0.04;
|
||||
const CARD_HOST_OPTIONS = Object.freeze({
|
||||
@@ -73,8 +75,12 @@ let instances = 0;
|
||||
* @param {{requestWorldFocus: (detail: object) => boolean}} [options.focus]
|
||||
* The camera transfer a clicked magnitude label asks for.
|
||||
* @param {{show: (target: {id: string, lon: number, lat: number,
|
||||
* radiusM: number, color: string}) => void, hide: () => void}} [options.ripples]
|
||||
* heightM?: number, heightAt?: () => number|null, radiusM: number,
|
||||
* color: string}) => void, hide: () => void}} [options.ripples]
|
||||
* The selected quake's animated contour rings.
|
||||
* @param {(viewer: object, lon: number, lat: number) => number|null} [options.groundHeight]
|
||||
* The loaded ground height under a point, so the rings sit on the disc
|
||||
* that is draped there; null (or no service) draws them at sea level.
|
||||
* @param {object} [options.text] Card formatters (see describeEarthquake).
|
||||
*/
|
||||
export function createEarthquakesLayer({
|
||||
@@ -87,6 +93,7 @@ export function createEarthquakesLayer({
|
||||
openExternal = null,
|
||||
focus = null,
|
||||
ripples = null,
|
||||
groundHeight = null,
|
||||
text = undefined,
|
||||
} = {}) {
|
||||
if (typeof source?.getSnapshot !== 'function')
|
||||
@@ -189,12 +196,14 @@ export function createEarthquakesLayer({
|
||||
function publishCard({ user = false } = {}) {
|
||||
const event = _selectedId ? _eventById.get(_selectedId) : null;
|
||||
if (!_enabled || !event) {
|
||||
clearSelection();
|
||||
// A refresh that no longer carries the selected quake evicts it, as
|
||||
// other feeds report; anything else is a deliberate clear.
|
||||
clearSelection({ evicted: _enabled && Boolean(_selectedId) && !user });
|
||||
return;
|
||||
}
|
||||
const { title, details, link, accessibilityLabel } = describeEarthquake(
|
||||
event,
|
||||
text,
|
||||
{ ...text, canOpen: Boolean(openExternal) },
|
||||
);
|
||||
_selectedLink = link && openExternal ? link : null;
|
||||
const card = {
|
||||
@@ -222,6 +231,12 @@ export function createEarthquakesLayer({
|
||||
openExternal(target);
|
||||
return true;
|
||||
};
|
||||
} else if (focus?.requestWorldFocus) {
|
||||
// No source to open: the card's keyboard action flies to its quake,
|
||||
// as a fire card's focuses its fire, so it stays in the action list.
|
||||
const stableId = event.stableId;
|
||||
card.accessibilityLabel = accessibilityLabel;
|
||||
card.activate = () => selectAndFocus(stableId);
|
||||
}
|
||||
_selectedCardId = card.id;
|
||||
overlayHost.setEntries(
|
||||
@@ -232,11 +247,22 @@ export function createEarthquakesLayer({
|
||||
overlayHost.setVisible(EARTHQUAKE_CARD_SOURCE_ID, true);
|
||||
publishContext(event, user);
|
||||
fadeDisc(event.stableId);
|
||||
let heightM = null;
|
||||
try {
|
||||
heightM = groundHeight?.(_viewer, event.lon, event.lat) ?? null;
|
||||
} catch {
|
||||
heightM = null;
|
||||
}
|
||||
ripples?.show?.(
|
||||
{
|
||||
id: event.stableId,
|
||||
lon: event.lon,
|
||||
lat: event.lat,
|
||||
heightM: Number.isFinite(heightM) ? heightM : 0,
|
||||
// Read again as the ground loads: a label's fly-to starts far away.
|
||||
heightAt: groundHeight
|
||||
? () => groundHeight(_viewer, event.lon, event.lat)
|
||||
: null,
|
||||
radiusM: earthquakeDiscRadiusM(event.mag),
|
||||
color: depthAccent(event.depthKm || 0),
|
||||
},
|
||||
@@ -284,10 +310,12 @@ export function createEarthquakesLayer({
|
||||
}
|
||||
}
|
||||
|
||||
function clearContext() {
|
||||
function clearContext({ evicted = false } = {}) {
|
||||
if (!context || !_contextId) return;
|
||||
try {
|
||||
context.clearSelectedEntityContextForLayer(EARTHQUAKES_LAYER_ID);
|
||||
context.clearSelectedEntityContextForLayer(EARTHQUAKES_LAYER_ID, {
|
||||
evicted,
|
||||
});
|
||||
context.getContextStore().entities.delete(_contextId);
|
||||
} catch {
|
||||
// store unavailable: nothing to clean
|
||||
@@ -295,12 +323,12 @@ export function createEarthquakesLayer({
|
||||
_contextId = null;
|
||||
}
|
||||
|
||||
function clearSelection() {
|
||||
function clearSelection({ evicted = false } = {}) {
|
||||
const had = _selectedId || _selectedCardId;
|
||||
_selectedId = null;
|
||||
_selectedCardId = null;
|
||||
_selectedLink = null;
|
||||
clearContext();
|
||||
clearContext({ evicted });
|
||||
ripples?.hide?.();
|
||||
fadeDisc(null);
|
||||
if (had)
|
||||
@@ -362,7 +390,11 @@ export function createEarthquakesLayer({
|
||||
sourceId: EARTHQUAKE_CARD_SOURCE_ID,
|
||||
});
|
||||
if (cardHit && cardHit.entryId === _selectedCardId) {
|
||||
// The card's action, as its keyboard action: open the source, or
|
||||
// with none, fly to the quake.
|
||||
if (_selectedLink) openExternal(_selectedLink);
|
||||
else if (focus?.requestWorldFocus && _selectedId)
|
||||
selectAndFocus(_selectedId);
|
||||
return;
|
||||
}
|
||||
// A magnitude label is what a far view (the whole globe) can click:
|
||||
@@ -399,6 +431,11 @@ export function createEarthquakesLayer({
|
||||
id: `${PICK_PREFIX}${stableId}`,
|
||||
label: earthquakeMagnitudeTitle(event.mag),
|
||||
position: fromDegrees(event.lon, event.lat),
|
||||
// The whole disc in view: the framing's range fits an M6 disc, so a
|
||||
// larger one scales it (the framing stays the floor).
|
||||
radiusM: earthquakeDiscRadiusM(event.mag),
|
||||
rangeM:
|
||||
earthquakeDiscRadiusM(event.mag) * EARTHQUAKE_FOCUS_RANGE_PER_RADIUS,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,12 @@ export const EARTHQUAKE_MARK_MAGNITUDE = 6;
|
||||
|
||||
/** The longest place a timeline mark's label carries, ellipsis and all. */
|
||||
const MARK_PLACE_LENGTH = 40;
|
||||
/**
|
||||
* The longest place line the detail card shows, ellipsis and all, so a long
|
||||
* place or translation keeps the card inside a phone's width. The card's
|
||||
* accessible name carries the whole place.
|
||||
*/
|
||||
const CARD_PLACE_LENGTH = 48;
|
||||
|
||||
/** A magnitude as the map's labels show it: `M6.4`. */
|
||||
export const earthquakeMagnitudeTitle = (magnitude) =>
|
||||
@@ -163,43 +169,77 @@ const oneDecimal = (value) => String(Math.round(value * 10) / 10);
|
||||
* @param {(text: string, values?: object) => string} [text.t] Translator.
|
||||
* @param {(time: number) => string} [text.formatTime] An event time.
|
||||
* @param {(value: number) => string} [text.formatDepth] A depth in km.
|
||||
* @param {boolean} [text.canOpen] Whether a link can be opened here (an
|
||||
* opener is injected); without one the card offers no link to click.
|
||||
* @returns {{title: string, details: string[], link: string|null,
|
||||
* accessibilityLabel: string}}
|
||||
* accessibilityLabel: string}} `accessibilityLabel` names the card's
|
||||
* action, with its details: opening the source, or focusing the quake.
|
||||
*/
|
||||
export function describeEarthquake(
|
||||
event,
|
||||
{ t = english, formatTime = utcMinute, formatDepth = oneDecimal } = {},
|
||||
{
|
||||
t = english,
|
||||
formatTime = utcMinute,
|
||||
formatDepth = oneDecimal,
|
||||
canOpen = true,
|
||||
} = {},
|
||||
) {
|
||||
const details = [];
|
||||
// What the card says, spoken: depth, the whole place, and the time.
|
||||
const spoken = [];
|
||||
// Severity at a glance, right under the title: the class meter, then
|
||||
// where in the crust it broke.
|
||||
const glance = [earthquakeSeverityMeter(event?.mag)];
|
||||
if (Number.isFinite(event?.depthKm)) {
|
||||
glance.push(
|
||||
`${earthquakeDepthBandName(event.depthKm, t)} · ${t('{km} km deep', {
|
||||
km: formatDepth(event.depthKm),
|
||||
})}`,
|
||||
);
|
||||
const depth = `${earthquakeDepthBandName(event.depthKm, t)} · ${t(
|
||||
'{km} km deep',
|
||||
{ km: formatDepth(event.depthKm) },
|
||||
)}`;
|
||||
glance.push(depth);
|
||||
spoken.push(depth);
|
||||
}
|
||||
details.push(glance.join(' '));
|
||||
const place =
|
||||
typeof event?.place === 'string'
|
||||
? event.place.replace(/\s+/g, ' ').trim()
|
||||
: '';
|
||||
if (place) details.push(place);
|
||||
if (Number.isFinite(event?.time)) details.push(formatTime(event.time));
|
||||
details.push(t('Source: {value}', { value: 'USGS' }));
|
||||
if (place) {
|
||||
// Cut by characters, not UTF-16 units, so a pair is never split.
|
||||
const chars = Array.from(place);
|
||||
details.push(
|
||||
chars.length > CARD_PLACE_LENGTH
|
||||
? `${chars
|
||||
.slice(0, CARD_PLACE_LENGTH - 1)
|
||||
.join('')
|
||||
.trimEnd()}…`
|
||||
: place,
|
||||
);
|
||||
spoken.push(place);
|
||||
}
|
||||
if (Number.isFinite(event?.time)) {
|
||||
const time = formatTime(event.time);
|
||||
details.push(time);
|
||||
spoken.push(time);
|
||||
}
|
||||
const source = t('Source: {value}', { value: 'USGS' });
|
||||
details.push(source);
|
||||
// The source closes the spoken details, so they are never empty.
|
||||
spoken.push(source);
|
||||
const link = earthquakeEventLink(event?.usgsId);
|
||||
if (link) details.push(t('Click the card to open the source ↗'));
|
||||
const opens = Boolean(link) && canOpen;
|
||||
if (opens) details.push(t('Click the card to open the source ↗'));
|
||||
const title = `${earthquakeMagnitudeTitle(event?.mag)} · ${earthquakeSeverityName(
|
||||
event?.mag,
|
||||
t,
|
||||
)}`;
|
||||
const summary = { title, details: spoken.join(', ') };
|
||||
return {
|
||||
title,
|
||||
details,
|
||||
link,
|
||||
accessibilityLabel: t('Open the source for {title}', { title }),
|
||||
accessibilityLabel: opens
|
||||
? t('Open the source for {title}, {details}', summary)
|
||||
: t('Focus earthquake {title}, {details}', summary),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -28,10 +28,15 @@ export function normalizeEarthquakeSnapshot(geojson) {
|
||||
return null;
|
||||
// A missing magnitude cannot establish that this event meets M2.5+.
|
||||
if (mag == null || mag < 2.5) continue;
|
||||
const stableId =
|
||||
feature.id == null || feature.id === ''
|
||||
? `event-${index + 1}`
|
||||
: String(feature.id);
|
||||
// An id-less event is named by what it is (time, position, depth and
|
||||
// magnitude), not by its row, so a refresh that inserts a row keeps the
|
||||
// selection on the same quake; a revision to any of those names a new
|
||||
// one. Two id-less events that match exactly fall back to the row.
|
||||
const idless = feature.id == null || feature.id === '';
|
||||
let stableId = idless
|
||||
? `event-${[properties.time ?? 'na', lon, lat, depthKm ?? 'na', mag].join(':')}`
|
||||
: String(feature.id);
|
||||
if (idless && ids.has(stableId)) stableId = `${stableId}:${index + 1}`;
|
||||
if (ids.has(stableId)) return null;
|
||||
ids.add(stableId);
|
||||
rows.push({
|
||||
|
||||
@@ -37,7 +37,7 @@ test('normalizeEarthquakeSnapshot parses valid GeoJSON earthquake features', ()
|
||||
});
|
||||
});
|
||||
|
||||
test('normalizeEarthquakeSnapshot generates index-based stable IDs when id is missing or blank', () => {
|
||||
test('normalizeEarthquakeSnapshot names id-less events by their content, not their row', () => {
|
||||
const geojson = {
|
||||
features: [
|
||||
{
|
||||
@@ -55,10 +55,35 @@ test('normalizeEarthquakeSnapshot generates index-based stable IDs when id is mi
|
||||
|
||||
const rows = normalizeEarthquakeSnapshot(geojson);
|
||||
assert.equal(rows.length, 2);
|
||||
assert.equal(rows[0].stableId, 'event-1');
|
||||
assert.equal(rows[0].stableId, 'event-1711930000000:139.6917:35.6895:25:3.5');
|
||||
assert.equal(rows[0].usgsId, null);
|
||||
assert.equal(rows[1].stableId, 'event-2');
|
||||
assert.equal(
|
||||
rows[1].stableId,
|
||||
'event-1711931000000:-70.6693:-33.4489:45.2:5.1',
|
||||
);
|
||||
assert.equal(rows[1].usgsId, '');
|
||||
// A row inserted ahead of them keeps each id-less quake's id, so a selected
|
||||
// one stays selected across the refresh.
|
||||
const inserted = normalizeEarthquakeSnapshot({
|
||||
features: [
|
||||
{
|
||||
id: 'us7000new',
|
||||
geometry: { type: 'Point', coordinates: [10, 20, 5] },
|
||||
properties: { mag: 4, place: 'New', time: 1711932000000 },
|
||||
},
|
||||
...geojson.features,
|
||||
],
|
||||
});
|
||||
assert.deepEqual(
|
||||
inserted.map((row) => row.stableId).slice(1),
|
||||
rows.map((row) => row.stableId),
|
||||
);
|
||||
// Two id-less events that match exactly stay apart.
|
||||
const twins = normalizeEarthquakeSnapshot({
|
||||
features: [geojson.features[0], geojson.features[0]],
|
||||
});
|
||||
assert.equal(twins.length, 2);
|
||||
assert.notEqual(twins[0].stableId, twins[1].stableId);
|
||||
});
|
||||
|
||||
test('normalizeEarthquakeSnapshot filters events below M2.5 without dropping the feed', () => {
|
||||
|
||||
@@ -39,7 +39,12 @@ const quake = (id, extra = {}) => ({
|
||||
/** A layer whose globe clicks, card hits and context store the test drives. */
|
||||
function harness(
|
||||
rows,
|
||||
{ context = null, ripples = null, input: inputFactory = null } = {},
|
||||
{
|
||||
context = null,
|
||||
ripples = null,
|
||||
groundHeight = null,
|
||||
input: inputFactory = null,
|
||||
} = {},
|
||||
) {
|
||||
let snapshot = rows;
|
||||
const handlers = [];
|
||||
@@ -95,6 +100,7 @@ function harness(
|
||||
picking,
|
||||
context,
|
||||
ripples,
|
||||
groundHeight,
|
||||
pointer: { isPointerFree: () => true },
|
||||
openExternal: (url) => opened.push(url),
|
||||
focus: {
|
||||
@@ -179,7 +185,10 @@ test('clicking a quake disc shows its detail card; empty map clears it', async (
|
||||
'Click the card to open the source ↗',
|
||||
]);
|
||||
assert.equal(card.interactive, true);
|
||||
assert.equal(card.accessibilityLabel, 'Open the source for M4.1 · Light');
|
||||
assert.equal(
|
||||
card.accessibilityLabel,
|
||||
'Open the source for M4.1 · Light, Intermediate · 112.4 km deep, 42 km W of Fixture, Alaska, 2026-11-13 15:37 UTC, Source: USGS',
|
||||
);
|
||||
assert.equal(h.visible.get(EARTHQUAKE_CARD_SOURCE_ID), true);
|
||||
|
||||
h.click(null);
|
||||
@@ -209,11 +218,17 @@ test('a quake with no USGS id gets a card with no link', async () => {
|
||||
h.clickDisc('event-1');
|
||||
const [card] = h.lastCard();
|
||||
assert.equal(card.interactive, true, 'hit-testable, so a click keeps it');
|
||||
assert.equal(card.activate, undefined);
|
||||
assert.equal(card.accessibilityLabel, undefined, 'no action to offer');
|
||||
assert.ok(!card.details.some((line) => line.includes('Click the card')));
|
||||
// No source to open: a click on the card flies to the quake instead.
|
||||
h.clickCard(card.id);
|
||||
assert.deepEqual(h.opened, []);
|
||||
assert.equal(h.focused.length, 1);
|
||||
// Its keyboard action does the same, so it still has a place in the
|
||||
// action list.
|
||||
assert.match(card.accessibilityLabel, /^Focus earthquake M2\.5 · Minor, /);
|
||||
assert.equal(card.activate(), true);
|
||||
assert.equal(h.focused.length, 2);
|
||||
assert.deepEqual(h.opened, []);
|
||||
assert.equal(h.lastCard()[0].id, card.id, 'the card stays');
|
||||
h.layer.destroy();
|
||||
});
|
||||
@@ -360,6 +375,24 @@ test('describeEarthquake translates through the given formatters', () => {
|
||||
assert.equal(bare.title, 'M3.0 · Minor');
|
||||
assert.deepEqual(bare.details, ['■□□□□□', 'Source: USGS']);
|
||||
assert.equal(bare.link, null);
|
||||
assert.equal(
|
||||
bare.accessibilityLabel,
|
||||
'Focus earthquake M3.0 · Minor, Source: USGS',
|
||||
);
|
||||
// A place cut short never splits a character made of a surrogate pair.
|
||||
const emoji = describeEarthquake(quake('ak9', { place: '🌋'.repeat(60) }));
|
||||
assert.equal(Array.from(emoji.details[1]).length, 48);
|
||||
assert.ok(!/[\uD800-\uDBFF]…$/.test(emoji.details[1]));
|
||||
// A long place is cut short on the card; the accessible name keeps it all.
|
||||
const long = 'A very long place name '.repeat(4).trim();
|
||||
const wide = describeEarthquake(quake('ak9', { place: long }));
|
||||
assert.equal(Array.from(wide.details[1]).length, 48);
|
||||
assert.ok(wide.details[1].endsWith('…'));
|
||||
assert.ok(wide.accessibilityLabel.includes(long));
|
||||
// With no opener to follow a link, the card does not offer one.
|
||||
const closed = describeEarthquake(quake('ak9'), { canOpen: false });
|
||||
assert.ok(!closed.details.some((line) => line.includes('Click the card')));
|
||||
assert.match(closed.accessibilityLabel, /^Focus earthquake /);
|
||||
});
|
||||
|
||||
test('severity follows the USGS magnitude classes; depth bands the disc colours', () => {
|
||||
@@ -418,6 +451,9 @@ test('clicking a magnitude label selects the quake and flies to it', async () =>
|
||||
assert.ok(
|
||||
Math.hypot(detail.position.x, detail.position.y, detail.position.z) > 6e6,
|
||||
);
|
||||
// The whole disc in view: radius and range scale with the magnitude.
|
||||
assert.equal(detail.radiusM, 32000);
|
||||
assert.equal(detail.rangeM, 32000 * 3.5);
|
||||
|
||||
// The keyboard path does the same.
|
||||
assert.equal(
|
||||
@@ -470,21 +506,34 @@ test('the selected quake runs contour rings to its disc edge; clearing stops the
|
||||
hide: () => calls.push(['hide']),
|
||||
dispose: () => calls.push(['dispose']),
|
||||
};
|
||||
// The ground the disc is draped on: the rings are drawn at its height.
|
||||
const heights = [];
|
||||
const h = harness(
|
||||
[quake('ak1', { mag: 5, depthKm: 10 }), quake('ak2', { mag: 3 })],
|
||||
{ ripples },
|
||||
{
|
||||
ripples,
|
||||
groundHeight: (viewer, lon, lat) => {
|
||||
heights.push([lon, lat]);
|
||||
return lon === -153.3 ? 1840 : null;
|
||||
},
|
||||
},
|
||||
);
|
||||
h.layer.enable(h.viewer);
|
||||
await h.layer.update(h.viewer);
|
||||
h.clickDisc('ak1');
|
||||
const shown = calls.findLast(([kind]) => kind === 'show')[1];
|
||||
assert.deepEqual(shown, {
|
||||
const { heightAt, ...rest } = shown;
|
||||
assert.deepEqual(rest, {
|
||||
id: 'ak1',
|
||||
lon: -153.3,
|
||||
lat: 60,
|
||||
heightM: 1840,
|
||||
radiusM: 32000,
|
||||
color: 'rgb(255,0,0)',
|
||||
});
|
||||
assert.deepEqual(heights.at(-1), [-153.3, 60]);
|
||||
// The painter can read the ground again as it loads (a label's fly-to).
|
||||
assert.equal(heightAt(), 1840);
|
||||
assert.equal(
|
||||
h.discs().items.get('earthquake:ak1').geometry.semiMajor,
|
||||
shown.radiusM,
|
||||
@@ -1054,3 +1103,81 @@ test('coarse FIRMS near-misses leave quake overlays actionable; exact fire hits
|
||||
input?.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
// A tap that drifts more than the tracking click travel is ignored by the
|
||||
// aircraft layers, so a quake card painted beside an aircraft keeps it.
|
||||
test('a quake card keeps a dragged tap beside an aircraft that declines it', async (t) => {
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
t.after(() => {
|
||||
if (previous) globalThis.matchMedia = previous;
|
||||
else delete globalThis.matchMedia;
|
||||
});
|
||||
const plane = { set: 'flights:1', id: 'plane-9' };
|
||||
let sceneHit = null;
|
||||
let nearby = null;
|
||||
let input;
|
||||
const h = harness([quake('ak1')], {
|
||||
input(viewer) {
|
||||
viewer.scene = {
|
||||
pick: () => (sceneHit ? { id: sceneHit } : null),
|
||||
drillPick: () => (nearby ? [{ id: nearby }] : []),
|
||||
};
|
||||
input = fakeInput(viewer);
|
||||
return input.input;
|
||||
},
|
||||
});
|
||||
picking.registerPickOwner('test-plane', (id) => id === plane.id, {
|
||||
expanded: true,
|
||||
declinesClick: (click) => (click?.gesture?.travelPx ?? 0) > 6,
|
||||
});
|
||||
t.after(() => {
|
||||
picking.unregisterPickOwner('test-plane');
|
||||
h.layer.destroy();
|
||||
input?.destroy();
|
||||
});
|
||||
h.layer.enable(h.viewer);
|
||||
await h.layer.update(h.viewer);
|
||||
sceneHit = { set: h.discs().spec.id, id: 'earthquake:ak1' };
|
||||
input.click();
|
||||
const card = h.lastCard()[0];
|
||||
h.overlayHits.set(EARTHQUAKE_CARD_SOURCE_ID, {
|
||||
sourceId: EARTHQUAKE_CARD_SOURCE_ID,
|
||||
entryId: card.id,
|
||||
});
|
||||
sceneHit = null;
|
||||
nearby = plane;
|
||||
// A still tap: the aircraft acts on its contact, so the card yields.
|
||||
input.tap({ x: 10, y: 10 });
|
||||
assert.deepEqual(h.opened, []);
|
||||
// A tap that drifts 10 px: the aircraft ignores it, so the card opens.
|
||||
input.down({ x: 10, y: 10 });
|
||||
input.move({ x: 20, y: 10 }, { x: 10, y: 10 });
|
||||
input.up({ x: 20, y: 10 });
|
||||
input.click({ x: 20, y: 10 });
|
||||
assert.equal(h.opened.length, 1, 'the card keeps the dragged tap');
|
||||
});
|
||||
|
||||
// A refresh that no longer carries the selected quake evicts it, as other
|
||||
// feeds report; a click on empty map is a deliberate clear.
|
||||
test('a quake that ages out of the feed is cleared as evicted', async () => {
|
||||
const clears = [];
|
||||
const context = {
|
||||
registerEntityContext: (record) => ({ ...record, id: record.id }),
|
||||
selectEntityContext() {},
|
||||
clearSelectedEntityContextForLayer: (layerId, options) =>
|
||||
clears.push([layerId, options?.evicted === true]),
|
||||
getContextStore: () => ({ entities: new Map() }),
|
||||
};
|
||||
const h = harness([quake('ak1'), quake('ak2')], { context });
|
||||
h.layer.enable(h.viewer);
|
||||
await h.layer.update(h.viewer);
|
||||
h.clickDisc('ak1');
|
||||
h.setRows([quake('ak2')]);
|
||||
await h.layer.update(h.viewer);
|
||||
assert.deepEqual(clears.at(-1), ['earthquakes', true], 'aged out: evicted');
|
||||
h.clickDisc('ak2');
|
||||
h.click(null);
|
||||
assert.deepEqual(clears.at(-1), ['earthquakes', false], 'empty map');
|
||||
h.layer.destroy();
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import { isTrackingSelectionGesture } from '../../data/trackingClickGesture.js';
|
||||
import { findCamera, findFrame } from '../../render/rendererOf.js';
|
||||
import { loadFleetModelSet } from '../../data/fleetModels.js';
|
||||
import { forgetPlacedAircraft } from './placed.js';
|
||||
@@ -141,6 +142,11 @@ export function createLifecycle({
|
||||
passive: (pickedId) =>
|
||||
Boolean(flightState._trackedIcao) &&
|
||||
pickedId === flightState._trackedIcao,
|
||||
// The click handler ignores a dragged tap and any tap in cockpit
|
||||
// mode, so a card over the aircraft keeps that tap.
|
||||
declinesClick: (click) =>
|
||||
!isTrackingSelectionGesture(click?.gesture) ||
|
||||
Boolean(document.body?.classList.contains('cockpit-mode')),
|
||||
},
|
||||
);
|
||||
const frame = findFrame(viewer);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { isTrackingSelectionGesture } from '../../data/trackingClickGesture.js';
|
||||
import { findCamera, findFrame } from '../../render/rendererOf.js';
|
||||
import { loadFleetModelSet } from '../../data/fleetModels.js';
|
||||
import { forgetPlacedAircraft } from '../flights/placed.js';
|
||||
@@ -122,6 +123,11 @@ export function createLifecycle({
|
||||
passive: (pickedId) =>
|
||||
Boolean(flightState._trackedIcao) &&
|
||||
pickedId === flightState._trackedIcao,
|
||||
// The click handler ignores a dragged tap and any tap in cockpit
|
||||
// mode, so a card over the aircraft keeps that tap.
|
||||
declinesClick: (click) =>
|
||||
!isTrackingSelectionGesture(click?.gesture) ||
|
||||
Boolean(document.body?.classList.contains('cockpit-mode')),
|
||||
},
|
||||
);
|
||||
// The flights layer suppresses its military duplicates while we render them
|
||||
|
||||
Reference in new issue
Block a user