Show ferry routes and terminals on the map

This commit is contained in:
Edward Betts 2024-05-01 11:59:21 +03:00
parent b9b849802d
commit afa2a2e934
2 changed files with 23 additions and 5 deletions

View file

@ -66,8 +66,13 @@ def load_ferries(data_dir: str) -> list[StrDict]:
for item in ferries: for item in ferries:
assert item["from"] in by_name and item["to"] in by_name assert item["from"] in by_name and item["to"] in by_name
item["from_terminal"] = by_name[item["from"]] from_terminal, to_terminal = by_name[item["from"]], by_name[item["to"]]
item["to_terminal"] = by_name[item["to"]] item["from_terminal"] = from_terminal
item["to_terminal"] = to_terminal
geojson = from_terminal["routes"].get(item["to"])
if geojson:
item["geojson_filename"] = geojson
return ferries return ferries
@ -229,7 +234,7 @@ def collect_trip_coordinates(trip: Trip) -> list[StrDict]:
locations = [ locations = [
("station", stations), ("station", stations),
("airport", airports), ("airport", airports),
("ferry_terminals", ferry_terminals), ("ferry_terminal", ferry_terminals),
] ]
for coord_type, coord_dict in locations: for coord_type, coord_dict in locations:
coords += [ coords += [
@ -252,7 +257,7 @@ def latlon_tuple(stop: StrDict) -> tuple[float, float]:
def read_geojson(data_dir: str, filename: str) -> str: def read_geojson(data_dir: str, filename: str) -> str:
"""Read GeoJSON from file.""" """Read GeoJSON from file."""
return open(os.path.join(data_dir, "train_routes", filename + ".geojson")).read() return open(os.path.join(data_dir, filename + ".geojson")).read()
def get_trip_routes(trip: Trip) -> list[StrDict]: def get_trip_routes(trip: Trip) -> list[StrDict]:
@ -261,6 +266,18 @@ def get_trip_routes(trip: Trip) -> list[StrDict]:
seen_geojson = set() seen_geojson = set()
for t in trip.travel: for t in trip.travel:
if t["type"] == "ferry": if t["type"] == "ferry":
ferry_from, ferry_to = t["from_terminal"], t["to_terminal"]
key = "_".join(["ferry"] + sorted([ferry_from["name"], ferry_to["name"]]))
filename = os.path.join("ferry_routes", t["geojson_filename"])
routes.append(
{
"type": "train",
"key": key,
"geojson_filename": filename,
}
)
continue continue
if t["type"] == "flight": if t["type"] == "flight":
if "from_airport" not in t or "to_airport" not in t: if "from_airport" not in t or "to_airport" not in t:
@ -300,7 +317,7 @@ def get_trip_routes(trip: Trip) -> list[StrDict]:
{ {
"type": "train", "type": "train",
"key": key, "key": key,
"geojson_filename": geojson_filename, "geojson_filename": os.path.join("train_routes", geojson_filename),
} }
) )

View file

@ -16,6 +16,7 @@ function emoji_icon(emoji) {
var icons = { var icons = {
"station": emoji_icon("🚉"), "station": emoji_icon("🚉"),
"airport": emoji_icon("✈️"), "airport": emoji_icon("✈️"),
"ferry_terminal": emoji_icon("✈️"),
"accommodation": emoji_icon("🏨"), "accommodation": emoji_icon("🏨"),
"conference": emoji_icon("🎤"), "conference": emoji_icon("🎤"),
"event": emoji_icon("🍷"), "event": emoji_icon("🍷"),