From 4e719a07abcb9b677714b736cde220919d2efa89 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 12 Jan 2024 19:52:00 +0000 Subject: [PATCH] Show flights and trains in different colours --- templates/trip_page.html | 3 ++- web_view.py | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/templates/trip_page.html b/templates/trip_page.html index ab039cd..f7c6e14 100644 --- a/templates/trip_page.html +++ b/templates/trip_page.html @@ -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); }); diff --git a/web_view.py b/web_view.py index d53d433..18077c4 100755 --- a/web_view.py +++ b/web_view.py @@ -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