Compare commits
	
		
			2 Commits
		
	
	
		
			17d36a032c
			...
			01af546b72
		
	
	| Author | SHA1 | Date | 
|---|---|---|
| 
							
							
								
									
								
								 | 
						01af546b72 | |
| 
							
							
								
									
								
								 | 
						f8e8b18591 | 
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
import express from "express";
 | 
					import express from "express";
 | 
				
			||||||
import * as courses from "../tam/courses.js";
 | 
					import * as courses from "../data/courses.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const app = express();
 | 
					const app = express();
 | 
				
			||||||
const port = 4321;
 | 
					const port = 4321;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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, it’s 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 can’t be
 | 
					    // If there is no way to link both stops, it can’t be
 | 
				
			||||||
| 
						 | 
					@ -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;
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
import network from "../tam/network.json";
 | 
					import network from "../data/network.json";
 | 
				
			||||||
import * as simulation from "../tam/simulation.js";
 | 
					import * as simulation from "../data/simulation.js";
 | 
				
			||||||
import * as map from "./map/index.js";
 | 
					import * as map from "./map/index.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Run courses simulation
 | 
					// Run courses simulation
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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 "../../tam/network.json";
 | 
					import network from "../../data/network.json";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const courseStyle = cacheStyle(
 | 
					const courseStyle = cacheStyle(
 | 
				
			||||||
    lineColor => {
 | 
					    lineColor => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,5 @@
 | 
				
			||||||
import network from "../../tam/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({
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue