Refactor
This commit is contained in:
parent
f3a4f1dcd1
commit
7883c89b76
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue