Allow segments with no routes
This commit is contained in:
parent
b67543cc0c
commit
76a187bbb6
|
@ -23,15 +23,31 @@ h0NmFsdzQ3emxqIn0.cyxF0h36emIMTk3cc4VqUw`;
|
||||||
|
|
||||||
const network = require('../tam/network.json');
|
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 makeDataSources = async () =>
|
||||||
{
|
{
|
||||||
const segmentsSource = new VectorSource();
|
const segmentsSource = new VectorSource();
|
||||||
const stopsSource = new VectorSource();
|
const stopsSource = new VectorSource();
|
||||||
|
|
||||||
segmentsSource.addFeatures(
|
segmentsSource.addFeatures(
|
||||||
Object.values(network.segments).map(({lines, points}) =>
|
Object.values(network.segments).map(({routes, points}) =>
|
||||||
new Feature({
|
new Feature({
|
||||||
colors: lines.map(line => network.lines[line].color),
|
colors: getRouteColors(routes),
|
||||||
geometry: new LineString(points.map(
|
geometry: new LineString(points.map(
|
||||||
({lat, lon}) => proj.fromLonLat([lon, lat])
|
({lat, lon}) => proj.fromLonLat([lon, lat])
|
||||||
)),
|
)),
|
||||||
|
@ -40,9 +56,9 @@ const makeDataSources = async () =>
|
||||||
);
|
);
|
||||||
|
|
||||||
stopsSource.addFeatures(
|
stopsSource.addFeatures(
|
||||||
Object.values(network.stops).map(({lines, lon, lat}) =>
|
Object.values(network.stops).map(({routes, lon, lat}) =>
|
||||||
new Feature({
|
new Feature({
|
||||||
colors: lines.map(line => network.lines[line].color),
|
colors: getRouteColors(routes),
|
||||||
geometry: new Point(proj.fromLonLat([lon, lat])),
|
geometry: new Point(proj.fromLonLat([lon, lat])),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue