Commit 7ed47bec authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

map: decrease stop circle size when stops are close together

parent 9d0af20c
Loading
Loading
Loading
Loading
+25 −9
Original line number Diff line number Diff line
@@ -224,7 +224,7 @@ sub estimate_train_positions {

# Input:
#   now: DateTime
#   route: hash
#   route: arrayref of hashrefs
#     lat: float
#     lon: float
#     name: str
@@ -241,9 +241,13 @@ sub estimate_train_positions2 {

	my @train_positions;
	my $next_stop;
	my $geo                    = Geo::Distance->new;
	my $stop_distance_sum      = 0;
	my $avg_inter_stop_beeline = 0;

	for my $i ( 1 .. $#route ) {
		if (    ( $route[$i]{arr} // $route[$i]{dep} )
		if (    not $next_stop
			and ( $route[$i]{arr} // $route[$i]{dep} )
			and ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} )
			and $now > ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} )
			and $now < ( $route[$i]{arr} // $route[$i]{dep} ) )
@@ -264,9 +268,9 @@ sub estimate_train_positions2 {
				type    => 'next',
				station => $route[$i],
			};
			last;
		}
		if ( ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} )
		if (    not $next_stop
			and ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} )
			and $now <= ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} ) )
		{
			@train_positions
@@ -275,8 +279,17 @@ sub estimate_train_positions2 {
				type    => 'present',
				station => $route[ $i - 1 ],
			};
			last;
		}
		$stop_distance_sum += $geo->distance(
			'meter',
			$route[ $i - 1 ]{lon},
			$route[ $i - 1 ]{lat},
			$route[$i]{lon}, $route[$i]{lat}
		);
	}

	if ($#route) {
		$avg_inter_stop_beeline = $stop_distance_sum / $#route;
	}

	if ( @route and not $next_stop ) {
@@ -291,6 +304,7 @@ sub estimate_train_positions2 {

	return {
		next_stop              => $next_stop,
		avg_inter_stop_beeline => $avg_inter_stop_beeline,
		position_now           => $position_now,
		positions              => \@train_positions,
	};
@@ -809,6 +823,8 @@ sub route {
					}
				],
				station_coordinates => [@station_coordinates],
				station_radius =>
				  ( $train_pos->{avg_inter_stop_beeline} > 500 ? 250 : 100 ),
				markers => [@markers],
			);
		}
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ for (var station_id in stations) {
		opacity: 0.7,
		fillColor: '#f03',
		fillOpacity: 0.5,
		radius: 250
		radius: <%= stash('station_radius') || 250 %>
	}).bindPopup(stations[station_id][1].join('<br/>')).addTo(map);
}