From a3c31ace061ba8fc90c972cea52f6610e8cbf62c Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Mon, 7 Sep 2026 12:38:30 +0200 Subject: [PATCH] Show track properties (distance, elevation gain, duration) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Maptool::TrackStats computes these once, shared by Gpx and Fit so both track feature shapes carry the same properties regardless of source format. Hovering a track line (not clicking — these describe the whole line, not one point) shows them in a popup, same mechanism GPX waypoints already use. --- docs/architecture.adoc | 17 ++++++++++ lib/maptool/fit.rb | 44 ++++++++++++++----------- lib/maptool/gpx.rb | 21 ++++++++++-- lib/maptool/track_stats.rb | 66 ++++++++++++++++++++++++++++++++++++++ public/js/gpx.js | 45 ++++++++++++++++++++++++++ 5 files changed, 172 insertions(+), 21 deletions(-) create mode 100644 lib/maptool/track_stats.rb diff --git a/docs/architecture.adoc b/docs/architecture.adoc index 40e25e2..408c206 100644 --- a/docs/architecture.adoc +++ b/docs/architecture.adoc @@ -233,6 +233,23 @@ assembling any HTML; the URL pattern excludes quote characters, so a matched URL can never break out of the `href="..."` attribute. Every other value is HTML-escaped before being handed to `Popup#setHTML`. +Track properties:: Every track feature (both formats) also carries +`distance_meters`, `elevation_gain_meters`, `duration_secs` and +`point_count`, computed once server-side by `Maptool::TrackStats` +(`lib/maptool/track_stats.rb`, shared by `Gpx`/`Fit` so neither +duplicates the haversine formula) rather than in the browser — cheap +either way, but it means a GPX and a FIT file end up with the same +properties shape, so the frontend doesn't need to know which format it +got. Distance sums the haversine distance between consecutive points; +elevation gain sums only the positive deltas (descents don't +subtract); duration is the gap between the first and last known +timestamp, skipping unknown ones in between — `nil` for any of these +where the source data doesn't have enough to compute it (e.g. a GPX +file with no `