|
|
@@ -94,14 +94,16 @@ const Elevation = (() => {
|
|
|
}
|
|
|
|
|
|
function computeElevStats(pts) {
|
|
|
- let gain = 0, loss = 0, prev = null;
|
|
|
+ // Use hysteresis threshold to filter GPS elevation noise.
|
|
|
+ // Only count a direction change as real gain/loss once it exceeds THRESHOLD metres.
|
|
|
+ const THRESHOLD = 5;
|
|
|
+ let gain = 0, loss = 0, anchor = null;
|
|
|
for (const p of pts) {
|
|
|
if (p.ele == null) continue;
|
|
|
- if (prev != null) {
|
|
|
- const d = p.ele - prev;
|
|
|
- if (d > 0) gain += d; else loss -= d;
|
|
|
- }
|
|
|
- prev = p.ele;
|
|
|
+ if (anchor == null) { anchor = p.ele; continue; }
|
|
|
+ const d = p.ele - anchor;
|
|
|
+ if (d >= THRESHOLD) { gain += d; anchor = p.ele; }
|
|
|
+ else if (d <= -THRESHOLD) { loss -= d; anchor = p.ele; }
|
|
|
}
|
|
|
return { gain: Math.round(gain), loss: Math.round(loss) };
|
|
|
}
|
|
|
@@ -212,7 +214,7 @@ const Elevation = (() => {
|
|
|
ctx.font = '10px sans-serif';
|
|
|
ctx.textAlign = 'right';
|
|
|
ctx.fillStyle = 'rgba(120,120,120,0.9)';
|
|
|
- ctx.fillText(text, PAD.left + cw - 2, PAD.top + 10);
|
|
|
+ ctx.fillText(text, PAD.left + cw - 2, PAD.top - 4);
|
|
|
}
|
|
|
|
|
|
// Draw a vertical cursor + dot at the given point (CSS pixel coords)
|