From 465c131a6324c4c1d151d82829384652e1740238 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Tue, 20 Aug 2024 19:44:51 +0200 Subject: Backend selection: add coverage maps --- lib/DBInfoscreen.pm | 1 + lib/DBInfoscreen/Controller/Map.pm | 22 ++++++++++++++- lib/DBInfoscreen/Controller/Stationboard.pm | 42 ++++++++++++++++++++++++++--- lib/DBInfoscreen/Helper/HAFAS.pm | 12 +++++++++ 4 files changed, 73 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/DBInfoscreen.pm b/lib/DBInfoscreen.pm index fd1aaf8..d5ed88f 100644 --- a/lib/DBInfoscreen.pm +++ b/lib/DBInfoscreen.pm @@ -318,6 +318,7 @@ sub startup { $r->get('/_ajax_mapinfo/:tripid/:lineno')->to('map#ajax_route'); $r->get('/map/:tripid/:lineno')->to('map#route'); + $r->get('/coverage/:backend/:service')->to('map#coverage'); $r->get( '/z/:train/*station' => [ format => [ 'html', 'json' ] ] ) ->to( 'stationboard#station_train_details', format => undef ) ->name('train_at_station'); diff --git a/lib/DBInfoscreen/Controller/Map.pm b/lib/DBInfoscreen/Controller/Map.pm index ef19324..f3f3f16 100644 --- a/lib/DBInfoscreen/Controller/Map.pm +++ b/lib/DBInfoscreen/Controller/Map.pm @@ -5,7 +5,7 @@ package DBInfoscreen::Controller::Map; # SPDX-License-Identifier: AGPL-3.0-or-later use Mojo::Base 'Mojolicious::Controller'; -use Mojo::JSON qw(decode_json); +use Mojo::JSON qw(decode_json encode_json); use Mojo::Promise; use DateTime; @@ -535,4 +535,24 @@ sub ajax_route { )->wait; } +sub coverage { + my ($self) = @_; + my $backend = $self->stash('backend'); + my $service = $self->stash('service'); + + my $coverage = {}; + + if ( $backend eq 'HAFAS' ) { + $coverage = $self->hafas->get_coverage($service); + } + + $self->render( + 'coverage_map', + title => "Abdeckung $service", + hide_opts => 1, + with_map => 1, + coverage => encode_json($coverage), + ); +} + 1; diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index caa2ef0..4f3d152 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -2166,6 +2166,36 @@ sub stations_by_coordinates { sub backend_list { my ($self) = @_; + my %place_map = ( + AT => 'Österreich', + CH => 'Schweiz', + 'CH-BE' => 'Kanton Bern', + 'CH-GE' => 'Kanton Genf', + 'CH-LU' => 'Kanton Luzern', + 'CH-ZH' => 'Kanton Zürich', + DE => 'Deutschland', + 'DE-BB' => 'Brandenburg', + 'DE-BW' => 'Baden-Württemberg', + 'DE-BE' => 'Berlin', + 'DE-BY' => 'Bayern', + 'DE-HB' => 'Bremen', + 'DE-HE' => 'Hessen', + 'DE-MV' => 'Mecklenburg-Vorpommern', + 'DE-NI' => 'Niedersachsen', + 'DE-NW' => 'Nordrhein-Westfalen', + 'DE-RP' => 'Rheinland-Pfalz', + 'DE-SH' => 'Schleswig-Holstein', + 'DE-ST' => 'Sachsen-Anhalt', + 'DE-TH' => 'Thüringen', + DK => 'Dänemark', + 'GB-NIR' => 'Nordirland', + LI => 'Litauen', + LU => 'Luxembourg', + IE => 'Irland', + 'US-CA' => 'California', + 'US-TX' => 'Texas', + ); + my @backends = ( { name => 'Deutsche Bahn', @@ -2179,14 +2209,20 @@ sub backend_list { { name => $backend->{name}, shortname => $backend->{shortname}, - type => 'HAFAS', - hafas => 1, + homepage => $backend->{homepage}, + regions => [ + map { $place_map{$_} // $_ } + @{ $backend->{coverage}{regions} } + ], + has_area => $backend->{coverage}{area} ? 1 : 0, + type => 'HAFAS', + hafas => 1, } ); } $self->render( - '_backend', + 'select_backend', backends => \@backends, hide_opts => 1 ); diff --git a/lib/DBInfoscreen/Helper/HAFAS.pm b/lib/DBInfoscreen/Helper/HAFAS.pm index a55f03f..0400d59 100644 --- a/lib/DBInfoscreen/Helper/HAFAS.pm +++ b/lib/DBInfoscreen/Helper/HAFAS.pm @@ -28,6 +28,18 @@ sub new { } +sub get_coverage { + my ( $self, $service ) = @_; + + my $service_definition = Travel::Status::DE::HAFAS::get_service($service); + + if ( not $service_definition ) { + return {}; + } + + return $service_definition->{coverage}{area} // {}; +} + sub get_route_p { my ( $self, %opt ) = @_; -- cgit v1.2.3