Precompute run analysis and serve compact route previews

This commit is contained in:
Peter Stockings
2026-10-02 14:19:47 +10:00
parent 2d7069c12d
commit 6bfab483d4
13 changed files with 518 additions and 56 deletions
+7 -2
View File
@@ -19,7 +19,7 @@ async function showDashboardRoute() {
const data = await response.json();
const segments = data.segments.filter(segment => segment.length);
if (!segments.length) { status.textContent = "No GPS route recorded for this run."; return; }
const map = L.map(container, {scrollWheelZoom: false});
const map = L.map(container, {scrollWheelZoom: false, preferCanvas: true});
L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: 19, attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
}).addTo(map);
@@ -48,7 +48,12 @@ async function showDashboardRoute() {
if (previous !== null) elapsed += now - previous;
previous = now;
const distance = ((elapsed % 20000) / 20000) * length;
const edge = edges.find(edge => edge.end >= distance) || edges.at(-1);
let low = 0, high = edges.length - 1;
while (low < high) {
const mid = Math.floor((low + high) / 2);
if (edges[mid].end < distance) low = mid + 1; else high = mid;
}
const edge = edges[low];
const fraction = (distance - edge.start) / (edge.end - edge.start);
runner.setLatLng([edge.a.lat + (edge.b.lat-edge.a.lat)*fraction, edge.a.lng + (edge.b.lng-edge.a.lng)*fraction]);
frame = requestAnimationFrame(tick);