From 7883c89b764583f0086934df3f2e786be25882a3 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 14 Jan 2024 16:50:16 +0000 Subject: [PATCH] Refactor --- static/js/map.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) 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); } });