Show flights and trains in different colours

This commit is contained in:
Edward Betts 2024-01-12 19:52:00 +00:00
parent 4b62ec96dc
commit 4e719a07ab
2 changed files with 7 additions and 4 deletions

View file

@ -126,7 +126,8 @@ coordinates.forEach(function(item) {
// Draw lines for routes
routes.forEach(function(route) {
L.polyline(route, {color: 'blue'}).addTo(map);
var color = route[0] === "train" ? "green" : "red"; // Green for trains, red for flights
L.polyline([route[1], route[2]], {color: color}).addTo(map);
});
</script>

View file

@ -303,20 +303,22 @@ def latlon_tuple(stop: StrDict) -> tuple[float, float]:
def get_trip_routes(
trip: Trip,
) -> list[tuple[tuple[float, float], tuple[float, float]]]:
) -> list[tuple[str, tuple[float, float], tuple[float, float]]]:
routes = []
for t in trip.travel:
if t["type"] == "flight":
if "from_airport" not in t or "to_airport" not in t:
continue
fly_from, fly_to = t["from_airport"], t["to_airport"]
routes.append((latlon_tuple(fly_from), latlon_tuple(fly_to)))
routes.append(("flight", latlon_tuple(fly_from), latlon_tuple(fly_to)))
else:
assert t["type"] == "train"
for leg in t["legs"]:
train_from, train_to = leg["from_station"], leg["to_station"]
routes.append((latlon_tuple(train_from), latlon_tuple(train_to)))
routes.append(
("train", latlon_tuple(train_from), latlon_tuple(train_to))
)
return routes