Files
f1-circuits/examples/circuits.html
T
jschoubben 49a2ebcf15 Add the photo picker, poster builder and licences pages
A pick is a repository edit, so the picker shows the Commons candidates cropped to the poster's
frame, natural or bw as the service treats them, beside the picks of the circuit's other
layouts, and gives the entry to copy (the picks file's "$comment" kept first). The builder sends
every option of docs/posters.md as a query parameter, renders only on request and shows the
answer's X-Credits and X-License. The licences page shows /licences: each source, its credit and
the licence a picture made from it gets.

Every page now carries the Formula 1 disclaimer at its foot, as F1's guidelines ask of an
unofficial site, and the posters page lists the backgrounds the design keeps (no Esri).

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

231 lines
10 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>Circuit browser · F1 Circuits API examples</title>
<meta name="description" content="Browse the F1 Circuits catalogue: countries, cities, circuits and layouts, with each layout's track image.">
<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" aria-current="page">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">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>Circuit browser</h1>
<p class="lead">
The catalogue is a tree: a country holds cities, a city holds circuits, a circuit holds layouts. Each level has a
route; pick an entry to make the next call. Every layout shows its track image.
</p>
<section class="card" id="countries">
<h2>1. Countries</h2>
<p><code>/circuits</code> lists every country, and nests its whole tree inside each one.</p>
<div class="request"></div>
<div class="status"></div>
<div class="choices" id="country-list"></div>
<details><summary>The JSON answer</summary><div class="result"></div></details>
</section>
<section class="card" id="cities">
<h2>2. Cities of a country</h2>
<p><code>/circuits/{country}</code> answers <code>{"cities": [...]}</code>, each city with its circuits.</p>
<div class="request"></div>
<div class="status idle">Pick a country above.</div>
<div class="choices" id="city-list"></div>
<details><summary>The JSON answer</summary><div class="result"></div></details>
</section>
<section class="card" id="circuits">
<h2>3. Circuits in a city</h2>
<p><code>/circuits/{country}/{city}</code> answers <code>{"circuits": [...]}</code>.</p>
<div class="request"></div>
<div class="status idle">Pick a city above.</div>
<div class="choices" id="circuit-list"></div>
<details><summary>The JSON answer</summary><div class="result"></div></details>
</section>
<section class="card" id="circuit">
<h2>4. One circuit and its layouts</h2>
<p>
<code>/circuits/{country}/{city}/{circuit}</code> answers the circuit’s name, its Wikipedia and Fandom pages and
its layouts. Each layout’s image below is its own call,
<code>/circuits/{country}/{city}/{circuit}/layout/{layout}/svg</code> (see <a href="tracks.html">Track images</a>).
</p>
<div class="request"></div>
<div class="status idle">Pick a circuit above.</div>
<div id="circuit-head"></div>
<div class="layouts" id="layout-list"></div>
<details><summary>The JSON answer</summary><div class="result"></div></details>
</section>
<section class="card" id="layout">
<h2>5. One layout</h2>
<p>
<code>/circuits/{country}/{city}/{circuit}/layout/{layout}</code> answers one layout: its slug, its description
and <code>imageUrl</code>, the source drawing on the F1 Fandom wiki.
</p>
<div class="request"></div>
<div class="status idle" data-idle="Press “Details” on a layout above.">Press “Details” on a layout above.</div>
<div class="result"></div>
</section>
</main>
<footer class="pager">
<a rel="prev" href="index.html">← Overview</a>
<a class="home" href="index.html">All examples</a>
<a rel="next" href="tracks.html">Track images →</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, callJSON, setRequest, layoutYears, layoutStart } = F1;
const $ = (id) => document.getElementById(id);
const want = {
country: F1.params.get('country') || 'belgium',
city: F1.params.get('city') || 'spa',
circuit: F1.params.get('circuit') || 'circuit-de-spa-francorchamps',
};
const state = {};
function remember() {
const url = new URL(location.href);
for (const k of ['country', 'city', 'circuit']) {
if (state[k]) url.searchParams.set(k, state[k]); else url.searchParams.delete(k);
}
history.replaceState(null, '', url.href);
}
function choices(el, items, pressed, onPick) {
el.replaceChildren(...items.map((it) => {
const b = h('button', { type: 'button', 'aria-pressed': String(it.slug === pressed), title: `slug: ${it.slug}` },
it.name, ' ', h('small', {}, it.note));
b.addEventListener('click', () => {
for (const o of el.querySelectorAll('button')) o.setAttribute('aria-pressed', String(o === b));
onPick(it.slug);
});
return b;
}));
}
function clear(...ids) {
for (const id of ids) {
const card = $(id);
card.querySelector('.request').replaceChildren();
const s = card.querySelector('.status');
s.className = 'status idle';
s.textContent = s.dataset.idle || 'Pick an entry above.';
card.querySelector('.result').replaceChildren();
}
if (ids.includes('cities')) $('city-list').replaceChildren();
if (ids.includes('circuits')) $('circuit-list').replaceChildren();
if (ids.includes('circuit')) { $('circuit-head').replaceChildren(); $('layout-list').replaceChildren(); }
}
const byName = (a, b) => a.name.localeCompare(b.name);
const count = (n, one, many) => `${n} ${n === 1 ? one : many}`;
async function loadCountries() {
const v = await callJSON($('countries'), api('/circuits'));
if (!v) return;
const list = [...v.countries].sort(byName);
choices($('country-list'), list.map((c) => ({ slug: c.slug, name: c.name, note: count(Object.keys(c.localities).length, 'city', 'cities') })),
want.country, pickCountry);
if (list.some((c) => c.slug === want.country)) pickCountry(want.country);
}
async function pickCountry(slug) {
state.country = slug; state.city = state.circuit = null; remember();
clear('cities', 'circuits', 'circuit', 'layout');
const v = await callJSON($('cities'), api(path`/circuits/${slug}`));
if (!v) return;
const list = [...v.cities].sort(byName);
choices($('city-list'), list.map((c) => ({ slug: c.slug, name: c.name, note: count(Object.keys(c.circuits).length, 'circuit', 'circuits') })),
want.city, pickCity);
const next = list.find((c) => c.slug === want.city) || (list.length === 1 ? list[0] : null);
if (next) { $('city-list').querySelector(`[title="slug: ${CSS.escape(next.slug)}"]`).setAttribute('aria-pressed', 'true'); pickCity(next.slug); }
}
async function pickCity(slug) {
state.city = slug; state.circuit = null; remember();
clear('circuits', 'circuit', 'layout');
const v = await callJSON($('circuits'), api(path`/circuits/${state.country}/${slug}`));
if (!v) return;
const list = [...v.circuits].sort(byName);
choices($('circuit-list'), list.map((c) => ({ slug: c.slug, name: c.name, note: count(Object.keys(c.layouts).length, 'layout', 'layouts') })),
want.circuit, pickCircuit);
const next = list.find((c) => c.slug === want.circuit) || (list.length === 1 ? list[0] : null);
if (next) { $('circuit-list').querySelector(`[title="slug: ${CSS.escape(next.slug)}"]`).setAttribute('aria-pressed', 'true'); pickCircuit(next.slug); }
}
async function pickCircuit(slug) {
state.circuit = slug; remember();
clear('circuit', 'layout');
const { country, city } = state;
const v = await callJSON($('circuit'), api(path`/circuits/${country}/${city}/${slug}`));
if (!v) return;
$('circuit-head').replaceChildren(
h('h3', {}, v.name),
h('p', {}, 'Read more: ',
v.urls.wikipedia ? h('a', { href: v.urls.wikipedia, target: '_blank', rel: 'noopener' }, 'Wikipedia') : null,
v.urls.wikipedia && v.urls.fandom ? ' · ' : null,
v.urls.fandom ? h('a', { href: v.urls.fandom, target: '_blank', rel: 'noopener' }, 'F1 Fandom wiki') : null));
const slugs = Object.keys(v.layouts).sort((a, b) => layoutStart(a) - layoutStart(b));
$('layout-list').replaceChildren(...slugs.map((l) => layoutCard(country, city, slug, v.layouts[l])));
}
function layoutCard(country, city, circuit, layout) {
const imgUrl = api(path`/circuits/${country}/${city}/${circuit}/layout/${layout.slug}/svg`);
const req = h('div', { class: 'request compact' });
setRequest(req, imgUrl);
const img = h('img', { src: imgUrl, alt: `Track layout ${layoutYears(layout.slug)}`, loading: 'lazy' });
const tile = h('div', { class: 'track-tile' }, img);
img.addEventListener('error', () => tile.replaceChildren(F1.notice('error', 'The image did not load; open its URL to see why.')));
const q = new URLSearchParams({ country, city, circuit, layout: layout.slug }).toString();
const details = h('button', { type: 'button' }, 'Details');
details.addEventListener('click', () => {
callJSON($('layout'), api(path`/circuits/${country}/${city}/${circuit}/layout/${layout.slug}`));
$('layout').scrollIntoView({ behavior: 'smooth', block: 'start' });
});
return h('div', { class: 'layout-card' },
h('h3', {}, layoutYears(layout.slug), ' ', h('small', {}, h('code', {}, layout.slug))),
tile,
req,
h('p', {}, layout.description || 'No description.'),
h('div', { class: 'links' },
details,
h('a', { href: F1.linkWithKept(`tracks.html?${q}`) }, 'All formats'),
h('a', { href: F1.linkWithKept(`map.html?${q}`) }, 'On the map'),
layout.imageUrl ? h('a', { href: layout.imageUrl, target: '_blank', rel: 'noopener' }, 'Source drawing') : null));
}
loadCountries();
})();
</script>
</body>
</html>