diff --git a/static/js/map.js b/static/js/map.js index 698dd39..cbf186b 100644 --- a/static/js/map.js +++ b/static/js/map.js @@ -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); } });