Files
f1-circuits/examples/posters.html
T
jschoubben ec94c69222 Draw dark and light posters from Esri; keep no poster whose picture failed
CARTO's basemaps now need an API key and answer every tile with an "API
KEY REQUIRED" picture under a 200, so the dark and light backgrounds and
the world locator showed that text. They now use Esri's grey canvases,
which need no key and draw to zoom 16; each provider names its deepest
zoom, and a race poster resolves its position once, capped to it, for
the map, the projected track and the locator alike. One tile stitcher
replaces three copies and refuses a map whose tiles are all the same
picture: a provider's placeholder is said in the log, not drawn.

A race poster, a thumb or a season poster whose map or photo failed is
served but no longer kept, so the next ask renders it again; race
posters carry a render version in their file name, so those drawn over
CARTO's placeholder are rendered again.

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

222 lines
9.8 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>Posters · F1 Circuits API examples</title>
<meta name="description" content="Render F1 race posters, season posters and session thumbnails for Plex from the F1 Circuits API.">
<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" aria-current="page">Posters</a>
<a href="kometa.html">Kometa</a>
</nav>
<div id="api-base"></div>
</header>
<main>
<h1>Posters</h1>
<p class="lead">
The API renders artwork for a Formula 1 library in Plex: a 1000×1500 poster per race and per season, and a
1920×1080 thumbnail per session of a race weekend. The server draws each one on request, fetching map tiles for its
background, and keeps it on disk afterwards; so this page renders only the one you ask for, when you press its
button.
</p>
<section class="card" id="races">
<h2>1. Choose a race</h2>
<p>The race poster and the session thumbnails name the race as Jolpica’s <code>raceName</code>; this list comes from Jolpica.</p>
<div class="controls" id="race-picker"></div>
<div class="request"></div>
<div class="status"></div>
</section>
<div class="grid-2">
<section class="card" id="race-poster">
<h2>Race poster</h2>
<p><code>/posters/race/{race name}/{season}.png?bg={background}</code>, 1000×1500: the round, the race’s name, the track and its date over a map of the circuit.</p>
<div class="controls">
<label><span>Background (<code>bg</code>)</span>
<select id="bg">
<option value="aerial">aerial: Esri satellite imagery (the default)</option>
<option value="osm">osm: OpenStreetMap street map</option>
<option value="dark">dark: Esri Dark Gray Canvas</option>
<option value="light">light: Esri Light Gray Canvas</option>
<option value="none">none: plain black, no tiles (fastest)</option>
</select>
</label>
<button type="button" class="primary" id="render-race">Render the race poster</button>
</div>
<div class="request compact"></div>
<div class="status idle">Not rendered yet.</div>
<div class="result preview"></div>
</section>
<section class="card" id="season-poster">
<h2>Season poster</h2>
<p><code>/posters/season/{season}.png</code>, 1000×1500: the year over a photo of that season’s cars, or over black when the server has no photo for it.</p>
<div class="controls">
<label>Season <input type="number" id="season" min="1950" max="2100"></label>
<button type="button" class="primary" id="render-season">Render the season poster</button>
</div>
<div class="request compact"></div>
<div class="status idle">Not rendered yet.</div>
<div class="result preview"></div>
</section>
</div>
<section class="card" id="session-thumb">
<h2>Session thumbnail</h2>
<p>
<code>/posters/session/{race name}/{season}/{session}.png</code>, 1920×1080: an aerial view of the circuit with
the race’s name and the session’s label. Kometa numbers a weekend’s episodes differently for a standard weekend
(10 episodes) and a sprint weekend (15); the list shows the chosen race’s format first, in episode order.
</p>
<div class="controls">
<label><span>Session (<code>session</code>)</span> <select id="session"></select></label>
<button type="button" class="primary" id="render-session">Render the thumbnail</button>
</div>
<div class="request"></div>
<div class="status idle">Not rendered yet.</div>
<div class="result preview"></div>
</section>
<h2>Every session slug</h2>
<table>
<thead><tr><th>Slug</th><th>Label on the thumbnail</th><th>Episode, standard weekend</th><th>Episode, sprint weekend</th></tr></thead>
<tbody id="slugs"></tbody>
</table>
</main>
<footer class="pager">
<a rel="prev" href="grand-prix.html">← Grand prix lookup</a>
<a class="home" href="index.html">All examples</a>
<a rel="next" href="kometa.html">Kometa →</a>
</footer>
<script src="site.js"></script>
<script>
(function () {
const { h, api, path, call, setRequest, setStatus, showImage, racePicker } = F1;
const $ = (id) => document.getElementById(id);
// Kometa's episode numbering per weekend format: the same maps the service renders from.
const STANDARD = [
['fp1', 'Free Practice 1'], ['fp2', 'Free Practice 2'], ['fp3', 'Free Practice 3'],
['pre-qualifying', 'Pre-Qualifying Buildup'], ['qualifying', 'Qualifying'], ['post-qualifying', 'Post-Qualifying'],
['pre-race', 'Pre-Race Buildup'], ['race', 'Race'], ['post-race', 'Post-Race'], ['highlights', 'Highlights'],
];
const SPRINT = [
['fp1', 'Free Practice 1'], ['pre-sprint-qualifying', 'Pre-Sprint-Qualifying Buildup'],
['sprint-qualifying', 'Sprint Qualifying'], ['post-sprint-qualifying', 'Post-Sprint-Qualifying'],
['pre-sprint', 'Pre-Sprint Buildup'], ['sprint', 'Sprint'], ['post-sprint', 'Post-Sprint'],
['pre-qualifying', 'Pre-Qualifying Buildup'], ['qualifying', 'Qualifying'], ['post-qualifying', 'Post-Qualifying'],
['pre-race', 'Pre-Race Buildup'], ['race', 'Race'], ['post-race', 'Post-Race'], ['highlights', 'Highlights'],
['bonus', 'Bonus Content'],
];
const LABEL = Object.fromEntries([...STANDARD, ...SPRINT]);
const ALL = Object.keys(LABEL);
$('slugs').replaceChildren(...ALL.map((slug) => {
const std = STANDARD.findIndex(([s]) => s === slug);
const spr = SPRINT.findIndex(([s]) => s === slug);
return h('tr', {}, h('td', {}, h('code', {}, slug)), h('td', {}, LABEL[slug]),
h('td', {}, std >= 0 ? String(std + 1) : '–'), h('td', {}, spr >= 0 ? String(spr + 1) : '–'));
}));
let chosen = null;
let seasonTouched = false;
/** Shows the URL a button will call, without calling it; a result of another URL is cleared. */
function preview(card, url) {
card._wanted = url;
if (card._shown === url) return;
setRequest(card.querySelector('.request'), url);
card.querySelector('.result').replaceChildren();
card._shown = null;
if (!card.querySelector('.status').classList.contains('pending')) {
setStatus(card.querySelector('.status'), 'idle', 'Not rendered yet: press the button.');
}
}
async function render(card, button, url, alt, portrait) {
button.disabled = true;
try {
const answer = await call(card, url, { waiting: 'Rendering on the server: it fetches map tiles first, a few seconds the first time…' });
const out = card.querySelector('.result');
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;
}
if (!answer) { out.replaceChildren(); return; }
await showImage(out, answer, 'png', { alt, tile: false, className: portrait ? 'poster portrait' : 'poster', status: card.querySelector('.status') });
card._shown = url;
} finally {
button.disabled = false;
}
}
const raceURL = () => api(path`/posters/race/${chosen.name}/${chosen.season}.png`) + `?bg=${encodeURIComponent($('bg').value)}`;
const seasonURL = () => api(path`/posters/season/${$('season').value}.png`);
const sessionURL = () => api(path`/posters/session/${chosen.name}/${chosen.season}/${$('session').value}.png`);
function fillSessions() {
const keep = $('session').value || 'race';
const own = chosen && chosen.sprint ? SPRINT : STANDARD;
const ownSlugs = new Set(own.map(([s]) => s));
const rest = ALL.filter((s) => !ownSlugs.has(s));
const format = chosen && chosen.race ? (chosen.sprint ? 'a sprint weekend' : 'a standard weekend') : 'format unknown, standard order';
$('session').replaceChildren(
h('optgroup', { label: `This race (${format})` },
...own.map(([s, label], i) => h('option', { value: s }, `Episode ${i + 1} · ${label} (${s})`))),
h('optgroup', { label: 'The other format’s slugs' },
...rest.map((s) => h('option', { value: s }, `${LABEL[s]} (${s})`))));
$('session').value = ALL.includes(keep) ? keep : 'race';
}
function previews() {
if (chosen && chosen.name) {
preview($('race-poster'), raceURL());
preview($('session-thumb'), sessionURL());
}
if ($('season').value) preview($('season-poster'), seasonURL());
}
$('bg').addEventListener('change', previews);
$('session').addEventListener('change', previews);
$('season').addEventListener('input', () => { seasonTouched = true; previews(); });
$('render-race').addEventListener('click', () => {
if (chosen && chosen.name) render($('race-poster'), $('render-race'), raceURL(), `${chosen.name} ${chosen.season} poster`, true);
});
$('render-season').addEventListener('click', () => {
if ($('season').value) render($('season-poster'), $('render-season'), seasonURL(), `${$('season').value} season poster`, true);
});
$('render-session').addEventListener('click', () => {
if (chosen && chosen.name) render($('session-thumb'), $('render-session'), sessionURL(), `${chosen.name} ${chosen.season} ${$('session').value} thumbnail`, false);
});
racePicker($('race-picker'), {
card: $('races'),
onChange: (c) => {
chosen = c;
if (!seasonTouched) $('season').value = c.season;
fillSessions();
previews();
},
});
})();
</script>
</body>
</html>