diff --git a/src/front/map.js b/src/front/map.js index 1953999..64b4af9 100644 --- a/src/front/map.js +++ b/src/front/map.js @@ -23,15 +23,31 @@ h0NmFsdzQ3emxqIn0.cyxF0h36emIMTk3cc4VqUw`; const network = require('../tam/network.json'); +const getRouteColors = routes => +{ + const colors = routes.filter( + // Only consider normal routes (excluding alternate routes) + ([lineRef, routeRef]) => + network.lines[lineRef].routes[routeRef].state === 'normal' + ).map(([lineRef]) => network.lines[lineRef].color); + + if (colors.length >= 1) + { + return colors; + } + + return ['#FFFFFF']; +}; + const makeDataSources = async () => { const segmentsSource = new VectorSource(); const stopsSource = new VectorSource(); segmentsSource.addFeatures( - Object.values(network.segments).map(({lines, points}) => + Object.values(network.segments).map(({routes, points}) => new Feature({ - colors: lines.map(line => network.lines[line].color), + colors: getRouteColors(routes), geometry: new LineString(points.map( ({lat, lon}) => proj.fromLonLat([lon, lat]) )), @@ -40,9 +56,9 @@ const makeDataSources = async () => ); stopsSource.addFeatures( - Object.values(network.stops).map(({lines, lon, lat}) => + Object.values(network.stops).map(({routes, lon, lat}) => new Feature({ - colors: lines.map(line => network.lines[line].color), + colors: getRouteColors(routes), geometry: new Point(proj.fromLonLat([lon, lat])), }) )