Loading lib/DBInfoscreen/Controller/Map.pm +56 −11 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ use Mojo::Base 'Mojolicious::Controller'; use Mojo::JSON qw(decode_json); use Mojo::Promise; use Encode qw(decode); use DateTime::Format::Strptime; my $dbf_version = qx{git describe --dirty} || 'experimental'; Loading @@ -31,8 +31,7 @@ sub get_hafas_polyline_p { ->then( sub { my ($tx) = @_; my $body = decode( 'utf-8', $tx->res->body ); my $json = decode_json($body); my $json = decode_json( $tx->res->body ); my @coordinate_list; for my $feature ( @{ $json->{polyline}{features} } ) { Loading @@ -48,7 +47,7 @@ sub get_hafas_polyline_p { my $ret = { name => $json->{line}{name} // '?', polyline => [@coordinate_list], stopovers => $json->{stopovers}, raw => $json, }; $cache->freeze( $url, $ret ); Loading Loading @@ -79,6 +78,11 @@ sub route { my @line_pairs; my @station_coordinates; my $strp = DateTime::Format::Strptime->new( pattern => '%Y-%m-%dT%H:%M:%S.000%z', time_zone => 'Europe/Berlin', ); for my $i ( 1 .. $#polyline ) { push( @line_pairs, Loading @@ -89,7 +93,40 @@ sub route { ); } for my $stop ( @{ $pl->{stopovers} // [] } ) { for my $stop ( @{ $pl->{raw}{stopovers} // [] } ) { my @stop_lines = ( $stop->{stop}{name} ); my $platform; if ( $stop->{arrival} and my $arrival = $strp->parse_datetime( $stop->{arrival} ) ) { my $delay = $stop->{arrivalDelay} // 0; $platform //= $stop->{arrivalPlatform}; my $arr_line = $arrival->strftime('Ankunft: %H:%M'); if ($delay) { $arr_line .= sprintf( ' (%+d)', $delay / 60 ); } push( @stop_lines, $arr_line ); } if ( $stop->{departure} and my $departure = $strp->parse_datetime( $stop->{departure} ) ) { my $delay = $stop->{departureDelay} // 0; $platform //= $stop->{departurePlatform}; my $dep_line = $departure->strftime('Abfahrt: %H:%M'); if ($delay) { $dep_line .= sprintf( ' (%+d)', $delay / 60 ); } push( @stop_lines, $dep_line ); } if ($platform) { splice( @stop_lines, 1, 0, "Gleis $platform" ); } push( @station_coordinates, [ Loading @@ -97,7 +134,7 @@ sub route { $stop->{stop}{location}{latitude}, $stop->{stop}{location}{longitude} ], $stop->{stop}{name} [@stop_lines], ] ); } Loading @@ -107,6 +144,14 @@ sub route { title => $pl->{name}, hide_opts => 1, with_map => 1, origin => { name => $pl->{raw}{origin}{name}, ts => $strp->parse_datetime( $pl->{raw}{departure} ), }, destination => { name => $pl->{raw}{destination}{name}, ts => $strp->parse_datetime( $pl->{raw}{arrival} ), }, polyline_groups => [ { polylines => \@line_pairs, Loading templates/route_map.html.ep +8 −3 Original line number Diff line number Diff line <div class="container" style="margin-top: 1ex; margin-bottom: 1ex;"> Fahrt von <strong><%= $origin->{name} %></strong> nach <strong><%= $destination->{name} %></strong> </div> <div class="container"> <div id="map" style="height: 500px;"> </div> Loading @@ -11,7 +16,7 @@ L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { }).addTo(map); var stations = [ % for my $station ( @{stash('station_coordinates') // [] } ) { [[<%= $station->[0][0] %>,<%= $station->[0][1] %>],'<%= $station->[1] %>'], [[<%= $station->[0][0] %>,<%= $station->[0][1] %>],['<%== join("','", map { Mojo::Util::xml_escape($_) } @{$station->[1]}) %>']], % } ]; Loading @@ -38,7 +43,7 @@ for (var station_id in stations) { fillColor: '#f03', fillOpacity: 0.5, radius: 250 }).bindPopup(stations[station_id][1]).addTo(map); }).bindPopup(stations[station_id][1].join('<br/>')).addTo(map); } </script> Loading
lib/DBInfoscreen/Controller/Map.pm +56 −11 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ use Mojo::Base 'Mojolicious::Controller'; use Mojo::JSON qw(decode_json); use Mojo::Promise; use Encode qw(decode); use DateTime::Format::Strptime; my $dbf_version = qx{git describe --dirty} || 'experimental'; Loading @@ -31,8 +31,7 @@ sub get_hafas_polyline_p { ->then( sub { my ($tx) = @_; my $body = decode( 'utf-8', $tx->res->body ); my $json = decode_json($body); my $json = decode_json( $tx->res->body ); my @coordinate_list; for my $feature ( @{ $json->{polyline}{features} } ) { Loading @@ -48,7 +47,7 @@ sub get_hafas_polyline_p { my $ret = { name => $json->{line}{name} // '?', polyline => [@coordinate_list], stopovers => $json->{stopovers}, raw => $json, }; $cache->freeze( $url, $ret ); Loading Loading @@ -79,6 +78,11 @@ sub route { my @line_pairs; my @station_coordinates; my $strp = DateTime::Format::Strptime->new( pattern => '%Y-%m-%dT%H:%M:%S.000%z', time_zone => 'Europe/Berlin', ); for my $i ( 1 .. $#polyline ) { push( @line_pairs, Loading @@ -89,7 +93,40 @@ sub route { ); } for my $stop ( @{ $pl->{stopovers} // [] } ) { for my $stop ( @{ $pl->{raw}{stopovers} // [] } ) { my @stop_lines = ( $stop->{stop}{name} ); my $platform; if ( $stop->{arrival} and my $arrival = $strp->parse_datetime( $stop->{arrival} ) ) { my $delay = $stop->{arrivalDelay} // 0; $platform //= $stop->{arrivalPlatform}; my $arr_line = $arrival->strftime('Ankunft: %H:%M'); if ($delay) { $arr_line .= sprintf( ' (%+d)', $delay / 60 ); } push( @stop_lines, $arr_line ); } if ( $stop->{departure} and my $departure = $strp->parse_datetime( $stop->{departure} ) ) { my $delay = $stop->{departureDelay} // 0; $platform //= $stop->{departurePlatform}; my $dep_line = $departure->strftime('Abfahrt: %H:%M'); if ($delay) { $dep_line .= sprintf( ' (%+d)', $delay / 60 ); } push( @stop_lines, $dep_line ); } if ($platform) { splice( @stop_lines, 1, 0, "Gleis $platform" ); } push( @station_coordinates, [ Loading @@ -97,7 +134,7 @@ sub route { $stop->{stop}{location}{latitude}, $stop->{stop}{location}{longitude} ], $stop->{stop}{name} [@stop_lines], ] ); } Loading @@ -107,6 +144,14 @@ sub route { title => $pl->{name}, hide_opts => 1, with_map => 1, origin => { name => $pl->{raw}{origin}{name}, ts => $strp->parse_datetime( $pl->{raw}{departure} ), }, destination => { name => $pl->{raw}{destination}{name}, ts => $strp->parse_datetime( $pl->{raw}{arrival} ), }, polyline_groups => [ { polylines => \@line_pairs, Loading
templates/route_map.html.ep +8 −3 Original line number Diff line number Diff line <div class="container" style="margin-top: 1ex; margin-bottom: 1ex;"> Fahrt von <strong><%= $origin->{name} %></strong> nach <strong><%= $destination->{name} %></strong> </div> <div class="container"> <div id="map" style="height: 500px;"> </div> Loading @@ -11,7 +16,7 @@ L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { }).addTo(map); var stations = [ % for my $station ( @{stash('station_coordinates') // [] } ) { [[<%= $station->[0][0] %>,<%= $station->[0][1] %>],'<%= $station->[1] %>'], [[<%= $station->[0][0] %>,<%= $station->[0][1] %>],['<%== join("','", map { Mojo::Util::xml_escape($_) } @{$station->[1]}) %>']], % } ]; Loading @@ -38,7 +43,7 @@ for (var station_id in stations) { fillColor: '#f03', fillOpacity: 0.5, radius: 250 }).bindPopup(stations[station_id][1]).addTo(map); }).bindPopup(stations[station_id][1].join('<br/>')).addTo(map); } </script>