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:
manjunath22466 committed 2026-11-18 19:19:41 +05:30
1 parent fde5f95b45
commit 7312280817
33 files changed
+702 -76

No files matched your search

+53
View File
@@ -1,7 +1,11 @@
import {
clearOverlaySource,
hitTestWorldOverlay,
setOverlayEntries,
} from '../overlays/worldOverlay.js';
import { inputFor } from '../input/dispatcher.js';
import { isActedOnByOtherLayer, resolvePickId } from './pickRegistry.js';
import { isTrackingSelectionGesture } from './trackingClickGesture.js';
import { governorRequestRender } from '../renderGovernor.js';
import { drawOf, findCamera } from '../render/rendererOf.js';
import { hexColor } from '../render/color.js';
@@ -279,8 +283,12 @@ export function createBhoteKoshiLocatorLayer({
cancelFrame = (handle) => cancelAnimationFrame(handle),
scheduleDelay = (callback, delayMs) => setTimeout(callback, delayMs),
cancelDelay = (handle) => clearTimeout(handle),
input = inputFor,
hitTest = hitTestWorldOverlay,
} = {}) {
let _viewer = null;
// The globe click that opens an actionable callout of ours on top.
let _removeClick = null;
const _serial = ++layerSerial;
// Whether the layer draws: from enable until it is let go.
let _drawing = false;
@@ -1107,6 +1115,7 @@ export function createBhoteKoshiLocatorLayer({
renderPresentation();
registerDynamicCredit(viewer, BHOTE_KOSHI_LOCATOR_CREDIT);
showOsmCredit(viewer, BHOTE_KOSHI_LOCATOR_LAYER_ID);
installCalloutClick(viewer);
requestRender('bhote-koshi-locator-callout');
try {
@@ -1141,8 +1150,52 @@ export function createBhoteKoshiLocatorLayer({
}
}
/**
* An actionable callout of ours (the trigger record's) is a card painted
* over the globe: a click on it opens its source, as its keyboard action
* does. Like the other cards, it leaves a drag alone and yields to a layer
* that acts on what is under it (an aircraft, a vessel): its exact pick, or
* a coarse tap's touch contact whose layer acts on nearby contacts.
*/
function installCalloutClick(viewer) {
if (_removeClick) return;
let clicks = null;
try {
clicks = input?.(viewer) ?? null;
} catch {
clicks = null;
}
_removeClick =
clicks?.onClick?.((event) => {
if (!_enabled || !isTrackingSelectionGesture(event.gesture)) return;
const top = hitTest?.(event.screenPosition?.x, event.screenPosition?.y);
if (top?.sourceId !== BHOTE_KOSHI_LOCATOR_OVERLAY_SOURCE_ID) return;
const exactId = resolvePickId(event.topHit ?? null);
if (
exactId &&
isActedOnByOtherLayer(BHOTE_KOSHI_LOCATOR_LAYER_ID, exactId, {
click: event,
})
)
return;
const contactId = resolvePickId(event.hit ?? null);
if (
contactId &&
contactId !== exactId &&
isActedOnByOtherLayer(BHOTE_KOSHI_LOCATOR_LAYER_ID, contactId, {
expanded: true,
click: event,
})
)
return;
if (typeof top.entry?.activate === 'function') top.entry.activate();
}) ?? null;
}
async function disable() {
hideOsmCredit(_viewer, BHOTE_KOSHI_LOCATOR_LAYER_ID);
_removeClick?.();
_removeClick = null;
_enabled = false;
_boundaryReady = false;
_boundaryResolved = false;
+86
View File
@@ -11,6 +11,7 @@ import {
import { BHOTE_KOSHI_FLOOD_PATH } from './bhoteKoshiFloodPath.js';
import * as Cesium from 'cesium';
import { setLocale } from '../i18n/index.js';
import { registerPickOwner, unregisterPickOwner } from './pickRegistry.js';
import { SceneDirector } from '../scenes/director.js';
import { createPlaybackClock } from '../director/clock.js';
import { createDefaultScenePacks } from '../scenes/packs/defaults.js';
@@ -1049,3 +1050,88 @@ test('Bhote Koshi locator layers draw sets of their own, and halos only as they
assert.equal(await second.disable(), true);
assert.equal(viewer._test.live().length, 0);
});
// The trigger record's callout is an actionable card: the layers under it
// stand aside for it, so a click on it opens its source, as its keyboard
// action does; anything else on top is left alone.
test('a click on the locator callout runs its action', async () => {
const viewer = viewerFixture();
let onClick = null;
let top = null;
const activated = [];
const layer = createBhoteKoshiLocatorLayer({
overlayHost: overlayHostFixture(),
requestRender() {},
...nonRunningAnimation(),
input: () => ({
onClick(callback) {
onClick = callback;
return () => {
onClick = null;
};
},
}),
hitTest: () => top,
});
await layer.init(viewer);
await layer.enable(viewer);
const click = (extra = {}) =>
onClick?.({
screenPosition: { x: 5, y: 5 },
gesture: { travelPx: 0, durationMs: 80 },
topHit: null,
hit: null,
...extra,
});
top = {
sourceId: BHOTE_KOSHI_LOCATOR_OVERLAY_SOURCE_ID,
entryId: 'bhote-koshi-trigger-record-callout',
entry: { activate: () => activated.push('trigger') },
};
click();
assert.deepEqual(activated, ['trigger']);
top = {
sourceId: 'earthquake-card',
entry: { activate: () => activated.push('other') },
};
click();
assert.deepEqual(activated, ['trigger'], 'another layer on top is its own');
// A drag that ends on it is not a click on it.
top = {
sourceId: BHOTE_KOSHI_LOCATOR_OVERLAY_SOURCE_ID,
entry: { activate: () => activated.push('trigger') },
};
click({ gesture: { travelPx: 30, durationMs: 80 } });
assert.deepEqual(activated, ['trigger'], 'a drag does not open it');
// An aircraft under it is that layer's click, exact or a touch contact.
registerPickOwner('test-planes', (id) => id === 'plane:1', {
expanded: true,
});
try {
const plane = { set: 'planes:1', id: 'plane:1' };
click({ topHit: plane, hit: plane });
click({ topHit: null, hit: plane });
assert.deepEqual(activated, ['trigger'], 'the aircraft takes it');
} finally {
unregisterPickOwner('test-planes');
}
// A layer that acts only on exact hits does not take a touch contact, and
// one that ignores this click (a long press on a camera) takes nothing: the
// callout keeps both.
registerPickOwner('test-cameras', (id) => id === 'cam:1', {
declinesClick: (event) => (event?.gesture?.durationMs ?? 0) > 400,
});
try {
const cam = { set: 'cams:1', id: 'cam:1' };
click({ topHit: null, hit: cam });
assert.equal(activated.length, 2, 'a near miss of an exact-only camera');
click({ topHit: cam, hit: cam, gesture: { travelPx: 0, durationMs: 900 } });
assert.equal(activated.length, 3, 'a long press the camera ignores');
click({ topHit: cam, hit: cam });
assert.equal(activated.length, 3, 'a clean click on the camera is its own');
} finally {
unregisterPickOwner('test-cameras');
}
await layer.disable();
assert.equal(onClick, null, 'disable removes the click handler');
});
+18 -3
View File
@@ -51,10 +51,12 @@ function recordingPicking() {
};
}
function withDocument(t) {
function withDocument(t, { cockpit = () => false } = {}) {
const previous = globalThis.document;
globalThis.document = {
body: { classList: { contains: () => false } },
body: {
classList: { contains: (name) => name === 'cockpit-mode' && cockpit() },
},
addEventListener() {},
removeEventListener() {},
};
@@ -73,7 +75,8 @@ for (const [name, layerId, create] of [
['military', 'military', createMilitaryLifecycle],
]) {
test(`${name} registers its aircraft as acting on nearby touch hits`, (t) => {
withDocument(t);
let cockpit = false;
withDocument(t, { cockpit: () => cockpit });
const { registered, services } = recordingPicking();
const flightState = stub({
_icons: { show: false, has: (id) => id === `${name}-1` },
@@ -92,6 +95,18 @@ for (const [name, layerId, create] of [
lifecycle.enable({});
assert.equal(registered.get(layerId)?.expanded, true);
assert.equal(actsOnNearbyHit(`${name}-1`), true);
// The handler ignores a dragged tap and any tap in cockpit mode, so the
// aircraft acts on neither click.
const nearby = (gesture) =>
picking.isActedOnByOtherLayer('earthquakes', `${name}-1`, {
expanded: true,
click: { gesture },
});
assert.equal(nearby({ travelPx: 0, durationMs: 80 }), true, 'a tap');
assert.equal(nearby({ travelPx: 12, durationMs: 80 }), false, 'a drag');
cockpit = true;
assert.equal(nearby({ travelPx: 0, durationMs: 80 }), false, 'cockpit');
cockpit = false;
// A click on the aircraft already tracked is ignored, so it is passive.
flightState._trackedIcao = `${name}-1`;
assert.equal(actsOnNearbyHit(`${name}-1`), false);
+23 -6
View File
@@ -35,6 +35,12 @@ const _owners = new Map();
const _passive = new Map();
/** Owners whose click handlers also select nearby contacts. */
const _expanded = new Set();
/**
* Owners whose click handlers act on none of their picks for some clicks
* (aircraft layers ignore a dragged tap, or any tap in cockpit mode).
* @type {Map<string, (click: object) => boolean>}
*/
const _declines = new Map();
/** @type {WeakMap<object, Map<string, [string, boolean][]>>} */
const clickActions = new WeakMap();
/**
@@ -64,20 +70,25 @@ export function resolvePickId(hit) {
* @param {string} layerId - Owning layer id (e.g. 'flights').
* @param {(pickedId: string) => boolean} predicate - Returns true when the
* picked primitive/entity id belongs to this layer.
* @param {{passive?: boolean | ((pickedId: string) => boolean), expanded?: boolean}} [options]
* @param {{passive?: boolean | ((pickedId: string) => boolean), expanded?: boolean, declinesClick?: (click: object) => boolean}} [options]
* `passive`: the layer never acts on a click on these picks (all of them,
* or those the predicate names). See {@link isActedOnByOtherLayer}.
* `expanded`: preserve precedence for handlers that select nearby contacts,
* through the shared contact hit or their own pick window.
* `declinesClick`: true for a click the layer's handler ignores whatever it
* picked (a dragged tap); for that click its picks act for nobody.
* @returns {void}
*/
export function registerPickOwner(
layerId,
predicate,
{ passive, expanded = false } = {},
{ passive, expanded = false, declinesClick } = {},
) {
if (!layerId || typeof predicate !== 'function') return;
_owners.set(layerId, predicate);
if (typeof declinesClick === 'function')
_declines.set(layerId, declinesClick);
else _declines.delete(layerId);
if (expanded) _expanded.add(layerId);
else _expanded.delete(layerId);
if (passive === true || typeof passive === 'function')
@@ -93,6 +104,7 @@ export function registerPickOwner(
export function unregisterPickOwner(layerId) {
_owners.delete(layerId);
_expanded.delete(layerId);
_declines.delete(layerId);
_passive.delete(layerId);
}
@@ -132,11 +144,16 @@ export function isOwnedByOtherLayer(layerId, pickedId) {
return false;
}
/** @param {string} pickedId @returns {Generator<[string, boolean]>} */
function* actingPickOwners(pickedId) {
/**
* @param {string} pickedId
* @param {object} [click] The click being arbitrated, if any.
* @returns {Generator<[string, boolean]>}
*/
function* actingPickOwners(pickedId, click) {
for (const [ownerId, predicate] of _owners) {
try {
if (!predicate(pickedId)) continue;
if (click && _declines.get(ownerId)?.(click)) continue;
const passive = _passive.get(ownerId);
if (passive === true) continue;
if (typeof passive === 'function' && passive(pickedId)) continue;
@@ -159,7 +176,7 @@ export function rememberClickPickActions(click, hit) {
let actions = clickActions.get(click);
if (!actions) clickActions.set(click, (actions = new Map()));
if (!actions.has(pickedId)) {
actions.set(pickedId, [...actingPickOwners(pickedId)]);
actions.set(pickedId, [...actingPickOwners(pickedId, click)]);
}
}
@@ -181,7 +198,7 @@ export function isActedOnByOtherLayer(
) {
if (!pickedId) return false;
const owners =
clickActions.get(click)?.get(pickedId) ?? actingPickOwners(pickedId);
clickActions.get(click)?.get(pickedId) ?? actingPickOwners(pickedId, click);
for (const [ownerId, selectsNearby] of owners) {
if (ownerId !== layerId && (!expanded || selectsNearby)) return true;
}