The operator wants to browse the posters the way a Plex or Emby Formula 1 library shows them. The page reads the whole library from the one Kometa file (rounds, race names in the race posters' addresses, sessions in the episodes'), waits through a fresh server's minutes-long first answer instead of failing, and loads each picture only when it is on screen, two at a time, dropping the queue when the reader leaves a level: every poster is a render of about 10 s that pulls map tiles. Each level has its own address and back/forward work; a picture the server has none for is a plain card with its name. The session order per weekend format moves into site.js, so the posters page and the library read the same list. Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
153 lines
6.2 KiB
HTML
153 lines
6.2 KiB
HTML
<!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>
|
|
<a href="library.html">Library</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><img></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>
|