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

203 lines
9.0 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>GPS traces on a map · F1 Circuits API examples</title>
<meta name="description" content="Draw an F1 track layout's GeoJSON GPS trace on a Leaflet map with OpenStreetMap or satellite tiles.">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="">
<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">Track images</a>
<a href="map.html" aria-current="page">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>GPS traces on a map</h1>
<p class="lead">
Each layout was traced by GPS along the track. Its <code>geojson</code> format is that trace: a GeoJSON
<code>FeatureCollection</code> holding one <code>LineString</code> of <code>[longitude, latitude]</code> points. Any
map library draws it as it comes; this page uses <a href="https://leafletjs.com/">Leaflet</a>. Switch to the
satellite layer (EOxCloudless, Sentinel-2 at 10 m) to see the trace over the ground.
</p>
<div class="card" id="tree">
<h3>The picker is filled from one call</h3>
<div class="request"></div>
<div class="status"></div>
<div class="result"></div>
</div>
<section class="card" id="trace">
<h2>A layout’s trace</h2>
<p><code>/circuits/{country}/{city}/{circuit}/layout/{layout}/geojson</code></p>
<div id="raw-note"></div>
<div class="controls" id="picker"></div>
<div class="request"></div>
<div class="status idle">Choose a layout.</div>
<div id="problem"></div>
<div id="map" role="region" aria-label="Map of the circuit"></div>
<div id="facts"></div>
<details><summary>The GeoJSON answer</summary><div class="result"></div></details>
</section>
<h2>Draw it yourself</h2>
<p>The whole of it, with Leaflet loaded:</p>
<pre class="code" id="snippet"></pre>
</main>
<footer class="pager">
<a rel="prev" href="tracks.html">← Track images</a>
<a class="home" href="index.html">All examples</a>
<a rel="next" href="grand-prix.html">Grand prix lookup →</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="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<script src="site.js"></script>
<script>
(function () {
const { h, api, path, call, layoutPicker, layoutYears, showJSON, notice, lineOf, lineLength } = F1;
const $ = (id) => document.getElementById(id);
const card = $('trace');
// ?raw=<base> reads the repository's own files (circuits/<country>/<city>/<circuit>/<layout>.geo.json)
// from <base> instead of the API: a way to try the page against the traces themselves.
const raw = (F1.params.get('raw') || '').replace(/\/+$/, '');
if (raw) {
$('raw-note').append(notice('info', 'Reading the repository’s raw trace files from ', h('code', {}, F1.absolute(raw)),
' (set by ?raw=), not from the API. Remove ?raw= from the address to call the API.'));
}
const map = L.map('map', { scrollWheelZoom: false }).setView([50.44, 5.97], 14);
const osm = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
}).addTo(map);
// EOxCloudless, the newest Sentinel-2 mosaic (10 m): the satellite source the posters use where no photo or national
// aerial photo exists (docs/posters.md). Tiles past zoom 15 are the same pixels, so Leaflet scales them up.
const satellite = L.tileLayer('https://tiles.maps.eox.at/wmts/1.0.0/s2cloudless-2025_3857/default/g/{z}/{y}/{x}.jpg', {
maxZoom: 19,
maxNativeZoom: 15,
attribution: 'EOxCloudless <a href="https://cloudless.eox.at">https://cloudless.eox.at</a> by EOX IT Services GmbH'
+ ' (Contains modified Copernicus Sentinel data 2025),'
+ ' <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>',
});
L.control.layers({ 'OpenStreetMap': osm, 'Satellite (EOxCloudless 2025)': satellite }).addTo(map);
// Top left: EOxCloudless's credit runs over two lines at the foot, where it would cover the scale.
L.control.scale({ imperial: false, position: 'topleft' }).addTo(map);
map.on('focus', () => map.scrollWheelZoom.enable());
map.on('blur', () => map.scrollWheelZoom.disable());
let drawn = null;
function traceURL(p) {
if (raw) {
const e = encodeURIComponent;
return `${raw}/${e(p.country)}/${e(p.city)}/${e(p.circuit)}/${e(p.layout)}.geo.json`;
}
return api(path`/circuits/${p.country}/${p.city}/${p.circuit}/layout/${p.layout}/geojson`);
}
function facts(p, data) {
const line = lineOf(data);
const props = line.properties || {};
const coords = line.geometry.coordinates;
const traced = Math.round(lineLength(coords));
const rows = [
['Circuit', `${p.circuitName}, ${p.cityName} (${p.countryName})`],
['Layout', `${layoutYears(p.layout)} (${p.layout})`],
['GPS points', String(coords.length)],
['Length of the trace', `${(traced / 1000).toFixed(3)} km, measured along the points on this page`],
];
if (props.length) rows.push(['Length (property)', `${(props.length / 1000).toFixed(3)} km`]);
if (props.altitude !== undefined) rows.push(['Altitude (property)', `${props.altitude} m`]);
for (const [k, v] of Object.entries(props)) {
if (['length', 'altitude'].includes(k) || typeof v === 'object') continue;
rows.push([`${k} (property)`, String(v)]);
}
$('facts').replaceChildren(h('table', { class: 'kv' },
...rows.map(([k, v]) => h('tr', {}, h('th', {}, k), h('td', {}, v)))));
}
async function draw(p) {
if (!p.layout) return;
const url = traceURL(p);
const answer = await call(card, url, { label: raw ? 'raw file' : null, waiting: 'Fetching the trace…' });
const out = card.querySelector('.result');
if (drawn) { drawn.remove(); drawn = null; }
$('facts').replaceChildren();
$('problem').replaceChildren();
out.replaceChildren();
if (!answer) return;
const fail = (why, ...content) => {
const status = card.querySelector('.status');
F1.setStatus(status, 'error', `${status.textContent} — ${why}`);
$('problem').replaceChildren(notice('error', ...content));
};
const text = await answer.blob.text();
let data;
try {
data = JSON.parse(text);
} catch {
const kind = await F1.sniff(answer.blob);
fail('not GeoJSON',
`Nothing drawn: the answer is ${kind === 'svg' ? 'an SVG document' : 'not JSON'}, not GeoJSON (its Content-Type header says ${answer.type}). It starts with: `,
h('code', {}, text.slice(0, 120)));
return;
}
if (!lineOf(data)) {
fail('no LineString', 'Nothing drawn: the answer is JSON but holds no LineString feature.');
showJSON(out, data);
return;
}
drawn = L.featureGroup().addTo(map);
L.geoJSON(data, { style: { color: '#e10600', weight: 4, opacity: 0.9 } }).addTo(drawn);
const [lon, lat] = lineOf(data).geometry.coordinates[0];
L.circleMarker([lat, lon], { radius: 7, color: '#ffffff', weight: 2, fillColor: '#15151e', fillOpacity: 1 })
.bindTooltip('First point of the trace').addTo(drawn);
map.fitBounds(drawn.getBounds(), { padding: [30, 30] });
facts(p, data);
showJSON(out, data);
}
$('snippet').textContent = [
`const map = L.map('map');`,
`L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {`,
` attribution: '© OpenStreetMap contributors' }).addTo(map);`,
`const res = await fetch('${F1.absolute(api('/circuits/belgium/spa/circuit-de-spa-francorchamps/layout/1983-/geojson'))}');`,
`const track = L.geoJSON(await res.json(), { style: { color: '#e10600', weight: 4 } }).addTo(map);`,
`map.fitBounds(track.getBounds());`,
].join('\n');
layoutPicker($('picker'), { treeCard: $('tree'), sync: true, onChange: draw });
})();
</script>
</body>
</html>