Ensure consistent time calculation across metric and imperial units
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
- Use
url: "../examples/tracks/very-long.gpx",in the demo. - Switch between imperial and metric units (
imperial: true/false).
Before this change:
imperial: trueshows a total time of3d 01:52'38".imperial: falseshows a total time of4d 22:53'38".
After this change:
imperial: trueshows a total time of4d 22:53'35".imperial: falseshows a total time of4d 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.