Precompute run analysis and serve compact route previews
This commit is contained in:
@@ -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: '© <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);
|
||||
|
||||
Reference in New Issue
Block a user