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
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 is defined as GeoJSON
L.geoJSON(JSON.parse(route.geojson), {
style: function(feature) {
return {color: route.type === "train" ? "blue" : "blue"}; // Green for trains, blue for flights
}
style: function(feature) { return style; }
}).addTo(map);
} else if (route.type === "flight") {
var flightPath = new L.Geodesic([[route.from, route.to]], {
weight: 3,
opacity: 0.5,
color: 'red'
}).addTo(map);
var flightPath = new L.Geodesic([[route.from, route.to]], style).addTo(map);
} else {
// 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], {color: color}).addTo(map);
L.polyline([route.from, route.to], style).addTo(map);
}
});