From b8eeebd24a20758a9f58247e8ba9c7228b920b02 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sat, 22 Mar 2025 21:50:04 +0100 Subject: Trip->polyline: provide Stop reference where appropriate, remove name/id --- lib/Travel/Status/DE/EFA/Trip.pm | 53 ++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/lib/Travel/Status/DE/EFA/Trip.pm b/lib/Travel/Status/DE/EFA/Trip.pm index 31938ec..8d6981d 100644 --- a/lib/Travel/Status/DE/EFA/Trip.pm +++ b/lib/Travel/Status/DE/EFA/Trip.pm @@ -54,18 +54,17 @@ sub polyline { return @{ $self->{polyline} }; } - if ( $opt{fallback} and not @{ $self->{polyline_raw} // [] } ) { - - # TODO add $_->{id} as well? - return map { - { - lat => $_->{latlon}[0], - lon => $_->{latlon}[1], - name => $_->name, - id_num => $_->id_num, - id_code => $_->id_code - } - } $self->route; + if ( not @{ $self->{polyline_raw} // [] } ) { + if ( $opt{fallback} ) { + return map { + { + lat => $_->{latlon}[0], + lon => $_->{latlon}[1], + stop => $_, + } + } $self->route; + } + return; } $self->{polyline} = [ map { { lat => $_->[0], lon => $_->[1] } } @@ -99,12 +98,8 @@ sub polyline { } for my $stop ( $self->route ) { if ( $min_dist{ $stop->{id_code} } ) { - $self->{polyline}[ $min_dist{ $stop->{id_code} }{index} ]{name} - = $stop->{name}; - $self->{polyline}[ $min_dist{ $stop->{id_code} }{index} ] - {id_num} = $stop->{id_num}; - $self->{polyline}[ $min_dist{ $stop->{id_code} }{index} ] - {id_code} = $stop->{id_code}; + $self->{polyline}[ $min_dist{ $stop->{id_code} }{index} ]{stop} + = $stop; } } } @@ -272,6 +267,28 @@ Note: The EFA API requires a stop to be specified when requesting trip details. The stops returned by this accessor appear to be limited to stops after the requested stop; earlier ones may be missing. +=item $journey->polyline(I<%opt>) + +List of geocoordinates that describe the trips's route. +Each list entry is a hash with the following keys. + +=over + +=item * lon (longitude) + +=item * lat (latitude) + +=item * stop (Stop object for this location, if any. undef otherwise) + +=back + +Note that stop is not provided by the backend and instead inferred by this +module. + +If the backend does not provide geocoordinates and this accessor was called +with B< fallback > set to a true value, it returns the list of stop coordinates +instead. Otherwise, it returns an empty list. + =back =head2 INTERNAL -- cgit v1.2.3