mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +00:00
Draw the card previews through the renderer, and show vessel photos too
- The route globe, turning model and cockpit view are the renderer's: the Cesium plugin hands them over as its `cardPreviews` application hook (src/render/cesium/cardPreviews.js), and the card's tiles keep only the words, figures and HUD laid over them. Nothing in the UI reaches Cesium, and a renderer without the hook leaves the card its photo and figures. - The turning model is the fleet model the globe draws for the aircraft's type, from the set loaded at startup, so opening a card fetches nothing. The flights layer's record now carries the type code and emitter category that pick it. - The photo comes from the item's own layer: the flights layer's Planespotters photo for the plane it tracks, and the vessels layer's Open Vessel Photos photo for the vessel selected, with its credit. It no longer waits for Contacts to follow the same aircraft. - The satellite models are left out: the card shows a satellite's ground view and graphs its altitude and speed. - The route globe's airport codes are drawn into its own small scene, the compass reads its course in the active language, the callouts no longer speak to screen readers every six seconds, and figures use the app's number format. Esri's tile address and credit live in one place. Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
c6bdd38b61
commit
3a0842c103
26 files changed
+1347
-676
No files matched your search
+287
-38
@@ -37,8 +37,20 @@ const flights = Array.from({ length: 2500 }, (_, i) => ({
|
||||
altitudeM: 10000,
|
||||
}));
|
||||
const dams = [
|
||||
{ id: 'Grand Coulee Dam', name: 'Grand Coulee Dam', lat: 47.957, lon: -118.981, operator: 'Bureau of Reclamation' },
|
||||
{ id: '123456', name: null, lat: 47.9, lon: -118.9, operator: 'Some Utility' },
|
||||
{
|
||||
id: 'Grand Coulee Dam',
|
||||
name: 'Grand Coulee Dam',
|
||||
lat: 47.957,
|
||||
lon: -118.981,
|
||||
operator: 'Bureau of Reclamation',
|
||||
},
|
||||
{
|
||||
id: '123456',
|
||||
name: null,
|
||||
lat: 47.9,
|
||||
lon: -118.9,
|
||||
operator: 'Some Utility',
|
||||
},
|
||||
];
|
||||
const dm = manager({
|
||||
flights: { name: 'Live Flights', records: flights },
|
||||
@@ -46,7 +58,12 @@ const dm = manager({
|
||||
});
|
||||
|
||||
test('a click identity finds its record by key, past the first 2000 records', () => {
|
||||
const record = findRecord(dm, { layerId: 'flights', id: 'a02400', lat: 0, lon: 0 });
|
||||
const record = findRecord(dm, {
|
||||
layerId: 'flights',
|
||||
id: 'a02400',
|
||||
lat: 0,
|
||||
lon: 0,
|
||||
});
|
||||
assert.equal(record?.callsign, 'FLT2400');
|
||||
});
|
||||
|
||||
@@ -74,7 +91,9 @@ test('a transit click finds its vehicle by the layer key and reads its state', (
|
||||
lon: -97.71,
|
||||
});
|
||||
assert.equal(card?.title, 'M634');
|
||||
const facts = Object.fromEntries(card.facts.map((fact) => [fact.label, fact.value]));
|
||||
const facts = Object.fromEntries(
|
||||
card.facts.map((fact) => [fact.label, fact.value]),
|
||||
);
|
||||
assert.equal(facts.Operator, 'CapMetro');
|
||||
assert.equal(facts.Status, 'Heading to next stop');
|
||||
assert.equal(facts.Key, undefined, 'the layer key is not shown');
|
||||
@@ -86,8 +105,20 @@ test('transit vehicles break down by motion, mode and reported state', () => {
|
||||
transit: {
|
||||
name: 'Transit',
|
||||
records: [
|
||||
{ id: '1', mode: 'bus', motion: 'moving', status: 'IN_TRANSIT_TO', ...at },
|
||||
{ id: '2', mode: 'bus', motion: 'stopped', status: 'STOPPED_AT', ...at },
|
||||
{
|
||||
id: '1',
|
||||
mode: 'bus',
|
||||
motion: 'moving',
|
||||
status: 'IN_TRANSIT_TO',
|
||||
...at,
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
mode: 'bus',
|
||||
motion: 'stopped',
|
||||
status: 'STOPPED_AT',
|
||||
...at,
|
||||
},
|
||||
{ id: '3', mode: 'rail', motion: 'moving', occupancy: 'FULL', ...at },
|
||||
],
|
||||
},
|
||||
@@ -95,15 +126,28 @@ test('transit vehicles break down by motion, mode and reported state', () => {
|
||||
const breakdown = layerBreakdown(buses, 'transit');
|
||||
assert.equal(breakdown.total, 3);
|
||||
const split = (title) =>
|
||||
Object.fromEntries(breakdown.splits.find((item) => item.title === title).parts.map((part) => [part.label, part.count]));
|
||||
Object.fromEntries(
|
||||
breakdown.splits
|
||||
.find((item) => item.title === title)
|
||||
.parts.map((part) => [part.label, part.count]),
|
||||
);
|
||||
assert.deepEqual(split('Motion'), { Moving: 2, Stopped: 1 });
|
||||
assert.deepEqual(split('Mode'), { Bus: 2, Rail: 1 });
|
||||
assert.deepEqual(split('Last reported'), { 'Heading to next stop': 1, 'Stopped at a stop': 1 });
|
||||
assert.deepEqual(split('Last reported'), {
|
||||
'Heading to next stop': 1,
|
||||
'Stopped at a stop': 1,
|
||||
});
|
||||
assert.deepEqual(split('Crowding'), { Full: 1 });
|
||||
});
|
||||
|
||||
test('a moving item never borrows a nearby craft when its key is unknown', () => {
|
||||
const record = findRecord(dm, { layerId: 'flights', id: 'zzzzzz', label: 'NOPE', lat: 34.0004, lon: -118.05 });
|
||||
const record = findRecord(dm, {
|
||||
layerId: 'flights',
|
||||
id: 'zzzzzz',
|
||||
label: 'NOPE',
|
||||
lat: 34.0004,
|
||||
lon: -118.05,
|
||||
});
|
||||
assert.equal(record, null);
|
||||
});
|
||||
|
||||
@@ -115,12 +159,19 @@ test('a card lists facts with units and keeps the title out of them', () => {
|
||||
const card = describeEntity(dm, { layerId: 'flights', id: 'a00001' });
|
||||
assert.equal(card.title, 'FLT1');
|
||||
assert.equal(card.kind, 'aircraft');
|
||||
assert.ok(card.facts.some((fact) => fact.label === 'Altitude' && fact.value === '32,808 ft'));
|
||||
assert.ok(
|
||||
card.facts.some(
|
||||
(fact) => fact.label === 'Altitude' && fact.value === '32,808 ft',
|
||||
),
|
||||
);
|
||||
assert.ok(!card.facts.some((fact) => fact.value === 'FLT1'));
|
||||
});
|
||||
|
||||
test('nearby lists the closest of the same kind and one of each other layer', () => {
|
||||
const card = describeEntity(dm, { layerId: 'local-dams', id: 'Grand Coulee Dam' });
|
||||
const card = describeEntity(dm, {
|
||||
layerId: 'local-dams',
|
||||
id: 'Grand Coulee Dam',
|
||||
});
|
||||
const { same, other } = nearbyEntities(dm, card, { radiusKm: 2000 });
|
||||
assert.equal(same[0].title, 'Some Utility');
|
||||
assert.equal(other.length, 1);
|
||||
@@ -138,7 +189,10 @@ test('fact formatting follows the field suffix', () => {
|
||||
assert.equal(formatFact('speedMps', 100).value, '194 kt');
|
||||
// Orbital speeds read in km/s, road and rail in km/h.
|
||||
assert.equal(formatFact('speedMps', 7670).value, '7.67 km/s');
|
||||
assert.equal(formatFact('speedMps', 10, { kind: 'vehicle' }).value, '36 km/h');
|
||||
assert.equal(
|
||||
formatFact('speedMps', 10, { kind: 'vehicle' }).value,
|
||||
'36 km/h',
|
||||
);
|
||||
// Units follow the field's suffix; feed codes and bare words read as words.
|
||||
assert.equal(formatFact('containedPct', 96).value, '96%');
|
||||
assert.equal(formatFact('windKt', 30).value, '30 kt');
|
||||
@@ -148,21 +202,54 @@ test('fact formatting follows the field suffix', () => {
|
||||
assert.equal(formatFact('icao24', 'abcdef').value, 'abcdef');
|
||||
assert.equal(formatFact('shipType', 70).value, 'Cargo');
|
||||
assert.equal(formatFact('shipType', 'Tanker').value, 'Tanker');
|
||||
assert.equal(formatFact('discoveredTime', Date.UTC(2026, 5, 29)).value, '29 Jun 2026');
|
||||
assert.equal(formatFact('updatedTime', 1_700_000_000_000, { nowMs: 1_700_000_060_000 }).age, 60_000);
|
||||
assert.equal(
|
||||
formatFact('discoveredTime', Date.UTC(2026, 5, 29)).value,
|
||||
'29 Jun 2026',
|
||||
);
|
||||
assert.equal(
|
||||
formatFact('updatedTime', 1_700_000_000_000, { nowMs: 1_700_000_060_000 })
|
||||
.age,
|
||||
60_000,
|
||||
);
|
||||
assert.equal(formatFact('altitudeM', 420000).value, '420 km');
|
||||
assert.equal(formatFact('confidence', 0.82).value, '82%');
|
||||
assert.equal(formatFact('onGround', false), null);
|
||||
assert.equal(formatFact('lastContactAtMs', 1_700_000_000_000, { nowMs: 1_700_000_060_000 }).age, 60_000);
|
||||
assert.equal(
|
||||
formatFact('lastContactAtMs', 1_700_000_000_000, {
|
||||
nowMs: 1_700_000_060_000,
|
||||
}).age,
|
||||
60_000,
|
||||
);
|
||||
});
|
||||
|
||||
test('warnings lead with an emergency, then the squawk code, and stay out of the facts', () => {
|
||||
assert.deepEqual(recordWarnings({ emergency: true, emergencyKind: 'medical' }), ['Emergency: medical']);
|
||||
assert.deepEqual(recordWarnings({ squawk: '7600' }), ['Radio failure (squawk 7600)']);
|
||||
assert.deepEqual(recordWarnings({ squawk: '1200', emergencyKind: 'none' }), []);
|
||||
assert.deepEqual(
|
||||
recordWarnings({ emergency: true, emergencyKind: 'medical' }),
|
||||
['Emergency: medical'],
|
||||
);
|
||||
assert.deepEqual(recordWarnings({ squawk: '7600' }), [
|
||||
'Radio failure (squawk 7600)',
|
||||
]);
|
||||
assert.deepEqual(
|
||||
recordWarnings({ squawk: '1200', emergencyKind: 'none' }),
|
||||
[],
|
||||
);
|
||||
assert.deepEqual(recordWarnings({ tsunami: 1 }), ['Tsunami warning issued']);
|
||||
const urgent = manager({
|
||||
flights: { name: 'Live Flights', records: [{ id: 'X1', icao24: 'x00001', callsign: 'X1', lat: 1, lon: 1, emergency: true, emergencyKind: 'fuel' }] },
|
||||
flights: {
|
||||
name: 'Live Flights',
|
||||
records: [
|
||||
{
|
||||
id: 'X1',
|
||||
icao24: 'x00001',
|
||||
callsign: 'X1',
|
||||
lat: 1,
|
||||
lon: 1,
|
||||
emergency: true,
|
||||
emergencyKind: 'fuel',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
const card = describeEntity(urgent, { layerId: 'flights', id: 'x00001' });
|
||||
assert.deepEqual(card.warnings, ['Emergency: fuel']);
|
||||
@@ -184,7 +271,13 @@ test('the view summary counts each layer inside the view, closest to the middle
|
||||
|
||||
test('flight insights work out phase, flight level, Mach, squawk meaning and signal age', () => {
|
||||
const insights = aircraftInsights(
|
||||
{ altitudeM: 10668, verticalRateMps: 0, speedMps: 230, squawk: '7000', lastContactAtMs: 1_000_000 },
|
||||
{
|
||||
altitudeM: 10668,
|
||||
verticalRateMps: 0,
|
||||
speedMps: 230,
|
||||
squawk: '7000',
|
||||
lastContactAtMs: 1_000_000,
|
||||
},
|
||||
{ nowMs: 1_012_000 },
|
||||
);
|
||||
const value = (label) => insights.find((item) => item.label === label)?.value;
|
||||
@@ -192,20 +285,57 @@ test('flight insights work out phase, flight level, Mach, squawk meaning and sig
|
||||
assert.equal(value('Flight level'), 'FL350');
|
||||
assert.equal(value('Mach'), 'M 0.78');
|
||||
assert.equal(value('Squawk {code}'), 'VFR conspicuity');
|
||||
assert.deepEqual(insights.find((item) => item.label === 'Squawk {code}').labelValues, { code: '7000' });
|
||||
assert.deepEqual(
|
||||
insights.find((item) => item.label === 'Squawk {code}').labelValues,
|
||||
{ code: '7000' },
|
||||
);
|
||||
assert.equal(value('Signal'), '12 s ago');
|
||||
assert.equal(aircraftInsights({ onGround: true })[0].value, 'On the ground');
|
||||
assert.match(aircraftInsights({ verticalRateMps: -8 })[0].value, /^Descending 1600 ft\/min$/);
|
||||
assert.match(
|
||||
aircraftInsights({ verticalRateMps: -8 })[0].value,
|
||||
/^Descending 1600 ft\/min$/,
|
||||
);
|
||||
});
|
||||
|
||||
test('a layer breakdown splits aircraft by status and type, inside a view when given', () => {
|
||||
const craft = [
|
||||
{ id: 'A', lat: 10, lon: 10, onGround: false, military: false, aircraftClass: 'airliner' },
|
||||
{ id: 'B', lat: 10, lon: 11, onGround: false, military: true, aircraftClass: 'fastjet' },
|
||||
{ id: 'C', lat: 10, lon: 12, onGround: true, military: true, aircraftClass: 'airliner' },
|
||||
{ id: 'D', lat: 60, lon: 12, onGround: false, military: false, aircraftClass: 'airliner' },
|
||||
{
|
||||
id: 'A',
|
||||
lat: 10,
|
||||
lon: 10,
|
||||
onGround: false,
|
||||
military: false,
|
||||
aircraftClass: 'airliner',
|
||||
},
|
||||
{
|
||||
id: 'B',
|
||||
lat: 10,
|
||||
lon: 11,
|
||||
onGround: false,
|
||||
military: true,
|
||||
aircraftClass: 'fastjet',
|
||||
},
|
||||
{
|
||||
id: 'C',
|
||||
lat: 10,
|
||||
lon: 12,
|
||||
onGround: true,
|
||||
military: true,
|
||||
aircraftClass: 'airliner',
|
||||
},
|
||||
{
|
||||
id: 'D',
|
||||
lat: 60,
|
||||
lon: 12,
|
||||
onGround: false,
|
||||
military: false,
|
||||
aircraftClass: 'airliner',
|
||||
},
|
||||
];
|
||||
const data = manager({ flights: { name: 'Live Flights', records: craft }, 'local-dams': { name: 'Dams', records: dams } });
|
||||
const data = manager({
|
||||
flights: { name: 'Live Flights', records: craft },
|
||||
'local-dams': { name: 'Dams', records: dams },
|
||||
});
|
||||
const all = layerBreakdown(data, 'flights');
|
||||
assert.equal(all.total, 4);
|
||||
assert.deepEqual(all.splits[0].parts, [
|
||||
@@ -217,23 +347,52 @@ test('a layer breakdown splits aircraft by status and type, inside a view when g
|
||||
{ label: 'Airliners', count: 3 },
|
||||
{ label: 'Fast jets', count: 1 },
|
||||
]);
|
||||
const near = layerBreakdown(data, 'flights', { rect: { west: 9, east: 13, south: 9, north: 11 } });
|
||||
const near = layerBreakdown(data, 'flights', {
|
||||
rect: { west: 9, east: 13, south: 9, north: 11 },
|
||||
});
|
||||
assert.equal(near.total, 3);
|
||||
assert.equal(layerBreakdown(data, 'local-dams'), null);
|
||||
});
|
||||
|
||||
test('a moving item with an unknown key is not matched to a craft right beside it', () => {
|
||||
// About 110 m from FLT0: well inside any nearest-item reach.
|
||||
assert.equal(findRecord(dm, { layerId: 'flights', id: 'zzzzzz', label: 'NOPE', lat: 34.001, lon: -118 }), null);
|
||||
assert.equal(
|
||||
findRecord(dm, {
|
||||
layerId: 'flights',
|
||||
id: 'zzzzzz',
|
||||
label: 'NOPE',
|
||||
lat: 34.001,
|
||||
lon: -118,
|
||||
}),
|
||||
null,
|
||||
);
|
||||
});
|
||||
|
||||
test('sites that share a key are told apart by where the identity says they are', () => {
|
||||
const sites = [
|
||||
{ id: 'Amazon Web Services', name: 'Amazon Web Services', lat: -52.942, lon: -70.849 },
|
||||
{ id: 'Amazon Web Services', name: 'Amazon Web Services', lat: -33.557, lon: -70.813 },
|
||||
{
|
||||
id: 'Amazon Web Services',
|
||||
name: 'Amazon Web Services',
|
||||
lat: -52.942,
|
||||
lon: -70.849,
|
||||
},
|
||||
{
|
||||
id: 'Amazon Web Services',
|
||||
name: 'Amazon Web Services',
|
||||
lat: -33.557,
|
||||
lon: -70.813,
|
||||
},
|
||||
];
|
||||
const data = manager({ 'local-datacenters': { name: 'Datacenters', records: sites } });
|
||||
const identity = { layerId: 'local-datacenters', id: 'Amazon Web Services', label: 'Amazon Web Services', lat: -33.557, lon: -70.813 };
|
||||
const data = manager({
|
||||
'local-datacenters': { name: 'Datacenters', records: sites },
|
||||
});
|
||||
const identity = {
|
||||
layerId: 'local-datacenters',
|
||||
id: 'Amazon Web Services',
|
||||
label: 'Amazon Web Services',
|
||||
lat: -33.557,
|
||||
lon: -70.813,
|
||||
};
|
||||
assert.equal(findRecord(data, identity), sites[1]);
|
||||
const card = describeEntity(data, identity);
|
||||
assert.equal(card.lat, -33.557);
|
||||
@@ -242,16 +401,106 @@ test('sites that share a key are told apart by where the identity says they are'
|
||||
});
|
||||
|
||||
test('a link is built only from a language code, and a level is not a warning', () => {
|
||||
const site = { id: 'X', name: 'X', lat: 1, lon: 1, wikipedia: 'evil.example/a#:Y' };
|
||||
const site = {
|
||||
id: 'X',
|
||||
name: 'X',
|
||||
lat: 1,
|
||||
lon: 1,
|
||||
wikipedia: 'evil.example/a#:Y',
|
||||
};
|
||||
const data = manager({ 'local-dams': { name: 'Dams', records: [site] } });
|
||||
assert.deepEqual(describeEntity(data, { layerId: 'local-dams', id: 'X', lat: 1, lon: 1 }).links, []);
|
||||
assert.deepEqual(
|
||||
describeEntity(data, { layerId: 'local-dams', id: 'X', lat: 1, lon: 1 })
|
||||
.links,
|
||||
[],
|
||||
);
|
||||
assert.deepEqual(recordWarnings({ alert: 'green' }), []);
|
||||
});
|
||||
|
||||
test('a breakdown names "Other" once', () => {
|
||||
const ships = [30, 30, 70, 70, 70, 80, 80, 60, 37, 52, 52, 90, 90, 90].map((shipType, i) => ({ id: `S${i}`, mmsi: String(i), lat: 1, lon: 1 + i * 0.01, shipType }));
|
||||
const data = manager({ 'ais-live-vessels': { name: 'Vessels', records: ships } });
|
||||
const labels = layerBreakdown(data, 'ais-live-vessels').splits[0].parts.map((part) => part.label);
|
||||
const ships = [30, 30, 70, 70, 70, 80, 80, 60, 37, 52, 52, 90, 90, 90].map(
|
||||
(shipType, i) => ({
|
||||
id: `S${i}`,
|
||||
mmsi: String(i),
|
||||
lat: 1,
|
||||
lon: 1 + i * 0.01,
|
||||
shipType,
|
||||
}),
|
||||
);
|
||||
const data = manager({
|
||||
'ais-live-vessels': { name: 'Vessels', records: ships },
|
||||
});
|
||||
const labels = layerBreakdown(data, 'ais-live-vessels').splits[0].parts.map(
|
||||
(part) => part.label,
|
||||
);
|
||||
assert.equal(labels.filter((label) => label === 'Other').length <= 1, true);
|
||||
assert.equal(new Set(labels).size, labels.length);
|
||||
});
|
||||
|
||||
test('a card shows the photo its layer looked up: the tracked airliner, the selected vessel', () => {
|
||||
const photo = {
|
||||
src: 'https://cdn.example/p.jpg',
|
||||
link: 'https://example/p',
|
||||
photographer: 'A. Spotter',
|
||||
width: 640,
|
||||
};
|
||||
const planes = manager({
|
||||
flights: {
|
||||
name: 'Live Flights',
|
||||
records: [
|
||||
{
|
||||
id: 'DAL1',
|
||||
icao24: 'aa0001',
|
||||
callsign: 'DAL1',
|
||||
lat: 34,
|
||||
lon: -118,
|
||||
typeCode: 'B739',
|
||||
category: 'A3',
|
||||
},
|
||||
{ id: 'DAL2', icao24: 'aa0002', callsign: 'DAL2', lat: 35, lon: -118 },
|
||||
],
|
||||
},
|
||||
'ais-live-vessels': {
|
||||
name: 'Vessels',
|
||||
records: [
|
||||
{
|
||||
id: 'EVER GIVEN',
|
||||
vesselId: 'v1',
|
||||
mmsi: '353136000',
|
||||
lat: 30,
|
||||
lon: 32,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
planes.layers.get('flights').module.getTrackedSubject = () => ({
|
||||
id: 'aa0001',
|
||||
photo,
|
||||
});
|
||||
planes.layers.get('ais-live-vessels').module.getVesselPhoto = (id) =>
|
||||
id === 'v1' ? { ...photo, licence: 'CC BY 4.0' } : null;
|
||||
|
||||
const tracked = describeEntity(planes, { layerId: 'flights', id: 'aa0001' });
|
||||
assert.deepEqual(tracked.photo, {
|
||||
src: photo.src,
|
||||
link: photo.link,
|
||||
photographer: 'A. Spotter',
|
||||
licence: '',
|
||||
});
|
||||
// What picks the globe's fleet model for it.
|
||||
assert.deepEqual(tracked.aircraftModel, {
|
||||
typeCode: 'B739',
|
||||
category: 'A3',
|
||||
callsign: 'DAL1',
|
||||
});
|
||||
// Photos are looked up for the tracked plane only.
|
||||
assert.equal(
|
||||
describeEntity(planes, { layerId: 'flights', id: 'aa0002' }).photo,
|
||||
null,
|
||||
);
|
||||
assert.equal(
|
||||
describeEntity(planes, { layerId: 'ais-live-vessels', id: 'EVER GIVEN' })
|
||||
.photo.licence,
|
||||
'CC BY 4.0',
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user