feat(aircraft): planespotters.net photo in aircraft popup
Add planespotters.net latest-photo lookup for ADS-B aircraft. - app/live_layers.py: fetch_planespotters_photo() (hex preferred, reg fallback) + _normalize_planespotter_photo(); 24h TTL cache (their ToS cap). - app/main.py: GET /api/aircraft/photo?hex=...|reg=... (422/404/502). - app/static/index.html: .ps-photo block in ADS-B popup; lazy load on popupopen; thumbnail links to photo page + photographer credit. Server-side proxy, not browser fetch(): planespotters 403s any request carrying an Origin header (every browser fetch() sends one). The thumbnail binary is loaded by the browser straight from their CDN, never re-hosted. Tests: 4 unit + 4 API contract (38 pass in the two files).
This commit is contained in:
parent
e568d013ca
commit
665aaec22f
5 changed files with 228 additions and 4 deletions
|
|
@ -356,6 +356,12 @@
|
|||
.cam-pop td { padding: 0.12rem 0.2rem; vertical-align: top; }
|
||||
.cam-pop td.k { color: var(--muted); text-transform: uppercase; font-size: 0.6rem; letter-spacing: 0.05em; white-space: nowrap; width: 34%; font-family: 'Share Tech Mono', monospace; }
|
||||
.cam-pop a { color: var(--cyan); word-break: break-all; }
|
||||
.cam-pop .ps-photo { margin-top: 0.35rem; }
|
||||
.cam-pop .ps-photo a.ps-link { display: block; }
|
||||
.cam-pop .ps-thumb { width: 100%; height: auto; max-height: 220px; object-fit: contain; border-radius: 4px; border: 1px solid var(--line); background: var(--bg-0); display: block; }
|
||||
.cam-pop .ps-credit { font-size: 0.68rem; color: var(--muted); margin-top: 0.2rem; }
|
||||
.cam-pop .ps-credit a { color: var(--cyan); }
|
||||
.cam-pop .ps-loading { font-size: 0.68rem; color: var(--muted); margin-top: 0.35rem; }
|
||||
.role-badge {
|
||||
display: inline-block; font-family: 'Share Tech Mono', monospace;
|
||||
font-size: 0.58rem; font-weight: 700; letter-spacing: 0.12em;
|
||||
|
|
@ -1984,6 +1990,7 @@ async function initMap() {
|
|||
}
|
||||
startHlsFrom(root);
|
||||
});
|
||||
map.on('popupopen', (e) => { loadPlanePhoto(e.popup.getElement()); });
|
||||
map.on('popupclose', () => {
|
||||
if (activeHls) { try { activeHls.destroy(); } catch (_) {} activeHls = null; }
|
||||
});
|
||||
|
|
@ -2648,7 +2655,49 @@ function pointPopup(p) {
|
|||
.slice(0, 8)
|
||||
.forEach(k => add(k, extra[k]));
|
||||
}
|
||||
return `<div class="cam-pop"><b>${esc(p.label || p.id)}</b>${badge}<table>${rows.join('')}</table></div>`;
|
||||
let photoBlock = '';
|
||||
if (src === 'adsb.lol' && (extra.hex || extra.reg)) {
|
||||
photoBlock = `<div class="ps-photo" data-hex="${esc(extra.hex || '')}" data-reg="${esc(extra.reg || '')}"></div>`;
|
||||
}
|
||||
return `<div class="cam-pop"><b>${esc(p.label || p.id)}</b>${badge}<table>${rows.join('')}</table>${photoBlock}</div>`;
|
||||
}
|
||||
|
||||
/* ── Planespotters.net aircraft photos ────────────────────────────────────
|
||||
Lazy-loaded into the ADS-B popup. Server-side endpoint (/api/aircraft/photo)
|
||||
proxies the JSON (planespotters 403s any Origin-bearing request, which every
|
||||
browser fetch() sends), but the thumbnail binary is always loaded by the
|
||||
browser straight from the planespotters CDN — never re-hosted. */
|
||||
function loadPlanePhoto(root) {
|
||||
if (!root) return;
|
||||
root.querySelectorAll('.ps-photo').forEach(box => {
|
||||
if (box.dataset.loaded === '1' || box.dataset.loading === '1') return;
|
||||
const hex = (box.dataset.hex || '').trim();
|
||||
const reg = (box.dataset.reg || '').trim();
|
||||
if (!hex && !reg) { box.remove(); return; }
|
||||
box.dataset.loading = '1';
|
||||
box.innerHTML = `<div class="ps-loading">photo…</div>`;
|
||||
const q = hex ? `hex=${encodeURIComponent(hex)}` : `reg=${encodeURIComponent(reg)}`;
|
||||
fetch(`${API}/api/aircraft/photo?${q}`, { headers: { 'Accept': 'application/json' } })
|
||||
.then(r => {
|
||||
if (r.status === 404) throw new Error('none');
|
||||
if (!r.ok) throw new Error('http ' + r.status);
|
||||
return r.json();
|
||||
})
|
||||
.then(ph => {
|
||||
if (!ph || !ph.src) { box.remove(); return; }
|
||||
const link = esc(ph.link || '');
|
||||
const alt = `Photo of ${esc(reg || hex)}`;
|
||||
const credit = ph.photographer ? `© ${esc(ph.photographer)}` : '';
|
||||
box.dataset.loaded = '1';
|
||||
box.innerHTML =
|
||||
`<a class="ps-link" href="${link}" target="_blank" rel="noopener">` +
|
||||
`<img class="ps-thumb" src="${esc(ph.src)}" alt="${alt}" loading="lazy"` +
|
||||
(ph.width ? ` width="${esc(ph.width)}"` : '') +
|
||||
(ph.height ? ` height="${esc(ph.height)}"` : '') + `></a>` +
|
||||
(credit ? `<div class="ps-credit"><a href="${link}" target="_blank" rel="noopener">${credit}</a></div>` : '');
|
||||
})
|
||||
.catch(() => { box.remove(); });
|
||||
});
|
||||
}
|
||||
|
||||
/* ── Heading-aware live-feed glyph markers ───────────────────────────────
|
||||
|
|
|
|||
Loading…
Reference in a new issue