Files
f1-circuits/examples/tracks.html
T
jschoubben 09a83f6ad9 Guide Plex and Emby users step by step to the posters, at /guides/
People put the posters in their own libraries (one in an automated F1 library in Emby), and
the only help was the Kometa example page, written for developers. The guides are for people
who are not: numbered steps of one action each, the exact menus and buttons of Plex, Kometa and
Emby as their own documentation names them, boxes to copy, the pictures from the live API,
what to see after a step and what to do when it does not work. The technical details (routes,
options, the address version, a script and Emby's API) sit at the end of each.

guides/ holds the index, plex.html (a Plex TV library on the Personal Media Shows agent, Kometa
pointed at /kometa/formula-1-metadata.yml, its daily run) and emby.html (Kometa needs Plex, so:
Set Image from URL by hand, or picture files named as Emby's TV naming page reads them, and a
script that saves a whole season from the Kometa file). They use the example site's style
sheet; every example page's nav links them, and README.md lists them.

cdn-api.py serves guides/ at /guides/ beside /examples/, and the image copies it. A mount of a
directory the image lacks stops the service at its start, so tests/test_image.py holds that
every directory the app serves is copied by service/Dockerfile.
2026-11-30 12:46:36 +01:00

164 lines
6.9 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>
<a href="../guides/index.html">Guides</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>