feat(map): dense per-article blip layer from /api/news/blips (T2 frontend) #65
1 changed files with 132 additions and 1 deletions
feat(map): dense per-article blip layer from /api/news/blips
Additive 'Article Blips' layer on the HUD map (default OFF), separate from the critical-news pins: - GET /api/news/blips?bbox=&limit=1000 (frozen T1 contract), own superseded-request counter + overlayAbort handling, bbox refresh on pan/zoom and a NEWS_REFRESH_MS timer while enabled - small radius-3 violet circleMarkers in a chunked markerClusterGroup (maxClusterRadius 40) with quiet violet cluster icons; one persistent SVG renderer (clickable paths, click-through root, no container leak) - click -> .blip-pop popup: headline, domain, category, location_name + confidence, score, source link (esc() on every field) - legend toggle + count, ARTICLES HUD chip, syncHud wiring - graceful 404/failure: warn + idle at 0, map and critical pins unaffected - .leaflet-heatmap-layer pointer-events:none — the visual-only FIRMS canvas sat on top of the overlay pane and ate clicks meant for vector blips/pins (pre-existing; fixes click-through for canvas pins too) Critical-news layer and /api/news/map consumption unchanged.
commit
e6ef6b79f9
|
|
@ -274,6 +274,21 @@
|
||||||
.marker-cluster-medium div { font-size: 11px; }
|
.marker-cluster-medium div { font-size: 11px; }
|
||||||
.marker-cluster-large div { font-size: 12px; }
|
.marker-cluster-large div { font-size: 12px; }
|
||||||
|
|
||||||
|
/* ── Article blip clusters (quiet violet, matches the small blips) ── */
|
||||||
|
.marker-cluster-articles { background-color: rgba(160, 108, 213, 0.16); }
|
||||||
|
.marker-cluster-articles div {
|
||||||
|
background-color: rgba(122, 74, 160, 0.88);
|
||||||
|
color: #efe6f9;
|
||||||
|
font-weight: 600;
|
||||||
|
box-shadow: 0 0 10px rgba(160, 108, 213, 0.35), 0 0 2px rgba(3, 6, 9, 0.9);
|
||||||
|
}
|
||||||
|
.articles-sm div { font-size: 10px; }
|
||||||
|
.articles-md div { font-size: 11px; }
|
||||||
|
.articles-lg div { font-size: 12px; }
|
||||||
|
/* FIRMS heat is visual-only (no listeners) but its canvas sits on top
|
||||||
|
of the overlay pane and eats clicks meant for vector blips/pins. */
|
||||||
|
.leaflet-heatmap-layer { pointer-events: none; }
|
||||||
|
|
||||||
/* ── Map hint + HUD chips ── */
|
/* ── Map hint + HUD chips ── */
|
||||||
.map-hint {
|
.map-hint {
|
||||||
position: absolute; left: 12px; bottom: 12px; z-index: 500;
|
position: absolute; left: 12px; bottom: 12px; z-index: 500;
|
||||||
|
|
@ -299,6 +314,7 @@
|
||||||
.hud-chip .c.cams { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
|
.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 .c.blips { background: var(--magenta); box-shadow: 0 0 6px var(--magenta); }
|
||||||
.hud-chip .c.news { background: var(--magenta); box-shadow: 0 0 6px var(--magenta); border-radius: 1px; transform: rotate(45deg); }
|
.hud-chip .c.news { background: var(--magenta); box-shadow: 0 0 6px var(--magenta); border-radius: 1px; transform: rotate(45deg); }
|
||||||
|
.hud-chip .c.articles { background: #a06cd5; box-shadow: 0 0 6px rgba(160,108,213,0.6); }
|
||||||
.hud-chip.off { opacity: 0.4; }
|
.hud-chip.off { opacity: 0.4; }
|
||||||
#dvr-bar {
|
#dvr-bar {
|
||||||
position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
|
position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
|
||||||
|
|
@ -357,6 +373,7 @@
|
||||||
.lp-dot.cams { background: #4ade80; box-shadow: 0 0 7px #4ade80; }
|
.lp-dot.cams { background: #4ade80; box-shadow: 0 0 7px #4ade80; }
|
||||||
.lp-dot.blips { background: var(--magenta); box-shadow: 0 0 7px var(--magenta); }
|
.lp-dot.blips { background: var(--magenta); box-shadow: 0 0 7px var(--magenta); }
|
||||||
.lp-dot.news { background: var(--cyan); box-shadow: 0 0 7px var(--cyan); }
|
.lp-dot.news { background: var(--cyan); box-shadow: 0 0 7px var(--cyan); }
|
||||||
|
.lp-dot.articles { background: #a06cd5; box-shadow: 0 0 7px rgba(160,108,213,0.6); }
|
||||||
.lp-dot.weather { background: var(--amber); box-shadow: 0 0 7px var(--amber); }
|
.lp-dot.weather { background: var(--amber); box-shadow: 0 0 7px var(--amber); }
|
||||||
.lp-dot.flights { background: #7dd3fc; box-shadow: 0 0 7px #7dd3fc; }
|
.lp-dot.flights { background: #7dd3fc; box-shadow: 0 0 7px #7dd3fc; }
|
||||||
.lp-dot.mil { background: #f472b6; box-shadow: 0 0 7px #f472b6; }
|
.lp-dot.mil { background: #f472b6; box-shadow: 0 0 7px #f472b6; }
|
||||||
|
|
@ -1017,6 +1034,12 @@
|
||||||
<span class="lp-count" id="lp-news-count">0</span>
|
<span class="lp-count" id="lp-news-count">0</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="lp-layer">
|
||||||
|
<div class="lp-row">
|
||||||
|
<label class="lp-name" title="Per-article proximate locations from the news feed (last 24h)"><input type="checkbox" id="lp-articles-on" onchange="toggleArticleBlips()"> <span class="lp-dot articles"></span> Article Blips</label>
|
||||||
|
<span class="lp-count" id="lp-articles-count">0</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="lp-layer">
|
<div class="lp-layer">
|
||||||
<div class="lp-row">
|
<div class="lp-row">
|
||||||
|
|
@ -1121,6 +1144,7 @@
|
||||||
<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-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 class="hud-chip" id="hud-blips"><span class="c blips"></span>BLIPS <b id="hud-blips-n">—</b></div>
|
||||||
<div class="hud-chip" id="hud-news"><span class="c news"></span>NEWS <b id="hud-news-n">—</b></div>
|
<div class="hud-chip" id="hud-news"><span class="c news"></span>NEWS <b id="hud-news-n">—</b></div>
|
||||||
|
<div class="hud-chip" id="hud-articles"><span class="c articles"></span>ARTICLES <b id="hud-articles-n">—</b></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="cheat-sheet" class="cheat-sheet" hidden role="dialog" aria-label="Keyboard shortcuts">
|
<div id="cheat-sheet" class="cheat-sheet" hidden role="dialog" aria-label="Keyboard shortcuts">
|
||||||
<h3>Shortcuts</h3>
|
<h3>Shortcuts</h3>
|
||||||
|
|
@ -1497,6 +1521,7 @@ const COUNT_HUD = {
|
||||||
'lp-cams-count': 'hud-cams-n',
|
'lp-cams-count': 'hud-cams-n',
|
||||||
'lp-blips-count': 'hud-blips-n',
|
'lp-blips-count': 'hud-blips-n',
|
||||||
'lp-news-count': 'hud-news-n',
|
'lp-news-count': 'hud-news-n',
|
||||||
|
'lp-articles-count': 'hud-articles-n',
|
||||||
};
|
};
|
||||||
function setLayerCount(id, value) {
|
function setLayerCount(id, value) {
|
||||||
const el = document.getElementById(id);
|
const el = document.getElementById(id);
|
||||||
|
|
@ -1756,6 +1781,7 @@ function showView(name) {
|
||||||
if (camsOn) loadCams();
|
if (camsOn) loadCams();
|
||||||
if (blipsOn) loadBlips();
|
if (blipsOn) loadBlips();
|
||||||
if (newsOn) loadNewsPins();
|
if (newsOn) loadNewsPins();
|
||||||
|
if (articlesOn) loadArticleBlips();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (name === 'news') loadNews(false);
|
if (name === 'news') loadNews(false);
|
||||||
|
|
@ -2324,6 +2350,7 @@ let map = null, mapLayer = null, mapInitStarted = false;
|
||||||
let firesHeat = null, camsGroup = null, firesOn = false, camsOn = false;
|
let firesHeat = null, camsGroup = null, firesOn = false, camsOn = false;
|
||||||
let blipsGroup = null, blipsOn = false, blipsSince = '24h';
|
let blipsGroup = null, blipsOn = false, blipsSince = '24h';
|
||||||
let newsGroup = null, newsOn = false, newsReq = 0;
|
let newsGroup = null, newsOn = false, newsReq = 0;
|
||||||
|
let articlesGroup = null, articlesOn = false, articlesReq = 0, articlesTimer = null, articlesRenderer = null;
|
||||||
let firesOpacity = 0.65, firesColor = 'brightness', firesSince = '24h';
|
let firesOpacity = 0.65, firesColor = 'brightness', firesSince = '24h';
|
||||||
let camsOpacity = 1.0, baseOpacity = 1.0;
|
let camsOpacity = 1.0, baseOpacity = 1.0;
|
||||||
let camReq = 0, fireReq = 0, blipReq = 0; // stale-response guards (rapid zoom races)
|
let camReq = 0, fireReq = 0, blipReq = 0; // stale-response guards (rapid zoom races)
|
||||||
|
|
@ -2611,6 +2638,7 @@ async function initMap() {
|
||||||
if (camsOn) loadCams();
|
if (camsOn) loadCams();
|
||||||
if (blipsOn) loadBlips();
|
if (blipsOn) loadBlips();
|
||||||
if (newsOn) loadNewsPins();
|
if (newsOn) loadNewsPins();
|
||||||
|
if (articlesOn) loadArticleBlips();
|
||||||
refreshLiveOverlays();
|
refreshLiveOverlays();
|
||||||
sendLiveViewport();
|
sendLiveViewport();
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
@ -2623,6 +2651,7 @@ async function initMap() {
|
||||||
camsOn = document.getElementById('lp-cams-on').checked;
|
camsOn = document.getElementById('lp-cams-on').checked;
|
||||||
blipsOn = document.getElementById('lp-blips-on').checked;
|
blipsOn = document.getElementById('lp-blips-on').checked;
|
||||||
newsOn = document.getElementById('lp-news-on').checked;
|
newsOn = document.getElementById('lp-news-on').checked;
|
||||||
|
articlesOn = document.getElementById('lp-articles-on').checked;
|
||||||
firesSince = document.getElementById('lp-fires-since').value;
|
firesSince = document.getElementById('lp-fires-since').value;
|
||||||
blipsSince = document.getElementById('lp-blips-since').value;
|
blipsSince = document.getElementById('lp-blips-since').value;
|
||||||
radarOn = document.getElementById('lp-radar-on').checked;
|
radarOn = document.getElementById('lp-radar-on').checked;
|
||||||
|
|
@ -2645,6 +2674,7 @@ async function initMap() {
|
||||||
if (camsOn) loadCams();
|
if (camsOn) loadCams();
|
||||||
if (blipsOn) loadBlips();
|
if (blipsOn) loadBlips();
|
||||||
if (newsOn) loadNewsPins();
|
if (newsOn) loadNewsPins();
|
||||||
|
if (articlesOn) loadArticleBlips();
|
||||||
refreshLiveOverlays();
|
refreshLiveOverlays();
|
||||||
}, 250);
|
}, 250);
|
||||||
});
|
});
|
||||||
|
|
@ -2667,8 +2697,9 @@ function syncHud() {
|
||||||
set('cams', camsOn);
|
set('cams', camsOn);
|
||||||
set('blips', blipsOn);
|
set('blips', blipsOn);
|
||||||
set('news', newsOn);
|
set('news', newsOn);
|
||||||
|
set('articles', articlesOn);
|
||||||
}
|
}
|
||||||
let hudFiresCount = null, hudCamsCount = null, hudBlipsCount = null, hudNewsCount = null;
|
let hudFiresCount = null, hudCamsCount = null, hudBlipsCount = null, hudNewsCount = null, hudArticlesCount = null;
|
||||||
|
|
||||||
function setMapAttribution(text) {
|
function setMapAttribution(text) {
|
||||||
if (!map) return;
|
if (!map) return;
|
||||||
|
|
@ -3289,6 +3320,106 @@ async function loadNewsPins() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ── ARTICLE BLIPS (per-article proximate geo, all severities) ──
|
||||||
|
GET /api/news/blips — dense field of small clustered circleMarkers.
|
||||||
|
Separate from the critical-pin layer above; default OFF. Until the
|
||||||
|
backend endpoint lands, a 404 idles the layer at 0 without breaking
|
||||||
|
the map or the critical pins. */
|
||||||
|
const ARTICLE_BLIP_COL = '#a06cd5'; // quiet violet — critical pins are cyan
|
||||||
|
function articleBlipPopup(b) {
|
||||||
|
const loc = esc(b.location_name || 'no location label') +
|
||||||
|
(b.location_confidence ? ' (' + esc(b.location_confidence) + ')' : '');
|
||||||
|
const meta = [newsTimeAgo(b.created_at), loc];
|
||||||
|
if (b.score != null) meta.push('score ' + esc(b.score));
|
||||||
|
return `<div class="blip-pop">` +
|
||||||
|
`<div class="blip-src">◈ ${esc(b.domain || 'article')}${b.category ? ' · ' + esc(b.category) : ''}</div>` +
|
||||||
|
`<b>${esc(b.headline || 'Untitled article')}</b>` +
|
||||||
|
`<div class="blip-time">${meta.join(' · ')}</div>` +
|
||||||
|
(b.url ? `<a href="${esc(b.url)}" target="_blank" rel="noopener">source ↗</a>` : '') +
|
||||||
|
`</div>`;
|
||||||
|
}
|
||||||
|
async function toggleArticleBlips() {
|
||||||
|
articlesOn = document.getElementById('lp-articles-on').checked;
|
||||||
|
if (articlesOn) {
|
||||||
|
await loadArticleBlips();
|
||||||
|
// Same cadence as the news poll; own timer so the layer refreshes
|
||||||
|
// even when the News view (which starts newsInterval) was never opened.
|
||||||
|
if (!articlesTimer) articlesTimer = setInterval(() => { if (articlesOn) loadArticleBlips(); }, NEWS_REFRESH_MS);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
articlesReq++;
|
||||||
|
if (articlesTimer) { clearInterval(articlesTimer); articlesTimer = null; }
|
||||||
|
articlesGroup = dropLayer(articlesGroup);
|
||||||
|
if (articlesRenderer && map) { map.removeLayer(articlesRenderer); articlesRenderer = null; }
|
||||||
|
hudArticlesCount = null;
|
||||||
|
setLayerCount('lp-articles-count', '0');
|
||||||
|
syncHud();
|
||||||
|
}
|
||||||
|
async function loadArticleBlips() {
|
||||||
|
if (!map) return;
|
||||||
|
const req = ++articlesReq;
|
||||||
|
const zero = () => {
|
||||||
|
articlesGroup = dropLayer(articlesGroup);
|
||||||
|
hudArticlesCount = 0;
|
||||||
|
setLayerCount('lp-articles-count', '0');
|
||||||
|
syncHud();
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const r = await overlayFetch(`${API}/api/news/blips?bbox=${currentBBox()}&limit=1000`);
|
||||||
|
if (req !== articlesReq) return; // superseded by a newer pan/zoom
|
||||||
|
if (!r.ok) {
|
||||||
|
console.warn(`Article blips: /api/news/blips ${r.status} — layer idle`);
|
||||||
|
zero();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = await r.json();
|
||||||
|
if (req !== articlesReq) return;
|
||||||
|
const seen = new Set();
|
||||||
|
const rows = (Array.isArray(data) ? data : []).filter(b => {
|
||||||
|
if (!Number.isFinite(Number(b.lat)) || !Number.isFinite(Number(b.lon))) return false;
|
||||||
|
if (b.id != null) { if (seen.has(b.id)) return false; seen.add(b.id); }
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
articlesGroup = dropLayer(articlesGroup);
|
||||||
|
// One persistent SVG renderer: paths are individually clickable and
|
||||||
|
// the pe:none root lets clicks fall through to the canvas pins below
|
||||||
|
// (Leaflet stacks svg z200 over canvas z100). A fresh renderer per
|
||||||
|
// refresh would leak a full-viewport container on every pan/zoom.
|
||||||
|
const renderer = articlesRenderer || (articlesRenderer = L.svg({ padding: 0.5 }));
|
||||||
|
const markers = rows.map(b => L.circleMarker([Number(b.lat), Number(b.lon)], {
|
||||||
|
radius: 3, weight: 1, color: ARTICLE_BLIP_COL, fillColor: ARTICLE_BLIP_COL,
|
||||||
|
fillOpacity: 0.5, opacity: 0.75, renderer,
|
||||||
|
}).bindPopup(articleBlipPopup(b)));
|
||||||
|
articlesGroup = L.markerClusterGroup({
|
||||||
|
maxClusterRadius: 40,
|
||||||
|
showCoverageOnHover: false,
|
||||||
|
spiderfyOnMaxZoom: true,
|
||||||
|
chunkedLoading: true,
|
||||||
|
chunkInterval: 100,
|
||||||
|
chunkDelay: 10,
|
||||||
|
iconCreateFunction: (cluster) => {
|
||||||
|
const n = cluster.getChildCount();
|
||||||
|
const size = n < 10 ? 'sm' : n < 100 ? 'md' : 'lg';
|
||||||
|
return L.divIcon({
|
||||||
|
html: '<div><span>' + n + '</span></div>',
|
||||||
|
className: 'marker-cluster marker-cluster-articles articles-' + size,
|
||||||
|
iconSize: L.point(40, 40),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
articlesGroup.addLayers(markers);
|
||||||
|
articlesGroup.addTo(map);
|
||||||
|
setLayerCount('lp-articles-count', rows.length.toLocaleString());
|
||||||
|
hudArticlesCount = rows.length;
|
||||||
|
syncHud();
|
||||||
|
} catch (e) {
|
||||||
|
if (isAbort(e)) return;
|
||||||
|
if (req !== articlesReq) return;
|
||||||
|
console.warn('Article blips load failed', e);
|
||||||
|
zero();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ── Live overlays (radar / alerts / WFIGS / aircraft / trains / AIS / NHC) ── */
|
/* ── Live overlays (radar / alerts / WFIGS / aircraft / trains / AIS / NHC) ── */
|
||||||
function refreshLiveOverlays() {
|
function refreshLiveOverlays() {
|
||||||
if (!map) return;
|
if (!map) return;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue