Map the start and end of trails with no track, with the notice beside it
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
a37f375101
commit
3709a9af5f
8 files changed
+309
-78
No files matched your search
+33
-4
@@ -123,8 +123,10 @@ def end_point(rec):
|
||||
|
||||
def sketch_points(rec):
|
||||
"""The points a map may sketch for a trail with no track: [start, end]
|
||||
when both are on file, or the one that is. Empty when the trail has a
|
||||
track or neither point (see sketch_end for which end a lone point is).
|
||||
when both are on file, or the one point of a loop (shape "loop", or the
|
||||
same place for both ends), which is its start and its end. Empty when the
|
||||
trail has a track, or when only one end of a point-to-point trail is known:
|
||||
one end alone says nothing a reader can use, so that trail gets no map.
|
||||
|
||||
A sketch is only ever these points. It is never a track: nothing here
|
||||
feeds a download, a GPX status or an elevation figure.
|
||||
@@ -132,8 +134,12 @@ def sketch_points(rec):
|
||||
derived = rec.get("derived", {})
|
||||
if derived.get("has_line") or "line" in derived.get("files", {}):
|
||||
return []
|
||||
points = [p for p in (start_point(rec), end_point(rec)) if p]
|
||||
return points[:1] if len(points) == 2 and points[0] == points[1] else points
|
||||
start, end = start_point(rec), end_point(rec)
|
||||
if start and end:
|
||||
return [start] if start == end else [start, end]
|
||||
if start and shape(rec) == "loop":
|
||||
return [start]
|
||||
return []
|
||||
|
||||
|
||||
def sketch_end(rec):
|
||||
@@ -143,6 +149,29 @@ def sketch_end(rec):
|
||||
return "start" if start_point(rec) else "end"
|
||||
|
||||
|
||||
def termini(rec):
|
||||
"""The markers of the trail page's map for a trail with no track, from the
|
||||
record only: [{"role": "start" | "end" | "both", "lonlat": [lon, lat],
|
||||
"place": name or "", "label": text}]. A loop has one marker that is both
|
||||
its start and its end. Empty whenever sketch_points is."""
|
||||
points = sketch_points(rec)
|
||||
if not points:
|
||||
return []
|
||||
h = table(rec)
|
||||
|
||||
def name(key):
|
||||
v = h.get(key)
|
||||
return v.strip() if isinstance(v, str) else ""
|
||||
|
||||
def marker(role, point, place):
|
||||
head = {"start": "Start", "end": "End", "both": "Start and end"}[role]
|
||||
return {"role": role, "lonlat": point, "place": place,
|
||||
"label": f"{head}: {place}" if place else head}
|
||||
if len(points) == 1:
|
||||
return [marker("both", points[0], name("start") or name("end"))]
|
||||
return [marker("start", points[0], name("start")), marker("end", points[1], name("end"))]
|
||||
|
||||
|
||||
def sketch_bbox(points, *, pad=False):
|
||||
"""[min lon, min lat, max lon, max lat] of sketch points, or None.
|
||||
|
||||
|
||||
+2
-2
@@ -669,12 +669,12 @@ def overview_map(recs, label, *, wide=False, scope="", saved=False):
|
||||
s = len(sketches)
|
||||
sentences.append(f'{s} trail{"s" if s != 1 else ""} with no GPX here '
|
||||
f'{"are" if s != 1 else "is"} shown as a dotted straight line between '
|
||||
'their start and end, or a ring where only one end is known. '
|
||||
'their start and end, or a ring for a loop, which starts and ends in one place. '
|
||||
'That is not the trail’s path.')
|
||||
if saved:
|
||||
sentences = ["Tracks are simplified for display. Select one for its name.",
|
||||
"A trail with no GPX here is shown by its start and end only: dots straight from one "
|
||||
"to the other, or a ring where only one end is known."]
|
||||
"to the other, or a ring for a loop."]
|
||||
ids_attr += f' data-drawable="{esc(" ".join(ids))}"'
|
||||
sentences.append("Each trail’s page names its source, credit and licence. "
|
||||
"Base map: OpenFreeMap, © OpenMapTiles, data © OpenStreetMap contributors.")
|
||||
|
||||
+1
-1
@@ -214,7 +214,7 @@ def _extent(rec):
|
||||
the one point on file. Coordinates come from the record or its track, never made up."""
|
||||
box = rec.get("derived", {}).get("bbox") or rec.get("derived", {}).get("map_bbox")
|
||||
if not box:
|
||||
pts = hike.sketch_points(rec)
|
||||
pts = [p for p in (hike.start_point(rec), hike.end_point(rec)) if p] # the record's own points, map or no map
|
||||
if len(pts) == 1:
|
||||
return {"@type": "GeoCoordinates", "longitude": pts[0][0], "latitude": pts[0][1]}
|
||||
if pts:
|
||||
|
||||
+32
-42
@@ -807,63 +807,53 @@ def empty_frame(rec):
|
||||
|
||||
|
||||
def sketch_figure(rec):
|
||||
"""A real map for a trail with no track but a known start or end: a dotted
|
||||
straight line between the two, or one ring. It says plainly that the line only
|
||||
joins the start and the end, and keeps the words about where to get a track."""
|
||||
"""A real map for a trail with no track whose start and end are on file (or a loop's one place):
|
||||
the base map fitted to those points, with each one marked and named. No line joins them and
|
||||
nothing is drawn that could be read as the route. The notice about where to get a track sits
|
||||
beside the map, not over it."""
|
||||
points = hike.sketch_points(rec)
|
||||
box = hike.sketch_bbox(points, pad=True)
|
||||
bbox_attr = f' data-bbox="{",".join(str(v) for v in box)}"' if box else ""
|
||||
route = common.is_route(rec)
|
||||
h = hike.table(rec)
|
||||
start = h.get("start") if isinstance(h.get("start"), str) else ""
|
||||
end = h.get("end") if isinstance(h.get("end"), str) else ""
|
||||
start, end = start.strip(), end.strip()
|
||||
if len(points) == 2:
|
||||
if start and end:
|
||||
where = (f"The dotted line runs straight from {esc(start)} to {esc(end)}. "
|
||||
"It only joins the start and the end; that is not the trail’s path.")
|
||||
elif start:
|
||||
where = (f"The dotted line runs straight from {esc(start)} to where it ends. "
|
||||
"It only joins the start and the end; that is not the trail’s path.")
|
||||
else:
|
||||
where = ("The dotted line runs straight between its start and its end. "
|
||||
"It only joins the two; that is not the trail’s path.")
|
||||
legend_text = "No GPX here: start and end only"
|
||||
marks = hike.termini(rec)
|
||||
items = "".join(
|
||||
f'<li class="terminus-item" data-lon="{m["lonlat"][0]}" data-lat="{m["lonlat"][1]}" '
|
||||
f'data-role="{m["role"]}" data-label="{esc(m["label"])}">'
|
||||
f'<strong>{"Start and end" if m["role"] == "both" else m["role"].capitalize()}</strong>'
|
||||
f'{" " + esc(m["place"]) if m["place"] else ""}</li>' for m in marks)
|
||||
if len(marks) == 1:
|
||||
caption = ("Only the place where it starts and ends is shown. There is no track for this trail here, "
|
||||
"and the site does not guess one.")
|
||||
else:
|
||||
if hike.sketch_end(rec) == "end":
|
||||
where = (f"The ring marks {esc(end)}, where it ends. " if end else "The ring marks where it ends. ")
|
||||
where += "No position is on file for the start, so no line is drawn."
|
||||
legend_text = "No GPX here: end only"
|
||||
elif h.get("shape") == "loop":
|
||||
where = (f"The ring marks {esc(start)}, where the loop starts and ends. " if start
|
||||
else "The ring marks where the loop starts and ends. ")
|
||||
where += "It shows where the trail is, not its path."
|
||||
legend_text = "No GPX here: start only"
|
||||
else:
|
||||
where = (f"The ring marks {esc(start)}, where it starts. " if start else "The ring marks where it starts. ")
|
||||
where += "No position is on file for the end, so no line is drawn."
|
||||
legend_text = "No GPX here: start only"
|
||||
_title, status, reason, rule, actions_html = _no_gpx_parts(rec)
|
||||
caption = ("Only the start and the end are shown. There is no track for this trail here, "
|
||||
"and the site does not guess one.")
|
||||
title, status, reason, rule, actions_html = _no_gpx_parts(rec)
|
||||
reason_html = reason if isinstance(reason, Markup) else common.rich(reason)
|
||||
frame_attr, drawing = sketch_of(box, sketch.trail_features(rec["id"]), route_main=route)
|
||||
return f"""<figure class="mapfig mapfig--detail detail__map" id="track" data-map="sketch" data-src="/trails/{esc(rec["id"])}/sketch.json" data-route="{"yes" if route else "no"}"{bbox_attr}{frame_attr} data-outdoor="{OUTDOOR_STYLE}">
|
||||
rid = esc(rec["id"])
|
||||
return f"""<figure class="mapfig mapfig--detail mapfig--termini detail__map" id="track" data-map="sketch" data-src="/trails/{rid}/sketch.json" data-route="{"yes" if route else "no"}"{bbox_attr}{frame_attr} data-outdoor="{OUTDOOR_STYLE}">
|
||||
<div class="mapfig__frame">
|
||||
<span class="mapfig__corner mapfig__corner--nw" aria-hidden="true"></span>
|
||||
<div class="map" role="region" aria-label="Map showing the start and end of the {esc(rec["name"])}; no GPX here">
|
||||
<div class="map" role="region" aria-label="Map of where the {esc(rec["name"])} starts and ends. No track is drawn." aria-describedby="termini-{rid}">
|
||||
<div class="map__fallback">{drawing}</div>
|
||||
<div class="map__canvas"></div>
|
||||
<p class="map__status" role="status">The map needs JavaScript. The ends of the trail are named below it.</p>
|
||||
<div class="map__termini" aria-hidden="true"></div>
|
||||
<p class="map__status" role="status">The map needs JavaScript. The ends of the trail are named beside it.</p>
|
||||
</div>
|
||||
<span class="mapfig__corner mapfig__corner--se" aria-hidden="true"></span>
|
||||
</div>
|
||||
<figcaption class="mapfig__caption mapfig__caption--sketch">
|
||||
<ul class="legend" aria-label="Legend"><li>{common.SWATCH_SKETCH}{esc(legend_text)}</li></ul>
|
||||
<div class="sketch-note">
|
||||
<p><strong>No GPX here.</strong> {where}</p>
|
||||
<p>{reason_html}</p>
|
||||
<p class="note">{esc(rule)}</p>
|
||||
{actions_html}
|
||||
<div class="termini-notice">
|
||||
<div class="map__message">
|
||||
<p class="kicker">GPX: {esc(facets.GPX_STATUS[status])}</p>
|
||||
<h2 id="noline-title">{esc(title)}</h2>
|
||||
<p class="map__reason">{reason_html}</p>
|
||||
<p class="note">{esc(rule)}</p>
|
||||
{actions_html}
|
||||
</div>
|
||||
</div>
|
||||
<figcaption class="mapfig__caption mapfig__caption--termini">
|
||||
<ul class="termini-list" id="termini-{rid}" aria-label="Marked on the map">{items}</ul>
|
||||
<p>{caption}</p>
|
||||
</figcaption>
|
||||
</figure>"""
|
||||
|
||||
|
||||
Reference in new issue
Block a user