This commit is contained in:
Edward Betts 2024-01-14 16:50:16 +00:00
parent f3a4f1dcd1
commit 7883c89b76

View file

@ -29,23 +29,18 @@ function build_map(map_id, coordinates, routes) {
// Draw routes // Draw routes
routes.forEach(function(route) { routes.forEach(function(route) {
var color = {"train": "blue", "flight": "red"}[route.type];
var style = { weight: 3, opacity: 0.5, color: color };
if (route.geojson) { if (route.geojson) {
// If route is defined as GeoJSON // If route is defined as GeoJSON
L.geoJSON(JSON.parse(route.geojson), { L.geoJSON(JSON.parse(route.geojson), {
style: function(feature) { style: function(feature) { return style; }
return {color: route.type === "train" ? "blue" : "blue"}; // Green for trains, blue for flights
}
}).addTo(map); }).addTo(map);
} else if (route.type === "flight") { } else if (route.type === "flight") {
var flightPath = new L.Geodesic([[route.from, route.to]], { var flightPath = new L.Geodesic([[route.from, route.to]], style).addTo(map);
weight: 3,
opacity: 0.5,
color: 'red'
}).addTo(map);
} else { } else {
// If route is defined by 'from' and 'to' coordinates // If route is defined by 'from' and 'to' coordinates
var color = route.type === "train" ? "blue" : "red"; // Green for trains, red for flights L.polyline([route.from, route.to], style).addTo(map);
L.polyline([route.from, route.to], {color: color}).addTo(map);
} }
}); });