mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 11:42:21 +00:00
Merge branch 'main' into samehkhamis/omnibar-centred
This commit is contained in:
28 files changed
+837
-22
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { resolvePickedContext } from '../data/pickedContext.js';
|
||||
import { onScreen } from '../data/locate.js';
|
||||
import { clickCard } from '../data/pickRegistry.js';
|
||||
import { followedOf, onFollowChanged } from '../data/followed.js';
|
||||
import { fromDegreesInto } from '../geo/ellipsoid.js';
|
||||
@@ -136,6 +137,21 @@ export function installEntityContext({
|
||||
}
|
||||
}
|
||||
|
||||
// An item back in its feed after it left it is selected again in its layer,
|
||||
// as the click that picked it: a vessel is highlighted with its trail, and
|
||||
// an aircraft found again (`follow`) is followed.
|
||||
function reselect(card, { follow: andFollow = false } = {}) {
|
||||
const layer = getDataManager()?.layers?.get?.(card?.layerId)?.module;
|
||||
const id = card?.identity?.id;
|
||||
if (!layer || !id) return;
|
||||
try {
|
||||
if (card.layerId === 'ais-live-vessels') layer.selectById?.(id);
|
||||
else if (andFollow && FOLLOWABLE.has(card.layerId)) follow(card);
|
||||
} catch {
|
||||
// A layer going away meanwhile has nothing to select.
|
||||
}
|
||||
}
|
||||
|
||||
// Aircraft can be flown from, and a satellite ridden in the orbital view:
|
||||
// track the craft, then enter Cockpit on it. Only layers the tracking
|
||||
// action can follow are offered (local ADS-B cannot be tracked).
|
||||
@@ -197,6 +213,14 @@ export function installEntityContext({
|
||||
flyTo,
|
||||
follow,
|
||||
letGo,
|
||||
reselect,
|
||||
// Whether the camera shows the card's item; null when it cannot tell.
|
||||
onScreen: (card) => {
|
||||
const pose = camera()?.pose();
|
||||
if (!pose || !Number.isFinite(card?.lat) || !Number.isFinite(card?.lon))
|
||||
return null;
|
||||
return onScreen(pose, card.lat, card.lon, card.altitudeM ?? 0);
|
||||
},
|
||||
isOpen,
|
||||
regionalBrief,
|
||||
// The renderer's card previews, when it has them.
|
||||
@@ -343,7 +367,12 @@ export function installEntityContext({
|
||||
if (!record?.layerId || inCockpit()) return;
|
||||
store.select({
|
||||
layerId: record.layerId,
|
||||
id: record.id,
|
||||
// A vessel goes by its own id, as a click on it names it, not by the
|
||||
// context store's (src/data/pickedContext.js).
|
||||
id:
|
||||
record.layerId === 'ais-live-vessels' && record.properties?.vesselId
|
||||
? String(record.properties.vesselId)
|
||||
: record.id,
|
||||
label: record.label || record.properties?.name,
|
||||
lat: record.latitude,
|
||||
lon: record.longitude,
|
||||
|
||||
@@ -83,3 +83,60 @@ test('Context names nothing under a card painted on top, and keeps its card', (t
|
||||
tap(null, null);
|
||||
assert.equal(clears, cleared, 'a card over open map is not open map');
|
||||
});
|
||||
|
||||
// A vessel's layer announces its selection with the context store's id; the
|
||||
// card names it by the vessel's own id, as a click on it does.
|
||||
test('a vessel announced by its layer is named by its own id', (t) => {
|
||||
// The page's events, which Node lacks.
|
||||
const events = new EventTarget();
|
||||
for (const name of [
|
||||
'addEventListener',
|
||||
'removeEventListener',
|
||||
'dispatchEvent',
|
||||
])
|
||||
globalThis[name] = events[name].bind(events);
|
||||
t.after(() => {
|
||||
for (const name of [
|
||||
'addEventListener',
|
||||
'removeEventListener',
|
||||
'dispatchEvent',
|
||||
])
|
||||
delete globalThis[name];
|
||||
});
|
||||
const pinia = createPinia();
|
||||
const viewer = { scene: { pick: () => null, drillPick: () => [] } };
|
||||
const input = fakeInput(viewer);
|
||||
const disconnect = installEntityContext({
|
||||
viewer,
|
||||
getDataManager: () => ({
|
||||
isEnabled: () => true,
|
||||
layers: new Map(),
|
||||
getAll: () => [],
|
||||
}),
|
||||
pinia,
|
||||
});
|
||||
t.after(() => {
|
||||
disconnect();
|
||||
input.destroy();
|
||||
});
|
||||
const store = useEntityCardStore(pinia);
|
||||
const named = [];
|
||||
store.select = (identity) => named.push(identity.id);
|
||||
globalThis.dispatchEvent(
|
||||
new CustomEvent('gev:entity-selected', {
|
||||
detail: {
|
||||
layerId: 'ais-live-vessels',
|
||||
id: 'ais-5fdca702',
|
||||
properties: { vesselId: '5fdca702' },
|
||||
latitude: 1,
|
||||
longitude: 2,
|
||||
},
|
||||
}),
|
||||
);
|
||||
globalThis.dispatchEvent(
|
||||
new CustomEvent('gev:entity-selected', {
|
||||
detail: { layerId: 'fires', id: 'fire:1', latitude: 1, longitude: 2 },
|
||||
}),
|
||||
);
|
||||
assert.deepEqual(named, ['5fdca702', 'fire:1']);
|
||||
});
|
||||
@@ -31,9 +31,9 @@ const heroViews = [
|
||||
test('the entity card hand-writes no button; each is a UiButton', () => {
|
||||
for (const markup of [card, camera, nearby, ...heroViews])
|
||||
assert.deepEqual(markup.match(/<button\b/gi) ?? [], []);
|
||||
// Photos, Route, 3D, Cockpit view, the cockpit entry, Fly to, Follow and
|
||||
// Ask GEV.
|
||||
assert.equal(card.match(/<UiButton\b/g)?.length, 8);
|
||||
// Photos, Route, 3D, Cockpit view, Find it, the cockpit entry, Fly to,
|
||||
// Follow and Ask GEV.
|
||||
assert.equal(card.match(/<UiButton\b/g)?.length, 9);
|
||||
assert.equal(card.match(/<UiCloseButton\b/g)?.length, 1);
|
||||
// A camera's bigger view and More info; its popup closes with a UiCloseButton.
|
||||
assert.equal(camera.match(/<UiButton\b/g)?.length, 2);
|
||||
@@ -59,9 +59,10 @@ test('the entity card hand-writes no Material glyph; each is a UiIcon', () => {
|
||||
for (const markup of [card, camera, nearby, ...heroViews])
|
||||
assert.deepEqual(markup.match(/material-symbols-outlined/g) ?? [], []);
|
||||
const counts = [
|
||||
// The preview switch's three, the hero glyph, the header icon, the
|
||||
// warning, the route's plane, the route note and the three actions.
|
||||
[card, 11],
|
||||
// The preview switch's three, the hero glyph, the header icon, Find
|
||||
// it, the warning, the route's plane, the route note and the three
|
||||
// actions.
|
||||
[card, 12],
|
||||
// Bigger view, the popup's camera and More info.
|
||||
[camera, 3],
|
||||
// The two weather glyphs, five headings and three row glyphs.
|
||||
|
||||
@@ -93,6 +93,26 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
|
||||
const lost = ref(false);
|
||||
/** Bumped on each refresh, so ages shown on the card tick. */
|
||||
const tick = ref(0);
|
||||
/**
|
||||
* True while the item is not to be seen: out of its feed, off screen or
|
||||
* behind the globe. The card then offers to find it.
|
||||
*/
|
||||
const away = ref(false);
|
||||
/**
|
||||
* Finding the item again (see locate): `'idle'`, `'finding'` while its
|
||||
* layer looks it up, or `'none'` when it has no reading at the time.
|
||||
*/
|
||||
const finding = ref('idle');
|
||||
/**
|
||||
* Where an item out of its feed was found (see locate):
|
||||
* `{lat, lon, altitudeM, observedAtMs, atMs}`, or null.
|
||||
*/
|
||||
const located = shallowRef(null);
|
||||
/** The track reference of the card's item, kept for when it leaves its feed. */
|
||||
let reference = null;
|
||||
let locating = null;
|
||||
/** An aircraft found again is followed once it is back in its feed. */
|
||||
let followWhenBack = false;
|
||||
/**
|
||||
* What the camera shows, for the panel to describe when nothing is picked:
|
||||
* `{center: {lat, lon}, rect: {west, south, east, north}, heightM}`.
|
||||
@@ -229,12 +249,105 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
|
||||
// Keep showing the last reading when the item drops out of its feed.
|
||||
if (!next || next.key !== current.key || next.basis !== 'record') {
|
||||
lost.value = current.basis === 'record';
|
||||
away.value = lost.value || !shown(current);
|
||||
tick.value++;
|
||||
return;
|
||||
}
|
||||
const wasLost = lost.value;
|
||||
card.value = markRaw(next);
|
||||
lost.value = false;
|
||||
// The camera follows it where it is drawn, which can be ahead of its last
|
||||
// reading; one being followed is always in view.
|
||||
away.value = !isFollowing() && !shown(next);
|
||||
tick.value++;
|
||||
if (wasLost) back(next);
|
||||
}
|
||||
|
||||
/** Whether the camera shows the item; true when the shell cannot tell. */
|
||||
function shown(current) {
|
||||
const test = shell.value?.onScreen;
|
||||
return typeof test === 'function' ? test(current) !== false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The item is back in its feed: its layer selects it again, as the click
|
||||
* that picked it did, and an aircraft just found is followed.
|
||||
*/
|
||||
function back(current) {
|
||||
const follows = followWhenBack;
|
||||
// A lookup still running is no longer needed: the feed has it.
|
||||
stopLocating();
|
||||
reference =
|
||||
layerOf(current.layerId)?.referenceOf?.(current.identity?.id) ??
|
||||
reference;
|
||||
shell.value?.reselect?.(current, { follow: follows });
|
||||
}
|
||||
|
||||
const layerOf = (layerId) =>
|
||||
shell.value?.dataManager?.()?.layers?.get?.(layerId)?.module ?? null;
|
||||
|
||||
/**
|
||||
* Take the camera back to the item. One the camera can see or one still in
|
||||
* its feed is flown to (an aircraft followed); one out of its feed is
|
||||
* looked up at the layer's time (the world clock's while it follows the
|
||||
* clock) on its own track, shown there and flown to, and its layer picks
|
||||
* it up again once its feed has it.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function locate() {
|
||||
const current = card.value;
|
||||
if (!current) return;
|
||||
if (!lost.value) {
|
||||
if (canFollow()) follow();
|
||||
else flyTo();
|
||||
return;
|
||||
}
|
||||
const layer = layerOf(current.layerId);
|
||||
if (typeof layer?.locate !== 'function') {
|
||||
flyTo();
|
||||
return;
|
||||
}
|
||||
locating?.abort();
|
||||
const controller = new AbortController();
|
||||
locating = controller;
|
||||
finding.value = 'finding';
|
||||
let result;
|
||||
try {
|
||||
result = await layer.locate(current.identity?.id, {
|
||||
reference,
|
||||
signal: controller.signal,
|
||||
});
|
||||
} catch {
|
||||
result = { status: 'none' };
|
||||
}
|
||||
if (locating !== controller) return;
|
||||
locating = null;
|
||||
const now = card.value;
|
||||
if (!now || now.key !== current.key) return;
|
||||
if (result?.status !== 'found') {
|
||||
finding.value = 'none';
|
||||
return;
|
||||
}
|
||||
finding.value = 'idle';
|
||||
located.value = markRaw({ ...result });
|
||||
card.value = markRaw({
|
||||
...now,
|
||||
lat: result.lat,
|
||||
lon: result.lon,
|
||||
altitudeM: Number.isFinite(result.altitudeM)
|
||||
? result.altitudeM
|
||||
: now.altitudeM,
|
||||
});
|
||||
followWhenBack = canFollow();
|
||||
shell.value?.flyTo?.(card.value);
|
||||
}
|
||||
|
||||
function stopLocating() {
|
||||
locating?.abort();
|
||||
locating = null;
|
||||
finding.value = 'idle';
|
||||
located.value = null;
|
||||
followWhenBack = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,6 +374,11 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
|
||||
*/
|
||||
function select(identity, { fly = false, follow: autoFollow = true } = {}) {
|
||||
if (!read(identity)) return false;
|
||||
stopLocating();
|
||||
away.value = false;
|
||||
reference =
|
||||
layerOf(identity.layerId)?.referenceOf?.(card.value?.identity?.id) ??
|
||||
null;
|
||||
clearInterval(timer);
|
||||
timer = setInterval(refresh, REFRESH_MS);
|
||||
shell.value?.openPanel?.();
|
||||
@@ -292,6 +410,9 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
|
||||
timer = null;
|
||||
card.value = null;
|
||||
lost.value = false;
|
||||
away.value = false;
|
||||
reference = null;
|
||||
stopLocating();
|
||||
}
|
||||
|
||||
const flyTo = () => card.value && shell.value?.flyTo?.(card.value);
|
||||
@@ -324,6 +445,10 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
|
||||
card,
|
||||
lost,
|
||||
tick,
|
||||
away,
|
||||
finding,
|
||||
located,
|
||||
locate,
|
||||
connect,
|
||||
select,
|
||||
clear,
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createPinia } from 'pinia';
|
||||
import { useEntityCardStore } from './entityCard.js';
|
||||
|
||||
/**
|
||||
* A vessels layer whose one vessel can leave its feed, and a shell that
|
||||
* records what the card asks of it.
|
||||
*/
|
||||
function setup({ found = true } = {}) {
|
||||
const vessel = {
|
||||
id: 'v1',
|
||||
name: 'ARCADIA',
|
||||
lat: 1,
|
||||
lon: 10,
|
||||
reference: 'vessel:v1',
|
||||
};
|
||||
let inFeed = true;
|
||||
const asked = [];
|
||||
const module = {
|
||||
getAnalystRecords: () => (inFeed ? [{ ...vessel }] : []),
|
||||
referenceOf: (id) => (id === 'v1' && inFeed ? vessel.reference : null),
|
||||
async locate(id, { reference }) {
|
||||
asked.push({ id, reference });
|
||||
return found
|
||||
? {
|
||||
status: 'found',
|
||||
lat: 5,
|
||||
lon: 50,
|
||||
altitudeM: null,
|
||||
observedAtMs: 1_000,
|
||||
atMs: 61_000,
|
||||
}
|
||||
: { status: 'none' };
|
||||
},
|
||||
};
|
||||
const dataManager = {
|
||||
isEnabled: () => true,
|
||||
layers: new Map([['ais-live-vessels', { module }]]),
|
||||
getAll: () => [],
|
||||
};
|
||||
const shell = {
|
||||
flown: [],
|
||||
followed: [],
|
||||
reselected: [],
|
||||
visible: true,
|
||||
dataManager: () => dataManager,
|
||||
openPanel() {},
|
||||
flyTo(card) {
|
||||
shell.flown.push([card.lat, card.lon]);
|
||||
},
|
||||
follow(card) {
|
||||
shell.followed.push(card.key);
|
||||
},
|
||||
reselect(card, options) {
|
||||
shell.reselected.push([card.identity.id, options.follow]);
|
||||
},
|
||||
onScreen: () => shell.visible,
|
||||
canFollow: () => false,
|
||||
};
|
||||
const store = useEntityCardStore(createPinia());
|
||||
store.connect(shell);
|
||||
return {
|
||||
store,
|
||||
shell,
|
||||
asked,
|
||||
leave: () => (inFeed = false),
|
||||
come: () => (inFeed = true),
|
||||
};
|
||||
}
|
||||
|
||||
test('a vessel out of its feed is looked up, shown where it was and flown to', async (t) => {
|
||||
const { store, shell, asked, leave, come } = setup();
|
||||
t.after(() => store.clear());
|
||||
assert.equal(store.select({ layerId: 'ais-live-vessels', id: 'v1' }), true);
|
||||
assert.equal(store.away, false, 'on screen and in its feed');
|
||||
|
||||
leave();
|
||||
store.refresh();
|
||||
assert.equal(store.lost, true);
|
||||
assert.equal(store.away, true, 'out of its feed: the card offers to find it');
|
||||
|
||||
await store.locate();
|
||||
assert.deepEqual(
|
||||
asked,
|
||||
[{ id: 'v1', reference: 'vessel:v1' }],
|
||||
'by the reference it had',
|
||||
);
|
||||
assert.equal(store.card.lat, 5);
|
||||
assert.equal(store.card.lon, 50);
|
||||
assert.deepEqual(shell.flown, [[5, 50]]);
|
||||
assert.equal(store.located.observedAtMs, 1_000);
|
||||
assert.equal(store.finding, 'idle');
|
||||
|
||||
come();
|
||||
store.refresh();
|
||||
assert.equal(store.lost, false, 'back in its feed');
|
||||
assert.equal(store.located, null);
|
||||
assert.deepEqual(
|
||||
shell.reselected,
|
||||
[['v1', false]],
|
||||
'its layer selects it again',
|
||||
);
|
||||
});
|
||||
|
||||
test('a vessel with no reading at the time says so and stays put', async (t) => {
|
||||
const { store, shell, leave } = setup({ found: false });
|
||||
t.after(() => store.clear());
|
||||
store.select({ layerId: 'ais-live-vessels', id: 'v1' });
|
||||
leave();
|
||||
store.refresh();
|
||||
await store.locate();
|
||||
assert.equal(store.finding, 'none');
|
||||
assert.deepEqual(shell.flown, [], 'the camera stays');
|
||||
assert.equal(store.card.lat, 1, 'the card keeps its last reading');
|
||||
});
|
||||
|
||||
test('an item in its feed but off screen is flown to without a lookup', async (t) => {
|
||||
const { store, shell, asked } = setup();
|
||||
t.after(() => store.clear());
|
||||
store.select({ layerId: 'ais-live-vessels', id: 'v1' });
|
||||
shell.visible = false;
|
||||
store.refresh();
|
||||
assert.equal(store.away, true, 'off screen');
|
||||
await store.locate();
|
||||
assert.deepEqual(asked, []);
|
||||
assert.deepEqual(shell.flown, [[1, 10]]);
|
||||
});
|
||||
|
||||
test('an item the camera follows is never away, wherever its last reading is', (t) => {
|
||||
const { store, shell } = setup();
|
||||
t.after(() => store.clear());
|
||||
store.select({ layerId: 'ais-live-vessels', id: 'v1' });
|
||||
shell.visible = false;
|
||||
store.following = store.card.key;
|
||||
store.refresh();
|
||||
assert.equal(store.away, false);
|
||||
});
|
||||
|
||||
test('a lookup still running when the item comes back is dropped', async (t) => {
|
||||
const { store, shell, leave, come } = setup();
|
||||
t.after(() => store.clear());
|
||||
store.select({ layerId: 'ais-live-vessels', id: 'v1' });
|
||||
leave();
|
||||
store.refresh();
|
||||
const pending = store.locate();
|
||||
come();
|
||||
store.refresh();
|
||||
await pending;
|
||||
assert.equal(store.lost, false);
|
||||
assert.equal(store.located, null, 'no old reading on a live card');
|
||||
assert.equal(store.card.lat, 1, 'the card keeps its live position');
|
||||
assert.deepEqual(shell.flown, [], 'the camera stays');
|
||||
});
|
||||
@@ -104,6 +104,33 @@
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
/* Find it: shown while the selected item is off screen or out of its feed. */
|
||||
.entity-card__find {
|
||||
display: grid;
|
||||
flex: none;
|
||||
place-items: center;
|
||||
width: 1.9rem;
|
||||
height: 1.9rem;
|
||||
color: #36dcff;
|
||||
background: rgba(29, 69, 81, 0.35);
|
||||
border: 1px solid rgba(48, 194, 224, 0.55);
|
||||
border-radius: 7px;
|
||||
}
|
||||
|
||||
.entity-card__find:hover,
|
||||
.entity-card__find:focus-visible {
|
||||
color: #fff;
|
||||
background: rgba(48, 194, 224, 0.3);
|
||||
}
|
||||
|
||||
.entity-card__find:disabled {
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.entity-card__find .material-symbols-outlined {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.entity-card__title {
|
||||
margin: 0.55rem 0 0.1rem;
|
||||
overflow-wrap: anywhere;
|
||||
@@ -2180,7 +2207,11 @@
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.entity-hero:is([data-hero='flight'], [data-hero='satellite'], [data-hero='photo']) {
|
||||
.entity-hero:is(
|
||||
[data-hero='flight'],
|
||||
[data-hero='satellite'],
|
||||
[data-hero='photo']
|
||||
) {
|
||||
height: 168px;
|
||||
background: radial-gradient(
|
||||
ellipse 55% 60% at 50% 55%,
|
||||
|
||||
@@ -26,7 +26,7 @@ const props = defineProps({
|
||||
withContacts: Boolean,
|
||||
});
|
||||
const store = useEntityCardStore();
|
||||
const { card, lost, tick } = storeToRefs(store);
|
||||
const { card, lost, tick, away, finding, located } = storeToRefs(store);
|
||||
// Cameras carry only an id; the CCTV panel's store knows the picked one's name.
|
||||
const { frame: cctvFrame } = storeToRefs(useCctvStore());
|
||||
const shownTitle = computed(() => {
|
||||
@@ -56,6 +56,15 @@ const status = computed(() => {
|
||||
void tick.value;
|
||||
const current = card.value;
|
||||
if (!current) return null;
|
||||
if (finding.value === 'finding') return { tone: 'aged', text: t('Finding it…') };
|
||||
if (finding.value === 'none') return { tone: 'lost', text: t('No reading at this time') };
|
||||
if (lost.value && located.value)
|
||||
return {
|
||||
tone: 'aged',
|
||||
text: t('Last reading · {age}', {
|
||||
age: ago(Math.max(0, located.value.atMs - located.value.observedAtMs)),
|
||||
}),
|
||||
};
|
||||
if (lost.value) return { tone: 'lost', text: t('Out of feed · last reading') };
|
||||
if (current.observedAgeMs !== null)
|
||||
return {
|
||||
@@ -399,6 +408,7 @@ watch(
|
||||
<h3 class="entity-card__title">{{ shownTitle }}</h3>
|
||||
<span v-if="subtitle" class="entity-card__subtitle">{{ subtitle }}</span>
|
||||
</div>
|
||||
<UiButton v-if="away && card.moving" class="entity-card__find" data-entity-find :label="t('Find it')" :title="t('Find it')" :disabled="finding === 'finding'" @click="store.locate()"><UiIcon name="my_location" :size="null" /></UiButton>
|
||||
<UiCloseButton class="entity-card__close" glyph="icon" :label="t('Close card')" :title="t('Close card')" @click="store.clear()" />
|
||||
</header>
|
||||
|
||||
|
||||
Reference in new issue
Block a user