map: set bounds on stations; move polyline feature to staging
This commit is contained in:
parent
6b1aa9cd39
commit
993f6be6c9
3 changed files with 84 additions and 9 deletions
|
@ -2785,6 +2785,10 @@ sub startup {
|
|||
# Otherwise, we grab a fresh one.
|
||||
my $db = $opt{db} // $self->pg->db;
|
||||
|
||||
my @select
|
||||
= (
|
||||
qw(journey_id train_type train_line train_no checkin_ts sched_dep_ts real_dep_ts dep_eva checkout_ts sched_arr_ts real_arr_ts arr_eva edited route messages user_data)
|
||||
);
|
||||
my %where = (
|
||||
user_id => $uid,
|
||||
cancelled => 0
|
||||
|
@ -2812,9 +2816,13 @@ sub startup {
|
|||
-between => [ $opt{after}->epoch, $opt{before}->epoch, ] };
|
||||
}
|
||||
|
||||
if ( $opt{with_polyline} ) {
|
||||
push( @select, 'polyline' );
|
||||
}
|
||||
|
||||
my @travels;
|
||||
|
||||
my $res = $db->select( 'journeys_str', '*', \%where, \%order );
|
||||
my $res = $db->select( 'journeys_str', \@select, \%where, \%order );
|
||||
|
||||
for my $entry ( $res->expand->hashes->each ) {
|
||||
|
||||
|
@ -2837,6 +2845,10 @@ sub startup {
|
|||
user_data => $entry->{user_data},
|
||||
};
|
||||
|
||||
if ( $opt{with_polyline} ) {
|
||||
$ref->{polyline} = $entry->{polyline};
|
||||
}
|
||||
|
||||
if ( my $station
|
||||
= $self->app->station_by_eva->{ $ref->{from_eva} } )
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@ use Mojo::Base 'Mojolicious::Controller';
|
|||
|
||||
use DateTime;
|
||||
use DateTime::Format::Strptime;
|
||||
use List::Util qw(uniq);
|
||||
use List::Util qw(uniq min max);
|
||||
use List::UtilsBy qw(uniq_by);
|
||||
use List::MoreUtils qw(first_index);
|
||||
use Travel::Status::DE::IRIS::Stations;
|
||||
|
@ -439,7 +439,9 @@ sub map_history {
|
|||
|
||||
my $location = $self->app->coordinates_by_station;
|
||||
|
||||
my @journeys = $self->get_user_travels;
|
||||
my $with_polyline = $self->param('poly') ? 1 : 0;
|
||||
|
||||
my @journeys = $self->get_user_travels( with_polyline => $with_polyline );
|
||||
|
||||
if ( not @journeys ) {
|
||||
$self->render(
|
||||
|
@ -464,11 +466,56 @@ sub map_history {
|
|||
grep { exists $location->{$_} } @stations;
|
||||
|
||||
my @station_pairs;
|
||||
my @coord_pairs;
|
||||
my %seen;
|
||||
|
||||
my @skipped_journeys;
|
||||
|
||||
for my $journey (@journeys) {
|
||||
for my $journey ( grep { $_->{polyline} } @journeys ) {
|
||||
my @polyline = @{ $journey->{polyline} };
|
||||
my $from_eva = $journey->{from_eva};
|
||||
my $to_eva = $journey->{to_eva};
|
||||
|
||||
my $from_index
|
||||
= first_index { $_->[2] and $_->[2] == $from_eva } @polyline;
|
||||
my $to_index = first_index { $_->[2] and $_->[2] == $to_eva } @polyline;
|
||||
|
||||
if ( $from_index == -1
|
||||
or $to_index == -1 )
|
||||
{
|
||||
# Fall back to route
|
||||
delete $journey->{polyline};
|
||||
next;
|
||||
}
|
||||
|
||||
my $key
|
||||
= $from_eva . '!' . $to_eva . '!' . $from_index . '!' . $to_index;
|
||||
|
||||
if ( $seen{$key} ) {
|
||||
next;
|
||||
}
|
||||
|
||||
$seen{$key} = 1;
|
||||
|
||||
# direction does not matter at the moment
|
||||
$key = $to_eva . '!' . $from_eva . '!' . $to_index . '!' . $from_index;
|
||||
$seen{$key} = 1;
|
||||
|
||||
@polyline = @polyline[ $from_index .. $to_index ];
|
||||
my $prev_coord = shift @polyline;
|
||||
for my $coord (@polyline) {
|
||||
push(
|
||||
@coord_pairs,
|
||||
[
|
||||
[ $prev_coord->[1], $prev_coord->[0] ],
|
||||
[ $coord->[1], $coord->[0] ]
|
||||
]
|
||||
);
|
||||
$prev_coord = $coord;
|
||||
}
|
||||
}
|
||||
|
||||
for my $journey ( grep { not $_->{polyline} } @journeys ) {
|
||||
|
||||
my @route = map { $_->[0] } @{ $journey->{route} };
|
||||
|
||||
|
@ -545,6 +592,13 @@ sub map_history {
|
|||
|
||||
my @routes;
|
||||
|
||||
my @lats = map { $_->[0][0] } @station_coordinates;
|
||||
my @lons = map { $_->[0][1] } @station_coordinates;
|
||||
my $min_lat = min @lats;
|
||||
my $max_lat = max @lats;
|
||||
my $min_lon = min @lons;
|
||||
my $max_lon = max @lons;
|
||||
|
||||
$self->render(
|
||||
template => 'history_map',
|
||||
with_map => 1,
|
||||
|
@ -554,10 +608,15 @@ sub map_history {
|
|||
{
|
||||
polylines => \@station_pairs,
|
||||
color => '#673ab7',
|
||||
opacity => 0.6,
|
||||
fit_bounds => 1,
|
||||
opacity => $with_polyline ? 0.4 : 0.6,
|
||||
},
|
||||
{
|
||||
polylines => \@coord_pairs,
|
||||
color => '#673ab7',
|
||||
opacity => 0.9,
|
||||
}
|
||||
]
|
||||
],
|
||||
bounds => [ [ $min_lat, $min_lon ], [ $max_lat, $max_lon ] ],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,10 @@ var pl;
|
|||
% }
|
||||
% }
|
||||
|
||||
% if (my $b = stash('bounds')) {
|
||||
map.fitBounds([[<%= $b->[0][0] %>,<%= $b->[0][1] %>],[<%= $b->[1][0] %>,<%= $b->[1][1] %>]]);
|
||||
% }
|
||||
|
||||
for (var station_id in stations) {
|
||||
L.circle(stations[station_id][0], {
|
||||
color: '#f03',
|
||||
|
|
Loading…
Reference in a new issue