/**
* Dossiers (DESIGN.md §12.1): every object has identity, live state, a track
* history, events, links and receipts. Tapping any entity anywhere (a globe
* pick, a search result, a track in a Moment, a node in the link graph)
* opens one. The Graph segment shows globe.graph(ref); globe, time machine
* and graph share one selection.
*/
import { icon } from './icons.js';
import {
$,
$$,
esc,
ago,
fmtNum,
haptic,
toast,
store,
sparkPath,
} from './dom.js';
import { createSheet } from './sheet.js';
import { createLinkGraph } from './linkGraph.js';
import { BAND_NAME, utc, llShort, mgrs, cardinal } from './bands.js';
import { bandOfKind } from './shim3.js';
export const KIND_ICON = {
aircraft: 'sky',
helicopter: 'heli',
military: 'sky',
satellite: 'satellite',
station: 'satellite',
vessel: 'sea',
quake: 'hazards',
fire: 'flame',
camera: 'video',
situation: 'now',
place: 'pin',
moment: 'film',
track: 'scope',
capture: 'seal',
};
export const KIND_NAME = {
aircraft: 'Aircraft',
helicopter: 'Helicopter',
military: 'Military aircraft',
satellite: 'Satellite',
vessel: 'Vessel',
quake: 'Earthquake',
camera: 'Public camera',
situation: 'Situation',
place: 'Place',
moment: 'Moment',
track: 'Track',
capture: 'Sealed capture',
};
const ID_LABEL = {
icao24: 'ICAO 24-bit',
callsign: 'Callsign',
registration: 'Registration',
norad: 'NORAD ID',
mmsi: 'MMSI',
};
const cap = (x) => (x ? `${x[0].toUpperCase()}${x.slice(1)}` : x);
function liveRows(d) {
const L = d.live;
if (!L) return [];
const rows = [];
if (Number.isFinite(L.altM) && L.altM > 0)
rows.push([
'Altitude',
L.altM > 100e3
? fmtNum(Math.round(L.altM / 1000))
: fmtNum(Math.round((L.altM * 3.28084) / 10) * 10),
L.altM > 100e3 ? 'km' : 'ft',
]);
if (Number.isFinite(L.speed) && L.speed > 0)
rows.push(
d.kind === 'satellite'
? ['Speed', (L.speed / 1000).toFixed(2), 'km/s']
: ['Speed', fmtNum(Math.round(L.speed * 1.94384)), 'kt'],
);
if (Number.isFinite(L.heading))
rows.push([
'Heading',
`${Math.round(((L.heading % 360) + 360) % 360)}°`,
cardinal(L.heading),
]);
if (L.squawk) rows.push(['Squawk', L.squawk, '']);
if (!rows.length && Number.isFinite(L.lat))
rows.push(['Position', llShort(L.lat, L.lon, 3), '']);
return rows.slice(0, 4);
}
/** Altitude profile (area) + ground track (polyline), both from real points. */
function trackHtml(d) {
const tr = (d.track || []).filter((p) => Number.isFinite(p.t));
if (tr.length < 3) return '';
if (Number.isFinite(tr[0].v)) {
const W = 300;
const H = 64;
const path = sparkPath(
tr.map((p) => p.v),
W,
H,
3,
);
return `History${tr.length} samples · ${esc(ago(tr[0].t))} → now
Track${tr.length} points · ${esc(utc(t0, { seconds: false }))} → ${esc(utc(t1, { seconds: false }))}
${icon('lock')}We track things that broadcast publicly, public infrastructure and events. Never people: no person search, no faces.
`; } async function show(ref, { push = true, detent } = {}) { const my = ++token; if (!sheet.isOpen) { sheet.head.innerHTML = `Drag a node · tap one to open its dossier
'; graph = createLinkGraph($('.ds-graph', sheet.body), { onOpen: (n) => { haptic('light'); seg = 'dossier'; show(n.id); }, onSelect: (n) => selectOnGlobe(n), }); graph.set(globe.graph(d.id), d.id); if (sheet.detent !== 'large') sheet.setDetent('large'); } else { sheet.body.innerHTML = bodyHtml(); sheet.body.scrollTop = 0; } } /** One selection: the globe follows the dossier. */ function sync() { const L = d.live; if (!L || !Number.isFinite(L.lat)) return; // Historical (Moment) things are shown by the Moment player, not live. if (d.illustrative && d.kind !== 'moment') return; const raw = String(d.id).replace(/^[a-z]+:/, ''); globe.select(raw); const height = { satellite: 2600e3, aircraft: 60e3, military: 80e3, helicopter: 4000, vessel: 30e3, place: 6000, capture: 2500, moment: 3500, camera: 3000, quake: 400e3, }[d.kind]; if (height) globe.flyTo({ lon: L.lon, lat: L.lat, height, pitch: -55, duration: 1.8, }); } function selectOnGlobe(n) { globe.select(String(n.id).replace(/^[a-z]+:/, '')); } sheet.head.addEventListener('click', (e) => { const s = e.target.closest('[data-seg]'); if (s && s.dataset.seg !== seg) { haptic('tick'); seg = s.dataset.seg; render(); return; } if (e.target.closest('.ds-back')) { stack.pop(); const prev = stack[stack.length - 1]; if (prev) show(prev.ref, { push: false }); } }); sheet.body.addEventListener('click', async (e) => { const link = e.target.closest('[data-link]'); if (link) { haptic('light'); const id = link.dataset.link; if (/^situation:/.test(id) && onOpenSituation) { const ok = await onOpenSituation(id.replace(/^situation:/, ''), { fromDossier: true, }); if (ok) return; } return show(id); } const ev = e.target.closest('[data-t]'); if (ev) { haptic('tick'); onShowOnTime?.(d, Number(ev.dataset.t)); return; } const hash = e.target.closest('[data-hash]'); if (hash) { try { await navigator.clipboard.writeText(hash.dataset.hash); toast('Hash copied', { icon: icon('receipt') }); } catch { toast(hash.dataset.hash.slice(0, 32), { icon: icon('receipt') }); } return; } const act = e.target.closest('[data-ds]')?.dataset.ds; if (!act || !d) return; haptic('light'); if (act === 'follow') { const on = store.toggleFollow(followKey()); watch?.noteFollow?.(d, on); toast(on ? `Following ${d.title}` : 'Unfollowed', { icon: icon(on ? 'starFill' : 'star'), }); render(); } else if (act === 'alert') watch?.ruleFor(d); else if (act === 'room') onOpenRoom?.(d); else if (act === 'time') onShowOnTime?.(d); else if (act === 'play') onOpenMoment?.(d.id.replace(/^moment:/, '')); }); // Picks on the globe highlight the same node in the graph. globe.on('pick', (p) => { if (!graph || !p) return; const id = [ ...[ `flights:${p.id}`, `military:${p.id}`, `satellites:${p.id}`, `vessels:${p.id}`, `situation:${p.id}`, String(p.id), ], ].find((x) => graph.has(x)); if (id) graph.select(id); }); return { open: (ref, o = {}) => { seg = o.graph ? 'graph' : 'dossier'; stack = []; return show(ref, { detent: o.detent || (o.graph ? 'large' : 'medium') }); }, close: () => sheet.close(), get isOpen() { return sheet.isOpen; }, get current() { return d; }, sheet, }; }