summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-03-22 21:50:04 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2025-03-22 21:50:04 +0100
commitb8eeebd24a20758a9f58247e8ba9c7228b920b02 (patch)
treeec3aa5f7e4e6653f6fedc7425468ee7e83f5d326
parente896cdbf310ae63f2a03ed9e6ec58e0fbb4bacd9 (diff)
Trip->polyline: provide Stop reference where appropriate, remove name/id
-rw-r--r--lib/Travel/Status/DE/EFA/Trip.pm53
1 files 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