diff --git a/src/data/courses.js b/src/data/courses.js index 0be1cd1..2c5470a 100644 --- a/src/data/courses.js +++ b/src/data/courses.js @@ -44,12 +44,6 @@ const stopsSet = new Set( /** Guess whether a stop comes directly before another one. */ const isPenultimateStop = (stop, finalStop) => { - // If there is a standard segment linking both stops, it’s certainly - // the penultimate stop - if ((stop + "-" + finalStop) in network.segments) { - return true; - } - const route = routing.findPath(stop, finalStop); // If there is no way to link both stops, it can’t be diff --git a/src/data/simulation.js b/src/data/simulation.js index f2f7a0a..dfb0f23 100644 --- a/src/data/simulation.js +++ b/src/data/simulation.js @@ -79,12 +79,6 @@ class Course { const name = `${this.departureStop}-${this.arrivalStop}`; - // Use predefined segment if it exists - if (name in network.segments) { - this.segment = network.segments[name]; - return; - } - if (!(this.departureStop in network.stops)) { console.warn(`Unknown stop: ${this.departureStop}`); this.segment = null; diff --git a/src/front/map/network.js b/src/front/map/network.js index 396f80d..96a8832 100644 --- a/src/front/map/network.js +++ b/src/front/map/network.js @@ -1,4 +1,5 @@ import network from "../../data/network.json"; +import * as routing from "../../data/routing.js"; import { cacheStyle, makeBorderColor, sizes } from "./common"; import GeoJSON from "ol/format/GeoJSON"; @@ -79,13 +80,9 @@ export const getLayers = () => { const segmentsSource = new VectorSource(); const stopsSource = new VectorSource(); - // Turn GeoJSON stops list and segments list into vector sources - const readFeatures = hash => Object.values(hash).map(json => { - json.properties.lines = json.properties.routes.filter( - // Only consider normal routes (excluding alternate routes) - ([lineRef, routeRef]) => - network.lines[lineRef].routes[routeRef].state === "normal" - ).map(([lineRef]) => lineRef); + // Turn GeoJSON stops list into a vector source + const readStops = hash => Object.values(hash).map(json => { + json.properties.lines = json.properties.routes.map(([lineRef]) => lineRef); if (json.properties.lines.length >= 1) { json.properties.colors = json.properties.lines.map( @@ -98,8 +95,27 @@ export const getLayers = () => { return geojsonReader.readFeature(json); }); - segmentsSource.addFeatures(readFeatures(network.segments)); - stopsSource.addFeatures(readFeatures(network.stops)); + stopsSource.addFeatures(readStops(network.stops)); + + // Link stops with segments + const makeSegments = function* (lines) { + for (const [lineRef, line] of Object.entries(network.lines)) { + for (const route of line.routes) { + for (let i = 0; i + 1 < route.stops.length; ++i) { + const stop1 = network.stops[route.stops[i]].id; + const stop2 = network.stops[route.stops[i + 1]].id; + + const segment = routing.findSegment(stop1, stop2); + segment.properties.lines = [lineRef]; + segment.properties.colors = [line.color]; + + yield geojsonReader.readFeature(segment); + } + } + } + }; + + segmentsSource.addFeatures([...makeSegments(network.lines)]); // Background layer on which the darker borders of line segments are drawn const segmentsBorderLayer = new VectorImageLayer({