fix(radio): a double-click follows a station again

Each station, and the selected one's dot, was an entity, which the default
renderer's double-click followed until the stations or the selection were
drawn anew. As draw-port items they took no part in it.
This commit is contained in:
Sameh Khamis committed 2026-11-14 01:20:12 -08:00
1 parent c57a8bea83
commit 6ac8aed1b5
4 files changed
+70

No files matched your search

+12
View File
@@ -1,4 +1,5 @@
import { inputFor } from '../../input/dispatcher.js';
import { followOnDoubleClick } from '../../data/stockFollow.js';
import {
RADIO_PREFIX,
RADIO_PICK_WINDOW_PX,
@@ -98,6 +99,15 @@ export function createInteraction({
);
}
});
// A double-click follows a station, as the default renderer followed
// its entity.
layerState._stockFollow = followOnDoubleClick({
viewer,
inputFor,
name: 'radio',
enabled: () => radioPresentationAllowed(),
targetFor: (hit) => parts.rendering.followTargetFor(hit),
});
// Polling remains bounded during flights, but a stationary camera no longer
// rewrites every station's visibility four times per second while voice and
// audio processing share the main thread.
@@ -111,6 +121,8 @@ export function createInteraction({
unregisterPickOwner('radio');
layerState._clickSubscription?.();
layerState._clickSubscription = null;
layerState._stockFollow?.destroy();
layerState._stockFollow = null;
if (layerState._horizonTimer) clearInterval(layerState._horizonTimer);
layerState._horizonTimer = null;
}
+33
View File
@@ -529,6 +529,10 @@ export function createRendering({
layerState._selectedId = null;
}
// Every station was drawn anew as an entity: that ended a follow of one.
layerState._stockFollow?.retain(
(key) => !key.startsWith(`${sets?.stations.id}:`),
);
layerState._renderById.clear();
drawnShow.clear();
clusteredIds = new Set();
@@ -571,6 +575,7 @@ export function createRendering({
/** Stop clustering and let the stations' draw sets go. */
function removeDataSource() {
layerState._stockFollow?.stop();
offCameraChanged?.();
offCameraChanged = null;
if (sets) for (const set of Object.values(sets)) set.dispose();
@@ -598,6 +603,10 @@ export function createRendering({
/** Take the selected station's dot and bracket down, if it has them. */
function removeSelectionEntity() {
if (!selection) return;
// The selection's dot was an entity: taking it down ended its follow.
layerState._stockFollow?.retain(
(key) => !key.startsWith(`${sets?.selectedDot.id}:`),
);
selection = null;
sets?.selectedDot.clear();
sets?.selectedBracket.clear();
@@ -613,8 +622,32 @@ export function createRendering({
governorRequestRender('radio-recluster');
}
/**
* What a double-click on a hit follows (`followOnDoubleClick`), as the
* default renderer followed a station's entity or the selected one's: a
* cluster, never an entity, is followed by nothing.
*/
function followTargetFor(hit) {
if (!sets || hit.surface) return null;
let at = null;
let set = hit.set;
if (set === sets.stations.id && hit.id.startsWith(RADIO_PREFIX))
at = layerState._renderById.get(
hit.id.slice(RADIO_PREFIX.length),
)?.position;
else if (
(set === sets.selectedDot.id || set === sets.selectedBracket.id) &&
selection?.dot.id === hit.id
) {
at = selection.position;
set = sets.selectedDot.id;
}
return at ? { key: `${set}:${hit.id}`, position: () => ({ ...at }) } : null;
}
return {
radioStationIdFromPick,
followTargetFor,
installDataSource,
removeDataSource,
setStationsShown,
+23
View File
@@ -139,3 +139,26 @@ test('a filter that hides stations clusters them again at once', async () => {
},
);
});
test('a double-click follows a station, as its entity was', async () => {
const { createStubRenderer } = await import('../../render/stub/index.js');
const renderer = createStubRenderer();
const stations = [station(1, -97.0, 30.0), station(2, -90, 35)];
try {
await withRadioLayer({ stations, renderer }, async () => {
const set = renderer.testing
.sets()
.find((id) => id.endsWith(':stations'));
renderer.testing.scriptPicks(() => [
{ set, id: `radio:${stations[1].id}`, surface: false },
]);
renderer.testing.pointer('dblclick', 10, 10);
const followed = renderer.camera.followed;
assert.ok(followed, 'the station is followed');
const { lon, lat } = toLonLatH(followed.position(0), WGS84);
assert.ok(Math.abs(lon + 90) < 1e-6 && Math.abs(lat - 35) < 1e-6);
});
} finally {
renderer.destroy();
}
});
+2
View File
@@ -119,6 +119,8 @@ export function createState({ services }) {
layerState._playFallbackAttemptId = null;
layerState._clickSubscription = null;
/** The follow a double-click on a station started, while installed. */
layerState._stockFollow = null;
layerState._horizonTimer = null;