Files
f1-circuits/examples/tracks.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

163 lines
6.8 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="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>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>
<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, 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>