Allow segments with no routes

This commit is contained in:
Mattéo Delabre 2020-07-22 23:11:00 +02:00
parent b67543cc0c
commit 76a187bbb6
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
1 changed files with 20 additions and 4 deletions

View File

@ -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])),
})
)