summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-01-05 18:37:55 +0100
committerDaniel Friesel <derf@finalrewind.org>2020-01-05 18:37:55 +0100
commitdaad7cff7f39609f61e39a641a8928f56443d106 (patch)
tree0e167f18c0ce6a8c420e8cfac9bd61ab93343a84
parentc6a7909fd5814ab768db5dfa8e9fea2e92525362 (diff)
map: show current / next stop name, arrival/departure time and platform2.5.7
-rw-r--r--lib/DBInfoscreen/Controller/Map.pm50
-rw-r--r--templates/route_map.html.ep60
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 @@
-<div class="container" style="margin-top: 1ex; margin-bottom: 1ex;">
-Fahrt von <strong><%= $origin->{name} %></strong>
-nach <strong><%= $destination->{name} %></strong>
-</div>
+% if ($origin and $destination) {
+ <div class="container" style="margin-top: 1ex; margin-bottom: 1ex;">
+ Fahrt
+ % if (stash('train_no')) {
+ <strong><%= stash('train_no') %></strong>
+ % }
+ von <strong><%= $origin->{name} %></strong>
+ nach <strong><%= $destination->{name} %></strong>
+ % if (my $next = stash('next_stop')) {
+ <br/>
+ % if ($next->{type} eq 'present' and $next->{station}{dep} and $next->{station}{arr}) {
+ Aufenthalt in <strong><%= $next->{station}{name} %></strong>
+ an Gleis <strong><%= $next->{station}{platform} %></strong>
+ bis <strong><%= $next->{station}{dep}->strftime('%H:%M') %></strong>
+ % if ($next->{station}{dep_delay}) {
+ %= sprintf('(%+d)', $next->{station}{dep_delay})
+ % }
+ % }
+ % if ($next->{type} eq 'present' and $next->{station}{dep}) {
+ Abfahrt in <strong><%= $next->{station}{name} %></strong>
+ von Gleis <strong><%= $next->{station}{platform} %></strong>
+ um <strong><%= $next->{station}{dep}->strftime('%H:%M') %></strong>
+ % if ($next->{station}{dep_delay}) {
+ %= sprintf('(%+d)', $next->{station}{dep_delay})
+ % }
+ % }
+ % elsif ($next->{type} eq 'present' and $next->{station}{arr}) {
+ Endstation erreicht um
+ <strong><%= $next->{station}{arr}->strftime('%H:%M') %></strong>
+ auf Gleis <strong><%= $next->{station}{platform} %></strong>
+ % if ($next->{station}{arr_delay}) {
+ %= sprintf('(%+d)', $next->{station}{arr_delay})
+ % }
+ % }
+ % elsif ($next->{type} eq 'present') {
+ Zug steht in
+ <strong><%= $next->{station}{arr}->strftime('%H:%M') %></strong>
+ auf Gleis <strong><%= $next->{station}{platform} %></strong>
+ % }
+ % elsif ($next->{type} eq 'next' and $next->{station}{arr}) {
+ Nächster Halt:
+ <strong><%= $next->{station}{name} %></strong>
+ um <strong><%= $next->{station}{arr}->strftime('%H:%M') %></strong>
+ % if ($next->{station}{arr_delay}) {
+ %= sprintf('(%+d)', $next->{station}{arr_delay})
+ % }
+ auf Gleis <strong><%= $next->{station}{platform} %></strong>
+ % }
+ % elsif ($next->{type} eq 'next') {
+ Nächster Halt:
+ <strong><%= $next->{station}{name} %></strong>
+ auf Gleis <strong><%= $next->{station}{platform} %></strong>
+ % }
+ % }
+ </div>
+% }
<div class="container">
<div id="map" style="height: 500px;">