CONTACTS takes the selected vessel as its subject instead of following the nearest flight

Turning CONTACTS on with a vessel selected made the nearest flight to the view the subject and followed it. The selected vessel is now adopted as if it had been selected while CONTACTS was on; a followed flight still comes first, and with nothing selected the nearest flight is still focused.
This commit is contained in:
Sameh Khamis committed 2026-11-15 18:33:29 -08:00
1 parent 725f2f2998
commit 2ac157aca2
4 files changed
+146 -1

No files matched your search

+1 -1
View File
@@ -7009,7 +7009,7 @@ silently demoting every later lookup for the session.
- The internal Context coordinator is available in every visual style. Its dedicated right-side `CONTEXT` chooser exposes the neutral shell; the coordinator is not duplicated in Data Layers and does not enable a live-data dependency until a mode is selected. - The internal Context coordinator is available in every visual style. Its dedicated right-side `CONTEXT` chooser exposes the neutral shell; the coordinator is not duplicated in Data Layers and does not enable a live-data dependency until a mode is selected.
- The expanded `CONTEXT` view offers mutually exclusive `CONTACTS` and `SPACE MISSIONS` modes. Selecting `CONTACTS` enables the context-owned Flights, Military Flights, AIS Vessels, and Mapped Installations dependencies only when they are not already user-enabled; selecting `SPACE MISSIONS` enables the recent-launch layer and its Satellite dependency. `CONTACTS` cycles the nearest supported contact of whatever type is selected. Satellites are deliberately excluded from those Awareness cohorts and keep their own tracking UX. Selecting the active mode again returns to the neutral chooser and releases only mode-owned dependencies. - The expanded `CONTEXT` view offers mutually exclusive `CONTACTS` and `SPACE MISSIONS` modes. Selecting `CONTACTS` enables the context-owned Flights, Military Flights, AIS Vessels, and Mapped Installations dependencies only when they are not already user-enabled; selecting `SPACE MISSIONS` enables the recent-launch layer and its Satellite dependency. `CONTACTS` cycles the nearest supported contact of whatever type is selected. Satellites are deliberately excluded from those Awareness cohorts and keep their own tracking UX. Selecting the active mode again returns to the neutral chooser and releases only mode-owned dependencies.
- If a civilian or military aircraft is already tracked when `CONTACTS` becomes operational, that source-owned track is adopted as the Context subject before nearest-contact autofocus. Context rechecks the tracker after its dependencies settle, so a newer selection wins, while an explicit clear during activation prevents fallback from silently selecting a replacement. Cockpit entry remains unavailable until that Context transaction has settled, so its camera takeover cannot clear Cesium tracking before adoption. Adoption does not recreate tracking or transfer camera ownership; it initializes the normal 250 km ring, history, proximity results, and Cockpit Previous/Next state for the original aircraft. - If a civilian or military aircraft is already tracked when `CONTACTS` becomes operational, that source-owned track is adopted as the Context subject before nearest-contact autofocus. Context rechecks the tracker after its dependencies settle, so a newer selection wins, while an explicit clear during activation prevents fallback from silently selecting a replacement. Cockpit entry remains unavailable until that Context transaction has settled, so its camera takeover cannot clear Cesium tracking before adoption. Adoption does not recreate tracking or transfer camera ownership; it initializes the normal 250 km ring, history, proximity results, and Cockpit Previous/Next state for the original aircraft. With no tracked aircraft, an AIS vessel already selected (the vessel layer's `getSelectedInfo()`) becomes the subject, at activation and again when a deferred dependency settles, exactly as a vessel selected while `CONTACTS` is on; no nearest flight is picked and the camera is not moved.
- `SEARCH NEARBY SITES` retains the bounded OSM results and makes one user-initiated, view-biased Google Maps Places text search for “military installation.” Google results are source-stamped, deduplicated against OSM by rounded location/name, and remain mapped context rather than operational claims. If Places is unavailable or the API is not enabled for the supplied key, OSM context remains available. A view across the antimeridian is searched around its own centre, with a radius from its real width. - `SEARCH NEARBY SITES` retains the bounded OSM results and makes one user-initiated, view-biased Google Maps Places text search for “military installation.” Google results are source-stamped, deduplicated against OSM by rounded location/name, and remain mapped context rather than operational claims. If Places is unavailable or the API is not enabled for the supplied key, OSM context remains available. A view across the antimeridian is searched around its own centre, with a radius from its real width.
- The Context header holds only its title and collapse control. It no longer carries a Radio shortcut or a compact Radio player: Radio is the `RADIO` section inside the panel, with its own disclosure and the single `ENABLE` power control. Cockpit keeps its own compact Radio utility. - The Context header holds only its title and collapse control. It no longer carries a Radio shortcut or a compact Radio player: Radio is the `RADIO` section inside the panel, with its own disclosure and the single `ENABLE` power control. Cockpit keeps its own compact Radio utility.
- Context is set for reading in every theme: mode, standby and action labels are 10 px, and the panel draws no glow halo. Outside Cyber, the two modes form one segmented control, the standby guidance is plain left-aligned text rather than a dashed placeholder, and the panel's section titles share the side panels' dock-label colour. Cyber keeps its separately framed mode buttons, its red panel titles, and in layout-focus a framed, centred standby card over its radar art. - Context is set for reading in every theme: mode, standby and action labels are 10 px, and the panel draws no glow halo. Outside Cyber, the two modes form one segmented control, the standby guidance is plain left-aligned text rather than a dashed placeholder, and the panel's section titles share the side panels' dock-label colour. Cyber keeps its separately framed mode buttons, its red panel titles, and in layout-focus a framed, centred standby card over its radar art.
+16
View File
@@ -17,11 +17,25 @@ export function createDependencies({
parts.subject.refreshSelectedSubject(true); parts.subject.refreshSelectedSubject(true);
return; return;
} }
if (adoptSelectedVessel()) return;
if (layerState.autoFocusRetryPending) { if (layerState.autoFocusRetryPending) {
layerState.autoFocusRetryPending = !parts.focus.focusAttentionTarget(); layerState.autoFocusRetryPending = !parts.focus.focusAttentionTarget();
} }
} }
/**
* Take the selected AIS vessel as the subject, as its selection would have
* had Contacts been on. A followed flight is checked first by the callers.
* @returns {boolean} Whether a vessel became the subject.
*/
function adoptSelectedVessel() {
const vessel = parts.subject.currentSelectedVesselSubject();
if (!vessel) return false;
layerState.autoFocusRetryPending = false;
parts.subject.selectSubject(vessel);
return Boolean(layerState.subject);
}
async function enableDependencies(activationId = layerState.activationId) { async function enableDependencies(activationId = layerState.activationId) {
const aircraftPending = []; const aircraftPending = [];
for (const layerId of DEPENDENCIES) { for (const layerId of DEPENDENCIES) {
@@ -104,6 +118,7 @@ export function createDependencies({
const initialTrackedSubject = parts.subject.currentTrackedFlightSubject(); const initialTrackedSubject = parts.subject.currentTrackedFlightSubject();
if (initialTrackedSubject) if (initialTrackedSubject)
parts.subject.selectSubject(initialTrackedSubject); parts.subject.selectSubject(initialTrackedSubject);
else adoptSelectedVessel();
return enableDependencies(activationId) return enableDependencies(activationId)
.then(() => { .then(() => {
if ( if (
@@ -121,6 +136,7 @@ export function createDependencies({
parts.subject.selectSubject(layerState.subject); parts.subject.selectSubject(layerState.subject);
return; return;
} }
if (adoptSelectedVessel()) return;
if (layerState.autoFocusAttempted) return; if (layerState.autoFocusAttempted) return;
layerState.autoFocusRetryPending = !parts.focus.focusAttentionTarget(); layerState.autoFocusRetryPending = !parts.focus.focusAttentionTarget();
}) })
@@ -0,0 +1,108 @@
// src/layers/awareness/selectedVessel.test.mjs — Contacts turned on while an
// AIS vessel is selected takes that vessel as its subject.
import test from 'node:test';
import assert from 'node:assert/strict';
import { summarizeAwarenessCohort } from '../../data/militaryAwarenessEngine.js';
import { createState } from './state.js';
import { createModel } from './model.js';
import { createQueries } from './queries.js';
import { createSubject } from './subject.js';
import { createHistory } from './history.js';
import { createDependencies } from './dependencies.js';
const VESSEL_ID = '367000001';
/** Contacts parts over fake sources; focus records each nearest-flight pick. */
function contacts(selection) {
globalThis.document ??= { body: null };
const noAircraft = {
getAllPositions: () => [],
getNearby: () => [],
getTrackedSubject: () => null,
};
const services = {
flights: noAircraft,
military: noAircraft,
vessels: {
getNearby: () => [],
getAllPositions: () => [],
getSelectedInfo: () => selection.vessel,
},
installations: {
getNearby: () => [],
getStats: () => ({}),
setContextAnchor() {},
},
};
const state = createState({ services });
state.enabled = true;
state.passive = false;
state.dataManager = {
isEnabled: () => true,
isEffectivelyEnabled: () => true,
setEnabled: async () => true,
getLayerLifecycleState: () => ({
enabled: true,
lifecycleState: 'enabled',
}),
layers: new Map(),
};
const focused = [];
const parts = {
navigation: {
summarizeAwarenessCohortForNavigation: (items, source) =>
summarizeAwarenessCohort(items, source),
isFlightLayer: (id) => id === 'flights' || id === 'military',
},
rendering: { renderVisual() {}, scheduleDirectionOverlayUpdate() {} },
panel: { renderResults() {}, startAwarenessPageRotation() {} },
focus: {
focusAttentionTarget() {
focused.push('nearest');
return true;
},
},
};
const context = { state, services, parts };
parts.model = createModel(context);
parts.queries = createQueries(context);
parts.subject = createSubject(context);
parts.history = createHistory(context);
parts.dependencies = createDependencies(context);
return { state, parts, focused };
}
/** The vessel layer's answer for a selected Royal Prince. */
const ROYAL_PRINCE = Object.freeze({
id: VESSEL_ID,
mmsi: VESSEL_ID,
name: 'ROYAL PRINCE',
latitude: 37.8,
longitude: -122.4,
});
test('Contacts turned on with a vessel selected takes it as the subject', async () => {
const { state, parts, focused } = contacts({ vessel: ROYAL_PRINCE });
await parts.dependencies.activateOperationalContext();
assert.deepEqual(focused, [], 'no nearest flight is picked or followed');
assert.equal(state.subject?.layerId, 'ais-live-vessels');
assert.equal(state.subject?.id, VESSEL_ID);
assert.match(state.subject.label, /ROYAL PRINCE/);
});
test('a late source settling keeps the selected vessel, not a nearest flight', () => {
const selection = { vessel: null };
const { state, parts, focused } = contacts(selection);
state.autoFocusRetryPending = true;
selection.vessel = ROYAL_PRINCE;
parts.dependencies.refreshAfterDeferredDependency(state.activationId);
assert.deepEqual(focused, []);
assert.equal(state.subject?.id, VESSEL_ID);
});
test('with no vessel selected, Contacts still picks the nearest flight', async () => {
const { state, parts, focused } = contacts({ vessel: null });
await parts.dependencies.activateOperationalContext();
assert.deepEqual(focused, ['nearest']);
assert.equal(state.subject, null);
});
+21
View File
@@ -531,6 +531,26 @@ export function createSubject({ state: layerState, services, parts, source }) {
}; };
} }
/**
* The AIS vessel the user has selected, as a subject. Contacts turned on
* after the selection never heard its `gev:entity-selected`, so activation
* asks the vessel layer and shapes its answer as that event's record.
* @returns {object|null} Detached subject, or null when no vessel is selected.
*/
function currentSelectedVesselSubject() {
const info = aisLiveVesselsLayer.getSelectedInfo?.();
if (!info?.id) return null;
return subjectFromContext({
layerId: 'ais-live-vessels',
id: info.id,
label: info.name || (info.mmsi ? `MMSI ${info.mmsi}` : info.id),
latitude: info.latitude,
longitude: info.longitude,
properties: { vesselId: info.id, mmsi: info.mmsi },
});
}
/** /**
* Record that the current subject left its feed on its own. * Record that the current subject left its feed on its own.
* *
@@ -579,6 +599,7 @@ export function createSubject({ state: layerState, services, parts, source }) {
resolveSubjectPhoto, resolveSubjectPhoto,
refreshSelectedSubject, refreshSelectedSubject,
subjectFromContext, subjectFromContext,
currentSelectedVesselSubject,
markSubjectEvicted, markSubjectEvicted,
clearAwarenessSubject, clearAwarenessSubject,
}; };