fix(input): no double-click follow or zoom on the map

The globe viewer's own double-click tracked a picked entity with a
position or zoomed to one without. Layers moving onto the draw port had it
re-created one by one (data/stockFollow.js); following is a click in GEV,
so the viewer's handler is removed where the viewer is made and every
re-creation goes: earthquakes, cyclones, air quality, news, perimeters,
drone airspace, ghost maps, places, radio, cables, CCTV, ALPR, launches,
bikeshare, Local ADS-B, installations, directions, trails, data packs,
annotations, the library's view and local GeoJSON. The Cockpit's own
double-click and the draw tool's finishing double-click stay.
This commit is contained in:
Sameh Khamis committed 2026-11-14 09:10:14 -08:00
1 parent bb2d22dbce
commit b86014244d
69 files changed
+94 -2797

No files matched your search

+2 -45
View File
@@ -1,7 +1,5 @@
import { fromDegrees } from '../../geo/ellipsoid.js';
import { followOnDoubleClick } from '../../data/stockFollow.js';
import { inputFor as defaultInputFor } from '../../input/dispatcher.js';
import { drawOf, findInput } from '../../render/rendererOf.js';
import { drawOf } from '../../render/rendererOf.js';
import {
EARTHQUAKE_OVERLAY_SOURCE_ID,
EARTHQUAKE_OVERLAY_COHORT_LIMIT,
@@ -34,20 +32,13 @@ let instances = 0;
* Given a Cesium viewer with no renderer bound, the
* caller loads the package's `./render/cesium/unbound` export first.
*/
export function createEarthquakesLayer({
source,
overlayHost,
inputFor = defaultInputFor,
} = {}) {
export function createEarthquakesLayer({ source, overlayHost } = {}) {
if (typeof source?.getSnapshot !== 'function')
throw new TypeError('Earthquakes require a snapshot source');
if (!overlayHost) throw new TypeError('Earthquakes require an overlay host');
let _viewer = null;
let _request = null;
let _discs = null;
// Each drawn disc's centre and radius, for a double-click to follow.
let _discsById = new Map();
let _stockFollow = null;
// What the discs were drawn from, so analyst reads come from the app, not the drawing.
let _events = [];
let _count = 0;
@@ -69,26 +60,6 @@ export function createEarthquakesLayer({
show: false,
});
_viewer = viewer;
// A double-click follows a disc, framed to fit it, as the default
// renderer followed the discs' entities (a scene that takes no input
// has no double-click).
_stockFollow =
findInput(viewer) &&
followOnDoubleClick({
viewer,
inputFor,
name: 'earthquakes',
enabled: () => _enabled,
targetFor: (hit) => {
const disc = hit.set === _discs?.id && _discsById.get(hit.id);
if (!disc) return null;
return {
key: `${hit.set}:${hit.id}`,
position: () => ({ ...disc.center }),
sphere: { center: disc.center, radius: disc.radius },
};
},
});
_count = 0;
_lastUpdate = null;
_lastError = null;
@@ -109,7 +80,6 @@ export function createEarthquakesLayer({
_request?.abort();
_request = null;
_enabled = false;
_stockFollow?.stop();
if (_discs) _discs.show = false;
overlayHost.clearSource(EARTHQUAKE_OVERLAY_SOURCE_ID);
overlayHost.setVisible(EARTHQUAKE_OVERLAY_SOURCE_ID, false);
@@ -126,7 +96,6 @@ export function createEarthquakesLayer({
return false;
const nextDiscs = [];
const nextById = new Map();
const nextEvents = [];
let count = 0;
const overlayEntries = [];
@@ -150,10 +119,6 @@ export function createEarthquakesLayer({
const position = fromDegrees(lon, lat);
nextEvents.push({ usgsId, mag, place, time, depthKm, lon, lat });
nextById.set(`earthquake:${stableId}`, {
center: position,
radius: baseRadius,
});
// A filled disc on the ground, with static axes: re-tessellating
// clamped ground geometry every frame is what once cost 30 fps.
// No outline: clamped to the ground, Cesium never drew one.
@@ -180,11 +145,6 @@ export function createEarthquakesLayer({
}
_discs.set(nextDiscs);
_discsById = nextById;
// A disc no longer reported takes its follow with it.
_stockFollow?.retain((key) =>
_discsById.has(key.slice(_discs.id.length + 1)),
);
_events = nextEvents;
if (_enabled) {
overlayHost.setEntries(
@@ -221,11 +181,8 @@ export function createEarthquakesLayer({
_enabled = false;
overlayHost.clearSource(EARTHQUAKE_OVERLAY_SOURCE_ID);
overlayHost.setVisible(EARTHQUAKE_OVERLAY_SOURCE_ID, false);
_stockFollow?.destroy();
_stockFollow = null;
_discs?.dispose();
_discs = null;
_discsById = new Map();
_events = [];
_count = 0;
_lastUpdate = null;
-52
View File
@@ -168,55 +168,3 @@ test('a viewer with nothing to draw with is refused at init, and init can be ret
layer.destroy();
unbind();
});
test('a double-click follows a disc, framed to fit it, as its entity was', async (t) => {
const { bindRenderer } = await import('../../render/rendererOf.js');
const { createStubRenderer } = await import('../../render/stub/index.js');
const { resetPointerOwnership } = await import('../../input/dispatcher.js');
resetPointerOwnership?.();
const renderer = createStubRenderer();
const viewer = { isDestroyed: () => false };
const unbind = bindRenderer(viewer, renderer);
const layer = createEarthquakesLayer({
source: { getSnapshot: async () => rows },
overlayHost: { setEntries() {}, setVisible() {}, clearSource() {} },
});
let rows = [row];
t.after(() => {
layer.destroy(viewer);
unbind();
renderer.destroy();
resetPointerOwnership?.();
});
layer.init(viewer);
layer.enable(viewer);
await layer.update(viewer);
const set = renderer.testing
.sets()
.find((id) => id.startsWith('earthquakes:'));
renderer.testing.scriptPicks(() => [
{ set, id: 'earthquake:event-a', surface: false },
]);
renderer.testing.pointer('dblclick', 10, 10);
const followed = renderer.camera.followed;
assert.ok(followed, 'the disc is followed');
assert.equal(followed.key, `${set}:earthquake:event-a`);
const p = followed.position(0);
const lon = (Math.atan2(p.y, p.x) * 180) / Math.PI;
assert.ok(Math.abs(lon - row.lon) < 1e-9, String(lon));
await layer.update(viewer);
assert.ok(renderer.camera.followed, 'still reported: still followed');
rows = [{ ...row, stableId: 'event-b', usgsId: 'event-b' }];
await layer.update(viewer);
assert.equal(
renderer.camera.followed,
null,
'gone from the feed: not followed',
);
rows = [row];
await layer.update(viewer);
renderer.testing.pointer('dblclick', 10, 10);
assert.ok(renderer.camera.followed);
layer.disable(viewer);
assert.equal(renderer.camera.followed, null, 'hiding the layer stops it');
});