From f384cfc0fe0d4d91740c571e95523b703be73278 Mon Sep 17 00:00:00 2001 From: Kumi Date: Mon, 14 Oct 2024 22:04:40 +0200 Subject: [PATCH] feat: display total travel distance in map view Added calculation and display of total distance traveled in the travel map history view. This enhancement provides users with a quick overview of the cumulative distance covered during their journeys. The addition is beneficial for users tracking their travel metrics for personal or record-keeping purposes. --- lib/Travelynx/Controller/Traveling.pm | 9 +++++++++ templates/history_map.html.ep | 3 +++ 2 files changed, 12 insertions(+) diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index 3151d42..b990cc7 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -1342,6 +1342,7 @@ sub map_history { with_polyline => $with_polyline, after => $filter_from, before => $filter_until, + verbose => 1 ); if ($filter_type) { @@ -1357,12 +1358,19 @@ sub map_history { skipped_journeys => [], station_coordinates => [], polyline_groups => [], + distance_traveled => 0, ); return; } my $include_manual = $self->param('include_manual') ? 1 : 0; + my $total_distance = 0; + + for my $journey (@journeys) { + $total_distance += $journey->{km_route} // 0; + } + my $res = $self->journeys_to_map_data( journeys => \@journeys, route_type => $route_type, @@ -1374,6 +1382,7 @@ sub map_history { year => $year, with_map => 1, title => 'travelynx: Karte', + total_distance => $total_distance, %{$res} ); } diff --git a/templates/history_map.html.ep b/templates/history_map.html.ep index 57ba81f..3232b4c 100644 --- a/templates/history_map.html.ep +++ b/templates/history_map.html.ep @@ -33,6 +33,9 @@ %= include '_map', station_coordinates => $station_coordinates, polyline_groups => $polyline_groups %= form_for '/history/map' => begin +

+ Gesamtdistanz: <%= sprintf("%.2f", $total_distance // 0) %> km +

Detailgrad: