diff --git a/templates/trip_page.html b/templates/trip_page.html index 43b9ed5..0ea5ac5 100644 --- a/templates/trip_page.html +++ b/templates/trip_page.html @@ -5,6 +5,13 @@ {% set row = { "flight": flight_row, "train": train_row } %} {% block style %} + +{% if station_coordinates %} + +{% endif %} + {% set conference_column_count = 6 %} {% set accommodation_column_count = 7 %} {% set travel_column_count = 7 %} @@ -33,6 +40,11 @@ .grid-item { /* Additional styling for grid items can go here */ } + +#map { + height: 400px; +} + {% endblock %} @@ -65,7 +77,36 @@ {% endfor %} - {#
{{ trip | pprint }}
#} + {% if station_coordinates %} +
+ {% endif %} {% endblock %} + +{% block scripts %} + +{% if station_coordinates %} + + + +{% endif %} +{% endblock %} diff --git a/web_view.py b/web_view.py index 1bbfbc9..8bb52ec 100755 --- a/web_view.py +++ b/web_view.py @@ -235,6 +235,26 @@ def trip_list() -> str: ) +def collect_station_coordinates(trip: Trip) -> list[tuple[float, float]]: + """Extract and deduplicate station coordinates from trip.""" + stations = {} + station_list = [] + for t in trip.travel: + if t["type"] != "train": + continue + station_list += [t["from_station"], t["to_station"]] + for leg in t["legs"]: + station_list.append(leg["from_station"]) + station_list.append(leg["to_station"]) + + for s in station_list: + if s["uic"] in stations: + continue + stations[s["uic"]] = s + + return [(s["latitude"], s["longitude"]) for s in stations.values()] + + @app.route("/trip/") def trip_page(start: str) -> str: """Individual trip page.""" @@ -246,10 +266,13 @@ def trip_page(start: str) -> str: if not trip: flask.abort(404) + station_coordinates = collect_station_coordinates(trip) + return flask.render_template( "trip_page.html", trip=trip, today=today, + station_coordinates=station_coordinates, get_country=agenda.get_country, format_list_with_ampersand=format_list_with_ampersand, )