From f6d9d738e1067397cc62485e76f2beeac85b914f Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 17 Aug 2025 10:00:37 +0200 Subject: Journey: Add JSON and GPX export of polylines --- lib/Travelynx.pm | 7 ++++ lib/Travelynx/Controller/Traveling.pm | 26 ++++++++++++ share/locales/en_GB.po | 15 +++++++ templates/journey.html.ep | 79 +++++++++++++++++++---------------- templates/polyline.gpx.ep | 20 +++++++++ 5 files changed, 112 insertions(+), 35 deletions(-) create mode 100644 templates/polyline.gpx.ep 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, diff --git a/share/locales/en_GB.po b/share/locales/en_GB.po index 6121045..48fb05a 100644 --- a/share/locales/en_GB.po +++ b/share/locales/en_GB.po @@ -270,6 +270,21 @@ msgstr "Export" msgid "journey.edit" msgstr "Edit" +msgid "journey.map-data" +msgstr "Map Data" + +msgid "journey.map.download" +msgstr "Download" + +msgid "journey.map.upload" +msgstr "Upload" + +msgid "journey.map.info" +msgstr "JSON format: [[lon, lat, station ID], ...], with lon/lat in WGS84 coordinates. GPX files are compatible with BRouter. Uploads may cover either the entire route or just the route segment that belongs to this checkin; station IDs are optional when uploading map data." + +msgid "journey.danger" +msgstr "Danger Zone" + msgid "journey.delete" msgstr "Delete" diff --git a/templates/journey.html.ep b/templates/journey.html.ep index f9c78ec..b7b4223 100644 --- a/templates/journey.html.ep +++ b/templates/journey.html.ep @@ -317,11 +317,24 @@ % if (not stash('readonly')) { - % if (stash('with_share')) { -
-
-
-
+
+ +
+ %= form_for '/journey/edit' => (method => 'POST') => begin + %= hidden_field 'journey_id' => param('journey_id') + + %= end +
+
+ % if (stash('with_share')) { -
+ % }
- % } +
+

<%= L('journey.map-data') %>

- -
+
- %= form_for '/journey/edit' => (method => 'POST') => begin - %= hidden_field 'journey_id' => param('journey_id') - - %= end + + file_upload + GPX +
-
-
- %= form_for '/journey/edit' => (method => 'POST') => begin - %= hidden_field 'journey_id' => param('journey_id') - - %= end +