Show map of past trips

This commit is contained in:
Edward Betts 2024-01-14 12:17:22 +00:00
parent bd61b1bccd
commit 36b5d38274
4 changed files with 43 additions and 26 deletions

View file

@ -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)

View file

@ -1,13 +1,13 @@
function emoji_icon(emoji) {
return L.divIcon({
className: 'custom-div-icon',
html: "<div style='font-size: 24px;'>🚉</div>",
html: "<div style='font-size: 24px;'>" + emoji + "</div>",
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

View file

@ -39,7 +39,7 @@
/* Additional styling for grid items can go here */
}
#map {
.map {
height: 80vh;
}
@ -91,11 +91,12 @@
{% block content %}
<div class="p-2">
<div id="map"></div>
<h1>Trips</h1>
<div id="future-map" class="map"></div>
{{ section("Current", current, "attending") }}
{{ section("Future", future, "going") }}
<div id="past-map" class="map"></div>
{{ section("Past", past|reverse, "went") }}
</div>
{% 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);
</script>
{% endblock %}

View file

@ -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,