From daad7cff7f39609f61e39a641a8928f56443d106 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 5 Jan 2020 18:37:55 +0100 Subject: map: show current / next stop name, arrival/departure time and platform --- lib/DBInfoscreen/Controller/Map.pm | 50 ++++++++++++++++++++++--------- templates/route_map.html.ep | 60 +++++++++++++++++++++++++++++++++++--- 2 files changed, 92 insertions(+), 18 deletions(-) diff --git a/lib/DBInfoscreen/Controller/Map.pm b/lib/DBInfoscreen/Controller/Map.pm index ccffa04..70b2644 100644 --- a/lib/DBInfoscreen/Controller/Map.pm +++ b/lib/DBInfoscreen/Controller/Map.pm @@ -80,6 +80,7 @@ sub route { my @route; my @markers; + my $next_stop; my $now = DateTime->now( time_zone => 'Europe/Berlin' ); my $strp = DateTime::Format::Strptime->new( @@ -149,6 +150,7 @@ sub route { dep => $dep, arr_delay => $arr_delay, dep_delay => $dep_delay, + platform => $platform, } ); @@ -177,30 +179,30 @@ sub route { my $geo = Geo::Distance->new; my ( $from_index, $to_index ); - for my $i ( 0 .. $#{ $pl->{raw}{polyline}{features} } ) { - my $this_point = $pl->{raw}{polyline}{features}[$i]; + for my $j ( 0 .. $#{ $pl->{raw}{polyline}{features} } ) { + my $this_point = $pl->{raw}{polyline}{features}[$j]; if ( not defined $from_index and $this_point->{properties}{type} and $this_point->{properties}{type} eq 'stop' and $this_point->{properties}{name} eq $from_name ) { - $from_index = $i; + $from_index = $j; } elsif ( $this_point->{properties}{type} and $this_point->{properties}{type} eq 'stop' and $this_point->{properties}{name} eq $to_name ) { - $to_index = $i; + $to_index = $j; last; } } if ( $from_index and $to_index ) { my $total_distance = 0; - for my $i ( $from_index + 1 .. $to_index ) { - my $prev = $pl->{raw}{polyline}{features}[ $i - 1 ] + for my $j ( $from_index + 1 .. $to_index ) { + my $prev = $pl->{raw}{polyline}{features}[ $j - 1 ] {geometry}{coordinates}; my $this - = $pl->{raw}{polyline}{features}[$i]{geometry} + = $pl->{raw}{polyline}{features}[$j]{geometry} {coordinates}; if ( $prev and $this ) { $total_distance += $geo->distance( @@ -212,11 +214,11 @@ sub route { my $marker_distance = $total_distance * $route_part_completion_ratio; $total_distance = 0; - for my $i ( $from_index + 1 .. $to_index ) { - my $prev = $pl->{raw}{polyline}{features}[ $i - 1 ] + for my $j ( $from_index + 1 .. $to_index ) { + my $prev = $pl->{raw}{polyline}{features}[ $j - 1 ] {geometry}{coordinates}; my $this - = $pl->{raw}{polyline}{features}[$i]{geometry} + = $pl->{raw}{polyline}{features}[$j]{geometry} {coordinates}; if ( $prev and $this ) { $total_distance += $geo->distance( @@ -233,6 +235,10 @@ sub route { title => $title } ); + $next_stop = { + type => 'next', + station => $route[$i], + }; last; } } @@ -252,6 +258,10 @@ sub route { title => $title } ); + $next_stop = { + type => 'next', + station => $route[$i], + }; } last; } @@ -268,6 +278,10 @@ sub route { title => $title } ); + $next_stop = { + type => 'present', + station => $route[ $i - 1 ], + }; last; } } @@ -280,6 +294,10 @@ sub route { title => $route[-1]{name} . ' - Endstation', } ); + $next_stop = { + type => 'present', + station => $route[-1] + }; } $self->render( @@ -299,6 +317,8 @@ sub route { ? scalar $strp->parse_datetime( $pl->{raw}{arrival} ) : undef, }, + train_no => scalar $pl->{raw}{line}{additionalName}, + next_stop => $next_stop, polyline_groups => [ { polylines => [@line_pairs], @@ -316,10 +336,12 @@ sub route { my ($err) = @_; $self->render( 'route_map', - title => "DBF", - hide_opts => 1, - with_map => 1, - error => $err, + title => "DBF", + hide_opts => 1, + with_map => 1, + error => $err, + origin => undef, + destination => undef, ); } diff --git a/templates/route_map.html.ep b/templates/route_map.html.ep index 4b38fc4..e8473a5 100644 --- a/templates/route_map.html.ep +++ b/templates/route_map.html.ep @@ -1,7 +1,59 @@ -
-Fahrt von <%= $origin->{name} %> -nach <%= $destination->{name} %> -
+% if ($origin and $destination) { +
+ Fahrt + % if (stash('train_no')) { + <%= stash('train_no') %> + % } + von <%= $origin->{name} %> + nach <%= $destination->{name} %> + % if (my $next = stash('next_stop')) { +
+ % if ($next->{type} eq 'present' and $next->{station}{dep} and $next->{station}{arr}) { + Aufenthalt in <%= $next->{station}{name} %> + an Gleis <%= $next->{station}{platform} %> + bis <%= $next->{station}{dep}->strftime('%H:%M') %> + % if ($next->{station}{dep_delay}) { + %= sprintf('(%+d)', $next->{station}{dep_delay}) + % } + % } + % if ($next->{type} eq 'present' and $next->{station}{dep}) { + Abfahrt in <%= $next->{station}{name} %> + von Gleis <%= $next->{station}{platform} %> + um <%= $next->{station}{dep}->strftime('%H:%M') %> + % if ($next->{station}{dep_delay}) { + %= sprintf('(%+d)', $next->{station}{dep_delay}) + % } + % } + % elsif ($next->{type} eq 'present' and $next->{station}{arr}) { + Endstation erreicht um + <%= $next->{station}{arr}->strftime('%H:%M') %> + auf Gleis <%= $next->{station}{platform} %> + % if ($next->{station}{arr_delay}) { + %= sprintf('(%+d)', $next->{station}{arr_delay}) + % } + % } + % elsif ($next->{type} eq 'present') { + Zug steht in + <%= $next->{station}{arr}->strftime('%H:%M') %> + auf Gleis <%= $next->{station}{platform} %> + % } + % elsif ($next->{type} eq 'next' and $next->{station}{arr}) { + Nächster Halt: + <%= $next->{station}{name} %> + um <%= $next->{station}{arr}->strftime('%H:%M') %> + % if ($next->{station}{arr_delay}) { + %= sprintf('(%+d)', $next->{station}{arr_delay}) + % } + auf Gleis <%= $next->{station}{platform} %> + % } + % elsif ($next->{type} eq 'next') { + Nächster Halt: + <%= $next->{station}{name} %> + auf Gleis <%= $next->{station}{platform} %> + % } + % } +
+% }
-- cgit v1.2.3