summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-08-17 10:00:37 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2025-08-17 10:00:37 +0200
commitf6d9d738e1067397cc62485e76f2beeac85b914f (patch)
treea20cd096e38df2b7f12c02158dfd701d94b9dfa1 /lib
parente97f7892a6d1a74e729dc676fb90db8afc408db5 (diff)
Journey: Add JSON and GPX export of polylines
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Travelynx.pm7
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm26
2 files changed, 33 insertions, 0 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index 607b153..586f1a0 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -69,6 +69,8 @@ sub startup {
$self->types->type( csv => 'text/csv; charset=utf-8' );
$self->types->type( json => 'application/json; charset=utf-8' );
+ $self->types->type( gpx => 'application/gpx+xml; charset=utf-8' );
+ $self->types->type( xml => 'text/xml; charset=utf-8' );
$self->plugin('Config');
@@ -3174,6 +3176,11 @@ sub startup {
$authed_r->get( '/journey/:id' => [ format => [ 'html', 'json' ] ] )
->to( 'traveling#journey_details', format => undef )
->name('journey');
+ $authed_r->get( '/polyline/:id' => [ format => [ 'gpx', 'json' ] ] )->to(
+ 'traveling#journey_details',
+ format => undef,
+ polyline_export => 1
+ )->name('polyline_download');
$authed_r->get('/s/*station')->to('traveling#station');
$authed_r->get('/confirm_mail/:token')->to('account#confirm_mail');
$authed_r->post('/account/privacy')->to('account#privacy');
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm
index e23301e..084b45e 100755
--- a/lib/Travelynx/Controller/Traveling.pm
+++ b/lib/Travelynx/Controller/Traveling.pm
@@ -2149,6 +2149,32 @@ sub journey_details {
);
if ($journey) {
+
+ if ( $self->stash('polyline_export') ) {
+ delete $self->stash->{layout};
+ my $xml = $self->render_to_string(
+ template => 'polyline',
+ name => sprintf( '%s %s: %s → %s',
+ $journey->{type}, $journey->{no},
+ $journey->{from_name}, $journey->{to_name} ),
+ polyline => $journey->{polyline}
+ );
+ $self->respond_to(
+ gpx => {
+ text => $xml,
+ format => 'gpx'
+ },
+ json => {
+ json => [
+ map {
+ $_->[2] ? [ $_->[0], $_->[1], int( $_->[2] ) ] : $_
+ } @{ $journey->{polyline} }
+ ]
+ },
+ );
+ return;
+ }
+
my $map_data = $self->journeys_to_map_data(
journeys => [$journey],
include_manual => 1,