Show map of past trips
This commit is contained in:
parent
bd61b1bccd
commit
36b5d38274
|
@ -182,3 +182,31 @@ def get_trip_routes(trip: Trip) -> list[StrDict]:
|
||||||
)
|
)
|
||||||
|
|
||||||
return routes
|
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)
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
function emoji_icon(emoji) {
|
function emoji_icon(emoji) {
|
||||||
return L.divIcon({
|
return L.divIcon({
|
||||||
className: 'custom-div-icon',
|
className: 'custom-div-icon',
|
||||||
html: "<div style='font-size: 24px;'>🚉</div>",
|
html: "<div style='font-size: 24px;'>" + emoji + "</div>",
|
||||||
iconSize: [30, 42],
|
iconSize: [30, 42],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var stationIcon = emoji_icon("🚉");
|
var stationIcon = emoji_icon("🚉");
|
||||||
var airportIcon = emoji_icon("✈️<");
|
var airportIcon = emoji_icon("✈️");
|
||||||
|
|
||||||
function build_map(map_id, coordinates, routes) {
|
function build_map(map_id, coordinates, routes) {
|
||||||
// Initialize the map
|
// Initialize the map
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
/* Additional styling for grid items can go here */
|
/* Additional styling for grid items can go here */
|
||||||
}
|
}
|
||||||
|
|
||||||
#map {
|
.map {
|
||||||
height: 80vh;
|
height: 80vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,11 +91,12 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="p-2">
|
<div class="p-2">
|
||||||
|
|
||||||
<div id="map"></div>
|
|
||||||
|
|
||||||
<h1>Trips</h1>
|
<h1>Trips</h1>
|
||||||
|
<div id="future-map" class="map"></div>
|
||||||
{{ section("Current", current, "attending") }}
|
{{ section("Current", current, "attending") }}
|
||||||
{{ section("Future", future, "going") }}
|
{{ section("Future", future, "going") }}
|
||||||
|
<div id="past-map" class="map"></div>
|
||||||
{{ section("Past", past|reverse, "went") }}
|
{{ section("Past", past|reverse, "went") }}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -113,7 +114,12 @@
|
||||||
var future_coordinates = {{ future_coordinates | tojson }};
|
var future_coordinates = {{ future_coordinates | tojson }};
|
||||||
var future_routes = {{ future_routes | 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>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
25
web_view.py
25
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]
|
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 = [item for item in trip_list if item.start > today]
|
||||||
|
|
||||||
future_coordinates = []
|
future_coordinates, future_routes = agenda.trip.get_coordinates_and_routes(future)
|
||||||
seen_future_coordinates: set[tuple[str, str]] = set()
|
past_coordinates, past_routes = agenda.trip.get_coordinates_and_routes(past)
|
||||||
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"))
|
|
||||||
|
|
||||||
return flask.render_template(
|
return flask.render_template(
|
||||||
"trip_list.html",
|
"trip_list.html",
|
||||||
|
@ -199,6 +180,8 @@ def trip_list() -> str:
|
||||||
future=future,
|
future=future,
|
||||||
future_coordinates=future_coordinates,
|
future_coordinates=future_coordinates,
|
||||||
future_routes=future_routes,
|
future_routes=future_routes,
|
||||||
|
past_coordinates=past_coordinates,
|
||||||
|
past_routes=past_routes,
|
||||||
today=today,
|
today=today,
|
||||||
get_country=agenda.get_country,
|
get_country=agenda.get_country,
|
||||||
format_list_with_ampersand=format_list_with_ampersand,
|
format_list_with_ampersand=format_list_with_ampersand,
|
||||||
|
|
Loading…
Reference in a new issue