summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-03-22 21:10:18 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2025-03-22 21:10:18 +0100
commit4f1cc8be5d05f1649623d01e9c407141b9b8acc3 (patch)
treeaa20d9307a4c0820a6fee1949816d127bfa8eacc
parent1f2949aa97df759fe46e6759ca024fd9bb9d87c7 (diff)
Trip: Fix polyline accessor. It never really worked.
-rw-r--r--lib/Travel/Status/DE/EFA/Trip.pm23
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/Travel/Status/DE/EFA/Trip.pm b/lib/Travel/Status/DE/EFA/Trip.pm
index deea901..6a50500 100644
--- a/lib/Travel/Status/DE/EFA/Trip.pm
+++ b/lib/Travel/Status/DE/EFA/Trip.pm
@@ -24,7 +24,7 @@ sub new {
operator => $json->{operator}{name},
product => $json->{product}{name},
product_class => $json->{product}{class},
- polyline => $json->{coords},
+ polyline_raw => $conf{json}{leg}{coords},
name => $json->{name},
line => $json->{disassembledName},
number => $json->{properties}{trainNumber},
@@ -39,8 +39,10 @@ sub new {
time_zone => 'UTC'
),
};
- if ( ref( $ref->{polyline} ) eq 'ARRAY' and @{ $ref->{polyline} } == 1 ) {
- $ref->{polyline} = $ref->{polyline}[0];
+ if ( ref( $ref->{polyline_raw} ) eq 'ARRAY'
+ and @{ $ref->{polyline_raw} } == 1 )
+ {
+ $ref->{polyline_raw} = $ref->{polyline_raw}[0];
}
return bless( $ref, $obj );
}
@@ -48,13 +50,22 @@ sub new {
sub polyline {
my ( $self, %opt ) = @_;
- if ( $opt{fallback} and not @{ $self->{polyline} // [] } ) {
+ if ( $self->{polyline} ) {
+ return @{ $self->{polyline} };
+ }
+
+ if ( $opt{fallback} and not @{ $self->{polyline_raw} // [] } ) {
# TODO add $_->{id} as well?
- return map { $_->{latlon} } $self->route;
+ return
+ map { { lat => $_->{latlon}[0], lon => $_->{latlon}[1] } }
+ $self->route;
}
- return @{ $self->{polyline} // [] };
+ $self->{polyline} = [ map { { lat => $_->[0], lon => $_->[1] } }
+ @{ $self->{polyline_raw} } ];
+
+ return @{ $self->{polyline} };
}
sub parse_dt {