@wemap/routers 12.10.8 → 12.10.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers/InstructionManager.d.ts +20 -0
- package/dist/helpers/InstructionManagerV1.d.ts +7 -0
- package/{index.ts → dist/index.d.ts} +1 -11
- package/dist/index.js +1 -5099
- package/dist/index.js.map +1 -1
- package/dist/src/ItineraryInfoManager.d.ts +31 -0
- package/dist/src/RoutingError.d.ts +24 -0
- package/{src/StatusCode.ts → dist/src/StatusCode.d.ts} +2 -3
- package/dist/src/Utils.d.ts +6 -0
- package/dist/src/graph/Edge.d.ts +32 -0
- package/dist/src/graph/Graph.d.ts +40 -0
- package/dist/src/graph/GraphProjection.d.ts +11 -0
- package/dist/src/graph/GraphProjectionOptions.d.ts +7 -0
- package/dist/src/graph/GraphRoute.d.ts +19 -0
- package/dist/src/graph/GraphRouter.d.ts +20 -0
- package/dist/src/graph/GraphRouterEngine.d.ts +77 -0
- package/{src/graph/GraphRouterOptions.ts → dist/src/graph/GraphRouterOptions.d.ts} +5 -7
- package/dist/src/graph/GraphRouterOptionsBuilder.d.ts +20 -0
- package/dist/src/graph/NoRouteFoundError.d.ts +12 -0
- package/dist/src/graph/Vertex.d.ts +19 -0
- package/dist/src/model/Itinerary.d.ts +81 -0
- package/dist/src/model/Leg.d.ts +66 -0
- package/dist/src/model/LevelChange.d.ts +7 -0
- package/dist/src/model/RouterRequest.d.ts +40 -0
- package/dist/src/model/Step.d.ts +42 -0
- package/dist/src/model/StepExtra.d.ts +3 -0
- package/dist/src/model/StepsBuilder.d.ts +16 -0
- package/dist/src/model/TransitMode.d.ts +5 -0
- package/{src/model/TravelMode.ts → dist/src/model/TravelMode.d.ts} +1 -2
- package/dist/src/model/generateSteps.d.ts +0 -0
- package/{src/remote/RemoteRouter.ts → dist/src/remote/RemoteRouter.d.ts} +2 -7
- package/dist/src/remote/RemoteRouterManager.d.ts +731 -0
- package/dist/src/remote/RemoteRouterUtils.d.ts +6 -0
- package/dist/src/remote/cityway/CitywayRemoteRouter.d.ts +109 -0
- package/dist/src/remote/deutsche-bahn/DeutscheBahnRemoteRouter.d.ts +31 -0
- package/dist/src/remote/geovelo/GeoveloRemoteRouter.d.ts +106 -0
- package/dist/src/remote/idfm/IdfmRemoteRouter.d.ts +123 -0
- package/dist/src/remote/navitia/NavitiaRemoteRouter.d.ts +34 -0
- package/dist/src/remote/navitia/types.d.ts +87 -0
- package/dist/src/remote/osrm/OsrmRemoteRouter.d.ts +70 -0
- package/dist/src/remote/otp/OtpRemoteRouter.d.ts +69 -0
- package/dist/src/remote/wemap-multi/WemapMultiRemoteRouter.d.ts +19 -0
- package/dist/src/types.d.ts +31 -0
- package/dist/src/wemap-multi/CustomGraphMap.d.ts +56 -0
- package/dist/src/wemap-multi/CustomGraphMapTester.d.ts +39 -0
- package/dist/src/wemap-multi/WemapMultiRouter.d.ts +14 -0
- package/dist/src/wemap-osm/OsmGraphUtils.d.ts +11 -0
- package/dist/tests/CommonTest.d.ts +8 -0
- package/package.json +11 -8
- package/assets/biocbon-bergere-rdc-network.osm +0 -163
- package/assets/bureaux-wemap-montpellier-network.osm +0 -174
- package/assets/components.osm +0 -146
- package/assets/elevator-models-4.osm +0 -89
- package/assets/elevator-models.osm +0 -354
- package/assets/exit-graph.osm +0 -25
- package/assets/gare-de-lest-network-pp-bounds.osm +0 -1613
- package/assets/gare-de-lyon-extract.osm +0 -174
- package/assets/geovelo-montpellier.json +0 -1144
- package/assets/horizontal-elevator.osm +0 -12
- package/assets/itinerary-deutsche-bahn-1.json +0 -368
- package/assets/itinerary-grenoble-otp-1.json +0 -1536
- package/assets/itinerary-grenoble-otp-2.json +0 -1092
- package/assets/itinerary-info-two-points-proj.osm +0 -39
- package/assets/itinerary-info-two-points.osm +0 -24
- package/assets/itinerary-lehavre-cityway-1.json +0 -6799
- package/assets/itinerary-lehavre-cityway-2.json +0 -2133
- package/assets/itinerary-lehavre-cityway-3.json +0 -12577
- package/assets/itinerary-lehavre-cityway-4.json +0 -1451
- package/assets/itinerary-lehavre-cityway-5.json +0 -5925
- package/assets/itinerary-lemans-navitia.json +0 -7768
- package/assets/itinerary-montpellier-osrm-3.json +0 -185
- package/assets/itinerary-montpellier-outdoor-without-steps.json +0 -110
- package/assets/itinerary-montpellier-outdoor.json +0 -513
- package/assets/itinerary-paris-idfm-2.json +0 -1838
- package/assets/itinerary-paris-idfm.json +0 -27727
- package/assets/itinerary-step-not-on-path-osrm.json +0 -457
- package/assets/itinerary-with-duplicate-nodes.json +0 -110
- package/assets/network-conveying-backward.osm +0 -74
- package/assets/network-elevator.osm +0 -48
- package/assets/network-escalators.osm +0 -50
- package/assets/network-simple.osm +0 -27
- package/assets/network-steps-same-level.osm +0 -283
- package/assets/network-with-modifiers.osm +0 -39
- package/assets/one-way.osm +0 -46
- package/assets/report-map-1.osm +0 -36
- package/assets/report-map-2.osm +0 -29
- package/assets/report-map-3.osm +0 -15
- package/assets/rr-wemap-multi-indoor-outdoor-indoor.json +0 -1352
- package/assets/rr-wemap-multi-indoor-outdoor.json +0 -145
- package/assets/rr-wemap-multi-multi-level.json +0 -262
- package/assets/rr-wemap-multi-outdoor-indoor.json +0 -145
- package/assets/rr-wemap-multi-outdoor-outdoor.json +0 -207
- package/assets/rr-wemap-multi-remote-indoor-indoor.json +0 -155
- package/assets/rr-wemap-multi-remote-indoor-outdoor-indoor.json +0 -668
- package/assets/rr-wemap-multi-remote-indoor-outdoor.json +0 -154
- package/assets/rr-wemap-multi-remote-outdoor-indoor.json +0 -179
- package/assets/rr-wemap-multi-remote-outdoor-outdoor.json +0 -109
- package/assets/stairs-and-exit.osm +0 -47
- package/helpers/InstructionManager.ts +0 -184
- package/helpers/InstructionManagerV1.ts +0 -95
- package/src/ItineraryInfoManager.spec.ts +0 -183
- package/src/ItineraryInfoManager.ts +0 -181
- package/src/RoutingError.ts +0 -60
- package/src/Utils.ts +0 -8
- package/src/graph/Edge.spec.ts +0 -32
- package/src/graph/Edge.ts +0 -64
- package/src/graph/Graph.spec.ts +0 -509
- package/src/graph/Graph.ts +0 -272
- package/src/graph/GraphProjection.ts +0 -15
- package/src/graph/GraphProjectionOptions.ts +0 -8
- package/src/graph/GraphRoute.spec.ts +0 -15
- package/src/graph/GraphRoute.ts +0 -43
- package/src/graph/GraphRouter.spec.ts +0 -317
- package/src/graph/GraphRouter.ts +0 -229
- package/src/graph/GraphRouterEngine.ts +0 -248
- package/src/graph/GraphRouterOptionsBuilder.ts +0 -98
- package/src/graph/NoRouteFoundError.ts +0 -39
- package/src/graph/Vertex.spec.ts +0 -42
- package/src/graph/Vertex.ts +0 -45
- package/src/model/Itinerary.spec.ts +0 -134
- package/src/model/Itinerary.ts +0 -370
- package/src/model/Leg.spec.ts +0 -107
- package/src/model/Leg.ts +0 -224
- package/src/model/LevelChange.spec.ts +0 -50
- package/src/model/LevelChange.ts +0 -14
- package/src/model/RouterRequest.ts +0 -33
- package/src/model/Step.spec.ts +0 -99
- package/src/model/Step.ts +0 -90
- package/src/model/StepExtra.ts +0 -1
- package/src/model/StepsBuilder.ts +0 -242
- package/src/model/TransitMode.spec.ts +0 -31
- package/src/model/TransitMode.ts +0 -28
- package/src/model/generateSteps.ts +0 -102
- package/src/remote/RemoteRouterManager.spec.ts +0 -178
- package/src/remote/RemoteRouterManager.ts +0 -72
- package/src/remote/RemoteRouterUtils.ts +0 -25
- package/src/remote/cityway/CitywayRemoteRouter.spec.ts +0 -122
- package/src/remote/cityway/CitywayRemoteRouter.ts +0 -435
- package/src/remote/deutsche-bahn/DeutscheBahnRemoteRouter.spec.ts +0 -52
- package/src/remote/deutsche-bahn/DeutscheBahnRemoteRouter.ts +0 -85
- package/src/remote/geovelo/GeoveloRemoteRouter.spec.ts +0 -54
- package/src/remote/geovelo/GeoveloRemoteRouter.ts +0 -293
- package/src/remote/idfm/IdfmRemoteRouter.spec.ts +0 -102
- package/src/remote/idfm/IdfmRemoteRouter.ts +0 -523
- package/src/remote/navitia/NavitiaRemoteRouter.spec.ts +0 -116
- package/src/remote/navitia/NavitiaRemoteRouter.ts +0 -445
- package/src/remote/navitia/types.ts +0 -73
- package/src/remote/osrm/OsrmRemoteRouter.spec.ts +0 -127
- package/src/remote/osrm/OsrmRemoteRouter.ts +0 -303
- package/src/remote/otp/OtpRemoteRouter.spec.ts +0 -103
- package/src/remote/otp/OtpRemoteRouter.ts +0 -223
- package/src/remote/wemap-multi/WemapMultiRemoteRouter.spec.ts +0 -103
- package/src/remote/wemap-multi/WemapMultiRemoteRouter.ts +0 -56
- package/src/types.ts +0 -32
- package/src/wemap-multi/CustomGraphMap.spec.ts +0 -40
- package/src/wemap-multi/CustomGraphMap.ts +0 -213
- package/src/wemap-multi/CustomGraphMapTester.spec.ts +0 -48
- package/src/wemap-multi/CustomGraphMapTester.ts +0 -90
- package/src/wemap-multi/WemapMultiRouter.spec.ts +0 -138
- package/src/wemap-multi/WemapMultiRouter.ts +0 -329
- package/src/wemap-osm/OsmGraphUtils.spec.ts +0 -165
- package/src/wemap-osm/OsmGraphUtils.ts +0 -173
- package/src/wemap-osm/OsmRouter.elevators.spec.ts +0 -106
- package/src/wemap-osm/OsmRouter.spec.ts +0 -292
- package/tests/CommonTest.ts +0 -78
- package/tsconfig.json +0 -3
- package/vite.config.ts +0 -4
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
2
|
-
import chai from 'chai';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
6
|
-
|
|
7
|
-
import { Coordinates } from '@wemap/geo';
|
|
8
|
-
|
|
9
|
-
import { verifyStepsCoherence } from '../../model/Itinerary.spec.js';
|
|
10
|
-
import { areTransitAndTravelModeConsistent } from '../../model/TransitMode.js';
|
|
11
|
-
import GeoveloRemoteRouter from './GeoveloRemoteRouter.js';
|
|
12
|
-
|
|
13
|
-
const { expect } = chai;
|
|
14
|
-
|
|
15
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
16
|
-
const assetsPath = path.resolve(__dirname, '../../../assets');
|
|
17
|
-
|
|
18
|
-
describe('GeoveloRouter - parseResponse', () => {
|
|
19
|
-
|
|
20
|
-
it('Itineraries - 1', () => {
|
|
21
|
-
|
|
22
|
-
const filePath = path.resolve(assetsPath, 'geovelo-montpellier.json');
|
|
23
|
-
const fileString = fs.readFileSync(filePath, 'utf8');
|
|
24
|
-
const json = JSON.parse(fileString);
|
|
25
|
-
|
|
26
|
-
const itineraries = GeoveloRemoteRouter.parseResponse(json);
|
|
27
|
-
itineraries.forEach(verifyStepsCoherence);
|
|
28
|
-
|
|
29
|
-
expect(itineraries.length).equal(3);
|
|
30
|
-
|
|
31
|
-
const itinerary1 = itineraries[0];
|
|
32
|
-
expect(itinerary1.origin.equals(new Coordinates(43.596949, 3.877772))).true;
|
|
33
|
-
expect(itinerary1.destination.equals(new Coordinates(43.609609, 3.914684))).true;
|
|
34
|
-
expect(itinerary1.distance).to.be.closeTo(4029, 1);
|
|
35
|
-
expect(itinerary1.duration).equal(1053);
|
|
36
|
-
expect(itinerary1.transitMode).equal('BIKE');
|
|
37
|
-
// Do not work because of the input time format
|
|
38
|
-
expect(itinerary1.startTime).equal(1643623200000);
|
|
39
|
-
expect(itinerary1.endTime).equal(1643624253000);
|
|
40
|
-
expect(itinerary1.legs.length).equal(1);
|
|
41
|
-
|
|
42
|
-
expect(areTransitAndTravelModeConsistent(itinerary1.transitMode, 'BIKE')).is.true;
|
|
43
|
-
|
|
44
|
-
const itinerary1leg1 = itinerary1.legs[0];
|
|
45
|
-
// Do not work because of the input time format
|
|
46
|
-
expect(itinerary1leg1.startTime).equal(1643623200000);
|
|
47
|
-
expect(itinerary1leg1.endTime).equal(1643624253000);
|
|
48
|
-
expect(itinerary1leg1.distance).to.be.closeTo(4029, 1);
|
|
49
|
-
expect(itinerary1leg1.transitMode).equal('BIKE');
|
|
50
|
-
expect(itinerary1leg1.transportInfo).is.null;
|
|
51
|
-
expect(itinerary1leg1.start.coords.distanceTo(new Coordinates(43.596949, 3.877772))).to.be.closeTo(0, 1);
|
|
52
|
-
expect(itinerary1leg1.end.coords.distanceTo(new Coordinates(43.609609, 3.914684))).to.be.closeTo(0, 1);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
2
|
-
import polyline from '@mapbox/polyline';
|
|
3
|
-
import { Coordinates } from '@wemap/geo';
|
|
4
|
-
|
|
5
|
-
import Itinerary from '../../model/Itinerary.js';
|
|
6
|
-
import Leg, { TransportInfo } from '../../model/Leg.js';
|
|
7
|
-
import StepsBuilder from '../../model/StepsBuilder.js';
|
|
8
|
-
import RemoteRouter from '../RemoteRouter.js';
|
|
9
|
-
import type { TransitMode } from '../../model/TransitMode.js';
|
|
10
|
-
import { RouterRequest } from '../../model/RouterRequest.js';
|
|
11
|
-
import { RemoteRoutingError } from '../../RoutingError.js';
|
|
12
|
-
|
|
13
|
-
type DistanceDetails = {
|
|
14
|
-
total: number;
|
|
15
|
-
normalRoads: number;
|
|
16
|
-
recommendedRoads: number;
|
|
17
|
-
discouragedRoads: number;
|
|
18
|
-
cycleway: number;
|
|
19
|
-
greenway: number;
|
|
20
|
-
lane: number;
|
|
21
|
-
livingstreet: number;
|
|
22
|
-
sharebusway: number;
|
|
23
|
-
footway: number;
|
|
24
|
-
pedestrian: number;
|
|
25
|
-
opposite: number;
|
|
26
|
-
steps: number;
|
|
27
|
-
zone30: number;
|
|
28
|
-
residential: number;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
type Waypoint = {
|
|
32
|
-
longitude: number;
|
|
33
|
-
latitude: number;
|
|
34
|
-
title?: string | null;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
type Instruction = Array<string | number>;
|
|
38
|
-
|
|
39
|
-
type SectionWithInstructions = {
|
|
40
|
-
transportMode: 'BIKE' | 'PEDESTRIAN';
|
|
41
|
-
duration: number;
|
|
42
|
-
waypointsIndices: number[] | null;
|
|
43
|
-
geometry: string;
|
|
44
|
-
estimatedDatetimeOfDeparture: string;
|
|
45
|
-
estimatedDatetimeOfArrival: string;
|
|
46
|
-
details: SectionDetails;
|
|
47
|
-
waypoints: Waypoint[];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
type SectionDetails = {
|
|
51
|
-
distances: DistanceDetails;
|
|
52
|
-
instructions: Instruction[];
|
|
53
|
-
profile: string;
|
|
54
|
-
direction: string;
|
|
55
|
-
verticalGain: number;
|
|
56
|
-
verticalLoss: number;
|
|
57
|
-
calories: number;
|
|
58
|
-
elevations: string | null;
|
|
59
|
-
ridesets: any[];
|
|
60
|
-
averageSpeed: number;
|
|
61
|
-
bikeType: string;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
type Route = {
|
|
65
|
-
sections: SectionWithInstructions[];
|
|
66
|
-
distances: {
|
|
67
|
-
total: number;
|
|
68
|
-
normalRoads: number;
|
|
69
|
-
recommendedRoads: number;
|
|
70
|
-
discouragedRoads: number;
|
|
71
|
-
};
|
|
72
|
-
title: string;
|
|
73
|
-
waypoints: Waypoint[];
|
|
74
|
-
estimatedDatetimeOfDeparture: string;
|
|
75
|
-
estimatedDatetimeOfArrival: string;
|
|
76
|
-
duration: number;
|
|
77
|
-
id: string;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
type Routes = Route[];
|
|
81
|
-
|
|
82
|
-
type QueryParams = {
|
|
83
|
-
instructions: boolean;
|
|
84
|
-
elevations: boolean;
|
|
85
|
-
geometry: boolean;
|
|
86
|
-
single_result: boolean;
|
|
87
|
-
bike_stations: boolean;
|
|
88
|
-
objects_as_ids: boolean;
|
|
89
|
-
merge_instructions: boolean;
|
|
90
|
-
show_pushing_bike_instructions: boolean;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
type RequestBodyParams = {
|
|
94
|
-
datetimeOfDeparture?: string;
|
|
95
|
-
datetimeOfArrival?: string;
|
|
96
|
-
bikeDetails?: {
|
|
97
|
-
profile: string;
|
|
98
|
-
bikeType: string;
|
|
99
|
-
averageSpeed: number;
|
|
100
|
-
eBike: boolean;
|
|
101
|
-
bikeStations: Array<{ from: number; to: number }>;
|
|
102
|
-
};
|
|
103
|
-
transportModes: Array<'BIKE' | 'PEDESTRIAN'>;
|
|
104
|
-
waypoints: Waypoint[];
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function unpackJSON(data: any[][]) {
|
|
108
|
-
const headers = data[0];
|
|
109
|
-
|
|
110
|
-
return data.slice(1).map(row => {
|
|
111
|
-
const obj: any = {};
|
|
112
|
-
headers.forEach((header, index) => {
|
|
113
|
-
obj[header] = row[index];
|
|
114
|
-
});
|
|
115
|
-
return obj;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const transitModeCorrespondance = new Map<string, TransitMode>();
|
|
120
|
-
transitModeCorrespondance.set('BIKE', 'BIKE');
|
|
121
|
-
transitModeCorrespondance.set('PEDESTRIAN', 'WALK');
|
|
122
|
-
|
|
123
|
-
const apiKey = 'qWHj6ax6DMttG8DX6tH9CQARaiTgQ1Di';
|
|
124
|
-
|
|
125
|
-
function waypointToCoordinates(waypoint: Waypoint) {
|
|
126
|
-
return new Coordinates(waypoint.latitude, waypoint.longitude);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function last<T>(array: T[]) {
|
|
130
|
-
return array[array.length - 1];
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Singleton.
|
|
135
|
-
*/
|
|
136
|
-
class GeoveloRemoteRouter extends RemoteRouter {
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* @override
|
|
140
|
-
*/
|
|
141
|
-
get rname() { return 'geovelo' as const; }
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
async getItineraries(endpointUrl: string, routerRequest: RouterRequest) {
|
|
145
|
-
const queryParams = this.getQueryParams();
|
|
146
|
-
const bodyParams = this.getBodyParams(routerRequest);
|
|
147
|
-
|
|
148
|
-
const url = new URL(endpointUrl);
|
|
149
|
-
|
|
150
|
-
for (const [key, value] of Object.entries(queryParams)) {
|
|
151
|
-
url.searchParams.append(key, value.toString());
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const res = await (fetch(url, {
|
|
155
|
-
method: 'POST',
|
|
156
|
-
headers: {
|
|
157
|
-
apiKey,
|
|
158
|
-
'Content-Type': 'application/json'
|
|
159
|
-
},
|
|
160
|
-
body: JSON.stringify(bodyParams)
|
|
161
|
-
}).catch(() => {
|
|
162
|
-
throw RemoteRoutingError.unreachableServer(this.rname, url.toString());
|
|
163
|
-
}));
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const jsonResponse: Routes = await res.json().catch(() => {
|
|
167
|
-
throw RemoteRoutingError.responseNotParsing(this.rname, url.toString());
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// When Geovélo failed to calculate an itinerary (ie. start or end
|
|
171
|
-
// point is far from network), it respond with empty routes
|
|
172
|
-
if (!jsonResponse || jsonResponse.length === 0) {
|
|
173
|
-
throw RemoteRoutingError.notFound(this.rname, 'No itineraries found.');
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const itineraries = this.parseResponse(jsonResponse);
|
|
177
|
-
|
|
178
|
-
return itineraries;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
getQueryParams(): QueryParams {
|
|
182
|
-
return {
|
|
183
|
-
instructions: true,
|
|
184
|
-
elevations: false,
|
|
185
|
-
geometry: true,
|
|
186
|
-
single_result: false,
|
|
187
|
-
bike_stations: false,
|
|
188
|
-
objects_as_ids: false,
|
|
189
|
-
merge_instructions: true,
|
|
190
|
-
show_pushing_bike_instructions: false
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
getBodyParams(routerRequest: RouterRequest): RequestBodyParams {
|
|
195
|
-
const { origin, destination, waypoints } = routerRequest;
|
|
196
|
-
let computedWaypoints: Waypoint[] = [];
|
|
197
|
-
if (waypoints && waypoints.length > 1) {
|
|
198
|
-
computedWaypoints = waypoints.map((waypoint) => ({
|
|
199
|
-
longitude: waypoint.longitude,
|
|
200
|
-
latitude: waypoint.latitude
|
|
201
|
-
}));
|
|
202
|
-
} else {
|
|
203
|
-
computedWaypoints = [
|
|
204
|
-
{ latitude: origin.latitude, longitude: origin.longitude },
|
|
205
|
-
{ latitude: destination.latitude, longitude: destination.longitude }
|
|
206
|
-
]
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return {
|
|
210
|
-
transportModes: ['BIKE'],
|
|
211
|
-
waypoints: computedWaypoints
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
parseResponse(json: Routes) {
|
|
216
|
-
if (!json || !json.length) {
|
|
217
|
-
throw RemoteRoutingError.notFound(this.rname);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const itineraries = [];
|
|
221
|
-
|
|
222
|
-
for (const route of json) {
|
|
223
|
-
|
|
224
|
-
const legs = [];
|
|
225
|
-
|
|
226
|
-
for (const section of route.sections) {
|
|
227
|
-
const from = waypointToCoordinates(section.waypoints[0]);
|
|
228
|
-
const to = waypointToCoordinates(last(section.waypoints));
|
|
229
|
-
const geometry = polyline.toGeoJSON(section.geometry, 6);
|
|
230
|
-
|
|
231
|
-
// A section can have multiple same coordinates, we need to remove them
|
|
232
|
-
let existingCoords: string[] = [];
|
|
233
|
-
const legCoords = geometry.coordinates.reduce((acc, [lon, lat]) => {
|
|
234
|
-
if (!existingCoords.includes(`${lon}-${lat}`)) {
|
|
235
|
-
existingCoords = existingCoords.concat(`${lon}-${lat}`);
|
|
236
|
-
acc.push(new Coordinates(lat, lon));
|
|
237
|
-
}
|
|
238
|
-
return acc;
|
|
239
|
-
}, [] as Coordinates[]);
|
|
240
|
-
|
|
241
|
-
const stepsBuilder = new StepsBuilder().setStart(from).setEnd(to).setPathCoords(legCoords);
|
|
242
|
-
const transitMode = transitModeCorrespondance.get(section.transportMode) as TransitMode;
|
|
243
|
-
|
|
244
|
-
const unpackedIntructions = unpackJSON(section.details.instructions);
|
|
245
|
-
|
|
246
|
-
for (const instruction of unpackedIntructions) {
|
|
247
|
-
const { geometryIndex, roadLength, roadName } = instruction;
|
|
248
|
-
const coordinates = geometry.coordinates[geometryIndex];
|
|
249
|
-
|
|
250
|
-
const intermediateStep = {
|
|
251
|
-
name: roadName,
|
|
252
|
-
distance: roadLength,
|
|
253
|
-
coords: new Coordinates(coordinates[1], coordinates[0])
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
stepsBuilder.addStepInfo(intermediateStep);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const leg = new Leg({
|
|
261
|
-
transitMode,
|
|
262
|
-
duration: section.duration,
|
|
263
|
-
startTime: new Date(section.estimatedDatetimeOfDeparture).getTime(),
|
|
264
|
-
endTime: new Date(section.estimatedDatetimeOfArrival).getTime(),
|
|
265
|
-
start: {
|
|
266
|
-
coords: from
|
|
267
|
-
},
|
|
268
|
-
end: {
|
|
269
|
-
coords: to
|
|
270
|
-
},
|
|
271
|
-
coords: legCoords,
|
|
272
|
-
steps: stepsBuilder.build()
|
|
273
|
-
});
|
|
274
|
-
legs.push(leg);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const itinerary = new Itinerary({
|
|
278
|
-
duration: route.duration,
|
|
279
|
-
startTime: new Date(route.estimatedDatetimeOfDeparture).getTime(),
|
|
280
|
-
endTime: new Date(route.estimatedDatetimeOfArrival).getTime(),
|
|
281
|
-
origin: waypointToCoordinates(route.waypoints[0]),
|
|
282
|
-
destination: waypointToCoordinates(last(route.waypoints)),
|
|
283
|
-
legs
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
itineraries.push(itinerary);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return itineraries;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
export default new GeoveloRemoteRouter();
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
2
|
-
import chai from 'chai';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
6
|
-
|
|
7
|
-
import { Coordinates } from '@wemap/geo';
|
|
8
|
-
|
|
9
|
-
import IdfmRemoteRouter from './IdfmRemoteRouter.js';
|
|
10
|
-
import { verifyStepsCoherence } from '../../model/Itinerary.spec.js';
|
|
11
|
-
import { areTransitAndTravelModeConsistent } from '../../model/TransitMode.js';
|
|
12
|
-
|
|
13
|
-
const { expect } = chai;
|
|
14
|
-
|
|
15
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
16
|
-
const assetsPath = path.resolve(__dirname, '../../../assets');
|
|
17
|
-
|
|
18
|
-
describe('IdfmRouter - parseResponse', () => {
|
|
19
|
-
|
|
20
|
-
it('Itineraries - 1', () => {
|
|
21
|
-
|
|
22
|
-
const filePath = path.resolve(assetsPath, 'itinerary-paris-idfm.json');
|
|
23
|
-
const fileString = fs.readFileSync(filePath, 'utf8');
|
|
24
|
-
const json = JSON.parse(fileString);
|
|
25
|
-
|
|
26
|
-
const itineraries = IdfmRemoteRouter.parseResponse(json);
|
|
27
|
-
itineraries.forEach(verifyStepsCoherence);
|
|
28
|
-
|
|
29
|
-
expect(itineraries.length).equal(9);
|
|
30
|
-
|
|
31
|
-
const itinerary1 = itineraries[0];
|
|
32
|
-
expect(itinerary1.origin.equals(new Coordinates(48.836123, 2.341896))).true;
|
|
33
|
-
expect(itinerary1.destination.equals(new Coordinates(48.867999, 2.32563))).true;
|
|
34
|
-
expect(itinerary1.distance).to.be.closeTo(5769, 1);
|
|
35
|
-
expect(itinerary1.duration).equal(1977);
|
|
36
|
-
expect(itinerary1.transitMode).equal('MULTI');
|
|
37
|
-
// Do not work because of the input time format
|
|
38
|
-
expect(itinerary1.startTime).equal(1712073372000);
|
|
39
|
-
expect(itinerary1.endTime).equal(1712075349000);
|
|
40
|
-
expect(itinerary1.legs.length).equal(4);
|
|
41
|
-
|
|
42
|
-
expect(areTransitAndTravelModeConsistent(itinerary1.transitMode, 'TRANSIT')).is.true;
|
|
43
|
-
|
|
44
|
-
const itinerary1leg1 = itinerary1.legs[0];
|
|
45
|
-
// Do not work because of the input time format
|
|
46
|
-
expect(itinerary1leg1.startTime).equal(1712073372000);
|
|
47
|
-
expect(itinerary1leg1.endTime).equal(1712074079000);
|
|
48
|
-
expect(itinerary1leg1.distance).to.be.closeTo(702, 1);
|
|
49
|
-
expect(itinerary1leg1.transitMode).equal('WALK');
|
|
50
|
-
expect(itinerary1leg1.transportInfo).is.null;
|
|
51
|
-
expect(itinerary1leg1.start.name).equal('29 Rue de la Santé (Paris)');
|
|
52
|
-
expect(itinerary1leg1.start.coords.distanceTo(new Coordinates(48.836123, 2.341896))).to.be.closeTo(0, 1);
|
|
53
|
-
expect(itinerary1leg1.end.name).equal('Port Royal (Paris)');
|
|
54
|
-
expect(itinerary1leg1.end.coords.distanceTo(new Coordinates(48.8400644, 2.3371384))).to.be.closeTo(0, 1);
|
|
55
|
-
|
|
56
|
-
const itinerary1leg2 = itinerary1.legs[1];
|
|
57
|
-
expect(itinerary1leg2.transitMode).equal('TRAIN');
|
|
58
|
-
expect(itinerary1leg2.transportInfo).is.not.null;
|
|
59
|
-
expect(itinerary1leg2.transportInfo?.name).equal('B');
|
|
60
|
-
expect(itinerary1leg2.transportInfo?.routeColor).equal('5091CB');
|
|
61
|
-
expect(itinerary1leg2.transportInfo?.routeTextColor).equal('FFFFFF');
|
|
62
|
-
expect(itinerary1leg2.transportInfo?.directionName).equal('Aéroport Charles de Gaulle 2 (Terminal 2) (Tremblay-en-France)');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('Itineraries - 2 - steps', () => {
|
|
66
|
-
|
|
67
|
-
const filePath = path.resolve(assetsPath, 'itinerary-paris-idfm-2.json');
|
|
68
|
-
const fileString = fs.readFileSync(filePath, 'utf8');
|
|
69
|
-
const json = JSON.parse(fileString);
|
|
70
|
-
|
|
71
|
-
const itineraries = IdfmRemoteRouter.parseResponse(json);
|
|
72
|
-
itineraries.forEach(verifyStepsCoherence);
|
|
73
|
-
|
|
74
|
-
expect(itineraries.length).equal(2);
|
|
75
|
-
|
|
76
|
-
// Get WALK itinerary
|
|
77
|
-
const itinerary1 = itineraries[1];
|
|
78
|
-
expect(itinerary1.origin.equals(new Coordinates(48.856222, 2.334505))).true;
|
|
79
|
-
expect(itinerary1.destination.equals(new Coordinates(48.85784, 2.332184))).true;
|
|
80
|
-
expect(itinerary1.distance).to.be.closeTo(457, 1);
|
|
81
|
-
expect(itinerary1.duration).equal(434);
|
|
82
|
-
expect(itinerary1.transitMode).equal('WALK');
|
|
83
|
-
// Do not work because of the input time format
|
|
84
|
-
expect(itinerary1.startTime).equal(1712237614000);
|
|
85
|
-
expect(itinerary1.endTime).equal(1712238048000);
|
|
86
|
-
expect(itinerary1.legs.length).equal(1);
|
|
87
|
-
|
|
88
|
-
expect(areTransitAndTravelModeConsistent(itinerary1.transitMode, 'WALK')).is.true;
|
|
89
|
-
|
|
90
|
-
const steps = itinerary1.steps;
|
|
91
|
-
|
|
92
|
-
expect(steps.length).equal(9);
|
|
93
|
-
expect(steps[0].firstStep).equal(true);
|
|
94
|
-
expect(steps[0].number).equal(1);
|
|
95
|
-
|
|
96
|
-
expect(steps[1].firstStep).equal(false);
|
|
97
|
-
expect(steps[1].number).equal(2);
|
|
98
|
-
|
|
99
|
-
expect(steps[8].lastStep).equal(true);
|
|
100
|
-
expect(steps[8].number).equal(9);
|
|
101
|
-
});
|
|
102
|
-
});
|