Show home marker for car journeys
This commit is contained in:
parent
086bc630c9
commit
1e9169b740
3 changed files with 56 additions and 5 deletions
|
|
@ -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)
|
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]:
|
def load_cars(data_dir: str) -> list[StrDict]:
|
||||||
"""Load car journeys."""
|
"""Load car journeys."""
|
||||||
filename = os.path.join(data_dir, "car_journeys.yaml")
|
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]),
|
("from", "from_location", from_label, endpoints[0]),
|
||||||
("to", "to_location", to_label, endpoints[1]),
|
("to", "to_location", to_label, endpoints[1]),
|
||||||
):
|
):
|
||||||
if not label:
|
if not label or not show_car_endpoint_marker(item, direction, label):
|
||||||
continue
|
continue
|
||||||
item[field] = {
|
item[field] = {
|
||||||
"name": label,
|
"name": label,
|
||||||
|
|
|
||||||
|
|
@ -267,10 +267,12 @@ Required fields:
|
||||||
Optional fields:
|
Optional fields:
|
||||||
|
|
||||||
- `from`, `to`: endpoint labels. If omitted and the route filename uses `A_to_B`, labels are inferred from the filename.
|
- `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`.
|
- `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:
|
Example:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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:
|
def test_load_cars_infers_route_labels_and_home_marker(
|
||||||
"""Car journeys should load direct GeoJSON routes and endpoint markers."""
|
tmp_path: pathlib.Path,
|
||||||
|
) -> None:
|
||||||
|
"""Car journeys should load direct GeoJSON routes and home endpoint markers."""
|
||||||
(tmp_path / "car_routes").mkdir()
|
(tmp_path / "car_routes").mkdir()
|
||||||
(tmp_path / "car_journeys.yaml").write_text("""---
|
(tmp_path / "car_journeys.yaml").write_text("""---
|
||||||
- trip: 2026-07-16
|
- 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]["to"] == "EMF"
|
||||||
assert cars[0]["geojson_filename"] == "PCH_to_EMF"
|
assert cars[0]["geojson_filename"] == "PCH_to_EMF"
|
||||||
assert cars[0]["distance"] > 0
|
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"] == {
|
assert cars[0]["from_location"] == {
|
||||||
"name": "PCH",
|
"name": "PCH",
|
||||||
"type": "home",
|
"type": "home",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue