leaflet-elevation icon indicating copy to clipboard operation
leaflet-elevation copied to clipboard

Ensure consistent time calculation across metric and imperial units

Open aronsommer opened this issue 3 months ago • 1 comments

Description

This pull request fixes a bug where the total time calculation was dependent on the selected display units (metric vs. imperial), leading to incorrect results.

The root cause was that the distance increment (dx) was derived from this._data[i].dist, a value that changes based on the unit system. The fix ensures the distance is always calculated in meters using latlng.distanceTo() and then converted to kilometers, making the time calculation consistent regardless of the selected display units.

This change resolves the issue described in #300.


How to Test

  1. Use url: "../examples/tracks/very-long.gpx", in the demo.
  2. Switch between imperial and metric units (imperial: true/false).

Before this change:

  • imperial: true shows a total time of 3d 01:52'38".
  • imperial: false shows a total time of 4d 22:53'38".

After this change:

  • imperial: true shows a total time of 4d 22:53'35".
  • imperial: false shows a total time of 4d 22:53'35".

The results are now consistent.


Additional Observation

While using url: "../examples/tracks/only-few-points.gpx", I observed a separate issue. A mismatch occurs between the durata value in the tooltip and the value on the top time axis when hovering between data points. This happens because the tooltip's time only updates when the cursor is directly over a point, not continuously. This behavior may also contribute to the user confusion mentioned in #170.

aronsommer avatar Sep 18 '25 04:09 aronsommer