Draw a picked photo only with bg=photo, keep bg=satellite to aerial imagery

The operator judged the Commons-photo poster unfit as a default: its crop lands beside the circuit and shows the
track only as an inset. bg=satellite is now the national aerial photo, else EOxCloudless (or the dark map where
"use": "map" is set); the new bg=photo draws the layout's picked photo and without one falls back to what
bg=satellite draws. A picks entry may hold the photo fields, "use": "map", or both; an unknown use and incomplete
photo fields are refused at load. The smallest width is 400 px so the full credit line stays readable, and the
ASCII credit header spells out ß, æ, ø, œ and đ so names stay readable.

Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
This commit is contained in:
2026-11-27 15:18:09 +01:00
parent d514eb57a3
commit 4362e2d10b
7 changed files with 89 additions and 49 deletions
+39 -22
View File
@@ -1,8 +1,9 @@
"""Where every poster picture comes from, under which licence, and the credit each source asks for (docs/posters.md,
Sources). Standard library only, so the merge check tests it as it is.
The satellite chain takes, per layout, the first source that has it: the layout's picked Wikimedia Commons photo,
then the national aerial photo of the circuit's country, then EOxCloudless. The national credit lines and tile
bg=satellite takes, per layout, the national aerial photo of the circuit's country, else EOxCloudless (or the dark
map where the operator set {"use": "map"}). bg=photo takes the layout's picked Wikimedia Commons photo, and without a
pick falls back to bg=satellite. The national credit lines and tile
addresses were read from each provider's own pages and confirmed against real tiles on 2026-11-27:
- USGS: the service description of USGSImageryOnly (its copyright text is the credit; cached to level 16, 17 is a
@@ -55,7 +56,7 @@ class MapSource:
return NC_SA if self.id == "eox" and self.year != EOX_FREE_YEAR else None
COMMONS = "commons" # the satellite chain's first link: the layout's picked Commons photo
COMMONS = "commons" # bg=photo: the layout's picked Commons photo
MAP_OVERRIDE = "map" # a layout's entry {"use": "map"}: its satellite background is the dark map, not EOX
# What a source asks of a picture made from it, beyond its credit: share-alike (a CC BY-SA photo) or
@@ -135,13 +136,11 @@ def dark_map() -> MapSource:
def satellite_source(country_slug: str, circuit_slug: str, layout_slug: str,
entry: Optional[dict] = None) -> Union[str, MapSource]:
"""The satellite chain: the layout's picked Commons photo (COMMONS), else the national aerial photo of the
circuit's country, else the chain's last link (satellite_fallback). The layout's entry in circuits/photos.json
is a photo, or the override {"use": "map"}, which a photo or a national source still wins over (they are
sharper)."""
if is_photo(entry):
return COMMONS
entry: Optional[dict] = None) -> MapSource:
"""The satellite chain (bg=satellite, aerial): the national aerial photo of the circuit's country, else the
chain's last link (satellite_fallback). "use": "map" in the layout's entry in circuits/photos.json makes that last
link the dark map, whether or not the entry also holds a photo; a national source still wins over it (it is
sharper). A picked photo is not in this chain."""
if country_slug == "united-states":
return usgs()
if country_slug == "netherlands":
@@ -153,6 +152,14 @@ def satellite_source(country_slug: str, circuit_slug: str, layout_slug: str,
return satellite_fallback(layout_slug)
def photo_source(country_slug: str, circuit_slug: str, layout_slug: str,
entry: Optional[dict] = None) -> Union[str, MapSource]:
"""bg=photo: the layout's picked Commons photo (COMMONS), drawn with the track as an inset; without the photo
fields, whatever bg=satellite draws for the layout (the dark map where "use": "map" is set). Never the default of
any style."""
return COMMONS if is_photo(entry) else satellite_source(country_slug, circuit_slug, layout_slug, entry)
def satellite_fallback(layout_slug: str) -> MapSource:
"""The satellite chain's last link, for a layout no picked photo and no national aerial photo has: EOxCloudless.
The one place that decides it."""
@@ -170,19 +177,23 @@ def is_free_licence(licence: str) -> bool:
return bool(_FREE_LICENCE.match((licence or "").strip()))
PHOTO_FIELDS = ("file", "licence", "author", "credit", "date")
def entry_problem(entry) -> Optional[str]:
"""Why a picks file's entry is refused, or None: an entry is a photo (file, licence, author, credit, date) under
a free licence, or the override {"use": "map"}, never both."""
"""Why a picks file's entry is refused, or None. An entry carries the photo fields (all of PHOTO_FIELDS, under a
free licence), which decide bg=photo; the override {"use": "map"}, which decides bg=satellite; or both."""
if not isinstance(entry, dict):
return "not an object"
if "use" in entry:
if entry["use"] != MAP_OVERRIDE:
return f"unknown use {entry['use']!r}; it takes {MAP_OVERRIDE!r}"
return "a file and a use at once" if "file" in entry else None
if not entry.get("file"):
return "neither a file nor a use"
if not is_free_licence(entry.get("licence", "")):
return f"licence {entry.get('licence')!r} is not CC0, public domain, CC BY or CC BY-SA"
if "use" in entry and entry["use"] != MAP_OVERRIDE:
return f"unknown use {entry['use']!r}; it takes {MAP_OVERRIDE!r}"
given = [field for field in PHOTO_FIELDS if entry.get(field)]
if given and len(given) < len(PHOTO_FIELDS):
return f"incomplete photo fields: no {', '.join(f for f in PHOTO_FIELDS if f not in given)}"
if not given and "use" not in entry:
return "neither the photo fields nor a use"
if given and not is_free_licence(entry["licence"]):
return f"licence {entry['licence']!r} is not CC0, public domain, CC BY or CC BY-SA"
return None
@@ -240,11 +251,17 @@ def credit_line(credits: list[str]) -> str:
return " · ".join(dict.fromkeys(c for c in credits if c))
_SPELLED = {"ß": "ss", "æ": "ae", "Æ": "AE", "ø": "o", "Ø": "O", "œ": "oe", "Œ": "OE", "đ": "d", "Đ": "D"}
def ascii_header(text: str) -> str:
"""The credit line as an ASCII header value (many clients read headers as Latin-1): "©" as "(c)", the " · "
between sources as " | ", accents folded, en and em dashes as "-", any other character outside ASCII as "?".
between sources as " | ", ß, æ, ø, œ and đ spelled out, accents folded, en and em dashes as "-", any other
character outside ASCII as "?".
The drawn line and /licences keep the exact text."""
text = text.replace("©", "(c)").replace(" · ", " | ")
for letter, spelled in _SPELLED.items(): # letters NFKD does not take apart, spelled out so names stay readable
text = text.replace(letter, spelled)
folded = "".join(c for c in unicodedata.normalize("NFKD", text) if not unicodedata.combining(c))
folded = folded.replace("–", "-").replace("—", "-")
return "".join(c if ord(c) < 128 else "?" for c in folded)
@@ -272,7 +289,7 @@ def licences() -> dict:
"tracks": {"licence": "MIT", "licence_url": "https://opensource.org/license/mit"},
"sources": [
source("commons", "Wikimedia Commons aerial and car photos, picked per layout and per season",
"bg=satellite where a photo is picked for the layout; season posters",
"bg=photo where a photo is picked for the layout; season posters",
"per file: CC0, public domain, CC BY or CC BY-SA only",
"https://commons.wikimedia.org/wiki/Commons:Licensing",
COMMONS_CREDIT.format(author="<author>", licence="<licence>"),