Files
2026-05-31 16:07:30 +02:00

209 lines
8.1 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ISS Tracker — Live Position Feed</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<link href="https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Orbitron:wght@400;700&display=swap" rel="stylesheet" />
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #050d1a;
--panel: #091628;
--border: #0d3a6e;
--accent: #00d4ff;
--accent2: #ff6b35;
--green: #39ff14;
--text: #c8e6ff;
--dim: #4a7aa0;
--font-mono: 'Share Tech Mono', monospace;
--font-disp: 'Orbitron', sans-serif;
}
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font-mono); overflow: hidden; }
#app { display: grid; grid-template-rows: 56px 1fr; height: 100vh; }
header {
display: flex; align-items: center; gap: 16px;
padding: 0 20px;
background: var(--panel);
border-bottom: 1px solid var(--border);
position: relative; z-index: 1000;
}
.logo { font-family: var(--font-disp); font-size: 15px; letter-spacing: 3px; color: var(--accent); white-space: nowrap; }
.logo span { color: var(--accent2); }
.status-bar { display: flex; gap: 24px; align-items: center; font-size: 11px; color: var(--dim); flex: 1; }
.stat { display: flex; flex-direction: column; gap: 1px; }
.stat-label { font-size: 9px; letter-spacing: 2px; color: var(--dim); text-transform: uppercase; }
.stat-value { color: var(--accent); font-size: 12px; }
#ping-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); margin-left: auto; transition: background .3s; }
#ping-dot.live { background: var(--green); box-shadow: 0 0 8px var(--green); animation: pulse 2s infinite; }
#ping-dot.error { background: var(--accent2); box-shadow: 0 0 8px var(--accent2); }
@keyframes pulse { 0%,100% { opacity:1 } 50% { opacity:.4 } }
#map { width: 100%; height: 100%; background: #020a14; }
.leaflet-tile { filter: brightness(.7) saturate(1.4) hue-rotate(190deg); }
.leaflet-container { background: #020a14; }
.leaflet-control-zoom a { background: var(--panel); color: var(--accent); border-color: var(--border); }
.leaflet-control-zoom a:hover { background: var(--border); }
.leaflet-control-attribution { background: rgba(5,13,26,.8) !important; color: var(--dim) !important; font-size: 9px; }
.leaflet-control-attribution a { color: var(--dim) !important; }
#toast {
position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
background: var(--panel); border: 1px solid var(--border);
color: var(--accent2); font-size: 12px; padding: 8px 20px;
border-radius: 2px; z-index: 9999; opacity: 0; transition: opacity .4s;
pointer-events: none;
}
#toast.show { opacity: 1; }
.iss-ring {
width: 24px; height: 24px; border-radius: 50%;
border: 2px solid var(--accent);
animation: sonar 1.5s ease-out infinite;
position: absolute; top: -4px; left: -4px;
}
@keyframes sonar { 0% { transform: scale(1); opacity:1 } 100% { transform: scale(2.5); opacity:0 } }
</style>
</head>
<body>
<div id="app">
<header>
<div class="logo">ISS/<span>TRACKER</span></div>
<div class="status-bar">
<div class="stat"><span class="stat-label">Points</span><span class="stat-value" id="s-count"></span></div>
<div class="stat"><span class="stat-label">Latitude</span><span class="stat-value" id="s-lat"></span></div>
<div class="stat"><span class="stat-label">Longitude</span><span class="stat-value" id="s-lon"></span></div>
<div class="stat"><span class="stat-label">Last seen</span><span class="stat-value" id="s-ts"></span></div>
<div class="stat"><span class="stat-label">Refresh</span><span class="stat-value" id="s-refresh">10s</span></div>
</div>
<div id="ping-dot" title="Connection status"></div>
</header>
<div id="map"></div>
</div>
<div id="toast"></div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
const CRATEDB_URL = window.CRATEDB_URL || '/cratedb';
const REFRESH_MS = parseInt(window.REFRESH_MS || '10000', 10);
const TRAIL_LIMIT = parseInt(window.TRAIL_LIMIT || '1000', 10);
const SQL = `
SELECT "timestamp", "position"
FROM "doc"."iss"
ORDER BY "timestamp" DESC
LIMIT ${TRAIL_LIMIT}
`;
const map = L.map('map', { center: [20, 0], zoom: 2 });
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors', maxZoom: 18,
}).addTo(map);
const trail = L.polyline([], {
color: '#00d4ff', weight: 1.5, opacity: 0.5, dashArray: '4 6',
}).addTo(map);
const ghostLayer = L.layerGroup().addTo(map);
const issIcon = L.divIcon({
className: '',
html: `<div style="width:16px;height:16px;border-radius:50%;background:#ff6b35;border:2px solid #fff;box-shadow:0 0 12px #ff6b35, 0 0 24px #ff6b35;position:relative;z-index:2"></div><div class="iss-ring"></div>`,
iconSize: [16, 16], iconAnchor: [8, 8],
});
const issMarker = L.marker([0, 0], { icon: issIcon, zIndexOffset: 1000 }).addTo(map);
function parseWKT(position) {
if (!position) return null;
// CrateDB returns position as [lon, lat] array
if (Array.isArray(position)) {
return { lon: position[0], lat: position[1] };
}
// fallback: WKT string
const m = typeof position === 'string' && position.match(/POINT\s*\(\s*([-\d.]+)\s+([-\d.]+)\s*\)/i);
if (!m) return null;
return { lon: parseFloat(m[1]), lat: parseFloat(m[2]) };
}
const dot = document.getElementById('ping-dot');
const toast = document.getElementById('toast');
let toastTimer;
function showToast(msg, isError = false) {
toast.textContent = msg;
toast.style.borderColor = isError ? 'var(--accent2)' : 'var(--border)';
toast.classList.add('show');
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove('show'), 3500);
}
function updateHeader(rows) {
document.getElementById('s-count').textContent = rows.length;
if (!rows.length) return;
const pt = parseWKT(rows[0][1]);
if (pt) {
document.getElementById('s-lat').textContent = pt.lat.toFixed(4) + '°';
document.getElementById('s-lon').textContent = pt.lon.toFixed(4) + '°';
}
const ts = rows[0][0];
document.getElementById('s-ts').textContent = ts
? new Date(ts).toUTCString().replace(/.*,\s*/, '').replace(' GMT', ' UTC') : '—';
}
async function fetchPositions() {
const res = await fetch(`${CRATEDB_URL}/_sql`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ stmt: SQL }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const json = await res.json();
return json.rows || [];
}
let firstLoad = true;
async function refresh() {
try {
const rows = await fetchPositions();
dot.className = 'live';
const points = rows.map(r => parseWKT(r[1])).filter(Boolean);
ghostLayer.clearLayers();
points.slice(1).forEach((pt, i) => {
const age = i / Math.max(points.length, 1);
L.circleMarker([pt.lat, pt.lon], {
radius: 2 + (1 - age) * 2,
color: '#00d4ff', fillColor: '#00d4ff',
fillOpacity: 0.15 + (1 - age) * 0.45, weight: 0,
}).addTo(ghostLayer);
});
trail.setLatLngs([...points].reverse().map(p => [p.lat, p.lon]));
if (points.length > 0) {
const latest = points[0];
issMarker.setLatLng([latest.lat, latest.lon]);
issMarker.bindPopup(`<div style="font-family:monospace;font-size:12px;color:#ff6b35"><b>ISS — Live</b><br>Lat: ${latest.lat.toFixed(4)}°<br>Lon: ${latest.lon.toFixed(4)}°</div>`);
if (firstLoad) { map.setView([latest.lat, latest.lon], 3); firstLoad = false; }
}
updateHeader(rows);
} catch (err) {
dot.className = 'error';
showToast(`CrateDB error: ${err.message}`, true);
}
}
document.getElementById('s-refresh').textContent = (REFRESH_MS / 1000) + 's';
refresh();
setInterval(refresh, REFRESH_MS);
</script>
</body>
</html>