Add an example site that calls every route, served at /examples/

A reader learns the API fastest from working calls: one page per area
(circuit browser, track images, GPS traces on a map, grand prix lookup,
posters, Kometa) shows the exact request URL next to its answer. Pages
call their own origin when the app serves them, and the public service
when opened from disk or given ?api=. Posters render only on a button
press, since each one fetches map tiles on the server. A body that does
not match the asked format is said in red, never shown as success.

The image copies examples/ so the deployed app serves the same pages.

Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
This commit is contained in:
2026-11-27 09:48:04 +01:00
parent 3271e2d563
commit b6e6e9d565
12 changed files with 2027 additions and 1 deletions
+151
View File
@@ -0,0 +1,151 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Track images · F1 Circuits API examples</title>
<meta name="description" content="Fetch one F1 track layout as SVG, PNG or GeoJSON, by layout or by the year it was raced.">
<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" aria-current="page">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="kometa.html">Kometa</a>
</nav>
<div id="api-base"></div>
</header>
<main>
<h1>Track images</h1>
<p class="lead">
Every layout comes in three formats: <code>svg</code> (a vector drawing), <code>png</code> (an image) and
<code>geojson</code> (the GPS trace it was drawn from). Ask for one by its layout, or by a year: the API then picks
the layout that was raced that year.
</p>
<div class="card" id="tree">
<h3>The pickers below are filled from one call</h3>
<div class="request"></div>
<div class="status"></div>
<div class="result"></div>
</div>
<section class="card" id="by-layout">
<h2>By layout</h2>
<p><code>/circuits/{country}/{city}/{circuit}/layout/{layout}/{format}</code></p>
<div class="controls" id="layout-picker"></div>
<div class="controls"><fieldset id="layout-format"><legend>Format</legend></fieldset></div>
<div class="request"></div>
<div class="status idle">Choose a layout.</div>
<div class="result"></div>
</section>
<section class="card" id="by-year">
<h2>By year</h2>
<p>
<code>/tracks/{country}/{city}/{circuit}/year/{year}/{format}</code>. A year no layout of the circuit covers has
no track; the list under the picker shows the years each layout covers.
</p>
<div class="controls" id="year-picker"></div>
<div class="controls">
<label>Year <input type="number" id="year" min="1950" max="2100"></label>
<fieldset id="year-format"><legend>Format</legend></fieldset>
</div>
<p class="hint" id="year-layouts"></p>
<div class="request"></div>
<div class="status idle">Choose a circuit and a year.</div>
<div class="result"></div>
</section>
<h2>About the answers</h2>
<table class="kv">
<tr><th><code>svg</code></th><td><code>image/svg+xml</code>, sent as an attachment: an <code>&lt;img&gt;</code> shows it, a browser tab opening the URL saves it. A black line on a transparent ground.</td></tr>
<tr><th><code>png</code></th><td><code>image/png</code>, shown inline.</td></tr>
<tr><th><code>geojson</code></th><td><code>application/geo+json</code>: a <code>FeatureCollection</code> whose <code>LineString</code> is the trace as <code>[longitude, latitude]</code> points; see <a href="map.html">GPS traces</a> to draw one.</td></tr>
<tr><th>Caching</th><td>Every file answers <code>Cache-Control: public, max-age=31536000</code> and an <code>ETag</code>.</td></tr>
</table>
</main>
<footer class="pager">
<a rel="prev" href="circuits.html">← Circuit browser</a>
<a class="home" href="index.html">All examples</a>
<a rel="next" href="map.html">GPS traces →</a>
</footer>
<script src="site.js"></script>
<script>
(function () {
const { h, api, path, call, showImage, showGeoJSON, layoutPicker, layoutYears, layoutStart } = F1;
const $ = (id) => document.getElementById(id);
const FORMATS = ['svg', 'png', 'geojson'];
function formatRadios(fieldset, name, initial, onChange) {
for (const f of FORMATS) {
const input = h('input', { type: 'radio', name, value: f, checked: f === initial });
input.addEventListener('change', () => onChange(f));
fieldset.append(h('label', { class: 'inline' }, input, f));
}
return () => fieldset.querySelector('input:checked').value;
}
async function show(card, url, format, alt) {
const answer = await call(card, url, { waiting: 'Fetching the file…' });
const out = card.querySelector('.result');
if (!answer) { out.replaceChildren(); return; }
const status = card.querySelector('.status');
if (format === 'geojson') await showGeoJSON(out, answer, { status });
else await showImage(out, answer, format, { alt, status });
}
// ---- by layout
const initialFormat = FORMATS.includes(F1.params.get('format')) ? F1.params.get('format') : 'svg';
let layoutPick = null;
const layoutFormat = formatRadios($('layout-format'), 'layout-format', initialFormat, () => byLayout());
function byLayout() {
if (!layoutPick || !layoutPick.layout) return;
const p = layoutPick;
const f = layoutFormat();
show($('by-layout'), api(path`/circuits/${p.country}/${p.city}/${p.circuit}/layout/${p.layout}/${f}`), f,
`${p.circuitName}, ${layoutYears(p.layout)}`);
}
layoutPicker($('layout-picker'), { treeCard: $('tree'), sync: true, onChange: (p) => { layoutPick = p; byLayout(); } });
// ---- by year
let yearPick = null;
const yearInput = $('year');
const yearFormat = formatRadios($('year-format'), 'year-format', 'png', () => byYear());
function byYear() {
if (!yearPick) return;
const p = yearPick;
const f = yearFormat();
const y = parseInt(yearInput.value, 10);
if (!(y > 0)) return;
show($('by-year'), api(path`/tracks/${p.country}/${p.city}/${p.circuit}/year/${y}/${f}`), f, `${p.circuitName}, ${y}`);
}
yearInput.addEventListener('change', byYear);
layoutPicker($('year-picker'), {
treeCard: $('tree'),
layout: false,
onChange: (p) => {
const first = yearPick === null;
yearPick = p;
const ranges = p.layouts.map(layoutYears).join(' · ');
F1.setHint($('year-layouts'), '', `Layouts of ${p.circuitName}: ${ranges}`);
const newest = p.layouts[p.layouts.length - 1];
const wanted = first ? parseInt(F1.params.get('year'), 10) : NaN;
yearInput.value = wanted > 0 ? wanted : (newest ? Math.max(layoutStart(newest), 1950) : 2024);
byYear();
},
});
})();
</script>
</body>
</html>