Show station and airport icons on the map

This commit is contained in:
Edward Betts 2024-01-12 16:54:52 +00:00
parent 0c02d9c899
commit 4b8b1f7556
2 changed files with 45 additions and 17 deletions

View file

@ -3,7 +3,6 @@
"""Web page to show upcoming events."""
import inspect
import itertools
import operator
import os.path
import sys
@ -182,8 +181,8 @@ def load_trains() -> list[StrDict]:
for leg in train["legs"]:
assert leg["from"] in by_name
assert leg["to"] in by_name
leg["from_station"] = by_name[train["from"]]
leg["to_station"] = by_name[train["to"]]
leg["from_station"] = by_name[leg["from"]]
leg["to_station"] = by_name[leg["to"]]
return trains
@ -256,8 +255,8 @@ def trip_list() -> str:
)
def collect_station_coordinates(trip: Trip) -> list[tuple[float, float]]:
"""Extract and deduplicate station coordinates from trip."""
def collect_trip_coordinates(trip: Trip) -> list[StrDict]:
"""Extract and deduplicate airport and station coordinates from trip."""
stations = {}
station_list = []
airports = {}
@ -279,8 +278,21 @@ def collect_station_coordinates(trip: Trip) -> list[tuple[float, float]]:
stations[s["uic"]] = s
return [
(s["latitude"], s["longitude"])
for s in itertools.chain(stations.values(), airports.values())
{
"name": s["name"],
"type": "station",
"latitude": s["latitude"],
"longitude": s["longitude"],
}
for s in stations.values()
] + [
{
"name": s["name"],
"type": "airport",
"latitude": s["latitude"],
"longitude": s["longitude"],
}
for s in airports.values()
]
@ -295,13 +307,13 @@ def trip_page(start: str) -> str:
if not trip:
flask.abort(404)
station_coordinates = collect_station_coordinates(trip)
coordinates = collect_trip_coordinates(trip)
return flask.render_template(
"trip_page.html",
trip=trip,
today=today,
station_coordinates=station_coordinates,
coordinates=coordinates,
get_country=agenda.get_country,
format_list_with_ampersand=format_list_with_ampersand,
)