Keep Context inside the package boundaries

The shell passes the ground picker to the click bridge, so the UI shell no
longer pulls in the annotation and search stack. Context's new modules are
owned by the packages that import them and formatted with the rest.

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-16 14:59:01 -08:00
1 parent c351e66af9
commit 902689da8a
11 files changed
+426 -122

No files matched your search

+1
View File
@@ -197,6 +197,7 @@ export class StyleManager extends ShellFacade {
viewer,
getDataManager: () => this._dataManager,
pinia: applicationPinia(),
pickWorld: services.pickWorldFromScreen,
});
this.mapStackController = mapStackController;
this.placeSearch = placeSearch;
+15 -3
View File
@@ -40,8 +40,18 @@ export const TAB_AFFECTS = {
export const LAYER_TABS = [
// Labels and cards the world overlay draws for the label layers.
{ id: 'labels', label: 'Labels', icon: 'label', when: (on) => TAB_AFFECTS.labels(on).length > 0 },
{ id: 'aircraft', label: '3D aircraft', icon: 'flight', when: (on) => TAB_AFFECTS.aircraft(on).length > 0 },
{
id: 'labels',
label: 'Labels',
icon: 'label',
when: (on) => TAB_AFFECTS.labels(on).length > 0,
},
{
id: 'aircraft',
label: '3D aircraft',
icon: 'flight',
when: (on) => TAB_AFFECTS.aircraft(on).length > 0,
},
];
/** Ids of the layers that are on; Context refreshes it. */
@@ -59,7 +69,9 @@ export const contextReady = ref(false);
/** The tabs available now. */
export const availableTabs = computed(() =>
contextReady.value ? LAYER_TABS.filter((tab) => tab.when(enabledLayerIds.value)) : [],
contextReady.value
? LAYER_TABS.filter((tab) => tab.when(enabledLayerIds.value))
: [],
);
export const hasTab = (id) => availableTabs.value.some((tab) => tab.id === id);
+3 -1
View File
@@ -7,7 +7,9 @@ import { ref } from 'vue';
const KEY = 'gev.contextRadiusKm';
/** The distances the control steps through, in km. */
export const CONTEXT_RADIUS_STEPS = Object.freeze([25, 50, 100, 250, 500, 1000, 2500]);
export const CONTEXT_RADIUS_STEPS = Object.freeze([
25, 50, 100, 250, 500, 1000, 2500,
]);
export const DEFAULT_CONTEXT_RADIUS_KM = 250;
/** The step closest to a distance; the default for anything unusable. */
+9 -2
View File
@@ -9,13 +9,20 @@ export const contextSearchOpen = ref(false);
/** The text as typed. */
export const contextSearchText = ref('');
/** The text to match against: trimmed, lower case, '' when not searching. */
export const contextNeedle = computed(() => (contextSearchOpen.value ? contextSearchText.value.trim().toLowerCase() : ''));
export const contextNeedle = computed(() =>
contextSearchOpen.value ? contextSearchText.value.trim().toLowerCase() : '',
);
/** Whether any of the given strings holds the searched text (true when not searching). */
export function matchesContextSearch(...parts) {
const needle = contextNeedle.value;
if (!needle) return true;
return parts.some((part) => part !== null && part !== undefined && String(part).toLowerCase().includes(needle));
return parts.some(
(part) =>
part !== null &&
part !== undefined &&
String(part).toLowerCase().includes(needle),
);
}
export function closeContextSearch() {
+53 -19
View File
@@ -1,5 +1,4 @@
import * as Cesium from 'cesium';
import { pickWorldFromScreen } from '../annotations/annotationResolver.js';
import { resolvePickedContext } from '../data/pickedContext.js';
import { isPointerFree } from '../data/inputOwnership.js';
import { useCockpitStore } from './stores/cockpit.js';
@@ -19,7 +18,12 @@ const FRAME_RANGE = Object.freeze({
});
const DEFAULT_RANGE = 8_000;
/** Items the voice runtime can keep the camera on. */
const FOLLOWABLE = new Set(['flights', 'military', 'ais-live-vessels', 'satellites']);
const FOLLOWABLE = new Set([
'flights',
'military',
'ais-live-vessels',
'satellites',
]);
/**
* Connects the Context panel's entity card to the globe: a click on anything a
@@ -30,9 +34,17 @@ const FOLLOWABLE = new Set(['flights', 'military', 'ais-live-vessels', 'satellit
* @param {object} options.viewer Cesium viewer.
* @param {() => object} options.getDataManager Layer lifecycle.
* @param {object} options.pinia
* @param {(viewer: object, x: number, y: number) => ({lat: number, lon: number}|null)} [options.pickWorld]
* The ground under a normalized screen point; the view's centre falls back
* to the point under the camera without it.
* @returns {() => void} disconnects
*/
export function installEntityContext({ viewer, getDataManager, pinia }) {
export function installEntityContext({
viewer,
getDataManager,
pinia,
pickWorld,
}) {
const store = useEntityCardStore(pinia);
const omnibar = useOmnibarStore(pinia);
const voice = useVoiceStore(pinia);
@@ -43,7 +55,8 @@ export function installEntityContext({ viewer, getDataManager, pinia }) {
const button = doc?.querySelector(
'.ui-rail--right .ui-rail__item[data-rail-item="global-context-panel"]',
);
if (button && button.getAttribute('aria-pressed') !== 'true') button.click();
if (button && button.getAttribute('aria-pressed') !== 'true')
button.click();
}
function flyTo(card) {
@@ -77,11 +90,19 @@ export function installEntityContext({ viewer, getDataManager, pinia }) {
// Aircraft can be flown from, and a satellite ridden in the orbital view:
// track the craft, then enter Cockpit on it.
const COCKPIT_LAYERS = new Set(['flights', 'military', 'local-adsb', 'satellites']);
const COCKPIT_LAYERS = new Set([
'flights',
'military',
'local-adsb',
'satellites',
]);
async function cockpit(card) {
const run = omnibar.runner;
if (!run || !COCKPIT_LAYERS.has(card.layerId)) return;
await run('track_entity', { query: card.identity.id || card.title, layerId: card.layerId });
await run('track_entity', {
query: card.identity.id || card.title,
layerId: card.layerId,
});
if (card.layerId !== 'satellites') {
await run('control_cockpit', { action: 'enter' });
return;
@@ -124,7 +145,8 @@ export function installEntityContext({ viewer, getDataManager, pinia }) {
ask,
askText,
cockpit,
canCockpit: (card) => Boolean(omnibar.runner) && COCKPIT_LAYERS.has(card?.layerId),
canCockpit: (card) =>
Boolean(omnibar.runner) && COCKPIT_LAYERS.has(card?.layerId),
canFollow: (card) => FOLLOWABLE.has(card?.layerId),
// Where the camera is, so a search prefers what is close by.
here: () => {
@@ -144,7 +166,7 @@ export function installEntityContext({ viewer, getDataManager, pinia }) {
const readView = () => {
const camera = viewer.camera;
const height = camera.positionCartographic?.height ?? 0;
const middle = pickWorldFromScreen(viewer, 0.5, 0.5);
const middle = pickWorld?.(viewer, 0.5, 0.5);
const center = middle
? { lat: middle.lat, lon: middle.lon }
: {
@@ -175,7 +197,12 @@ export function installEntityContext({ viewer, getDataManager, pinia }) {
setTimeout(readView, 0);
/** Layers whose own map click already follows what was clicked. */
const CLICK_FOLLOWS = new Set(['flights', 'military', 'satellites', 'ais-live-vessels']);
const CLICK_FOLLOWS = new Set([
'flights',
'military',
'satellites',
'ais-live-vessels',
]);
// Keep the card's "following" in step with the camera. When the camera
// stops following (Escape, another tool, the craft gone) the card stops
@@ -184,13 +211,16 @@ export function installEntityContext({ viewer, getDataManager, pinia }) {
// A layer switching what it follows lets go for a moment and takes hold
// again in the same turn, so this is checked once that settles.
let trackCheck = 0;
const removeTrackedChanged = viewer.trackedEntityChanged.addEventListener(() => {
clearTimeout(trackCheck);
trackCheck = setTimeout(() => {
if (!viewer.trackedEntity) store.following = null;
else if (CLICK_FOLLOWS.has(store.card?.layerId)) store.following = store.card.key;
}, 250);
});
const removeTrackedChanged = viewer.trackedEntityChanged.addEventListener(
() => {
clearTimeout(trackCheck);
trackCheck = setTimeout(() => {
if (!viewer.trackedEntity) store.following = null;
else if (CLICK_FOLLOWS.has(store.card?.layerId))
store.following = store.card.key;
}, 250);
},
);
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
// What is under the pointer is read when the button goes down: by the time
@@ -206,14 +236,17 @@ export function installEntityContext({ viewer, getDataManager, pinia }) {
};
let pressed = null;
handler.setInputAction(({ position }) => {
pressed = isPointerFree() ? { picked: pickAt(position), x: position.x, y: position.y } : null;
pressed = isPointerFree()
? { picked: pickAt(position), x: position.x, y: position.y }
: null;
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
handler.setInputAction(({ position }) => {
// A tool that owns the pointer (draw, measure) keeps its clicks.
const press = pressed;
pressed = null;
if (!isPointerFree()) return;
const samePlace = press && Math.hypot(press.x - position.x, press.y - position.y) < 6;
const samePlace =
press && Math.hypot(press.x - position.x, press.y - position.y) < 6;
const picked = samePlace ? press.picked : pickAt(position);
const identity = resolvePickedContext(picked, {
dataManager: getDataManager(),
@@ -229,7 +262,8 @@ export function installEntityContext({ viewer, getDataManager, pinia }) {
// photorealistic ground is a tileset, so a click on it counts as ground.
// A click on something else Context cannot describe (a label, a trail)
// leaves the card as it is.
if (!picked || picked.primitive instanceof Cesium.Cesium3DTileset) store.clear();
if (!picked || picked.primitive instanceof Cesium.Cesium3DTileset)
store.clear();
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
// Layers that select through the context store (GeoJSON sites, fires,
+40 -15
View File
@@ -37,9 +37,12 @@ function snapshot(name, load) {
feeds.set(name, { at: Date.now(), promise });
return promise;
}
const quakes = () => snapshot('quakes', () => createUsgsEarthquakeSource().getSnapshot());
const storms = () => snapshot('storms', () => createCycloneSource().getSnapshot());
const perimeters = () => snapshot('perimeters', () => createWfigsPerimeterSource().getSnapshot());
const quakes = () =>
snapshot('quakes', () => createUsgsEarthquakeSource().getSnapshot());
const storms = () =>
snapshot('storms', () => createCycloneSource().getSnapshot());
const perimeters = () =>
snapshot('perimeters', () => createWfigsPerimeterSource().getSnapshot());
const fires = () => snapshot('fires', () => createFirmsSource().getSnapshot());
const COMPASS = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
@@ -49,7 +52,9 @@ export function compassPoint(from, to) {
const y = Math.sin((to.lon - from.lon) * rad) * Math.cos(to.lat * rad);
const x =
Math.cos(from.lat * rad) * Math.sin(to.lat * rad) -
Math.sin(from.lat * rad) * Math.cos(to.lat * rad) * Math.cos((to.lon - from.lon) * rad);
Math.sin(from.lat * rad) *
Math.cos(to.lat * rad) *
Math.cos((to.lon - from.lon) * rad);
const deg = (Math.atan2(y, x) / rad + 360) % 360;
return compassName(deg);
}
@@ -98,14 +103,19 @@ export async function hazardsNear(lat, lon, radiusKm = 250) {
add({
kind: 'quake',
icon: 'earthquake',
title: Number.isFinite(Number.parseFloat(quake.mag)) ? `M${Number(quake.mag).toFixed(1)} earthquake` : 'Earthquake',
title: Number.isFinite(Number.parseFloat(quake.mag))
? `M${Number(quake.mag).toFixed(1)} earthquake`
: 'Earthquake',
detail: quake.place || '',
time: quake.time,
at,
});
}
for (const storm of stormSnap?.storms || []) {
const at = { lat: storm.position?.latitude, lon: storm.position?.longitude };
const at = {
lat: storm.position?.latitude,
lon: storm.position?.longitude,
};
if (!(distanceKm(here, at) <= radiusKm)) continue;
add({
kind: 'storm',
@@ -125,8 +135,12 @@ export async function hazardsNear(lat, lon, radiusKm = 250) {
icon: 'local_fire_department',
title: fire.name || 'Wildfire',
detail: [
Number.isFinite(acres) ? `${Math.round(acres).toLocaleString()} acres` : '',
Number.isFinite(fire.containedPct) ? `${fire.containedPct}% contained` : '',
Number.isFinite(acres)
? `${Math.round(acres).toLocaleString()} acres`
: '',
Number.isFinite(fire.containedPct)
? `${fire.containedPct}% contained`
: '',
fire.category === 'RX' ? 'prescribed burn' : '',
]
.filter(Boolean)
@@ -137,10 +151,15 @@ export async function hazardsNear(lat, lon, radiusKm = 250) {
}
// Satellite fire hits are many small points: count the close ones.
const hits = (Array.isArray(fireSnap?.fires) ? fireSnap.fires : [])
.map((fire) => ({ lat: Number(fire.lat ?? fire.latitude), lon: Number(fire.lon ?? fire.longitude) }))
.map((fire) => ({
lat: Number(fire.lat ?? fire.latitude),
lon: Number(fire.lon ?? fire.longitude),
}))
.filter((at) => distanceKm(here, at) <= radiusKm);
if (hits.length) {
const nearest = hits.reduce((a, b) => (distanceKm(here, a) <= distanceKm(here, b) ? a : b));
const nearest = hits.reduce((a, b) =>
distanceKm(here, a) <= distanceKm(here, b) ? a : b,
);
add({
kind: 'hotspots',
icon: 'local_fire_department',
@@ -151,22 +170,28 @@ export async function hazardsNear(lat, lon, radiusKm = 250) {
});
}
const order = { storm: 0, wildfire: 1, hotspots: 2, quake: 3 };
return found.sort((a, b) => order[a.kind] - order[b.kind] || a.distanceKm - b.distanceKm);
return found.sort(
(a, b) => order[a.kind] - order[b.kind] || a.distanceKm - b.distanceKm,
);
}
/** Title-case copy for a WMO weather code, and the icon that goes with it. */
export function weatherLook(code) {
const value = Number(code);
if (!Number.isFinite(value)) return { label: 'Conditions unknown', icon: 'partly_cloudy_day' };
if (!Number.isFinite(value))
return { label: 'Conditions unknown', icon: 'partly_cloudy_day' };
if (value === 0) return { label: 'Clear', icon: 'sunny' };
if (value <= 2) return { label: 'Partly cloudy', icon: 'partly_cloudy_day' };
if (value === 3) return { label: 'Overcast', icon: 'cloud' };
if (value === 45 || value === 48) return { label: 'Fog', icon: 'foggy' };
if (value >= 51 && value <= 57) return { label: 'Drizzle', icon: 'rainy' };
if (value >= 61 && value <= 67) return { label: 'Rain', icon: 'rainy' };
if (value >= 71 && value <= 77) return { label: 'Snow', icon: 'weather_snowy' };
if (value >= 80 && value <= 82) return { label: 'Rain showers', icon: 'rainy' };
if (value >= 85 && value <= 86) return { label: 'Snow showers', icon: 'weather_snowy' };
if (value >= 71 && value <= 77)
return { label: 'Snow', icon: 'weather_snowy' };
if (value >= 80 && value <= 82)
return { label: 'Rain showers', icon: 'rainy' };
if (value >= 85 && value <= 86)
return { label: 'Snow showers', icon: 'weather_snowy' };
if (value >= 95) return { label: 'Thunderstorm', icon: 'thunderstorm' };
return { label: 'Mixed conditions', icon: 'partly_cloudy_day' };
}
+22 -6
View File
@@ -62,7 +62,10 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
const dm = shell.value?.dataManager?.();
const layer = dm?.getAll?.().find((row) => row.id === current.layerId);
const stats = layer?.stats || {};
const raw = stats.sourceVerbatim === true && stats.source ? stats.source : sourceLabel(stats.source || layer?.source);
const raw =
stats.sourceVerbatim === true && stats.source
? stats.source
: sourceLabel(stats.source || layer?.source);
return raw || '';
}
const canCockpit = () => Boolean(shell.value?.canCockpit?.(card.value));
@@ -101,7 +104,9 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
function askAboutView(summary) {
const where = view.value;
if (!where) return;
const counts = summary.map((group) => `${group.count} ${group.layerName}`).join(', ');
const counts = summary
.map((group) => `${group.count} ${group.layerName}`)
.join(', ');
shell.value?.askText?.(
`What am I looking at? The view is centred on ${where.center.lat.toFixed(4)}, ${where.center.lon.toFixed(4)} from about ${Math.round(where.heightM)} m up${counts ? `, showing ${counts}` : ''}. What is here and what stands out?`,
);
@@ -170,7 +175,13 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
* @returns {boolean} Whether a card could be made.
*/
/** Things that move are followed as soon as they are picked. */
const AUTO_FOLLOW = new Set(['flights', 'military', 'local-adsb', 'satellites', 'ais-live-vessels']);
const AUTO_FOLLOW = new Set([
'flights',
'military',
'local-adsb',
'satellites',
'ais-live-vessels',
]);
/** The key of the item the camera is following, if any. */
const following = ref(null);
@@ -185,7 +196,10 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
timer = setInterval(refresh, REFRESH_MS);
shell.value?.openPanel?.();
const current = card.value;
const followNow = autoFollow && AUTO_FOLLOW.has(current?.layerId) && shell.value?.canFollow?.(current);
const followNow =
autoFollow &&
AUTO_FOLLOW.has(current?.layerId) &&
shell.value?.canFollow?.(current);
if (followNow) {
// Tracking can announce the craft again; following what is already
// followed would loop, so it only starts once per item.
@@ -194,7 +208,8 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
shell.value?.follow?.(current);
}
} else {
if (following.value && following.value !== current?.key) following.value = null;
if (following.value && following.value !== current?.key)
following.value = null;
if (fly) shell.value?.flyTo?.(current);
}
requestRoute(current?.identity);
@@ -215,7 +230,8 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
following.value = card.value.key;
shell.value?.follow?.(card.value);
};
const isFollowing = () => Boolean(card.value && following.value === card.value.key);
const isFollowing = () =>
Boolean(card.value && following.value === card.value.key);
const ask = () => card.value && shell.value?.ask?.(card.value);
const canFollow = () => Boolean(shell.value?.canFollow?.(card.value));
/** Loaded items whose name or id matches typed text, for the omnibar. */