Initial commit: Breadcrumb GPS trip viewer
Go server receiving Colota location data into SQLite, with a trip-segmentation API and embedded web frontend for browsing trips on a map.
This commit is contained in:
commit
c41a2c5411
6 changed files with 1268 additions and 0 deletions
692
static/index.html
Normal file
692
static/index.html
Normal file
|
|
@ -0,0 +1,692 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Breadcrumb</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
|
||||
<style>
|
||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
:root {
|
||||
--page-bg: #1b1b1b;
|
||||
--section-bg: #2b2b2b;
|
||||
--header-bg: #3c3c3c;
|
||||
--input-bg: #111111;
|
||||
--border: #4a4a4a;
|
||||
--text: #f0f0f0;
|
||||
--text-dim: #a0a0a0;
|
||||
--link: #b4c7d9;
|
||||
--link-vis: #9b8fd4;
|
||||
--accent: #f2ac08;
|
||||
--danger: #c0392b;
|
||||
}
|
||||
|
||||
html, body { height: 100%; overflow: hidden; }
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--page-bg);
|
||||
color: var(--text);
|
||||
font-family: 'Open Sans', Verdana, sans-serif;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
a { color: var(--link); text-decoration: none; }
|
||||
a:visited { color: var(--link-vis); }
|
||||
a:hover { color: var(--accent); text-decoration: underline; }
|
||||
|
||||
/* ── Header ── */
|
||||
#header {
|
||||
background: #111;
|
||||
border-bottom: 2px solid #000;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
#header-inner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 5px 12px;
|
||||
}
|
||||
|
||||
#logo {
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
color: var(--accent);
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
|
||||
#logo em {
|
||||
font-style: normal;
|
||||
font-size: 11px;
|
||||
color: var(--text-dim);
|
||||
font-weight: 400;
|
||||
letter-spacing: 0;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
#header-count {
|
||||
font-size: 11px;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
|
||||
/* ── Layout: desktop side-by-side, mobile stacked ── */
|
||||
.layout {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
/* ── Sidebar ── */
|
||||
aside {
|
||||
width: 230px;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--section-bg);
|
||||
border-right: 1px solid var(--border);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Date navigator */
|
||||
#date-nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: var(--header-bg);
|
||||
border-bottom: 1px solid var(--border);
|
||||
flex-shrink: 0;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
#date-nav button {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--text-dim);
|
||||
font-size: 16px;
|
||||
padding: 4px 10px;
|
||||
cursor: pointer;
|
||||
line-height: 1;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
#date-nav button:hover { color: var(--accent); }
|
||||
#date-nav button:disabled { color: #555; cursor: default; }
|
||||
|
||||
#date-label {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
color: var(--text);
|
||||
cursor: pointer;
|
||||
padding: 5px 0;
|
||||
}
|
||||
#date-label:hover { color: var(--accent); }
|
||||
|
||||
#date-input {
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
}
|
||||
|
||||
/* Section header */
|
||||
.section-header {
|
||||
padding: 4px 8px;
|
||||
font-size: 10px;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: .06em;
|
||||
color: var(--text-dim);
|
||||
background: var(--header-bg);
|
||||
border-bottom: 1px solid var(--border);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
#trip-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
#trip-list::-webkit-scrollbar { width: 5px; }
|
||||
#trip-list::-webkit-scrollbar-track { background: transparent; }
|
||||
#trip-list::-webkit-scrollbar-thumb { background: var(--border); }
|
||||
|
||||
.trip-entry {
|
||||
padding: 6px 8px;
|
||||
cursor: pointer;
|
||||
border-bottom: 1px solid #333;
|
||||
}
|
||||
|
||||
.trip-entry:hover { background: #323232; }
|
||||
|
||||
.trip-entry.active {
|
||||
background: #1a1a2e;
|
||||
border-left: 3px solid var(--accent);
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
.trip-entry .trip-date { color: var(--accent); font-weight: 700; font-size: 11px; }
|
||||
.trip-entry .trip-time { color: var(--text-dim); font-size: 11px; }
|
||||
|
||||
.trip-entry .trip-tags {
|
||||
margin-top: 3px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
.ttag { font-size: 10px; white-space: nowrap; }
|
||||
.ttag-dur { color: #b4c7d9; }
|
||||
.ttag-dist { color: #00aa00; }
|
||||
.ttag-pts { color: #ffffff; }
|
||||
.ttag::before { content: attr(data-count) '\00a0'; color: var(--text-dim); }
|
||||
|
||||
.empty, .error {
|
||||
padding: 16px 8px;
|
||||
color: var(--text-dim);
|
||||
font-size: 11px;
|
||||
text-align: center;
|
||||
}
|
||||
.error { color: var(--danger); }
|
||||
|
||||
/* ── Map ── */
|
||||
.map-wrap {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
#map { position: absolute; inset: 0; }
|
||||
|
||||
.map-loading {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(17,17,17,.8);
|
||||
z-index: 1000;
|
||||
font-size: 12px;
|
||||
color: var(--text-dim);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* ── Token overlay ── */
|
||||
#token-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0,0,0,.85);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
#token-box {
|
||||
width: min(340px, 92vw);
|
||||
background: var(--section-bg);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
#token-box > header {
|
||||
background: var(--header-bg);
|
||||
padding: 5px 8px;
|
||||
font-weight: 700;
|
||||
font-size: 11px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: .05em;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
#token-box-body {
|
||||
padding: 14px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
#token-box p { font-size: 11px; color: var(--text-dim); }
|
||||
|
||||
#token-box input {
|
||||
background: var(--input-bg);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
padding: 6px 8px;
|
||||
width: 100%;
|
||||
outline: none;
|
||||
}
|
||||
#token-box input:focus { border-color: var(--accent); }
|
||||
|
||||
#token-box button {
|
||||
align-self: flex-start;
|
||||
background: var(--header-bg);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
font-family: inherit;
|
||||
font-size: 12px;
|
||||
padding: 5px 16px;
|
||||
cursor: pointer;
|
||||
}
|
||||
#token-box button:hover { background: var(--accent); color: #000; border-color: var(--accent); }
|
||||
|
||||
#token-err { color: var(--danger); font-size: 11px; display: none; }
|
||||
|
||||
/* ── Leaflet overrides ── */
|
||||
.leaflet-container { background: #111; font-family: 'Open Sans', Verdana, sans-serif; }
|
||||
.leaflet-control-zoom a { background: var(--section-bg) !important; color: var(--text) !important; border-color: var(--border) !important; }
|
||||
.leaflet-control-zoom a:hover { background: var(--header-bg) !important; color: var(--accent) !important; }
|
||||
.leaflet-control-attribution { background: rgba(17,17,17,.75) !important; color: var(--text-dim) !important; }
|
||||
.leaflet-control-attribution a { color: var(--link) !important; }
|
||||
.leaflet-popup-content-wrapper {
|
||||
background: var(--section-bg); color: var(--text);
|
||||
border: 1px solid var(--border); border-radius: 0;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,.6);
|
||||
font-size: 11px; font-family: 'Open Sans', Verdana, sans-serif;
|
||||
}
|
||||
.leaflet-popup-tip { background: var(--section-bg); }
|
||||
.leaflet-popup-content { margin: 8px 10px; }
|
||||
.leaflet-popup-content b { color: var(--accent); }
|
||||
|
||||
/* ── Points toggle ── */
|
||||
#pts-toggle {
|
||||
position: absolute;
|
||||
bottom: 12px;
|
||||
left: 12px;
|
||||
z-index: 900;
|
||||
background: var(--section-bg);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text-dim);
|
||||
font-family: 'Open Sans', Verdana, sans-serif;
|
||||
font-size: 11px;
|
||||
line-height: 1.3;
|
||||
padding: 4px 6px;
|
||||
cursor: pointer;
|
||||
display: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
#pts-toggle:hover { color: var(--accent); border-color: var(--accent); }
|
||||
#pts-toggle.on { color: var(--accent); border-color: var(--accent); background: #1a1a00; }
|
||||
|
||||
/* ── Mobile ── */
|
||||
@media (max-width: 640px) {
|
||||
html, body { overflow: hidden; }
|
||||
|
||||
.layout { flex-direction: column; }
|
||||
|
||||
aside {
|
||||
width: 100%;
|
||||
flex-shrink: 0;
|
||||
max-height: 44vh;
|
||||
border-right: none;
|
||||
border-bottom: 2px solid var(--border);
|
||||
}
|
||||
|
||||
/* horizontal scroll trip list on mobile */
|
||||
#trip-list {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
#trip-list::-webkit-scrollbar { height: 4px; }
|
||||
|
||||
.trip-entry {
|
||||
flex-shrink: 0;
|
||||
width: 160px;
|
||||
border-bottom: none;
|
||||
border-right: 1px solid #333;
|
||||
padding: 8px 10px;
|
||||
}
|
||||
|
||||
.trip-entry.active {
|
||||
border-left: none;
|
||||
border-top: 3px solid var(--accent);
|
||||
padding-left: 10px;
|
||||
padding-top: 5px;
|
||||
}
|
||||
|
||||
.map-wrap { flex: 1; min-height: 0; }
|
||||
|
||||
#logo font-size { font-size: 18px; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="header">
|
||||
<div id="header-inner">
|
||||
<div id="logo">breadcrumb <em>/ trips</em></div>
|
||||
<span id="header-count">loading…</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="token-overlay" style="display:none">
|
||||
<div id="token-box">
|
||||
<header>Authentication Required</header>
|
||||
<div id="token-box-body">
|
||||
<p>Enter your Bearer token to access this Colota instance.</p>
|
||||
<input id="token-input" type="password" placeholder="bearer token" autocomplete="current-password">
|
||||
<span id="token-err">» Invalid token — please try again.</span>
|
||||
<button id="token-submit">Login</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layout">
|
||||
<aside>
|
||||
<div id="date-nav">
|
||||
<button id="date-prev" title="Previous day">‹</button>
|
||||
<div id="date-label">—</div>
|
||||
<button id="date-next" title="Next day" disabled>›</button>
|
||||
<input type="date" id="date-input">
|
||||
</div>
|
||||
<div class="section-header">Trips</div>
|
||||
<div id="trip-list"><div class="empty">Loading…</div></div>
|
||||
</aside>
|
||||
|
||||
<div class="map-wrap">
|
||||
<div id="map"></div>
|
||||
<div class="map-loading" id="map-overlay" style="display:none">Loading track…</div>
|
||||
<button id="pts-toggle" title="Toggle GPS points">Show Points</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||
<script>
|
||||
(function () {
|
||||
const STORAGE_KEY = 'colota_token';
|
||||
let token = localStorage.getItem(STORAGE_KEY) || '';
|
||||
|
||||
class AuthError extends Error {}
|
||||
|
||||
async function apiFetch(url) {
|
||||
const headers = token ? { 'Authorization': 'Bearer ' + token } : {};
|
||||
const res = await fetch(url, { headers });
|
||||
if (res.status === 401) throw new AuthError();
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
function showTokenOverlay(invalid = false) {
|
||||
document.getElementById('token-overlay').style.display = 'flex';
|
||||
document.getElementById('token-err').style.display = invalid ? 'block' : 'none';
|
||||
setTimeout(() => document.getElementById('token-input').focus(), 50);
|
||||
}
|
||||
|
||||
function hideTokenOverlay() {
|
||||
document.getElementById('token-overlay').style.display = 'none';
|
||||
}
|
||||
|
||||
document.getElementById('token-submit').addEventListener('click', async () => {
|
||||
const val = document.getElementById('token-input').value.trim();
|
||||
const headers = val ? { 'Authorization': 'Bearer ' + val } : {};
|
||||
const res = await fetch('/api/trips', { headers });
|
||||
if (res.status === 401) { showTokenOverlay(true); return; }
|
||||
token = val;
|
||||
localStorage.setItem(STORAGE_KEY, token);
|
||||
hideTokenOverlay();
|
||||
loadTrips();
|
||||
});
|
||||
|
||||
document.getElementById('token-input').addEventListener('keydown', e => {
|
||||
if (e.key === 'Enter') document.getElementById('token-submit').click();
|
||||
});
|
||||
|
||||
// ── Date navigation ───────────────────────────────────────────────────────────
|
||||
let allTrips = [];
|
||||
let availableDates = []; // sorted array of 'YYYY-MM-DD' strings
|
||||
let selectedDateIdx = 0;
|
||||
|
||||
function localDateStr(tst) {
|
||||
const d = new Date(tst * 1000);
|
||||
return d.getFullYear() + '-' +
|
||||
String(d.getMonth() + 1).padStart(2, '0') + '-' +
|
||||
String(d.getDate()).padStart(2, '0');
|
||||
}
|
||||
|
||||
function prettyDate(ymd) {
|
||||
const [y, m, d] = ymd.split('-').map(Number);
|
||||
return new Date(y, m - 1, d).toLocaleDateString(undefined, {
|
||||
weekday: 'short', day: 'numeric', month: 'short', year: 'numeric'
|
||||
});
|
||||
}
|
||||
|
||||
function updateDateNav() {
|
||||
const ymd = availableDates[selectedDateIdx];
|
||||
document.getElementById('date-label').textContent = prettyDate(ymd);
|
||||
document.getElementById('date-prev').disabled = selectedDateIdx >= availableDates.length - 1;
|
||||
document.getElementById('date-next').disabled = selectedDateIdx <= 0;
|
||||
}
|
||||
|
||||
document.getElementById('date-prev').addEventListener('click', () => {
|
||||
if (selectedDateIdx < availableDates.length - 1) {
|
||||
selectedDateIdx++;
|
||||
updateDateNav();
|
||||
renderTripList();
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('date-next').addEventListener('click', () => {
|
||||
if (selectedDateIdx > 0) {
|
||||
selectedDateIdx--;
|
||||
updateDateNav();
|
||||
renderTripList();
|
||||
}
|
||||
});
|
||||
|
||||
// clicking the date label opens a native date picker
|
||||
document.getElementById('date-label').addEventListener('click', () => {
|
||||
const inp = document.getElementById('date-input');
|
||||
inp.value = availableDates[selectedDateIdx];
|
||||
inp.style.position = 'absolute';
|
||||
inp.style.opacity = '0';
|
||||
inp.style.pointerEvents = 'auto';
|
||||
inp.focus();
|
||||
inp.showPicker?.();
|
||||
});
|
||||
|
||||
document.getElementById('date-input').addEventListener('change', (e) => {
|
||||
const val = e.target.value;
|
||||
const idx = availableDates.indexOf(val);
|
||||
if (idx !== -1) {
|
||||
selectedDateIdx = idx;
|
||||
updateDateNav();
|
||||
renderTripList();
|
||||
}
|
||||
e.target.style.pointerEvents = 'none';
|
||||
});
|
||||
|
||||
// ── Map ───────────────────────────────────────────────────────────────────────
|
||||
const map = L.map('map', { zoomControl: true }).setView([20, 0], 2);
|
||||
|
||||
L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png', {
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="https://carto.com/">CARTO</a>',
|
||||
maxZoom: 19
|
||||
}).addTo(map);
|
||||
|
||||
let trackLayer = null, markerStart = null, markerEnd = null, pointsLayer = null;
|
||||
let showPoints = false;
|
||||
let lastSorted = [];
|
||||
|
||||
const ptsToggleBtn = document.getElementById('pts-toggle');
|
||||
|
||||
function renderPoints() {
|
||||
if (pointsLayer) { map.removeLayer(pointsLayer); pointsLayer = null; }
|
||||
if (!showPoints || lastSorted.length === 0) return;
|
||||
pointsLayer = L.layerGroup(
|
||||
lastSorted.map(r => L.circleMarker([r.lat, r.lon], {
|
||||
radius: 3,
|
||||
color: '#f2ac08',
|
||||
fillColor: '#f2ac08',
|
||||
fillOpacity: 0.8,
|
||||
weight: 0,
|
||||
}).bindPopup(`${fmtTime(r.tst)}${r.acc != null ? '<br><span style="color:var(--text-dim)">acc ' + Math.round(r.acc) + 'm</span>' : ''}`))
|
||||
).addTo(map);
|
||||
}
|
||||
|
||||
ptsToggleBtn.addEventListener('click', () => {
|
||||
showPoints = !showPoints;
|
||||
ptsToggleBtn.classList.toggle('on', showPoints);
|
||||
renderPoints();
|
||||
});
|
||||
|
||||
function fmtTime(tst) {
|
||||
return new Date(tst * 1000).toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' });
|
||||
}
|
||||
function fmtDuration(s, e) {
|
||||
const sec = Math.round(e - s);
|
||||
const h = Math.floor(sec / 3600), m = Math.floor((sec % 3600) / 60);
|
||||
return h > 0 ? `${h}h_${m}m` : `${m}m`;
|
||||
}
|
||||
function fmtDist(km) {
|
||||
return km < 1 ? `${Math.round(km * 1000)}m` : `${km.toFixed(1)}km`;
|
||||
}
|
||||
|
||||
// ── Load all trips, then group by date ───────────────────────────────────────
|
||||
async function loadTrips() {
|
||||
const list = document.getElementById('trip-list');
|
||||
const headerCount = document.getElementById('header-count');
|
||||
list.innerHTML = '<div class="empty">Loading…</div>';
|
||||
|
||||
try {
|
||||
allTrips = await apiFetch('/api/trips');
|
||||
} catch (e) {
|
||||
if (e instanceof AuthError) { showTokenOverlay(!!token); return; }
|
||||
list.innerHTML = `<div class="error">Error: ${e.message}</div>`;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!allTrips || allTrips.length === 0) {
|
||||
list.innerHTML = '<div class="empty">No trips recorded yet.</div>';
|
||||
headerCount.textContent = '0 trips';
|
||||
document.getElementById('date-label').textContent = 'No data';
|
||||
return;
|
||||
}
|
||||
|
||||
headerCount.textContent = `${allTrips.length} trip${allTrips.length === 1 ? '' : 's'}`;
|
||||
|
||||
// Build sorted unique date list (newest first)
|
||||
const dateSet = new Set(allTrips.map(t => localDateStr(t.start_tst)));
|
||||
availableDates = [...dateSet].sort((a, b) => b.localeCompare(a));
|
||||
selectedDateIdx = 0;
|
||||
|
||||
updateDateNav();
|
||||
renderTripList();
|
||||
}
|
||||
|
||||
function renderTripList() {
|
||||
const list = document.getElementById('trip-list');
|
||||
const ymd = availableDates[selectedDateIdx];
|
||||
const filtered = allTrips.filter(t => localDateStr(t.start_tst) === ymd).reverse();
|
||||
|
||||
list.innerHTML = '';
|
||||
|
||||
if (filtered.length === 0) {
|
||||
list.innerHTML = '<div class="empty">No trips on this date.</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
filtered.forEach((trip) => {
|
||||
const el = document.createElement('div');
|
||||
el.className = 'trip-entry';
|
||||
el.innerHTML = `
|
||||
<div class="trip-time">${fmtTime(trip.start_tst)} – ${fmtTime(trip.end_tst)}</div>
|
||||
<div class="trip-tags">
|
||||
<span class="ttag ttag-dur" data-count="${fmtDuration(trip.start_tst, trip.end_tst)}">duration</span>
|
||||
<span class="ttag ttag-dist" data-count="${fmtDist(trip.distance_km)}">distance</span>
|
||||
<span class="ttag ttag-pts" data-count="${trip.point_count}">points</span>
|
||||
</div>`;
|
||||
el.addEventListener('click', () => selectTrip(trip, el));
|
||||
list.appendChild(el);
|
||||
});
|
||||
|
||||
selectTrip(filtered[0], list.firstElementChild);
|
||||
}
|
||||
|
||||
// ── Draw trip ─────────────────────────────────────────────────────────────────
|
||||
async function selectTrip(trip, el) {
|
||||
document.querySelectorAll('.trip-entry').forEach(e => e.classList.remove('active'));
|
||||
el.classList.add('active');
|
||||
|
||||
const overlay = document.getElementById('map-overlay');
|
||||
overlay.style.display = 'flex';
|
||||
|
||||
if (trackLayer) { map.removeLayer(trackLayer); trackLayer = null; }
|
||||
if (markerStart) { map.removeLayer(markerStart); markerStart = null; }
|
||||
if (markerEnd) { map.removeLayer(markerEnd); markerEnd = null; }
|
||||
if (pointsLayer) { map.removeLayer(pointsLayer); pointsLayer = null; }
|
||||
lastSorted = [];
|
||||
ptsToggleBtn.style.display = 'none';
|
||||
|
||||
let allRecords = [];
|
||||
try {
|
||||
const pageSize = 50000;
|
||||
let page = 1, total = Infinity;
|
||||
while (allRecords.length < total) {
|
||||
const data = await apiFetch(
|
||||
`/api/locations?from=${trip.start_tst}&to=${trip.end_tst}&limit=${pageSize}&page=${page}`
|
||||
);
|
||||
total = data.total;
|
||||
allRecords.push(...(data.records || []));
|
||||
if (allRecords.length >= total) break;
|
||||
page++;
|
||||
}
|
||||
} catch (e) {
|
||||
overlay.style.display = 'none';
|
||||
if (e instanceof AuthError) { showTokenOverlay(true); return; }
|
||||
alert(`Failed to load track: ${e.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
overlay.style.display = 'none';
|
||||
|
||||
const sorted = allRecords.slice().sort((a, b) => a.tst - b.tst);
|
||||
lastSorted = sorted;
|
||||
const pts = sorted.map(r => [r.lat, r.lon]);
|
||||
if (pts.length === 0) return;
|
||||
ptsToggleBtn.style.display = 'block';
|
||||
renderPoints();
|
||||
|
||||
trackLayer = L.polyline(pts, {
|
||||
color: '#f2ac08', weight: 3, opacity: 0.9,
|
||||
lineJoin: 'round', lineCap: 'round'
|
||||
}).addTo(map);
|
||||
|
||||
const dotIcon = (color) => L.divIcon({
|
||||
className: '',
|
||||
html: `<div style="width:10px;height:10px;border-radius:50%;background:${color};border:2px solid #111;box-shadow:0 1px 4px rgba(0,0,0,.7)"></div>`,
|
||||
iconSize: [10, 10], iconAnchor: [5, 5]
|
||||
});
|
||||
|
||||
const first = sorted[0], last = sorted[sorted.length - 1];
|
||||
|
||||
markerStart = L.marker([first.lat, first.lon], { icon: dotIcon('#00aa00') })
|
||||
.addTo(map).bindPopup(`<b>start</b><br>${fmtTime(first.tst)}`);
|
||||
|
||||
markerEnd = L.marker([last.lat, last.lon], { icon: dotIcon('#c0392b') })
|
||||
.addTo(map).bindPopup(`<b>end</b><br>${fmtTime(last.tst)}`);
|
||||
|
||||
map.fitBounds(trackLayer.getBounds(), { padding: [48, 48] });
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
showTokenOverlay(false);
|
||||
} else {
|
||||
loadTrips();
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue