diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-11-16 14:50:07 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-11-16 14:50:07 +0100 |
commit | 45f747961e14c5f63e895cdda97a830c5837a118 (patch) | |
tree | cf5e3c76a6f848d8d600ce190cf8ceaf4fa52f39 | |
parent | 0bfb71d78d1a7996fe0fb32af063ccfdc6ceea15 (diff) |
map: add station names to points
-rwxr-xr-x | lib/Travelynx/Controller/Traveling.pm | 2 | ||||
-rw-r--r-- | templates/map.html.ep | 13 |
2 files changed, 9 insertions, 6 deletions
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index a3d5e67..3c4a8d7 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -431,7 +431,7 @@ sub map_history { push( @stations, uniq map { $_->{from_name} } @journeys ); @stations = uniq @stations; my @station_coordinates - = map { $location{$_} } grep { exists $location{$_} } @stations; + = map { [ $location{$_}, $_ ] } grep { exists $location{$_} } @stations; my @uniq_by_route = uniq_by { join( '|', map { $_->[0] } @{ $_->{route} } ) diff --git a/templates/map.html.ep b/templates/map.html.ep index 1930e51..707b28e 100644 --- a/templates/map.html.ep +++ b/templates/map.html.ep @@ -14,7 +14,7 @@ L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { var stations = [ % for my $station ( @{stash('station_coordinates') // [] } ) { -[<%= $station->[0] %>,<%= $station->[1] %>], +[[<%= $station->[0][0] %>,<%= $station->[0][1] %>],'<%= $station->[1] %>'], % } ]; @@ -25,14 +25,17 @@ var routes = [ ]; for (var station_id in stations) { - L.circle(stations[station_id], { + L.circle(stations[station_id][0], { color: '#f03', fillColor: '#f03', fillOpacity: 0.5, - radius: 100 - }).addTo(map); + radius: 250 + }).bindPopup(stations[station_id][1]).addTo(map); } -L.polyline(routes, {color: '#f09', opacity: 0.5}).addTo(map); +var pl = L.polyline(routes, {color: '#f09', opacity: 0.5}).addTo(map); +if (routes.length) { + map.fitBounds(pl.getBounds()); +} </script> |