From 1e9169b7408f1fec42ab2ae77beab0ef2835fa8d Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Thu, 9 Jul 2026 10:10:17 +0100 Subject: [PATCH] Show home marker for car journeys --- agenda/trip.py | 15 +++++++++++++- docs/personal-data-yaml.md | 6 ++++-- tests/test_trip.py | 40 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/agenda/trip.py b/agenda/trip.py index 842e37c..c6573d3 100644 --- a/agenda/trip.py +++ b/agenda/trip.py @@ -384,6 +384,19 @@ def car_endpoint_marker_type(item: StrDict, direction: str, label: str) -> str: return marker_type if isinstance(marker_type, str) else car_endpoint_type(label) +def show_car_endpoint_marker(item: StrDict, direction: str, label: str) -> bool: + """Return whether to show a car endpoint marker on the map.""" + direction_marker = item.get(direction + "_show_marker") + if isinstance(direction_marker, bool): + return direction_marker + + show_markers = item.get("show_markers") + if isinstance(show_markers, bool): + return show_markers + + return car_endpoint_type(label) == "home" + + def load_cars(data_dir: str) -> list[StrDict]: """Load car journeys.""" filename = os.path.join(data_dir, "car_journeys.yaml") @@ -416,7 +429,7 @@ def load_cars(data_dir: str) -> list[StrDict]: ("from", "from_location", from_label, endpoints[0]), ("to", "to_location", to_label, endpoints[1]), ): - if not label: + if not label or not show_car_endpoint_marker(item, direction, label): continue item[field] = { "name": label, diff --git a/docs/personal-data-yaml.md b/docs/personal-data-yaml.md index adccd2f..10e8674 100644 --- a/docs/personal-data-yaml.md +++ b/docs/personal-data-yaml.md @@ -267,10 +267,12 @@ Required fields: Optional fields: - `from`, `to`: endpoint labels. If omitted and the route filename uses `A_to_B`, labels are inferred from the filename. -- `from_type`, `to_type`: marker type override. Use `home` to render a house icon. Otherwise car endpoints render as car markers. +- `show_markers`: boolean. When true, render both car endpoint markers on maps. Defaults to false because car endpoints often duplicate airport, accommodation, ferry terminal, or conference pins. Home endpoints still render by default. +- `from_show_marker`, `to_show_marker`: booleans. Per-endpoint marker overrides. +- `from_type`, `to_type`: marker type override used when that endpoint marker is shown. Use `home` to render a house icon. Otherwise car endpoints render as car markers. - `operator`, `vehicle`, `price`, `currency`, `distance`. -The route distance is calculated from the GeoJSON when `distance` is not present. If an inferred or explicit endpoint label is `home`, `PCH`, or `Picture House Court`, the marker is rendered as a house. +The route distance is calculated from the GeoJSON when `distance` is not present. Car routes render on maps by default. Non-home endpoint pins are opt-in. If an endpoint label is `home`, `PCH`, or `Picture House Court`, the marker is rendered as a house by default. Example: diff --git a/tests/test_trip.py b/tests/test_trip.py index 409c0a5..efb3b9b 100644 --- a/tests/test_trip.py +++ b/tests/test_trip.py @@ -171,8 +171,10 @@ def test_get_trip_routes_assumes_unbooked_paris_trip_is_by_train( ] -def test_load_cars_infers_route_labels_and_home_marker(tmp_path: pathlib.Path) -> None: - """Car journeys should load direct GeoJSON routes and endpoint markers.""" +def test_load_cars_infers_route_labels_and_home_marker( + tmp_path: pathlib.Path, +) -> None: + """Car journeys should load direct GeoJSON routes and home endpoint markers.""" (tmp_path / "car_routes").mkdir() (tmp_path / "car_journeys.yaml").write_text("""--- - trip: 2026-07-16 @@ -201,6 +203,40 @@ def test_load_cars_infers_route_labels_and_home_marker(tmp_path: pathlib.Path) - assert cars[0]["to"] == "EMF" assert cars[0]["geojson_filename"] == "PCH_to_EMF" assert cars[0]["distance"] > 0 + assert cars[0]["from_location"] == { + "name": "PCH", + "type": "home", + "latitude": 51.44083, + "longitude": -2.60283, + } + assert "to_location" not in cars[0] + + +def test_load_cars_can_show_endpoint_markers(tmp_path: pathlib.Path) -> None: + """Car endpoint markers should be opt-in.""" + (tmp_path / "car_routes").mkdir() + (tmp_path / "car_journeys.yaml").write_text("""--- +- trip: 2026-07-16 + depart: 2026-07-16 + arrive: 2026-07-16 + route: PCH_to_EMF.geojson + show_markers: true +""") + (tmp_path / "car_routes" / "PCH_to_EMF.geojson").write_text( + json.dumps( + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [[-2.60283, 51.44083], [-1.2, 52.0]], + }, + } + ) + ) + + cars = agenda.trip.load_cars(str(tmp_path)) + assert cars[0]["from_location"] == { "name": "PCH", "type": "home",