|
@@ -7,6 +7,7 @@ const Elevation = (() => {
|
|
|
let points = null; // full-res flat [{lat,lon,ele,time,dist}]
|
|
let points = null; // full-res flat [{lat,lon,ele,time,dist}]
|
|
|
let chartPts = null; // downsampled
|
|
let chartPts = null; // downsampled
|
|
|
let bounds = null; // computed after draw: {cw,ch,minE,eRange,totDist}
|
|
let bounds = null; // computed after draw: {cw,ch,minE,eRange,totDist}
|
|
|
|
|
+ let trackMeta = null; // {name, trackDate, ...} from the track's meta
|
|
|
|
|
|
|
|
// ===== Public API =====
|
|
// ===== Public API =====
|
|
|
|
|
|
|
@@ -19,15 +20,16 @@ const Elevation = (() => {
|
|
|
window.addEventListener('resize', () => { if (points) raf(draw); });
|
|
window.addEventListener('resize', () => { if (points) raf(draw); });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function setTrack(pts) {
|
|
|
|
|
- points = pts;
|
|
|
|
|
- chartPts = downsample(pts, CHART_MAX_PTS);
|
|
|
|
|
- bounds = null;
|
|
|
|
|
|
|
+ function setTrack(pts, meta) {
|
|
|
|
|
+ points = pts;
|
|
|
|
|
+ trackMeta = meta || null;
|
|
|
|
|
+ chartPts = downsample(pts, CHART_MAX_PTS);
|
|
|
|
|
+ bounds = null;
|
|
|
raf(draw);
|
|
raf(draw);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function clear() {
|
|
function clear() {
|
|
|
- points = chartPts = bounds = null;
|
|
|
|
|
|
|
+ points = chartPts = bounds = trackMeta = null;
|
|
|
hideTooltip();
|
|
hideTooltip();
|
|
|
if (canvas) {
|
|
if (canvas) {
|
|
|
canvas.width = canvas.width; // reset context
|
|
canvas.width = canvas.width; // reset context
|
|
@@ -49,11 +51,19 @@ const Elevation = (() => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Shared tooltip formatter used by MapView for the Leaflet map tooltip
|
|
// Shared tooltip formatter used by MapView for the Leaflet map tooltip
|
|
|
- function formatTooltip(p) {
|
|
|
|
|
|
|
+ function formatTooltip(p, meta) {
|
|
|
const dist = p.dist >= 1000
|
|
const dist = p.dist >= 1000
|
|
|
? (p.dist / 1000).toFixed(2) + ' km'
|
|
? (p.dist / 1000).toFixed(2) + ' km'
|
|
|
: Math.round(p.dist) + ' m';
|
|
: Math.round(p.dist) + ' m';
|
|
|
- let html = `<div><b>Dist:</b> ${dist}</div>`;
|
|
|
|
|
|
|
+ let html = '';
|
|
|
|
|
+ if (meta?.name) {
|
|
|
|
|
+ html += `<div style="font-weight:600;margin-bottom:2px">${escHtml(meta.name)}</div>`;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (meta?.trackDate) {
|
|
|
|
|
+ const d = new Date(meta.trackDate);
|
|
|
|
|
+ if (!isNaN(d)) html += `<div style="color:rgba(255,255,255,0.75);margin-bottom:4px">${d.toLocaleDateString()}</div>`;
|
|
|
|
|
+ }
|
|
|
|
|
+ html += `<div><b>Dist:</b> ${dist}</div>`;
|
|
|
if (p.ele != null) html += `<div><b>Ele:</b> ${Math.round(p.ele)} m</div>`;
|
|
if (p.ele != null) html += `<div><b>Ele:</b> ${Math.round(p.ele)} m</div>`;
|
|
|
if (p.time) {
|
|
if (p.time) {
|
|
|
const t = new Date(p.time);
|
|
const t = new Date(p.time);
|
|
@@ -242,7 +252,7 @@ const Elevation = (() => {
|
|
|
positionTooltip(chartPt, x, e.clientY - rect.top);
|
|
positionTooltip(chartPt, x, e.clientY - rect.top);
|
|
|
|
|
|
|
|
if (fullPt && typeof MapView !== 'undefined') {
|
|
if (fullPt && typeof MapView !== 'undefined') {
|
|
|
- MapView.showHoverMarker(fullPt.lat, fullPt.lon, fullPt);
|
|
|
|
|
|
|
+ MapView.showHoverMarker(fullPt.lat, fullPt.lon, fullPt, trackMeta);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -264,7 +274,7 @@ const Elevation = (() => {
|
|
|
|
|
|
|
|
function positionTooltip(point, cx, cy) {
|
|
function positionTooltip(point, cx, cy) {
|
|
|
if (!tooltip || !canvas) return;
|
|
if (!tooltip || !canvas) return;
|
|
|
- tooltip.innerHTML = formatTooltip(point);
|
|
|
|
|
|
|
+ tooltip.innerHTML = formatTooltip(point, trackMeta);
|
|
|
tooltip.classList.add('visible');
|
|
tooltip.classList.add('visible');
|
|
|
const cRect = canvas.getBoundingClientRect();
|
|
const cRect = canvas.getBoundingClientRect();
|
|
|
tooltip.style.left = Math.min(cx + 10, cRect.width - tooltip.offsetWidth - 4) + 'px';
|
|
tooltip.style.left = Math.min(cx + 10, cRect.width - tooltip.offsetWidth - 4) + 'px';
|