Show rail routes using GeoJSON

This commit is contained in:
Edward Betts 2024-01-12 22:29:10 +00:00
parent 4e719a07ab
commit e2fdd1d198
2 changed files with 46 additions and 8 deletions

View file

@ -124,10 +124,20 @@ coordinates.forEach(function(item) {
marker.bindPopup(item.name);
});
// Draw lines for routes
// Draw routes
routes.forEach(function(route) {
var color = route[0] === "train" ? "green" : "red"; // Green for trains, red for flights
L.polyline([route[1], route[2]], {color: color}).addTo(map);
if (route.geojson) {
// If route is defined as GeoJSON
L.geoJSON(JSON.parse(route.geojson), {
style: function(feature) {
return {color: route.type === "train" ? "green" : "blue"}; // Green for trains, blue for flights
}
}).addTo(map);
} else {
// If route is defined by 'from' and 'to' coordinates
var color = route.type === "train" ? "green" : "red"; // Green for trains, red for flights
L.polyline([route.from, route.to], {color: color}).addTo(map);
}
});
</script>