Files
f1-circuits/examples/builder.html
T
jschoubben 445235ca58 Show bg=photo apart from bg=satellite, on the service's layers
The operator, after seeing real posters: EOX's 2016 mosaic is rejected, and a layout's Commons
photo now serves only an explicit bg=photo, which falls back to what bg=satellite draws. The
picker therefore puts the satellite-or-map choice first, per layout, on the layers the service
uses (PDOK HR, IGN's frozen BD ORTHO 2021-2023, USGS, EOxCloudless 2025), and offers the photos
as optional for bg=photo. One picks entry may carry a photo, "use": "map", or both, and each
choice keeps the other half. The builder and the posters page offer bg=photo; width starts at
400; the licences page sets the options in "used for" as code.

Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
2026-11-27 15:20:09 +01:00

361 lines
17 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Poster builder · F1 Circuits API examples</title>
<meta name="description" content="Build a race poster, season poster or session thumbnail address of the F1 Circuits API option by option, render it, and read the credits it carries.">
<link rel="icon" href="data:,">
<link rel="stylesheet" href="site.css">
</head>
<body>
<header class="site">
<a class="brand" href="index.html">F1 <span>Circuits</span> API</a>
<nav aria-label="Examples">
<a href="index.html">Overview</a>
<a href="circuits.html">Circuit browser</a>
<a href="tracks.html">Track images</a>
<a href="map.html">GPS traces</a>
<a href="grand-prix.html">Grand prix lookup</a>
<a href="posters.html">Posters</a>
<a href="builder.html" aria-current="page">Poster builder</a>
<a href="kometa.html">Kometa</a>
<a href="library.html">Library</a>
<a href="picker.html">Photo picker</a>
<a href="licences.html">Licences</a>
</nav>
<div id="api-base"></div>
</header>
<main>
<h1>Poster builder</h1>
<p class="lead">
Every poster route takes the same options as query parameters. Tick an option to send it; an option left out takes
its default. The address below follows every change, and the picture is rendered only when you press the button,
because the server draws it and may fetch map tiles first.
</p>
<section class="card" id="what">
<h2>1. Which picture</h2>
<div class="controls">
<label><span>Route</span>
<span class="seg" id="route">
<button type="button" data-v="race">Race poster</button><button type="button" data-v="season">Season poster</button><button type="button" data-v="session">Session thumbnail</button>
</span>
</label>
</div>
<div id="race-wrap"><div class="controls" id="race-picker"></div></div>
<div class="controls">
<label id="season-label">Season <input type="number" id="season" min="1950" max="2100"></label>
<label id="session-label"><span>Session</span> <select id="session"></select></label>
</div>
<div class="request"></div>
<div class="status"></div>
</section>
<section class="card">
<h2>2. The options</h2>
<p class="hint">An unknown option or value is answered 422, naming it. The credit line is drawn on every picture
whatever the options; no option takes it off.</p>
<div class="options" id="options"></div>
</section>
<section class="card" id="render-card">
<h2>3. The picture</h2>
<div class="controls">
<button type="button" class="primary" id="render">Render it</button>
</div>
<div class="request"></div>
<div class="status idle">Not rendered yet.</div>
<div class="result preview"></div>
<div class="credits" id="credits"></div>
</section>
</main>
<footer class="pager">
<a rel="prev" href="posters.html">← Posters</a>
<a class="home" href="index.html">All examples</a>
<a rel="next" href="kometa.html">Kometa →</a>
</footer>
<footer class="disclaimer">
<p>This website is unofficial and is not associated in any way with the Formula 1 companies. F1, FORMULA ONE,
FORMULA 1, FIA FORMULA ONE WORLD CHAMPIONSHIP, GRAND PRIX and related marks are trade marks of Formula One
Licensing B.V.</p>
<p><a href="licences.html">Licences and credits</a>: every source the pictures are made from, the licence each
picture takes from its sources, and the licence of the track files and the GPS traces (MIT).</p>
</footer>
<script src="site.js"></script>
<script>
(function () {
const { h, api, path, call, setRequest, setStatus, showImage, racePicker, notice, params } = F1;
const $ = (id) => document.getElementById(id);
const FRAME_WIDTH = { race: 1000, season: 1000, session: 1920 };
const SHOW = ['wordmark', 'round', 'name', 'subtitle', 'date', 'circuit', 'locality', 'session'];
// The design's Options table (docs/posters.md), in its order; photo per the operator's decision of 2026-11-27.
const OPTIONS = [
{ name: 'style', kind: 'select', def: 'classic', values: [['classic', 'classic'], ['minimal', 'minimal']],
note: 'A preset of the options below; any option given overrides it.' },
{ name: 'bg', kind: 'select', def: 'satellite', values: [
['satellite', 'satellite: the national aerial photo, else EOxCloudless 2025; the dark map for a layout that asks for it'],
['aerial', 'aerial: the same as satellite, for addresses in use'],
['photo', 'photo: the layout’s picked Commons photo, else what satellite draws'],
['osm', 'osm: OpenStreetMap'], ['dark', 'dark: OpenStreetMap, recoloured dark'],
['light', 'light: OpenStreetMap, recoloured light'], ['none', 'none: no map']],
note: 'The kept map or photo layer.' },
{ name: 'photo', kind: 'select', def: 'natural', values: [['natural', 'natural'], ['bw', 'bw: black and white']],
note: 'The treatment of a photo layer.' },
{ name: 'show', kind: 'list', def: 'the style’s', note: 'What is written on the picture, drawn on the fly.' },
{ name: 'locator', kind: 'select', def: 'on', values: [['on', 'on'], ['off', 'off']], note: 'The kept world locator.' },
{ name: 'checker', kind: 'select', def: 'on', values: [['on', 'on'], ['off', 'off']], note: 'The chequered band, drawn on the fly.' },
{ name: 'track', kind: 'track', def: 'white, 6', note: 'The outline, from the kept points; an inset over a photo layer.' },
{ name: 'dim', kind: 'range', def: 'the style’s', note: 'How much the background is darkened, 0 to 1.' },
{ name: 'accent', kind: 'color', def: 'the style’s', note: 'The wordmark’s colour.' },
{ name: 'width', kind: 'width', def: 'the frame’s', note: 'Scaled down at encoding, from 400 up to the frame’s width.' },
{ name: 'format', kind: 'select', def: 'png', values: [['png', 'png'], ['jpg', 'jpg'], ['webp', 'webp']], note: 'The encoding.' },
];
let route = ['race', 'season', 'session'].includes(params.get('route')) ? params.get('route') : 'race';
let chosen = null;
let seasonTouched = false;
// ------------------------------------------------------------ the option cards
/** One card per option: a tick to send it, and its control. Each returns its value, or null when not sent. */
const controls = OPTIONS.map((o) => {
const give = h('input', { type: 'checkbox', 'aria-label': `Send ${o.name}` });
const body = h('div', { class: 'opt-body' });
const box = h('div', { class: 'option' },
h('div', { class: 'opt-head' },
h('label', {}, give, ' ', h('code', {}, o.name)),
h('small', {}, `default: ${o.def}`)),
body,
h('div', { class: 'hint' }, o.note));
let value = () => null;
const touch = () => { give.checked = true; changed(); };
if (o.kind === 'select') {
const sel = h('select', { 'aria-label': o.name }, ...o.values.map(([v, label]) => h('option', { value: v }, label)));
sel.value = o.def;
sel.addEventListener('change', touch);
body.append(sel);
value = () => sel.value;
box._set = (v) => { sel.value = v; };
} else if (o.kind === 'list') {
const boxes = SHOW.map((s) => {
const c = h('input', { type: 'checkbox', value: s, checked: true });
c.addEventListener('change', touch);
body.append(h('label', {}, c, s));
return c;
});
value = () => boxes.filter((c) => c.checked).map((c) => c.value).join(',');
box._set = (v) => { const want = new Set(v.split(',')); for (const c of boxes) c.checked = want.has(c.value); };
} else if (o.kind === 'track') {
const off = h('input', { type: 'radio', name: 'track-kind', value: 'off' });
const colour = h('input', { type: 'radio', name: 'track-kind', value: 'colour', checked: true });
const pick = h('input', { type: 'color', value: '#ffffff', 'aria-label': 'Track colour' });
const width = h('input', { type: 'number', min: 1, max: 40, value: '6', 'aria-label': 'Track width', style: 'width:4.5rem' });
for (const el of [off, colour, pick, width]) el.addEventListener('input', touch);
pick.addEventListener('input', () => { colour.checked = true; });
width.addEventListener('input', () => { colour.checked = true; });
body.append(h('label', {}, off, 'off'), h('label', {}, colour, 'colour'), pick, h('label', {}, 'width', width));
value = () => (off.checked ? 'off' : `${pick.value}${width.value ? `,${width.value}` : ''}`);
box._set = (v) => {
if (v === 'off') { off.checked = true; return; }
const [c, w] = v.split(',');
colour.checked = true;
if (/^#[0-9a-f]{6}$/i.test(c)) pick.value = c;
width.value = w || '';
};
} else if (o.kind === 'range') {
const range = h('input', { type: 'range', min: 0, max: 1, step: 0.05, value: 0.5, 'aria-label': o.name });
const shown = h('output', {}, '0.50');
range.addEventListener('input', () => { shown.textContent = Number(range.value).toFixed(2); touch(); });
body.append(range, shown);
value = () => String(Number(range.value));
box._set = (v) => { range.value = v; shown.textContent = Number(v).toFixed(2); };
} else if (o.kind === 'color') {
const pick = h('input', { type: 'color', value: '#dc1220', 'aria-label': o.name });
pick.addEventListener('input', touch);
body.append(pick);
value = () => pick.value;
box._set = (v) => { if (/^#[0-9a-f]{6}$/i.test(v)) pick.value = v; };
} else if (o.kind === 'width') {
const num = h('input', { type: 'number', min: 400, step: 10, value: 600, 'aria-label': o.name });
const max = h('span', { class: 'hint' });
num.addEventListener('input', touch);
body.append(num, max);
box._max = (m) => { num.max = m; max.textContent = `400 to ${m} for this route`; };
value = () => num.value;
box._set = (v) => { num.value = v; };
}
give.addEventListener('change', changed);
$('options').append(box);
return { o, box, give, value: () => (give.checked ? value() : null) };
});
// Options given in the page's address are ticked and set: a copied address opens as it was built.
for (const c of controls) {
if (params.has(c.o.name) && c.box._set) { c.box._set(params.get(c.o.name)); c.give.checked = true; }
}
// ------------------------------------------------------------ the address
/** A query value encoded, its commas kept readable (a comma needs no encoding in a query). */
const enc = (v) => encodeURIComponent(v).replace(/%2C/gi, ',');
function query() {
const parts = [];
for (const c of controls) {
c.box.classList.toggle('set', c.give.checked);
const v = c.value();
if (v !== null) parts.push(`${c.o.name}=${enc(v)}`);
}
return parts.length ? `?${parts.join('&')}` : '';
}
function routePath() {
if (route === 'season') return $('season').value ? path`/posters/season/${$('season').value}.png` : null;
if (!chosen || !chosen.name) return null;
if (route === 'race') return path`/posters/race/${chosen.name}/${chosen.season}.png`;
return path`/posters/session/${chosen.name}/${chosen.season}/${$('session').value}.png`;
}
function currentURL() {
const p = routePath();
return p ? api(p) + query() : null;
}
function syncPage() {
const url = new URL(location.href);
url.searchParams.set('route', route);
for (const c of controls) {
const v = c.value();
if (v === null) url.searchParams.delete(c.o.name); else url.searchParams.set(c.o.name, v);
}
if (route === 'season') url.searchParams.set('season', $('season').value);
history.replaceState(null, '', url.href);
}
const card = $('render-card');
function changed() {
for (const b of $('route').querySelectorAll('button')) b.setAttribute('aria-pressed', String(b.dataset.v === route));
// The race picker, its hint and its Jolpica call serve the race and session routes only.
$('race-wrap').hidden = route === 'season';
for (const sel of ['.request', '.status']) $('what').querySelector(`:scope > ${sel}`).hidden = route === 'season';
$('season-label').hidden = route !== 'season';
$('session-label').hidden = route !== 'session';
const width = controls.find((c) => c.o.name === 'width');
width.box._max(FRAME_WIDTH[route]);
const url = currentURL();
syncPage();
card._wanted = url;
if (!url) {
card.querySelector('.request').replaceChildren();
setStatus(card.querySelector('.status'), 'idle', 'Choose a race first.');
return;
}
if (card._shown === url) return;
setRequest(card.querySelector('.request'), url);
card.querySelector('.result').replaceChildren();
$('credits').replaceChildren();
card._shown = null;
if (!card.querySelector('.status').classList.contains('pending')) {
setStatus(card.querySelector('.status'), 'idle', 'Not rendered yet: press the button.');
}
}
// ------------------------------------------------------------ rendering, and the credits it carries
/** The answer's credit headers: what a page on another origin reads only when the service exposes them. */
function showCredits(answer) {
const get = (n) => answer.headers.get(n);
const credits = get('X-Credits');
const licence = get('X-License');
const link = get('Link');
const rows = [
['X-Credits', credits ? h('code', {}, credits) : h('em', {}, 'not readable')],
['X-License', licence ? h('code', {}, licence) : h('em', {}, 'not readable')],
['Link', link ? h('code', {}, link) : h('em', {}, 'not readable')],
['Cache-Control', get('Cache-Control') ? h('code', {}, get('Cache-Control')) : h('em', {}, 'none')],
['ETag', get('ETag') ? h('code', {}, get('ETag')) : h('em', {}, 'none or not readable')],
];
const parts = [
h('h3', {}, 'What the answer says about its sources and its licence'),
h('table', { class: 'kv' }, h('tbody', {}, ...rows.map(([k, v]) => h('tr', {}, h('th', {}, k), h('td', {}, v))))),
];
const unread = [!credits && 'X-Credits', !licence && 'X-License'].filter(Boolean);
if (unread.length) {
parts.push(notice('error', `The answer carries no ${unread.join(' or ')} header this page can read. Either the service does not send it yet, or the page runs on another origin and the service does not expose the header through CORS (Access-Control-Expose-Headers).`));
}
if (credits) {
parts.push(h('p', { class: 'hint' }, 'X-Credits is plain ASCII, folded from the credit drawn on the picture: accents dropped, dashes written as "-". The exact text of every credit is on ',
h('a', { href: F1.linkWithKept('licences.html') }, 'the licences page'), '.'));
}
$('credits').replaceChildren(...parts);
}
async function render() {
const url = currentURL();
if (!url) return;
const button = $('render');
button.disabled = true;
try {
const answer = await call(card, url, { waiting: 'Rendering on the server: a picture whose layers are not kept yet fetches them first…' });
if (card._wanted !== url) {
setRequest(card.querySelector('.request'), card._wanted);
setStatus(card.querySelector('.status'), 'idle', 'The choice changed while it rendered: press the button again.');
return;
}
const out = card.querySelector('.result');
if (!answer) { out.replaceChildren(); $('credits').replaceChildren(); return; }
const format = (controls.find((c) => c.o.name === 'format').value()) || 'png';
await showImage(out, answer, format, {
alt: 'The rendered picture', tile: false,
className: route === 'session' ? 'poster' : 'poster portrait', status: card.querySelector('.status'),
});
showCredits(answer);
card._shown = url;
} finally {
button.disabled = false;
}
}
// ------------------------------------------------------------ the picture's subject
function fillSessions() {
const keep = $('session').value || params.get('session') || 'race';
const own = chosen && chosen.sprint ? F1.SESSIONS.sprint : F1.SESSIONS.standard;
$('session').replaceChildren(...own.map(([s, label], i) => h('option', { value: s }, `Episode ${i + 1} · ${label} (${s})`)));
$('session').value = own.some(([s]) => s === keep) ? keep : 'race';
}
$('route').addEventListener('click', (e) => {
const b = e.target.closest('button');
if (!b) return;
route = b.dataset.v;
changed();
});
$('season').addEventListener('input', () => { seasonTouched = true; changed(); });
$('session').addEventListener('change', changed);
$('render').addEventListener('click', render);
$('season').value = params.get('season') || 2024;
changed();
racePicker($('race-picker'), {
card: $('what'),
onChange: (c) => {
chosen = c;
if (!seasonTouched && !params.get('season')) $('season').value = c.season;
fillSessions();
changed();
},
});
})();
</script>
</body>
</html>