mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Keep Context's follow, clicks, Radio, Cockpit entry and credits right
- Following comes only from the camera's own follow, never claimed ahead of it; vessels, which the camera does not follow, are flown to. - A drag or a long press never selects, and only a clean click on open map closes the card; a card painted on the overlay is not open map. - Closing the card lets go through its own layer only, as the person's action, leaving other layers' selections alone. - Radio's panel, with its local SDR tuner, shows whether or not the Radio layer is on; Contacts' Cockpit entry hides only while the card offers its own. - Expanded Context keeps the credits beside it right to left and with the minimal HUD. - Context counts as closed until its panel says it is open; closed, the card's refresh and the view reading pause, and opening reads the view. - The five-minute re-read fetches again past the caches, keeps what is shown meanwhile, and an empty brief is not kept. Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
547687fecf
commit
57f9c03eaa
10 files changed
+599
-188
No files matched your search
@@ -199,6 +199,7 @@ export class StyleManager extends ShellFacade {
|
||||
pinia: applicationPinia(),
|
||||
pickWorld: services.pickWorldFromScreen,
|
||||
regionalBrief: services.fetchRegionalBrief,
|
||||
overlayHit: services.hitTestWorldOverlay,
|
||||
});
|
||||
this.mapStackController = mapStackController;
|
||||
this.placeSearch = placeSearch;
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
import {
|
||||
activateWorldOverlayAction,
|
||||
destroyWorldOverlay,
|
||||
hitTestWorldOverlay,
|
||||
initWorldOverlay,
|
||||
subscribeWorldOverlayActions,
|
||||
} from '../overlays/worldOverlay.js';
|
||||
@@ -73,6 +74,7 @@ export class StyleManager extends ApplicationShell {
|
||||
super(viewer, {
|
||||
...options,
|
||||
services: {
|
||||
hitTestWorldOverlay,
|
||||
CITY_POIS,
|
||||
GLOBE_VIEW,
|
||||
flyToGlobeView,
|
||||
|
||||
@@ -2,10 +2,15 @@ import { resolvePickedContext } from '../data/pickedContext.js';
|
||||
import { followedOf, onFollowChanged } from '../data/followed.js';
|
||||
import { fromDegreesInto } from '../geo/ellipsoid.js';
|
||||
import { inputFor } from '../input/dispatcher.js';
|
||||
import {
|
||||
isTrackingClickGesture,
|
||||
isTrackingSelectionGesture,
|
||||
} from '../data/trackingClickGesture.js';
|
||||
import { findCamera } from '../render/rendererOf.js';
|
||||
import { useCockpitStore } from './stores/cockpit.js';
|
||||
import { useEntityCardStore } from './stores/entityCard.js';
|
||||
import { useOmnibarStore } from './stores/omnibar.js';
|
||||
import { usePanelChromeStore } from './stores/panelChrome.js';
|
||||
import { useVoiceStore } from './stores/voice.js';
|
||||
|
||||
/** Camera distance (m) that frames an item of each kind. */
|
||||
@@ -19,13 +24,11 @@ const FRAME_RANGE = Object.freeze({
|
||||
'fire perimeter': 40_000,
|
||||
});
|
||||
const DEFAULT_RANGE = 8_000;
|
||||
/** Items the voice runtime can keep the camera on. */
|
||||
const FOLLOWABLE = new Set([
|
||||
'flights',
|
||||
'military',
|
||||
'ais-live-vessels',
|
||||
'satellites',
|
||||
]);
|
||||
/**
|
||||
* Items the camera can follow: their layers follow through the camera port
|
||||
* with a key naming the item (src/data/followed.js). A vessel is flown to.
|
||||
*/
|
||||
const FOLLOWABLE = new Set(['flights', 'military', 'satellites']);
|
||||
|
||||
/**
|
||||
* Connects the Context panel's entity card to the globe: a click on anything a
|
||||
@@ -41,6 +44,8 @@ const FOLLOWABLE = new Set([
|
||||
* to the point under the camera without it.
|
||||
* @param {(lat: number, lon: number) => Promise<object>} [options.regionalBrief]
|
||||
* The app's regional brief service, for the weather and news Context shows.
|
||||
* @param {(x: number, y: number) => object|null} [options.overlayHit]
|
||||
* The overlay card under a screen point, if any (a vessel's, a fire's).
|
||||
* @returns {() => void} disconnects
|
||||
*/
|
||||
export function installEntityContext({
|
||||
@@ -49,11 +54,16 @@ export function installEntityContext({
|
||||
pinia,
|
||||
pickWorld,
|
||||
regionalBrief,
|
||||
overlayHit,
|
||||
}) {
|
||||
const store = useEntityCardStore(pinia);
|
||||
const omnibar = useOmnibarStore(pinia);
|
||||
const voice = useVoiceStore(pinia);
|
||||
const cockpitStore = useCockpitStore(pinia);
|
||||
const chrome = usePanelChromeStore(pinia);
|
||||
/** Whether Context is open; a closed panel reads nothing. */
|
||||
const isOpen = () =>
|
||||
chrome.panels['global-context-panel']?.collapsed === false;
|
||||
const doc = globalThis.document;
|
||||
let disposed = false;
|
||||
// The renderer's camera; looked up on use, as a renderer can be bound
|
||||
@@ -116,9 +126,15 @@ export function installEntityContext({
|
||||
// Closing the card lets go of the camera, when the camera follows the
|
||||
// card's own item and nothing else took it over since.
|
||||
function letGo(card) {
|
||||
const run = omnibar.runner;
|
||||
if (!run || !followsCard(card)) return;
|
||||
Promise.resolve(run('stop_tracking', {})).catch(() => {});
|
||||
if (!followsCard(card)) return;
|
||||
// Only the card's own layer lets go, as the person's own action; other
|
||||
// layers' selections stay as they are.
|
||||
const layer = getDataManager()?.layers?.get?.(card.layerId);
|
||||
try {
|
||||
layer?.module?.stopTracking?.({ origin: 'user' });
|
||||
} catch {
|
||||
// A layer going away meanwhile has nothing left to let go of.
|
||||
}
|
||||
}
|
||||
|
||||
// Aircraft can be flown from, and a satellite ridden in the orbital view:
|
||||
@@ -182,6 +198,7 @@ export function installEntityContext({
|
||||
flyTo,
|
||||
follow,
|
||||
letGo,
|
||||
isOpen,
|
||||
regionalBrief,
|
||||
ask,
|
||||
askText,
|
||||
@@ -203,7 +220,7 @@ export function installEntityContext({
|
||||
// the height. Read when the camera settles, not every frame.
|
||||
const readView = () => {
|
||||
const port = camera();
|
||||
if (!port) return;
|
||||
if (!port || !isOpen()) return;
|
||||
const pose = port.pose();
|
||||
if (![pose.lat, pose.lon, pose.height].every(Number.isFinite)) return;
|
||||
const middle = pickWorld?.(viewer, 0.5, 0.5);
|
||||
@@ -252,14 +269,16 @@ export function installEntityContext({
|
||||
listen();
|
||||
readView();
|
||||
}, 0);
|
||||
// Opening the panel describes the view as it is now.
|
||||
let wasOpen = isOpen();
|
||||
const offChrome = chrome.$subscribe(() => {
|
||||
const open = isOpen();
|
||||
if (open && !wasOpen) readView();
|
||||
wasOpen = open;
|
||||
});
|
||||
|
||||
/** 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']);
|
||||
|
||||
// Keep the card's "following" in step with the camera: it says Following
|
||||
// while the camera follows the card's own item (the follow's key names
|
||||
@@ -269,9 +288,16 @@ export function installEntityContext({
|
||||
let followCheck = 0;
|
||||
const offFollow = onFollowChanged(viewer, () => {
|
||||
clearTimeout(followCheck);
|
||||
const card = store.card;
|
||||
// Taking hold of the card's item shows at once; letting go waits a
|
||||
// moment, in case the layer is only switching follows.
|
||||
if (followsCard(card)) {
|
||||
store.following = card.key;
|
||||
return;
|
||||
}
|
||||
followCheck = setTimeout(() => {
|
||||
const card = store.card;
|
||||
store.following = followsCard(card) ? card.key : null;
|
||||
const now = store.card;
|
||||
store.following = followsCard(now) ? now.key : null;
|
||||
}, 250);
|
||||
});
|
||||
|
||||
@@ -279,8 +305,9 @@ export function installEntityContext({
|
||||
// dispatcher hands every subscriber the same click, picked once before
|
||||
// any layer acts on it, and only while no tool holds the pointer.
|
||||
const offClick = inputFor(viewer).onClick((event) => {
|
||||
// Cockpit has its own picks, and Context is hidden while it runs.
|
||||
if (inCockpit()) return;
|
||||
// Cockpit has its own picks, and Context is hidden while it runs. A
|
||||
// camera drag never selects, even if it ends over something.
|
||||
if (inCockpit() || !isTrackingSelectionGesture(event.gesture)) return;
|
||||
const identity = resolvePickedContext(event.hit, {
|
||||
dataManager: getDataManager(),
|
||||
});
|
||||
@@ -294,7 +321,14 @@ export function installEntityContext({
|
||||
// A click on open ground, sea or sky lets go of what was selected. A
|
||||
// click on something else Context cannot describe (a label, a trail)
|
||||
// leaves the card as it is.
|
||||
if (event.surface) store.clear();
|
||||
// Only a clean click lets go, as the layers' own clicks do; a card
|
||||
// painted on the overlay (a vessel's, a fire's) is not open map.
|
||||
if (
|
||||
event.surface &&
|
||||
isTrackingClickGesture(event.gesture) &&
|
||||
!overlayHit?.(event.screenPosition?.x, event.screenPosition?.y)
|
||||
)
|
||||
store.clear();
|
||||
});
|
||||
|
||||
// Layers that select through the context store (GeoJSON sites, fires,
|
||||
@@ -318,6 +352,7 @@ export function installEntityContext({
|
||||
for (const off of cameraOff) off?.();
|
||||
clearTimeout(trailing);
|
||||
offFollow();
|
||||
offChrome();
|
||||
clearTimeout(followCheck);
|
||||
globalThis.removeEventListener?.('gev:entity-selected', onSelected);
|
||||
store.connect(null);
|
||||
|
||||
+28
-20
@@ -23,37 +23,45 @@ const briefs = new Map();
|
||||
* @param {number} lat
|
||||
* @param {number} lon
|
||||
* @param {(lat: number, lon: number) => Promise<object>} load
|
||||
* @param {{force?: boolean}} [options] `force` reads again whatever is kept.
|
||||
*/
|
||||
export function regionalBrief(lat, lon, load) {
|
||||
export function regionalBrief(lat, lon, load, { force = false } = {}) {
|
||||
const key = `${lat.toFixed(2)},${lon.toFixed(2)}`;
|
||||
const kept = briefs.get(key);
|
||||
if (kept && Date.now() - kept.at < BRIEF_TTL_MS) return kept.promise;
|
||||
if (!force && kept && Date.now() - kept.at < BRIEF_TTL_MS)
|
||||
return kept.promise;
|
||||
const forget = () => {
|
||||
if (briefs.get(key)?.promise === promise) briefs.delete(key);
|
||||
return null;
|
||||
};
|
||||
const promise = Promise.resolve()
|
||||
.then(() => load(lat, lon))
|
||||
.catch(() => {
|
||||
if (briefs.get(key)?.promise === promise) briefs.delete(key);
|
||||
return null;
|
||||
});
|
||||
.then((brief) => brief ?? forget(), forget);
|
||||
briefs.set(key, { at: Date.now(), promise });
|
||||
if (briefs.size > 40) briefs.delete(briefs.keys().next().value);
|
||||
return promise;
|
||||
}
|
||||
|
||||
const feeds = new Map();
|
||||
function snapshot(name, load) {
|
||||
function snapshot(name, load, force) {
|
||||
const kept = feeds.get(name);
|
||||
if (kept && Date.now() - kept.at < FEED_TTL_MS) return kept.promise;
|
||||
if (!force && kept && Date.now() - kept.at < FEED_TTL_MS) return kept.promise;
|
||||
const promise = load().catch(() => null);
|
||||
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 fires = () => snapshot('fires', () => createFirmsSource().getSnapshot());
|
||||
const quakes = (force) =>
|
||||
snapshot('quakes', () => createUsgsEarthquakeSource().getSnapshot(), force);
|
||||
const storms = (force) =>
|
||||
snapshot('storms', () => createCycloneSource().getSnapshot(), force);
|
||||
const perimeters = (force) =>
|
||||
snapshot(
|
||||
'perimeters',
|
||||
() => createWfigsPerimeterSource().getSnapshot(),
|
||||
force,
|
||||
);
|
||||
const fires = (force) =>
|
||||
snapshot('fires', () => createFirmsSource().getSnapshot(), force);
|
||||
|
||||
// English compass points, which the UI shows through t().
|
||||
const COMPASS = [
|
||||
@@ -118,14 +126,14 @@ export async function hazardsNear(
|
||||
lat,
|
||||
lon,
|
||||
radiusKm = 250,
|
||||
{ fires: withFires = false } = {},
|
||||
{ fires: withFires = false, force = false } = {},
|
||||
) {
|
||||
const here = { lat, lon };
|
||||
const [quakeRows, stormSnap, perimeterRows, fireSnap] = await Promise.all([
|
||||
quakes(),
|
||||
storms(),
|
||||
perimeters(),
|
||||
withFires ? fires() : null,
|
||||
quakes(force),
|
||||
storms(force),
|
||||
perimeters(force),
|
||||
withFires ? fires(force) : null,
|
||||
]);
|
||||
const found = [];
|
||||
const add = (row) => {
|
||||
|
||||
+14
-13
@@ -218,6 +218,8 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
|
||||
// A card does not outlive its layer: turning the layer off (or clearing
|
||||
// all layers) closes it and lets go of the camera.
|
||||
if (layerOff(current.layerId)) return clear();
|
||||
// A closed panel shows nothing, so it reads nothing until it opens.
|
||||
if (shell.value?.isOpen && !shell.value.isOpen()) return;
|
||||
const next = describeEntity(dataManager(), current.identity);
|
||||
// Keep showing the last reading when the item drops out of its feed.
|
||||
if (!next || next.key !== current.key || next.basis !== 'record') {
|
||||
@@ -238,15 +240,14 @@ 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',
|
||||
]);
|
||||
/** The key of the item the camera is following, if any. */
|
||||
const AUTO_FOLLOW = new Set(['flights', 'military', 'satellites']);
|
||||
/**
|
||||
* The key of the item the camera follows, if any. The shell sets it from
|
||||
* the camera's own follow, so it is never claimed before the camera does.
|
||||
*/
|
||||
const following = ref(null);
|
||||
/** The item a follow was last asked for, so it is asked once per item. */
|
||||
let asked = null;
|
||||
|
||||
/**
|
||||
* @param {object} identity
|
||||
@@ -266,13 +267,12 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
|
||||
if (followNow) {
|
||||
// Tracking can announce the craft again; following what is already
|
||||
// followed would loop, so it only starts once per item.
|
||||
if (following.value !== current.key) {
|
||||
following.value = current.key;
|
||||
if (following.value !== current.key && asked !== current.key) {
|
||||
asked = current.key;
|
||||
shell.value?.follow?.(current);
|
||||
}
|
||||
} else {
|
||||
if (following.value && following.value !== current?.key)
|
||||
following.value = null;
|
||||
asked = null;
|
||||
if (fly) shell.value?.flyTo?.(current);
|
||||
}
|
||||
requestRoute(current?.identity);
|
||||
@@ -282,6 +282,7 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
|
||||
function clear() {
|
||||
if (following.value) shell.value?.letGo?.(card.value);
|
||||
following.value = null;
|
||||
asked = null;
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
card.value = null;
|
||||
@@ -291,7 +292,7 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
|
||||
const flyTo = () => card.value && shell.value?.flyTo?.(card.value);
|
||||
const follow = () => {
|
||||
if (!card.value) return;
|
||||
following.value = card.value.key;
|
||||
asked = card.value.key;
|
||||
shell.value?.follow?.(card.value);
|
||||
};
|
||||
const isFollowing = () =>
|
||||
|
||||
@@ -202,8 +202,32 @@ body.mobile-shell .context-dock-btn {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* With the minimal HUD the credits sit at the bottom right, where the
|
||||
column is: they move out to its left. */
|
||||
body.context-docked:not(.ui-clean-view):not(.recording-mode):has(
|
||||
#intel-hud[data-variant='minimal'].active
|
||||
)
|
||||
:is(#cesium-credits, #gev-credits) {
|
||||
right: calc(36px + var(--context-dock-width));
|
||||
}
|
||||
|
||||
/* Right to left, the rail sits on the left edge (rtl.css), and so does the
|
||||
expanded column. */
|
||||
expanded column; the credits start past it. */
|
||||
html[dir='rtl']
|
||||
body.context-docked:not(.ui-clean-view):not(.recording-mode)
|
||||
:is(#cesium-credits, #gev-credits) {
|
||||
left: calc(36px + var(--context-dock-width));
|
||||
}
|
||||
|
||||
html[dir='rtl']
|
||||
body.context-docked:not(.ui-clean-view):not(.recording-mode):has(
|
||||
#intel-hud[data-variant='minimal'].active
|
||||
)
|
||||
:is(#cesium-credits, #gev-credits) {
|
||||
right: 36px;
|
||||
left: auto;
|
||||
}
|
||||
|
||||
html[dir='rtl'] body.context-docked #right-context-rail {
|
||||
right: auto !important;
|
||||
left: 0 !important;
|
||||
|
||||
@@ -325,13 +325,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* Radio can move between Context's two body hosts. Keep its visibility
|
||||
tied to the Inspector and layer state in either location. */
|
||||
/* The Properties tab shows only the layers' settings. The idle hint gives
|
||||
way to the view summary, and Contacts' Cockpit entry to the card's own
|
||||
while the card offers one. */
|
||||
#global-context-panel[data-context-tab='props']
|
||||
:is(.global-context-modes, .context-mode-view, #radio-panel),
|
||||
#global-context-panel #radio-panel:not(.radio-enabled),
|
||||
#global-context-panel #context-mode-standby,
|
||||
#global-context-panel #cockpit-entry {
|
||||
#global-context-panel:has([data-entity-cockpit-entry]) #cockpit-entry {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ function setDocked(next) {
|
||||
}
|
||||
}
|
||||
// Only an open panel reads what is picked and in view; closed, it does no work.
|
||||
const contextOpen = computed(() => chromePanels.value['global-context-panel']?.collapsed !== true);
|
||||
const contextOpen = computed(() => chromePanels.value['global-context-panel']?.collapsed === false);
|
||||
watch(
|
||||
() => chromePanels.value['global-context-panel']?.collapsed,
|
||||
(collapsed) => {
|
||||
@@ -232,7 +232,7 @@ watch(
|
||||
</div>
|
||||
<section id="context-flights-view" class="context-mode-view" role="tabpanel" aria-labelledby="global-context-flights-btn" :hidden="!ctx?.flightsActive">
|
||||
<div class="global-context-actions" :aria-label="t('Contact Context actions')">
|
||||
<button id="cockpit-entry" type="button" :hidden="!cockpit?.entryAvailable" aria-hidden="true" tabindex="-1">
|
||||
<button id="cockpit-entry" type="button" :hidden="!cockpit?.entryAvailable">
|
||||
<span class="material-symbols-outlined" aria-hidden="true">{{ entry.icon }}</span>
|
||||
<span>{{ entry.label }}</span>
|
||||
</button>
|
||||
|
||||
@@ -53,18 +53,19 @@ const pickRadius = (index) => setContextRadiusKm(CONTEXT_RADIUS_STEPS[index]);
|
||||
const firesOn = () =>
|
||||
Boolean((omnibar.controls?.layers() || []).find((layer) => layer.id === HAZARD_LAYER.hotspots)?.enabled);
|
||||
|
||||
async function read(lat, lon) {
|
||||
if (readAt && distanceKm(readAt, { lat, lon }) <= props.settleKm) return;
|
||||
async function read(lat, lon, { force = false } = {}) {
|
||||
if (!force && readAt && distanceKm(readAt, { lat, lon }) <= props.settleKm) return;
|
||||
readAt = { lat, lon };
|
||||
const mine = ++reading;
|
||||
const mineHazards = ++readingHazards;
|
||||
loading.value = true;
|
||||
// A forced re-read keeps what is shown until the new reading lands.
|
||||
if (!force) loading.value = true;
|
||||
const [nextBrief, nextHazards] = await Promise.all([
|
||||
regionalBrief(lat, lon, store.readBrief),
|
||||
hazardsNear(lat, lon, radiusKm.value, { fires: firesOn() }).catch(() => []),
|
||||
regionalBrief(lat, lon, store.readBrief, { force }),
|
||||
hazardsNear(lat, lon, radiusKm.value, { fires: firesOn(), force }).catch(() => []),
|
||||
]);
|
||||
if (reading !== mine) return;
|
||||
brief.value = nextBrief;
|
||||
if (nextBrief || !force) brief.value = nextBrief;
|
||||
// A radius change meanwhile has its own, newer hazard read.
|
||||
if (readingHazards === mineHazards) hazards.value = nextHazards;
|
||||
loading.value = false;
|
||||
@@ -91,10 +92,7 @@ watch(radiusKm, (km) => void rereadHazards(km));
|
||||
const REREAD_MS = 5 * 60_000;
|
||||
let rereadTimer = 0;
|
||||
onMounted(() => {
|
||||
rereadTimer = setInterval(() => {
|
||||
readAt = null;
|
||||
void read(props.lat, props.lon);
|
||||
}, REREAD_MS);
|
||||
rereadTimer = setInterval(() => void read(props.lat, props.lon, { force: true }), REREAD_MS);
|
||||
});
|
||||
onBeforeUnmount(() => clearInterval(rereadTimer));
|
||||
// Hazard rows are worded as they are read, so a new language reads them again.
|
||||
|
||||
Reference in new issue
Block a user