Unverified Commit f6d9d738 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Journey: Add JSON and GPX export of polylines

parent e97f7892
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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');
+26 −0
Original line number Diff line number Diff line
@@ -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,
+15 −0
Original line number Diff line number Diff line
@@ -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"

+44 −35
Original line number Diff line number Diff line
@@ -317,11 +317,24 @@
		</div>
	</div>
	% if (not stash('readonly')) {
		% if (stash('with_share')) {
		<div class="row">
				<div class="col s12 m6 l6">
			<div class="col s12 m6 l4 center-align">
				<a class="btn waves-effect waves-light" href="<%= url_for('journey', id => $journey->{id}, format => 'json' ) %>">
					<i class="material-icons left" aria-hidden="true">file_download</i>
					%= L('journey.export')
				</a>
			</div>
				<div class="col s12 m6 l6 center-align">
			<div class="col s12 m6 l4 center-align">
				%= form_for '/journey/edit' => (method => 'POST') => begin
					%= hidden_field 'journey_id' => param('journey_id')
					<button class="btn waves-effect waves-light" type="submit" name="action" value="edit">
						<i class="material-icons left" aria-hidden="true">edit</i>
						%= L('journey.edit')
					</button>
				%= end
			</div>
			<div class="col s12 m6 l4 center-align">
				% if (stash('with_share')) {
					<a class="btn waves-effect waves-light action-share"
						% if (stash('journey_visibility') eq 'public') {
							data-url="<%= url_for('public_journey', name => current_user()->{name}, id => $journey->{id} )->to_abs->scheme('https'); %>"
@@ -334,50 +347,46 @@
						<i class="material-icons left" aria-hidden="true">share</i>
						%= L('journey.share')
					</a>
				% }
			</div>
		</div>
		% }
		<h2><%= L('journey.map-data') %></h2>
		<div class="row">
			<div class="col s12 m6 l6">
			<div class="col s12 m6 l6 center-align">
				<a class="btn waves-effect waves-light" href="<%= url_for('polyline_download', id => $journey->{id}, format => 'json' ) %>">
					<i class="material-icons left" aria-label="<%= L('journey.map.download') %>">file_download</i>
					JSON
				</a>
			</div>
			<div class="col s12 m6 l6 center-align">
				<a class="btn waves-effect waves-light" href="<%= url_for('journey', id => $journey->{id}, format => 'json' ) %>">
					<i class="material-icons left" aria-hidden="true">file_download</i>
					%= L('journey.export')
				<a class="btn waves-effect waves-light" href="<%= url_for('polyline_download', id => $journey->{id}, format => 'gpx' ) %>">
					<i class="material-icons left" aria-label="<%= L('journey.map.download') %>">file_download</i>
					GPX
				</a>
			</div>
		</div>
		<div class="row hide-on-small-only">
		<div class="row">
			<div class="col s12 m6 l6 center-align">
				<a class="waves-effect waves-light red btn action-delete"
						data-id="<%= $journey->{id} %>"
						data-checkin="<%= $journey->{checkin}->epoch %>"
						data-checkout="<%= $journey->{checkout}->epoch %>">
					<i class="material-icons left">delete_forever</i>
					%= L('journey.delete')
				<a class="btn disabled waves-effect waves-light" href="<%= url_for('journey', id => $journey->{id}, format => 'json' ) %>">
					<i class="material-icons left" aria-label="<%= L('journey.map.upload') %>">file_upload</i>
					JSON
				</a>
			</div>
			<div class="col s12 m6 l6 center-align">
				%= form_for '/journey/edit' => (method => 'POST') => begin
					%= hidden_field 'journey_id' => param('journey_id')
					<button class="btn waves-effect waves-light" type="submit" name="action" value="edit">
						<i class="material-icons left" aria-hidden="true">edit</i>
						%= L('journey.edit')
					</button>
				%= end
				<a class="btn disabled waves-effect waves-light" href="<%= url_for('journey', id => $journey->{id}, format => 'json' ) %>">
					<i class="material-icons left" aria-label="<%= L('journey.map.upload') %>">file_upload</i>
					GPX
				</a>
			</div>
		</div>
		<div class="row hide-on-med-and-up">
			<div class="col s12 m6 l6 center-align">
				%= form_for '/journey/edit' => (method => 'POST') => begin
					%= hidden_field 'journey_id' => param('journey_id')
					<button class="btn waves-effect waves-light" type="submit" name="action" value="edit">
						<i class="material-icons left" aria-hidden="true">edit</i>
						%= L('journey.edit')
					</button>
				%= end
		<div class="row">
			<div class="col s12">
				%= L('journey.map.info')
			</div>
		</div>
			<div class="col s12 m6 l6 center-align" style="margin-top: 1em;">
		<h2><%= L('journey.danger') %></h2>
		<div class="row">
			<div class="col s12 m12 l12 center-align" style="margin-top: 1em;">
				<a class="waves-effect waves-light red btn action-delete"
						data-id="<%= $journey->{id} %>"
						data-checkin="<%= $journey->{checkin}->epoch %>"
+20 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<gpx
 xmlns="http://www.topografix.com/GPX/1/1"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
 version="1.1"
 creator="travelynx <%= $version %>">
 <trk>
  <name><%= $name %></name>
  <trkseg>
  % for my $entry (@{$polyline // []}) {
   <trkpt lon="<%= $entry->[0] %>" lat="<%= $entry->[1] %>">
   % if ($entry->[2]) {
     <name><%= $entry->[2] %></name>
   % }
   </trkpt>
  % }
  </trkseg>
 </trk>
</gpx>