fix(submarine-cables): a double-click follows a landing point or reference and zooms to a cable again

The cables, landing points and references were entities, which the default
renderer's double-click followed (a point, or a reference at its tip) or
zoomed to (a cable or area) until the sources were replaced or hidden. As
draw-port items they took no part in it.
This commit is contained in:
Sameh Khamis committed 2026-11-14 01:24:24 -08:00
1 parent d003d9ee78
commit 94ea9cd01d
5 files changed
+92

No files matched your search

@@ -564,6 +564,8 @@ function createCableHarness({
// event-dirty behavior with no wall-clock coupling. // event-dirty behavior with no wall-clock coupling.
let clockMs = 0; let clockMs = 0;
let clickHandler = null; let clickHandler = null;
let doubleHandler = null;
let picked = null;
const layer = createTeleGeographySubmarineCableLayer({ const layer = createTeleGeographySubmarineCableLayer({
overlayHost: { overlayHost: {
setVisible: (...args) => hostCalls.push(['visible', ...args]), setVisible: (...args) => hostCalls.push(['visible', ...args]),
@@ -577,6 +579,14 @@ function createCableHarness({
if (clickHandler === fn) clickHandler = null; if (clickHandler === fn) clickHandler = null;
}; };
}, },
onPointer: (type, fn) => {
if (type !== 'dblclick') return () => {};
doubleHandler = fn;
return () => {
if (doubleHandler === fn) doubleHandler = null;
};
},
stockEnabled: (name) => name === 'dblclickFollow',
}), }),
source, source,
mapStackEventTarget, mapStackEventTarget,
@@ -607,8 +617,13 @@ function createCableHarness({
camera.port.cancelFlight = () => flights.push('cancel'); camera.port.cancelFlight = () => flights.push('cancel');
camera.port.flyTo = (destination, options) => camera.port.flyTo = (destination, options) =>
flights.push({ destination, options }); flights.push({ destination, options });
camera.port.followed = null;
camera.port.follow = (target) => (camera.port.followed = target ?? null);
const zooms = [];
camera.port.flyToBounds = (sphere) => zooms.push(sphere);
const { draw } = bindFakeDraw(viewer, { const { draw } = bindFakeDraw(viewer, {
camera: camera.port, camera: camera.port,
query: { pick: () => picked },
frame: fakeSceneFrame(viewer), frame: fakeSceneFrame(viewer),
}); });
layer.init(viewer); layer.init(viewer);
@@ -637,6 +652,13 @@ function createCableHarness({
click(drawHit) { click(drawHit) {
clickHandler?.({ drawHit, pick: null }); clickHandler?.({ drawHit, pick: null });
}, },
/** A double-click over a drawn item; what the camera then does. */
dblclick(hit) {
picked = hit;
doubleHandler?.({ position: { x: 1, y: 1 } });
},
followed: () => camera.port.followed,
zooms,
async load() { async load() {
layer.enable(viewer); layer.enable(viewer);
source.releaseAll?.(); source.releaseAll?.();
@@ -1340,3 +1362,26 @@ test('every bundled cable segment is drawn with its source feature', async () =>
assert.equal(env.set('references').items.size, features.length); assert.equal(env.set('references').items.size, features.length);
env.layer.destroy(); env.layer.destroy();
}); });
test('a double-click follows a landing point or reference and zooms to a cable, as their entities did', async () => {
const env = await loadedHarness();
const [lineId] = env.set('lines').items.keys();
const [pinId] = env.set('pins').items.keys();
const [cableRef] = env.set('references').items.keys();
const surface = { surface: false };
env.dblclick({ set: env.set('pins').spec.id, id: pinId, ...surface });
assert.ok(env.followed(), 'a landing point is followed');
env.dblclick({ set: env.set('stems').spec.id, id: cableRef, ...surface });
assert.equal(
env.followed().key,
`${env.set('references').spec.id}:${cableRef}`,
'a stem follows its reference, one entity before',
);
env.dblclick({ set: env.set('lines').spec.id, id: lineId, ...surface });
assert.equal(env.followed(), null, 'a cable is zoomed to');
assert.ok(env.zooms.at(-1)?.radius > 0);
env.dblclick({ set: env.set('pins').spec.id, id: pinId, ...surface });
env.layer.disable();
assert.equal(env.followed(), null, 'hidden, its entities went: no follow');
env.layer.destroy();
});
+10
View File
@@ -1,5 +1,6 @@
import { toRadians } from '../../geo/vector.js'; import { toRadians } from '../../geo/vector.js';
import { cameraOf } from '../../render/rendererOf.js'; import { cameraOf } from '../../render/rendererOf.js';
import { followOnDoubleClick } from '../../data/stockFollow.js';
export function createInteraction({ state, parts, inputFor }) { export function createInteraction({ state, parts, inputFor }) {
function beginInteraction(viewer) { function beginInteraction(viewer) {
@@ -10,6 +11,15 @@ export function createInteraction({ state, parts, inputFor }) {
if (!record?.reference) return; if (!record?.reference) return;
flyToReference(viewer, record.reference); flyToReference(viewer, record.reference);
}); });
// A double-click follows a landing point or reference and zooms to a
// cable, as the default renderer did for their entities.
state._stockFollow = followOnDoubleClick({
viewer,
inputFor,
name: 'submarine-cables',
enabled: () => state._enabled,
targetFor: (hit) => parts.rendering.followTargetFor(hit),
});
} }
/** /**
+2
View File
@@ -109,6 +109,8 @@ export function createLifecycle({ state, parts, source, mapStackEventTarget }) {
state._overlayPublisher.hide(); state._overlayPublisher.hide();
state._clickSubscription?.(); state._clickSubscription?.();
state._clickSubscription = null; state._clickSubscription = null;
state._stockFollow?.destroy();
state._stockFollow = null;
if (state._preRenderRemover) { if (state._preRenderRemover) {
state._preRenderRemover(); state._preRenderRemover();
state._preRenderRemover = null; state._preRenderRemover = null;
+32
View File
@@ -4,6 +4,7 @@ import { densifyRhumb } from '../../geo/rhumb.js';
import { distance, toRadians } from '../../geo/vector.js'; import { distance, toRadians } from '../../geo/vector.js';
import { cssColor } from '../../render/color.js'; import { cssColor } from '../../render/color.js';
import { cameraOf, canvasOf, drawOf } from '../../render/rendererOf.js'; import { cameraOf, canvasOf, drawOf } from '../../render/rendererOf.js';
import { drawnItemTarget } from '../../data/stockFollow.js';
import { import {
clampLabel, clampLabel,
createCableOverlayEntry, createCableOverlayEntry,
@@ -180,6 +181,9 @@ export function createRendering({ state }) {
state._publishScratch.length = 0; state._publishScratch.length = 0;
state._loaded = false; state._loaded = false;
state._referenceSweepGate.reset(); state._referenceSweepGate.reset();
// The sources' entities went with them, and so did a follow of one.
state._stockFollow?.stop();
state._drawnItems = new Map();
if (!state._sets) return; if (!state._sets) return;
if (clearSets) for (const set of Object.values(state._sets)) set.clear(); if (clearSets) for (const set of Object.values(state._sets)) set.clear();
for (const picks of state._picks.values()) picks.clear(); for (const picks of state._picks.values()) picks.clear();
@@ -395,6 +399,18 @@ export function createRendering({ state }) {
map.clear(); map.clear();
for (const [id, info] of picks) map.set(id, info); for (const [id, info] of picks) map.set(id, info);
} }
// Drawn anew, as new sources' entities were: a follow of one ends.
state._stockFollow?.stop();
state._drawnItems = new Map([
[sets.lines.id, new Map(out.lines.map((item) => [item.id, item]))],
[sets.fills.id, new Map(out.fills.map((item) => [item.id, item]))],
[sets.pins.id, new Map(out.pins.map((item) => [item.id, item]))],
// A reference's stem and point were one entity, placed at the tip.
...[sets.stems.id, sets.references.id].map((id) => [
id,
new Map(out.references.map((record) => [record.id, record.point])),
]),
]);
sets.lines.set(out.lines); sets.lines.set(out.lines);
sets.fills.set(out.fills); sets.fills.set(out.fills);
sets.pins.set(out.pins); sets.pins.set(out.pins);
@@ -402,6 +418,21 @@ export function createRendering({ state }) {
sets.references.set(out.references.map((record) => record.point)); sets.references.set(out.references.map((record) => record.point));
} }
/**
* What a double-click on a hit follows or zooms to, as the default
* renderer did for the entity it was: a landing point or a reference is
* followed, a cable or area zoomed to.
*/
function followTargetFor(hit) {
if (!hit || hit.surface || !state._setIds.has(hit.set)) return null;
const item = state._drawnItems?.get(hit.set)?.get(hit.id);
if (!item) return null;
// A reference's stem and point follow as one.
const set =
hit.set === state._sets?.stems.id ? state._sets.references.id : hit.set;
return drawnItemTarget(set, item);
}
/** What a pick on one of the layer's sets names, or null. */ /** What a pick on one of the layer's sets names, or null. */
function pickInfo(hit) { function pickInfo(hit) {
if (!hit || !state._setIds.has(hit.set)) return null; if (!hit || !state._setIds.has(hit.set)) return null;
@@ -502,6 +533,7 @@ export function createRendering({ state }) {
applyCableClassification, applyCableClassification,
drawFeatures, drawFeatures,
pickInfo, pickInfo,
followTargetFor,
updateReferenceVisibility, updateReferenceVisibility,
}; };
} }
+3
View File
@@ -62,6 +62,9 @@ export function createState({ sweepClock, overlayHost }) {
state._referenceRecords = []; state._referenceRecords = [];
state._clickSubscription = null; state._clickSubscription = null;
/** The follow a double-click started, and each set's drawn items by id. */
state._stockFollow = null;
state._drawnItems = new Map();
state._preRenderRemover = null; state._preRenderRemover = null;