Compare commits

..

No commits in common. "01af546b72db5330c2eacbba3e0b56075c3532bf" and "17d36a032ca7543adf547715ff17c86882adbd8c" have entirely different histories.

12 changed files with 26 additions and 30 deletions

View File

@ -1,5 +1,5 @@
import express from "express"; import express from "express";
import * as courses from "../data/courses.js"; import * as courses from "../tam/courses.js";
const app = express(); const app = express();
const port = 4321; const port = 4321;

View File

@ -1,5 +1,5 @@
import network from "../data/network.json"; import network from "../tam/network.json";
import * as simulation from "../data/simulation.js"; import * as simulation from "../tam/simulation.js";
import * as map from "./map/index.js"; import * as map from "./map/index.js";
// Run courses simulation // Run courses simulation

View File

@ -3,7 +3,7 @@ import Point from "ol/geom/Point";
import { fromExtent } from 'ol/geom/Polygon'; import { fromExtent } from 'ol/geom/Polygon';
import { Style, Icon } from "ol/style"; import { Style, Icon } from "ol/style";
import { sizes, cacheStyle, makeBorderColor, makeCourseColor } from "./common"; import { sizes, cacheStyle, makeBorderColor, makeCourseColor } from "./common";
import network from "../../data/network.json"; import network from "../../tam/network.json";
const courseStyle = cacheStyle( const courseStyle = cacheStyle(
lineColor => { lineColor => {

View File

@ -1,5 +1,4 @@
import network from "../../data/network.json"; import network from "../../tam/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";
@ -80,9 +79,13 @@ export const getLayers = () => {
const segmentsSource = new VectorSource(); const segmentsSource = new VectorSource();
const stopsSource = new VectorSource(); const stopsSource = new VectorSource();
// Turn GeoJSON stops list into a vector source // Turn GeoJSON stops list and segments list into vector sources
const readStops = hash => Object.values(hash).map(json => { const readFeatures = hash => Object.values(hash).map(json => {
json.properties.lines = json.properties.routes.map(([lineRef]) => lineRef); 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);
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(
@ -95,27 +98,8 @@ export const getLayers = () => {
return geojsonReader.readFeature(json); return geojsonReader.readFeature(json);
}); });
stopsSource.addFeatures(readStops(network.stops)); segmentsSource.addFeatures(readFeatures(network.segments));
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({

View File

@ -44,6 +44,12 @@ 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,6 +79,12 @@ 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;