Ensure consistent time calculation across metric and imperial units #303
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

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 fromthis._data[i].dist, a value that changes based on the unit system. The fix ensures the distance is always calculated in meters usinglatlng.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
url: "../examples/tracks/very-long.gpx",in the demo.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 theduratavalue 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.