Let the picker keep a layout's satellite or give it the map instead

EOX's newest mosaic suits some circuits and not others (the operator, 2026-11-27). Beside a
layout's Commons candidates the picker now frames its trace on what bg=satellite draws without
a photo: the country's own aerial photo (PDOK, IGN, USGS) and EOxCloudless (2016 for a layout
raced in or before 2016, else 2025), with each picture's licence, and the service's own poster
on request. "Keep the satellite" means no entry; "use the map instead" gives {"use": "map"},
from which the service draws the dark map for that layout.

Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
This commit is contained in:
2026-11-27 15:13:20 +01:00
parent c3c98a9a74
commit 4a9bd4464b
2 changed files with 266 additions and 29 deletions
+254 -29
View File
@@ -6,6 +6,8 @@
<title>Photo picker · F1 Circuits API examples</title>
<meta name="description" content="Pick a freely licensed Wikimedia Commons photo per circuit layout and per season for the F1 Circuits posters, and copy its entry for the picks file.">
<link rel="icon" href="data:,">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="">
<link rel="stylesheet" href="site.css">
</head>
<body>
@@ -106,6 +108,8 @@
<div id="photos-root">
<h2 id="others-title">Picks of the circuit’s other layouts</h2>
<div id="others"></div>
<h2 id="sat-title" hidden>Without a photo: the satellite, or the map</h2>
<div id="sat"></div>
<h2 id="cands-title">Candidates</h2>
<div id="cands"></div>
</div>
@@ -124,10 +128,12 @@
picture takes from its sources, and the licence of the track files and the GPS traces (MIT).</p>
</footer>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<script src="site.js"></script>
<script>
(function () {
const { h, notice, setRequest, setStatus, showJSON, layoutPicker, layoutYears, params } = F1;
const { h, notice, setRequest, setStatus, showJSON, layoutPicker, layoutYears, params, api, path, call, showImage } = F1;
const $ = (id) => document.getElementById(id);
const FRAMES = { poster: [1000, 1500], thumb: [1920, 1080] };
@@ -164,7 +170,7 @@
if (!value || typeof value !== 'object' || Array.isArray(value)) return 'it is not a JSON object';
for (const [k, v] of Object.entries(value)) {
if (k.startsWith('$')) continue;
if (!v || typeof v !== 'object' || typeof v.file !== 'string') return `its entry “${k}” has no file`;
if (!v || typeof v !== 'object' || (typeof v.file !== 'string' && v.use !== 'map')) return `its entry “${k}” has no file and does not say {"use": "map"}`;
}
return '';
}
@@ -273,7 +279,7 @@
...(c.restrictions || []).map((r) => h('span', { class: 'tag warn', title: 'A right beside copyright the file names' }, `${r} rights`)),
up ? h('span', { class: 'tag warn', title: 'Smaller than the frame: the service scales it up' }, `scaled up ×${up.toFixed(1)}`) : null,
].filter(Boolean);
const chosen = opts.choose && state.chosen && state.chosen.cand.file === c.file;
const chosen = opts.choose && state.chosen && state.chosen.cand && state.chosen.cand.file === c.file;
const card = h('article', { class: `photo-card${opts.picked ? ' picked' : ''}${chosen ? ' chosen' : ''}` },
h('div', { class: 'photo-frame' },
h('img', { src: c.thumb || thumbOf(c.file), alt: c.file, loading: 'lazy', decoding: 'async', referrerpolicy: 'no-referrer' })),
@@ -293,6 +299,17 @@
return card;
}
/** A pick as the picks file holds it: a photo, or {"use": "map"}. */
function pickCard(entry, label, picked) {
if (entry.use === 'map') {
return h('article', { class: `photo-card${picked ? ' picked' : ''}` },
h('div', { class: 'map-frame plain' }, h('span', {}, 'The dark map')),
h('div', { class: 'meta' }, h('b', {}, label)),
h('div', { class: 'name' }, '{"use": "map"}'));
}
return photoCard({ ...entry, thumb: thumbOf(entry.file) }, { label, picked });
}
function grid(cards, extra = '') {
const cls = `photos${frameNow() === 'thumb' ? ' thumb' : ''}${extra ? ` ${extra}` : ''}`;
return h('div', { class: cls }, ...cards);
@@ -313,7 +330,7 @@
function withPick(file, key, entry) {
const notes = Object.entries(file).filter(([k]) => k.startsWith('$'));
const picks = new Map(Object.entries(file).filter(([k]) => !k.startsWith('$')));
picks.set(key, entry);
if (entry === null) picks.delete(key); else picks.set(key, entry);
const sorted = [...picks.keys()].sort((a, b) => a.localeCompare(b, 'en', { numeric: true })).map((k) => [k, picks.get(k)]);
const pairs = [...notes, ...sorted];
const indent = (text) => text.replace(/\n/g, '\n ');
@@ -337,25 +354,38 @@
const section = $('entry');
const body = $('entry-body');
if (!state.chosen) { section.hidden = true; return; }
const { key, cand, fileName, fileKey } = state.chosen;
const entry = entryOf(cand);
const fragment = `${JSON.stringify(key)}: ${JSON.stringify(entry, null, 2)}`;
const parts = [
h('p', {}, 'For ', h('code', {}, key), ': ', h('b', {}, cand.file), '. Copy the entry into ', h('code', {}, fileName),
', or the whole file below with the entry in place.'),
copyBlock(`The entry, for ${fileName}`, fragment),
];
const sa = /\bBY-SA\b/i.test(cand.licence);
parts.push(notice('info', sa
? `${cand.licence} is share-alike: a poster made from it is adapted material, shared under CC BY-SA terms. Such a poster is CC BY-SA 4.0.`
: `A poster made from it is CC BY 4.0: a picture’s licence follows its sources, and ${cand.licence} asks no share-alike.`,
' ', h('a', { href: F1.linkWithKept('licences.html') }, 'The licences page'), ' states the rule.'));
if ((cand.restrictions || []).length) {
parts.push(notice('', `Commons names ${cand.restrictions.join(' and ')} rights for this file: rights beside its copyright licence, such as a person’s likeness or a trade mark shown in it.`));
}
const { key, cand, fileName, fileKey, kind } = state.chosen;
const file = state.picks[fileKey];
if (file) parts.push(copyBlock(`The whole of ${fileName} with this pick`, withPick(file, key, entry)));
else parts.push(notice('error', `${fileName} was not read, so the whole file cannot be shown: copy the entry, or load the file from disk above.`));
const rule = [' ', h('a', { href: F1.linkWithKept('licences.html') }, 'The licences page'), ' states the rule.'];
const parts = [];
if (kind === 'satellite') {
const src = satelliteSource(key);
const has = file && Object.prototype.hasOwnProperty.call(file, key);
parts.push(h('p', {}, 'Keep the satellite for ', h('code', {}, key), ': no entry. Without a picked photo, ', h('code', {}, 'bg=satellite'),
` draws ${src.name}; a poster from it is ${src.poster}.`), notice('info', 'A picture’s licence follows its sources.', ...rule));
if (!file) parts.push(notice('error', `${fileName} was not read, so the page cannot say whether it has an entry for this layout to remove.`));
else if (has) parts.push(h('p', {}, `${fileName} has an entry for it now: remove it. The whole file without it:`), copyBlock(`The whole of ${fileName} without an entry for ${key}`, withPick(file, key, null)));
else parts.push(h('p', { class: 'hint' }, `${fileName} has no entry for it: nothing to change.`));
} else {
const entry = kind === 'map' ? { use: 'map' } : entryOf(cand);
parts.push(
h('p', {}, 'For ', h('code', {}, key), ': ', h('b', {}, kind === 'map' ? 'the dark map instead of the satellite' : cand.file), '. Copy the entry into ', h('code', {}, fileName),
', or the whole file below with the entry in place.'),
copyBlock(`The entry, for ${fileName}`, `${JSON.stringify(key)}: ${JSON.stringify(entry, null, 2)}`));
if (kind === 'map') {
parts.push(notice('info', 'With this entry and no picked photo, the service draws the dark OpenStreetMap map for this layout where bg=satellite is asked. A poster on it is CC BY 4.0.', ...rule));
} else {
const sa = /\bBY-SA\b/i.test(cand.licence);
parts.push(notice('info', sa
? `${cand.licence} is share-alike: a poster made from it is adapted material, shared under CC BY-SA terms. Such a poster is CC BY-SA 4.0.`
: `A poster made from it is CC BY 4.0: a picture’s licence follows its sources, and ${cand.licence} asks no share-alike.`, ...rule));
if ((cand.restrictions || []).length) {
parts.push(notice('', `Commons names ${cand.restrictions.join(' and ')} rights for this file: rights beside its copyright licence, such as a person’s likeness or a trade mark shown in it.`));
}
}
if (file) parts.push(copyBlock(`The whole of ${fileName} with this entry`, withPick(file, key, entry)));
else parts.push(notice('error', `${fileName} was not read, so the whole file cannot be shown: copy the entry, or load the file from disk above.`));
}
body.replaceChildren(...parts);
section.hidden = false;
}
@@ -363,11 +393,201 @@
function choose(key, cand, card, fileName, fileKey) {
for (const el of document.querySelectorAll('.photo-card.chosen')) el.classList.remove('chosen');
card.classList.add('chosen');
state.chosen = { key, cand, fileName, fileKey, mode: state.mode };
state.chosen = { key, cand, fileName, fileKey, mode: state.mode, kind: 'photo' };
markChoices();
showEntry();
$('entry').scrollIntoView({ behavior: 'smooth', block: 'start' });
}
/** "Keep the satellite" (no entry) or "use the map instead" ({"use": "map"}) for a layout. */
function chooseSurface(key, kind) {
for (const el of document.querySelectorAll('.photo-card.chosen')) el.classList.remove('chosen');
state.chosen = { key, kind, fileName: 'circuits/photos.json', fileKey: 'circuits', mode: 'layout' };
markChoices();
showEntry();
$('entry').scrollIntoView({ behavior: 'smooth', block: 'start' });
}
function markChoices() {
for (const b of document.querySelectorAll('#sat .choices button')) {
b.setAttribute('aria-pressed', String(!!state.chosen && state.chosen.kind === b.dataset.kind));
}
}
// ------------------------------------------------------------ without a photo: the satellite, or the map
// The satellite chain without a pick (docs/posters.md, Sources): the country's own aerial photo, else EOxCloudless
// (its 2016 mosaic for a layout raced in or before 2016, else the newest). Tile addresses as each provider serves
// them, checked 2026-11-27; past maxNativeZoom Leaflet scales the deepest tiles up.
const NATIONAL = {
netherlands: { name: 'PDOK’s aerial photo', url: 'https://service.pdok.nl/hwh/luchtfotorgb/wmts/v1_0/Actueel_ortho25/EPSG:3857/{z}/{x}/{y}.jpeg',
maxNativeZoom: 19, credit: 'Luchtfoto: PDOK / Beeldmateriaal Nederland', licence: 'CC BY 4.0', poster: 'CC BY 4.0' },
france: { name: 'IGN’s BD ORTHO', url: 'https://data.geopf.fr/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=ORTHOIMAGERY.ORTHOPHOTOS&STYLE=normal&TILEMATRIXSET=PM&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&FORMAT=image/jpeg',
maxNativeZoom: 19, credit: '© IGN – BD ORTHO', licence: 'Licence Ouverte (Etalab) 2.0', poster: 'CC BY 4.0' },
'united-states': { name: 'USGS imagery', url: 'https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/{z}/{y}/{x}',
maxNativeZoom: 16, credit: 'Imagery: USGS', licence: 'public domain', poster: 'CC BY 4.0' },
};
const NEWEST_EOX = 2025;
function eox(year) {
return {
name: `EOxCloudless ${year}`,
url: `https://tiles.maps.eox.at/wmts/1.0.0/${year === 2016 ? 's2cloudless_3857' : `s2cloudless-${year}_3857`}/default/g/{z}/{y}/{x}.jpg`,
maxNativeZoom: 15,
credit: `EOxCloudless https://cloudless.eox.at by EOX IT Services GmbH (Contains modified Copernicus Sentinel data ${year})`,
licence: year === 2016 ? 'CC BY 4.0' : 'CC BY-NC-SA 4.0',
poster: year === 2016 ? 'CC BY 4.0' : 'CC BY-NC-SA 4.0',
};
}
/** The EOX mosaic of a layout: 2016 for one raced in or before 2016, else the newest. */
function eoxOf(layout) {
const last = layout.endsWith('-') ? Infinity : parseInt(layout.split('-')[1] || layout, 10);
return eox(last <= 2016 ? 2016 : NEWEST_EOX);
}
/** What bg=satellite draws for a layout with no picked photo. */
function satelliteSource(key) {
const [country, , , layout] = key.split('/');
return NATIONAL[country] || eoxOf(layout);
}
const traces = new Map();
const races = new Map();
let satMaps = [];
let satShown = '';
/** A layout's GPS trace as [lat, lon] points, or null when it has none. */
async function traceOf(p) {
const key = `${p.country}/${p.city}/${p.circuit}/${p.layout}`;
if (!traces.has(key)) {
traces.set(key, (async () => {
const res = await fetch(api(path`/circuits/${p.country}/${p.city}/${p.circuit}/layout/${p.layout}/geojson`));
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const line = F1.lineOf(await res.json());
const pts = line ? line.geometry.coordinates.map(([lon, lat]) => [lat, lon]) : [];
return pts.length > 1 ? pts : null;
})());
}
return traces.get(key);
}
/** The latest race at a circuit within a layout's years, from Jolpica; null when none. */
async function raceOn(p) {
const id = p.circuitData && p.circuitData.ergastId;
if (!id) return null;
if (!races.has(id)) {
races.set(id, (async () => {
const all = [];
for (let offset = 0; ; offset += 100) {
const res = await fetch(`${F1.JOLPICA}/circuits/${encodeURIComponent(id)}/races.json?limit=100&offset=${offset}`);
if (!res.ok) throw new Error(`Jolpica answered HTTP ${res.status}`);
const d = (await res.json()).MRData;
all.push(...d.RaceTable.Races);
if (offset + 100 >= Number(d.total)) return all;
}
})());
}
const list = await races.get(id);
const first = parseInt(p.layout, 10);
const last = p.layout.endsWith('-') ? Infinity : parseInt(p.layout.split('-')[1] || p.layout, 10);
const fit = list.filter((r) => Number(r.season) >= first && Number(r.season) <= last);
return fit.length ? fit[fit.length - 1] : null;
}
function mapCard(src, note) {
const box = h('div', { class: 'map-box' });
const card = h('article', { class: 'photo-card' },
h('div', { class: 'map-frame' }, box),
note ? h('div', { class: 'meta' }, h('b', {}, note)) : null,
h('div', { class: 'name' }, src.name),
h('div', { class: 'meta' }, src.credit, h('br'), `${src.licence}; a poster from it: `, h('b', {}, src.poster)));
card._box = box;
card._src = src;
return card;
}
function serviceCard(p) {
const route = frameNow() === 'thumb' ? 'session thumbnail' : 'race poster';
const button = h('button', { type: 'button' }, `Render the service’s ${route}`);
const card = h('article', { class: 'photo-card' },
h('div', { class: 'map-frame plain result' }, h('span', {}, 'What the service draws now, on demand: it renders and may fetch tiles first.')),
h('div', { class: 'name' }, `The service’s ${route}, bg=satellite`),
h('div', { class: 'request compact' }),
h('div', { class: 'status idle' }, 'Not rendered yet.'),
h('div', { class: 'actions' }, button));
button.addEventListener('click', async () => {
button.disabled = true;
const st = card.querySelector('.status');
try {
setStatus(st, 'pending', 'Finding a race on this layout at Jolpica…');
const race = await raceOn(p);
if (!race) { setStatus(st, 'error', `Jolpica lists no race at this circuit in ${layoutYears(p.layout)}.`); return; }
const url = frameNow() === 'thumb'
? api(path`/posters/session/${race.raceName}/${race.season}/race.png`) + '?bg=satellite'
: api(path`/posters/race/${race.raceName}/${race.season}.png`) + '?bg=satellite';
const answer = await call(card, url, { label: `${race.raceName} ${race.season}`, waiting: 'Rendering on the server…' });
const frame = card.querySelector('.map-frame');
if (!answer) { frame.replaceChildren(h('span', {}, 'No picture: see the status below.')); return; }
frame.classList.remove('plain');
await showImage(frame, answer, 'png', { alt: `${race.raceName} ${race.season}, bg=satellite`, tile: false, status: st });
} catch (e) {
setStatus(st, 'error', e.message);
} finally {
button.disabled = false;
}
});
return card;
}
function renderSat(p, key, current) {
const sig = `${key}|${frameNow()}`;
const src = satelliteSource(key);
const status = !state.picks.circuits ? 'circuits/photos.json was not read, so what this layout uses now is not known.'
: !current ? `No entry: without a photo, bg=satellite draws ${src.name} for it now.`
: current.use === 'map' ? 'Its entry says {"use": "map"}: it uses the dark map now.'
: `A photo is picked for it (${current.file}), so neither is used now.`;
const head = h('p', { class: 'hint' }, `Without a picked photo, bg=satellite draws ${src.name} for this layout. Judge it below, its trace drawn in white: keep the satellite, or have the service draw the dark map instead. `, h('b', {}, status));
const choices = h('div', { class: 'choices' },
h('button', { type: 'button', 'data-kind': 'satellite', onclick: () => chooseSurface(key, 'satellite') }, 'Keep the satellite (no entry)'),
h('button', { type: 'button', 'data-kind': 'map', onclick: () => chooseSurface(key, 'map') }, 'Use the map instead'));
if (sig === satShown && satMaps.length) {
$('sat').firstChild.replaceWith(head);
$('sat').querySelector('.choices').replaceWith(choices);
markChoices();
return;
}
for (const m of satMaps) m.remove();
satMaps = [];
satShown = sig;
const country = p.country;
const cards = [];
if (NATIONAL[country]) cards.push(mapCard(NATIONAL[country], 'What bg=satellite draws for this country'));
const e = eoxOf(p.layout);
cards.push(mapCard(e, NATIONAL[country] ? 'What bg=satellite draws where the national photo has no tiles' : 'What bg=satellite draws here'));
cards.push(serviceCard(p));
$('sat').replaceChildren(head, grid(cards), choices);
markChoices();
traceOf(p).then((pts) => {
if (satShown !== sig) return;
for (const card of cards.filter((c) => c._box)) {
// Whole zoom levels: at a fractional one the browser draws seams between tiles that read as flaws in the imagery.
const m = L.map(card._box, { attributionControl: false, scrollWheelZoom: false });
L.tileLayer(card._src.url, { maxZoom: 19, maxNativeZoom: card._src.maxNativeZoom }).addTo(m);
if (pts) {
const line = L.polyline(pts, { color: '#ffffff', weight: 2, opacity: 0.9 }).addTo(m);
m.fitBounds(line.getBounds(), { padding: [14, 14] });
} else {
m.setView([0, 0], 2);
card._box.after(h('div', { class: 'meta' }, 'This layout has no trace to frame.'));
}
satMaps.push(m);
}
}).catch((err) => {
for (const card of cards.filter((c) => c._box)) card._box.replaceWith(notice('error', `The layout’s trace could not be read: ${err.message}`));
});
}
// ------------------------------------------------------------ rendering a layout or a season
function picksOf(name) {
@@ -405,6 +625,9 @@
const picks = picksOf('circuits');
const list = state.candidates.layouts[key];
const current = picks && picks[key];
if (state.chosen && state.chosen.key !== key) { state.chosen = null; showEntry(); }
$('sat-title').hidden = false;
renderSat(p, key, current);
// The circuit's other layouts, and this one's pick when it has one.
$('others-title').hidden = false;
@@ -415,7 +638,7 @@
const cards = p.layouts.filter((l) => picks[`${circuitKey}/${l}`]).map((l) => {
const k = `${circuitKey}/${l}`;
const label = `${layoutYears(l)}${l === p.layout ? ' (this layout, picked now)' : ''}`;
return photoCard({ ...picks[k], thumb: thumbOf(picks[k].file) }, { label, picked: l === p.layout });
return pickCard(picks[k], label, l === p.layout);
});
$('others').replaceChildren(cards.length ? grid(cards, 'small')
: h('p', { class: 'hint' }, `None of its ${p.layouts.length} layout${p.layouts.length === 1 ? '' : 's'} has a pick yet.`));
@@ -429,10 +652,9 @@
}
const why = undated ? ` The tool found ${undated} more photo${undated === 1 ? '' : 's'} of this circuit with no date it can read; a layout lists only photos dated within its years.` : '';
if (!list.length) {
$('cands').replaceChildren(notice('', `Commons has no freely licensed aerial photo of this circuit dated ${layoutYears(p.layout)} that the tool found. Without a pick, bg=satellite uses the national aerial photo, then EOxCloudless.${why}`));
$('cands').replaceChildren(notice('', `Commons has no freely licensed aerial photo of this circuit dated ${layoutYears(p.layout)} that the tool found: the layout keeps the satellite or uses the map (above).${why}`));
return;
}
state.chosen = state.chosen && state.chosen.key === key ? state.chosen : null;
$('cands').replaceChildren(
why ? h('p', { class: 'hint' }, why.trim()) : '',
grid(list.map((c) => photoCard(c, {
@@ -440,12 +662,16 @@
label: current && current.file === c.file ? 'Picked now' : null,
choose: (card) => choose(key, c, card, 'circuits/photos.json', 'circuits'),
}))));
if (!state.chosen) showEntry();
}
function renderSeason() {
const year = $('season').value;
if (!year) return;
$('sat-title').hidden = true;
$('sat').replaceChildren();
for (const m of satMaps) m.remove();
satMaps = [];
satShown = '';
const picks = picksOf('seasons');
const list = state.candidates.seasons[year] || null;
const current = picks && picks[year];
@@ -457,8 +683,7 @@
} else {
const near = Object.keys(picks).sort((a, b) => Math.abs(a - year) - Math.abs(b - year) || a - b).slice(0, 10);
$('others').replaceChildren(near.length
? grid(near.map((y) => photoCard({ ...picks[y], thumb: thumbOf(picks[y].file) },
{ label: `${y}${y === year ? ' (this season, picked now)' : ''}`, picked: y === year })), 'small')
? grid(near.map((y) => pickCard(picks[y], `${y}${y === year ? ' (this season, picked now)' : ''}`, y === year)), 'small')
: h('p', { class: 'hint' }, 'No season has a pick yet.'));
}