Update front/back for new network data format

This commit is contained in:
Mattéo Delabre 2022-07-05 18:10:48 -04:00
parent f8e8b18591
commit 01af546b72
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
3 changed files with 25 additions and 21 deletions

View File

@ -44,12 +44,6 @@ const stopsSet = new Set(
/** Guess whether a stop comes directly before another one. */ /** Guess whether a stop comes directly before another one. */
const isPenultimateStop = (stop, finalStop) => { const isPenultimateStop = (stop, finalStop) => {
// If there is a standard segment linking both stops, its certainly
// the penultimate stop
if ((stop + "-" + finalStop) in network.segments) {
return true;
}
const route = routing.findPath(stop, finalStop); const route = routing.findPath(stop, finalStop);
// If there is no way to link both stops, it cant be // If there is no way to link both stops, it cant be

View File

@ -79,12 +79,6 @@ class Course {
const name = `${this.departureStop}-${this.arrivalStop}`; 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)) { if (!(this.departureStop in network.stops)) {
console.warn(`Unknown stop: ${this.departureStop}`); console.warn(`Unknown stop: ${this.departureStop}`);
this.segment = null; this.segment = null;

View File

@ -1,4 +1,5 @@
import network from "../../data/network.json"; import network from "../../data/network.json";
import * as routing from "../../data/routing.js";
import { cacheStyle, makeBorderColor, sizes } from "./common"; import { cacheStyle, makeBorderColor, sizes } from "./common";
import GeoJSON from "ol/format/GeoJSON"; import GeoJSON from "ol/format/GeoJSON";
@ -79,13 +80,9 @@ export const getLayers = () => {
const segmentsSource = new VectorSource(); const segmentsSource = new VectorSource();
const stopsSource = new VectorSource(); const stopsSource = new VectorSource();
// Turn GeoJSON stops list and segments list into vector sources // Turn GeoJSON stops list into a vector source
const readFeatures = hash => Object.values(hash).map(json => { const readStops = hash => Object.values(hash).map(json => {
json.properties.lines = json.properties.routes.filter( json.properties.lines = json.properties.routes.map(([lineRef]) => lineRef);
// Only consider normal routes (excluding alternate routes)
([lineRef, routeRef]) =>
network.lines[lineRef].routes[routeRef].state === "normal"
).map(([lineRef]) => lineRef);
if (json.properties.lines.length >= 1) { if (json.properties.lines.length >= 1) {
json.properties.colors = json.properties.lines.map( json.properties.colors = json.properties.lines.map(
@ -98,8 +95,27 @@ export const getLayers = () => {
return geojsonReader.readFeature(json); return geojsonReader.readFeature(json);
}); });
segmentsSource.addFeatures(readFeatures(network.segments)); stopsSource.addFeatures(readStops(network.stops));
stopsSource.addFeatures(readFeatures(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 // Background layer on which the darker borders of line segments are drawn
const segmentsBorderLayer = new VectorImageLayer({ const segmentsBorderLayer = new VectorImageLayer({