feat: lean-Pi WS fan-out, geofences, DVR playback, fire/aircraft correlation
Phase 1: in-memory ConnectionManager viewport fan-out, 500ms map debounce, cachetools TTLCache, background masscan/ffmpeg, compose memory caps. Phase 2: PostGIS geofences + ST_Intersects alerts, Timescale 1-min CAGGs and timestamp playback, FIRMS/WFIGS x firefighting ADS-B within 20 miles. No Redis/Kafka/Celery.
This commit is contained in:
parent
8978324d33
commit
5ea9a4e879
28 changed files with 2318 additions and 50 deletions
|
|
@ -265,6 +265,26 @@
|
|||
.hud-chip .c.cams { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
|
||||
.hud-chip .c.blips { background: var(--magenta); box-shadow: 0 0 6px var(--magenta); }
|
||||
.hud-chip.off { opacity: 0.4; }
|
||||
#dvr-bar {
|
||||
position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
|
||||
z-index: 520; display: flex; align-items: center; gap: 0.55rem;
|
||||
background: rgba(6,11,20,0.86); border: 1px solid var(--line-hi);
|
||||
border-radius: 4px; padding: 0.28rem 0.7rem;
|
||||
font-family: 'Share Tech Mono', monospace; font-size: 0.66rem; color: var(--muted);
|
||||
min-width: 280px; max-width: 52%;
|
||||
}
|
||||
#dvr-bar input[type=range] { flex: 1; accent-color: var(--cyan); }
|
||||
#dvr-bar.live #dvr-live { color: var(--green); text-shadow: 0 0 8px rgba(83,240,165,0.5); }
|
||||
#dvr-toast {
|
||||
position: absolute; top: 12px; right: 12px; z-index: 700;
|
||||
max-width: 280px; pointer-events: none;
|
||||
}
|
||||
#dvr-toast .gf-alert {
|
||||
background: rgba(255,46,151,0.16); border: 1px solid var(--magenta);
|
||||
color: var(--text); font-family: 'Share Tech Mono', monospace;
|
||||
font-size: 0.68rem; padding: 0.4rem 0.6rem; margin-bottom: 0.35rem;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* ── Layer control panel (dark HUD) ── */
|
||||
#layer-panel {
|
||||
|
|
@ -754,6 +774,12 @@
|
|||
</div>
|
||||
<div class="lp-note">Needs AISSTREAM_API_KEY in Keys.</div>
|
||||
</div>
|
||||
<div class="lp-layer">
|
||||
<div class="lp-row">
|
||||
<button class="btn" id="gf-draw" type="button" onclick="toggleGeofenceDraw()">Draw geofence</button>
|
||||
</div>
|
||||
<div class="lp-note">No Leaflet.Draw — click vertices, double-click to close. Saved to POST /api/geofences.</div>
|
||||
</div>
|
||||
<div class="lp-layer">
|
||||
<div class="lp-row">
|
||||
<label class="lp-name"><input type="checkbox" id="lp-storms-on" checked onchange="toggleStorms()"> <span class="lp-dot storms"></span> NHC Storms</label>
|
||||
|
|
@ -776,6 +802,12 @@
|
|||
<div class="hud-chip" id="hud-cams"><span class="c cams"></span>CAMS <b id="hud-cams-n">—</b></div>
|
||||
<div class="hud-chip" id="hud-blips"><span class="c blips"></span>BLIPS <b id="hud-blips-n">—</b></div>
|
||||
</div>
|
||||
<div id="dvr-bar" class="live">
|
||||
<button class="btn" id="dvr-live" type="button" onclick="dvrGoLive()">LIVE</button>
|
||||
<input type="range" id="dvr-slider" min="0" max="360" value="360" oninput="dvrScrub(this.value)" aria-label="DVR time">
|
||||
<span id="dvr-label">live</span>
|
||||
</div>
|
||||
<div id="dvr-toast"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
|
@ -1658,6 +1690,76 @@ function bboxCell() {
|
|||
if (!map) return '';
|
||||
return currentBBox().split(',').map(n => Number(n).toFixed(2)).join(',') + '@' + map.getZoom();
|
||||
}
|
||||
let liveWs = null;
|
||||
const FF_ICAO = new Set(['AT802','AT8T','AT8P','C130','C30J','C130J','DC10','MD10','MD87','S64','UH60','S70','CL415','CL215','B350','OV10','C208']);
|
||||
let firefighterHex = new Set();
|
||||
let dvrTs = null;
|
||||
let dvrMinMs = 0, dvrMaxMs = 0;
|
||||
let gfDrawOn = false, gfVerts = [], gfLayer = null, gfSaved = null;
|
||||
function liveWsUrl() {
|
||||
const proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
return proto + '//' + location.host + '/ws/live';
|
||||
}
|
||||
function sendLiveViewport() {
|
||||
if (!liveWs || liveWs.readyState !== 1 || !map) return;
|
||||
liveWs.send(JSON.stringify({ type: 'viewport', bbox: currentBBox() }));
|
||||
}
|
||||
function upsertLivePoint(group, p, colorFn, feed) {
|
||||
if (!map || !p || p.id == null || p.lat == null || p.lon == null) return group;
|
||||
if (!group || !map.hasLayer(group) || !group._osintById) {
|
||||
return renderPoints(group, [p], colorFn, true, feed);
|
||||
}
|
||||
const id = String(p.id);
|
||||
const col = sanitizeColor(colorFn(p), '#35e0ff');
|
||||
let m = group._osintById.get(id);
|
||||
if (m) {
|
||||
m.setLatLng([p.lat, p.lon]);
|
||||
if (feed) m.setIcon(feedIcon(feed, col, p.heading));
|
||||
else if (m.setStyle) m.setStyle({ color: col, fillColor: col });
|
||||
} else {
|
||||
m = makePointMarker(p, colorFn, feed, pointCanvas());
|
||||
if (m) { group.addLayer(m); group._osintById.set(id, m); }
|
||||
}
|
||||
return group;
|
||||
}
|
||||
function applyLiveMarker(kind, p) {
|
||||
if (!p) return;
|
||||
if (kind === 'ais' && vesselsOn && map && map.getZoom() > 3 && !dvrTs) {
|
||||
vesselsGroup = upsertLivePoint(vesselsGroup, p, q => {
|
||||
const sog = Number(q.speed || 0);
|
||||
return sog > 0.5 ? '#2dd4bf' : '#64748b';
|
||||
}, 'vessel');
|
||||
} else if (kind === 'adsb' && acOn && map && map.getZoom() > 3 && !dvrTs) {
|
||||
acGroup = upsertLivePoint(acGroup, p, q => acColor(q), 'ac');
|
||||
} else if (kind === 'geofence_alert') {
|
||||
showGeofenceToast(p);
|
||||
} else if (kind === 'fire_aircraft') {
|
||||
firefighterHex.add(String(p.aircraft_hex || ''));
|
||||
if (acOn && p.aircraft_lat != null) {
|
||||
acGroup = upsertLivePoint(acGroup, {
|
||||
id: p.aircraft_hex, lat: p.aircraft_lat, lon: p.aircraft_lon,
|
||||
label: p.label || p.aircraft_hex, extra: { type: p.aircraft_type, firefighter: true },
|
||||
}, q => acColor(q), 'ac');
|
||||
}
|
||||
}
|
||||
}
|
||||
function acColor(p) {
|
||||
const t = String(((p.extra || {}).type || '')).toUpperCase();
|
||||
if ((p.extra || {}).firefighter || firefighterHex.has(String(p.id)) || FF_ICAO.has(t)) return '#fb923c';
|
||||
return altColor((p.extra || {}).alt_baro);
|
||||
}
|
||||
function connectLiveWs() {
|
||||
if (liveWs && (liveWs.readyState === 0 || liveWs.readyState === 1)) return;
|
||||
try { liveWs = new WebSocket(liveWsUrl()); } catch (e) { return; }
|
||||
liveWs.onopen = () => sendLiveViewport();
|
||||
liveWs.onmessage = (ev) => {
|
||||
try {
|
||||
const msg = JSON.parse(ev.data);
|
||||
applyLiveMarker(msg.type, msg.payload);
|
||||
} catch (e) { /* ignore malformed */ }
|
||||
};
|
||||
liveWs.onclose = () => { liveWs = null; setTimeout(connectLiveWs, 4000); };
|
||||
}
|
||||
function overlayFetch(url) {
|
||||
return fetch(url, overlayAbort ? { signal: overlayAbort.signal } : {});
|
||||
}
|
||||
|
|
@ -1754,7 +1856,8 @@ async function initMap() {
|
|||
if (camsOn) loadCams();
|
||||
if (blipsOn) loadBlips();
|
||||
refreshLiveOverlays();
|
||||
}, 300);
|
||||
sendLiveViewport();
|
||||
}, 500);
|
||||
});
|
||||
// Static Blue Marble has no time-domain fetch — don't block overlays on GIBS.
|
||||
mapLayerChanged();
|
||||
|
|
@ -1778,6 +1881,7 @@ async function initMap() {
|
|||
if (camsOn) loadCams();
|
||||
if (blipsOn) loadBlips();
|
||||
refreshLiveOverlays();
|
||||
connectLiveWs();
|
||||
} catch(e) {
|
||||
hint.textContent = `Failed to load map layers: ${e.message || e}`;
|
||||
console.error('Map init failed', e);
|
||||
|
|
@ -2226,6 +2330,8 @@ function refreshLiveOverlays() {
|
|||
if (trainsOn) loadTrains();
|
||||
if (vesselsOn) loadVessels();
|
||||
if (stormsOn) loadStorms();
|
||||
loadGeofences();
|
||||
loadFireAircraftHits();
|
||||
}
|
||||
function addExtraAttrib(html) {
|
||||
if (!map || !html || extraAttribs.has(html)) return;
|
||||
|
|
@ -2554,10 +2660,10 @@ async function loadAircraft() {
|
|||
}
|
||||
const req = ++overlayReq.ac;
|
||||
try {
|
||||
const r = await overlayFetch(`${API}/api/aircraft?bbox=${currentBBox()}`);
|
||||
const r = await overlayFetch(`${API}/api/aircraft?bbox=${currentBBox()}${dvrQs()}`);
|
||||
const pts = await r.json();
|
||||
if (req !== overlayReq.ac) return;
|
||||
acGroup = renderPoints(acGroup, Array.isArray(pts) ? pts : [], p => altColor((p.extra || {}).alt_baro), true, 'ac');
|
||||
acGroup = renderPoints(acGroup, Array.isArray(pts) ? pts : [], p => acColor(p), true, 'ac');
|
||||
document.getElementById('lp-ac-count').textContent = (pts.length || 0).toLocaleString();
|
||||
addExtraAttrib('<a href="https://www.adsb.lol/docs/open-data/api">ADSB.lol</a> ODbL');
|
||||
} catch (e) {
|
||||
|
|
@ -2622,7 +2728,7 @@ async function loadVessels() {
|
|||
}).catch(() => {});
|
||||
}
|
||||
try {
|
||||
const r = await overlayFetch(`${API}/api/vessels?bbox=${bb}`);
|
||||
const r = await overlayFetch(`${API}/api/vessels?bbox=${bb}${dvrQs()}`);
|
||||
const pts = await r.json();
|
||||
if (req !== overlayReq.vessels) return;
|
||||
vesselsGroup = renderPoints(vesselsGroup, Array.isArray(pts) ? pts : [], p => {
|
||||
|
|
@ -2674,6 +2780,122 @@ initMap();
|
|||
// contend with the first bbox burst. Payload is slim (no article bodies).
|
||||
setTimeout(() => loadNews(true), 400);
|
||||
setInterval(checkHealth, 30000);
|
||||
|
||||
/* Phase 2: DVR slider + geofence draw (no Leaflet.Draw) + fire/aircraft hits */
|
||||
function dvrQs() { return dvrTs ? `×tamp=${encodeURIComponent(dvrTs)}` : ''; }
|
||||
function dvrGoLive() {
|
||||
dvrTs = null;
|
||||
const bar = document.getElementById('dvr-bar');
|
||||
if (bar) bar.classList.add('live');
|
||||
const sl = document.getElementById('dvr-slider');
|
||||
if (sl) sl.value = sl.max;
|
||||
const lab = document.getElementById('dvr-label');
|
||||
if (lab) lab.textContent = 'live';
|
||||
if (acOn) loadAircraft();
|
||||
if (vesselsOn) loadVessels();
|
||||
}
|
||||
function dvrScrub(v) {
|
||||
if (!dvrMaxMs) { dvrGoLive(); return; }
|
||||
const ms = dvrMinMs + (Number(v) / 360) * (dvrMaxMs - dvrMinMs);
|
||||
dvrTs = new Date(ms).toISOString();
|
||||
const bar = document.getElementById('dvr-bar');
|
||||
if (bar) bar.classList.toggle('live', Number(v) >= 359);
|
||||
if (Number(v) >= 359) { dvrGoLive(); return; }
|
||||
const lab = document.getElementById('dvr-label');
|
||||
if (lab) lab.textContent = dvrTs.slice(11, 16) + 'Z';
|
||||
if (acOn) loadAircraft();
|
||||
if (vesselsOn) loadVessels();
|
||||
}
|
||||
async function initDvrRange() {
|
||||
try {
|
||||
const r = await fetch(`${API}/api/tracks/range`);
|
||||
const b = await r.json();
|
||||
dvrMinMs = Date.parse(b.min);
|
||||
dvrMaxMs = Date.parse(b.max);
|
||||
if (!dvrMinMs || !dvrMaxMs) {
|
||||
dvrMaxMs = Date.now();
|
||||
dvrMinMs = dvrMaxMs - 6 * 3600 * 1000;
|
||||
}
|
||||
} catch (e) {
|
||||
dvrMaxMs = Date.now();
|
||||
dvrMinMs = dvrMaxMs - 6 * 3600 * 1000;
|
||||
}
|
||||
}
|
||||
function showGeofenceToast(p) {
|
||||
const box = document.getElementById('dvr-toast');
|
||||
if (!box) return;
|
||||
const el = document.createElement('div');
|
||||
el.className = 'gf-alert';
|
||||
el.textContent = `GEOFENCE ${p.geofence_name || ''} · ${p.source_kind} ${p.entity_id || ''}`;
|
||||
box.prepend(el);
|
||||
setTimeout(() => el.remove(), 8000);
|
||||
}
|
||||
function toggleGeofenceDraw() {
|
||||
gfDrawOn = !gfDrawOn;
|
||||
gfVerts = [];
|
||||
if (gfLayer && map) { map.removeLayer(gfLayer); gfLayer = null; }
|
||||
const btn = document.getElementById('gf-draw');
|
||||
if (btn) btn.textContent = gfDrawOn ? 'Click map… (dbl-click close)' : 'Draw geofence';
|
||||
if (!map) return;
|
||||
if (gfDrawOn) {
|
||||
map.getContainer().style.cursor = 'crosshair';
|
||||
map.on('click', onGfClick);
|
||||
map.on('dblclick', onGfClose);
|
||||
} else {
|
||||
map.getContainer().style.cursor = '';
|
||||
map.off('click', onGfClick);
|
||||
map.off('dblclick', onGfClose);
|
||||
}
|
||||
}
|
||||
function onGfClick(e) {
|
||||
if (!gfDrawOn) return;
|
||||
L.DomEvent.stop(e);
|
||||
gfVerts.push([e.latlng.lng, e.latlng.lat]);
|
||||
if (gfLayer && map) map.removeLayer(gfLayer);
|
||||
if (gfVerts.length >= 2) {
|
||||
gfLayer = L.polyline(gfVerts.map(v => [v[1], v[0]]), { color: '#ff2e97', weight: 2 }).addTo(map);
|
||||
}
|
||||
}
|
||||
async function onGfClose(e) {
|
||||
if (!gfDrawOn) return;
|
||||
L.DomEvent.stop(e);
|
||||
if (gfVerts.length < 3) return;
|
||||
const ring = gfVerts.concat([gfVerts[0]]);
|
||||
const geojson = { type: 'Polygon', coordinates: [ring] };
|
||||
try {
|
||||
await fetch(`${API}/api/geofences`, {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name: 'Fence ' + new Date().toISOString().slice(11, 19), geojson }),
|
||||
});
|
||||
} catch (err) { console.error('geofence save failed', err); }
|
||||
toggleGeofenceDraw();
|
||||
loadGeofences();
|
||||
}
|
||||
async function loadGeofences() {
|
||||
if (!map) return;
|
||||
try {
|
||||
const r = await overlayFetch(`${API}/api/geofences`);
|
||||
const rows = await r.json();
|
||||
if (gfSaved && map.hasLayer(gfSaved)) map.removeLayer(gfSaved);
|
||||
const feats = (Array.isArray(rows) ? rows : []).map(f => ({
|
||||
type: 'Feature', properties: { name: f.name, id: f.id }, geometry: f.geojson,
|
||||
}));
|
||||
gfSaved = L.geoJSON({ type: 'FeatureCollection', features: feats }, {
|
||||
style: { color: '#ff2e97', weight: 2, fillOpacity: 0.08 },
|
||||
}).addTo(map);
|
||||
} catch (e) { if (!isAbort(e)) console.error('geofences load failed', e); }
|
||||
}
|
||||
async function loadFireAircraftHits() {
|
||||
try {
|
||||
const r = await fetch(`${API}/api/fire-aircraft`);
|
||||
const rows = await r.json();
|
||||
(Array.isArray(rows) ? rows : []).forEach(h => {
|
||||
if (h.aircraft_hex) firefighterHex.add(String(h.aircraft_hex));
|
||||
});
|
||||
} catch (e) { /* empty without table */ }
|
||||
}
|
||||
initDvrRange();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Reference in a new issue