Show inferred Bristol rail leg for Eurostar trips

This commit is contained in:
Edward Betts 2026-08-03 14:40:53 +01:00
parent ea80166229
commit 6a601f5c14
4 changed files with 299 additions and 36 deletions

View file

@ -59,12 +59,46 @@ function emojiIcon(emoji, zoom) {
function build_map(map_id, coordinates, routes) {
var bounds = coordinates.map(function(station) { return [station.latitude, station.longitude]; });
if (bounds.length === 0) {
routes.forEach(function(r) {
if (r.from) bounds.push(r.from);
if (r.to) bounds.push(r.to);
});
function addGeoJsonCoordinatesToBounds(geojsonCoordinates) {
if (!geojsonCoordinates) return;
if (typeof geojsonCoordinates[0] === "number" && typeof geojsonCoordinates[1] === "number") {
bounds.push([geojsonCoordinates[1], geojsonCoordinates[0]]);
return;
}
geojsonCoordinates.forEach(addGeoJsonCoordinatesToBounds);
}
function addGeoJsonGeometryToBounds(geometry) {
if (!geometry) return;
if (geometry.type === "GeometryCollection") {
geometry.geometries.forEach(addGeoJsonGeometryToBounds);
return;
}
addGeoJsonCoordinatesToBounds(geometry.coordinates);
}
function addGeoJsonToBounds(geojson) {
if (!geojson) return;
if (geojson.type === "FeatureCollection") {
geojson.features.forEach(function(feature) {
addGeoJsonGeometryToBounds(feature.geometry);
});
return;
}
if (geojson.type === "Feature") {
addGeoJsonGeometryToBounds(geojson.geometry);
return;
}
addGeoJsonGeometryToBounds(geojson);
}
routes.forEach(function(r) {
if (r.from) bounds.push(r.from);
if (r.to) bounds.push(r.to);
if (r.geojson) addGeoJsonToBounds(JSON.parse(r.geojson));
});
var map = bounds.length > 0
? L.map(map_id).fitBounds(bounds)
: L.map(map_id).setView([20, 0], 2);