diff --git a/agenda/trip.py b/agenda/trip.py index a306bee..ed9005a 100644 --- a/agenda/trip.py +++ b/agenda/trip.py @@ -182,3 +182,31 @@ def get_trip_routes(trip: Trip) -> list[StrDict]: ) return routes + + +def get_coordinates_and_routes( + trip_list: list[Trip], +) -> tuple[list[StrDict], list[StrDict]]: + coordinates = [] + seen_coordinates: set[tuple[str, str]] = set() + routes = [] + seen_routes: set[str] = set() + for trip in trip_list: + for stop in collect_trip_coordinates(trip): + key = (stop["type"], stop["name"]) + if key in seen_coordinates: + continue + coordinates.append(stop) + seen_coordinates.add(key) + + for route in get_trip_routes(trip): + if route["key"] in seen_routes: + continue + routes.append(route) + seen_routes.add(route["key"]) + + for route in routes: + if "geojson_filename" in route: + route["geojson"] = read_geojson(route.pop("geojson_filename")) + + return (coordinates, routes) diff --git a/static/js/map.js b/static/js/map.js index 3bd6a42..698dd39 100644 --- a/static/js/map.js +++ b/static/js/map.js @@ -1,13 +1,13 @@ function emoji_icon(emoji) { return L.divIcon({ className: 'custom-div-icon', - html: "
🚉
", + html: "
" + emoji + "
", iconSize: [30, 42], }); } var stationIcon = emoji_icon("🚉"); -var airportIcon = emoji_icon("✈️<"); +var airportIcon = emoji_icon("✈️"); function build_map(map_id, coordinates, routes) { // Initialize the map diff --git a/templates/trip_list.html b/templates/trip_list.html index d856cae..9118f1c 100644 --- a/templates/trip_list.html +++ b/templates/trip_list.html @@ -39,7 +39,7 @@ /* Additional styling for grid items can go here */ } -#map { +.map { height: 80vh; } @@ -91,11 +91,12 @@ {% block content %}
-

Trips

+
{{ section("Current", current, "attending") }} {{ section("Future", future, "going") }} +
{{ section("Past", past|reverse, "went") }}
{% endblock %} @@ -113,7 +114,12 @@ var future_coordinates = {{ future_coordinates | tojson }}; var future_routes = {{ future_routes | tojson }}; -build_map("map", future_coordinates, future_routes); +build_map("future-map", future_coordinates, future_routes); + +var past_coordinates = {{ past_coordinates | tojson }}; +var past_routes = {{ past_routes | tojson }}; + +build_map("past-map", past_coordinates, past_routes); {% endblock %} diff --git a/web_view.py b/web_view.py index 16daefe..2f17afb 100755 --- a/web_view.py +++ b/web_view.py @@ -170,27 +170,8 @@ def trip_list() -> str: past = [item for item in trip_list if (item.end or item.start) < today] future = [item for item in trip_list if item.start > today] - future_coordinates = [] - seen_future_coordinates: set[tuple[str, str]] = set() - future_routes = [] - seen_future_routes: set[str] = set() - for trip in future: - for stop in agenda.trip.collect_trip_coordinates(trip): - key = (stop["type"], stop["name"]) - if key in seen_future_coordinates: - continue - future_coordinates.append(stop) - seen_future_coordinates.add(key) - - for route in agenda.trip.get_trip_routes(trip): - if route["key"] in seen_future_routes: - continue - future_routes.append(route) - seen_future_routes.add(route["key"]) - - for route in future_routes: - if "geojson_filename" in route: - route["geojson"] = agenda.trip.read_geojson(route.pop("geojson_filename")) + future_coordinates, future_routes = agenda.trip.get_coordinates_and_routes(future) + past_coordinates, past_routes = agenda.trip.get_coordinates_and_routes(past) return flask.render_template( "trip_list.html", @@ -199,6 +180,8 @@ def trip_list() -> str: future=future, future_coordinates=future_coordinates, future_routes=future_routes, + past_coordinates=past_coordinates, + past_routes=past_routes, today=today, get_country=agenda.get_country, format_list_with_ampersand=format_list_with_ampersand,