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

197 lines
8.4 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>
</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 to see the trace follow the tarmac.
</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);
const satellite = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
maxZoom: 19,
maxNativeZoom: 18,
attribution: 'Imagery &copy; Esri, Maxar, Earthstar Geographics',
});
L.control.layers({ 'OpenStreetMap': osm, 'Satellite (Esri)': satellite }).addTo(map);
L.control.scale({ imperial: false }).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>