@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.
Files changed (167) hide show
  1. package/dist/helpers/InstructionManager.d.ts +20 -0
  2. package/dist/helpers/InstructionManagerV1.d.ts +7 -0
  3. package/{index.ts → dist/index.d.ts} +1 -11
  4. package/dist/index.js +1 -5099
  5. package/dist/index.js.map +1 -1
  6. package/dist/src/ItineraryInfoManager.d.ts +31 -0
  7. package/dist/src/RoutingError.d.ts +24 -0
  8. package/{src/StatusCode.ts → dist/src/StatusCode.d.ts} +2 -3
  9. package/dist/src/Utils.d.ts +6 -0
  10. package/dist/src/graph/Edge.d.ts +32 -0
  11. package/dist/src/graph/Graph.d.ts +40 -0
  12. package/dist/src/graph/GraphProjection.d.ts +11 -0
  13. package/dist/src/graph/GraphProjectionOptions.d.ts +7 -0
  14. package/dist/src/graph/GraphRoute.d.ts +19 -0
  15. package/dist/src/graph/GraphRouter.d.ts +20 -0
  16. package/dist/src/graph/GraphRouterEngine.d.ts +77 -0
  17. package/{src/graph/GraphRouterOptions.ts → dist/src/graph/GraphRouterOptions.d.ts} +5 -7
  18. package/dist/src/graph/GraphRouterOptionsBuilder.d.ts +20 -0
  19. package/dist/src/graph/NoRouteFoundError.d.ts +12 -0
  20. package/dist/src/graph/Vertex.d.ts +19 -0
  21. package/dist/src/model/Itinerary.d.ts +81 -0
  22. package/dist/src/model/Leg.d.ts +66 -0
  23. package/dist/src/model/LevelChange.d.ts +7 -0
  24. package/dist/src/model/RouterRequest.d.ts +40 -0
  25. package/dist/src/model/Step.d.ts +42 -0
  26. package/dist/src/model/StepExtra.d.ts +3 -0
  27. package/dist/src/model/StepsBuilder.d.ts +16 -0
  28. package/dist/src/model/TransitMode.d.ts +5 -0
  29. package/{src/model/TravelMode.ts → dist/src/model/TravelMode.d.ts} +1 -2
  30. package/dist/src/model/generateSteps.d.ts +0 -0
  31. package/{src/remote/RemoteRouter.ts → dist/src/remote/RemoteRouter.d.ts} +2 -7
  32. package/dist/src/remote/RemoteRouterManager.d.ts +731 -0
  33. package/dist/src/remote/RemoteRouterUtils.d.ts +6 -0
  34. package/dist/src/remote/cityway/CitywayRemoteRouter.d.ts +109 -0
  35. package/dist/src/remote/deutsche-bahn/DeutscheBahnRemoteRouter.d.ts +31 -0
  36. package/dist/src/remote/geovelo/GeoveloRemoteRouter.d.ts +106 -0
  37. package/dist/src/remote/idfm/IdfmRemoteRouter.d.ts +123 -0
  38. package/dist/src/remote/navitia/NavitiaRemoteRouter.d.ts +34 -0
  39. package/dist/src/remote/navitia/types.d.ts +87 -0
  40. package/dist/src/remote/osrm/OsrmRemoteRouter.d.ts +70 -0
  41. package/dist/src/remote/otp/OtpRemoteRouter.d.ts +69 -0
  42. package/dist/src/remote/wemap-multi/WemapMultiRemoteRouter.d.ts +19 -0
  43. package/dist/src/types.d.ts +31 -0
  44. package/dist/src/wemap-multi/CustomGraphMap.d.ts +56 -0
  45. package/dist/src/wemap-multi/CustomGraphMapTester.d.ts +39 -0
  46. package/dist/src/wemap-multi/WemapMultiRouter.d.ts +14 -0
  47. package/dist/src/wemap-osm/OsmGraphUtils.d.ts +11 -0
  48. package/dist/tests/CommonTest.d.ts +8 -0
  49. package/package.json +11 -8
  50. package/assets/biocbon-bergere-rdc-network.osm +0 -163
  51. package/assets/bureaux-wemap-montpellier-network.osm +0 -174
  52. package/assets/components.osm +0 -146
  53. package/assets/elevator-models-4.osm +0 -89
  54. package/assets/elevator-models.osm +0 -354
  55. package/assets/exit-graph.osm +0 -25
  56. package/assets/gare-de-lest-network-pp-bounds.osm +0 -1613
  57. package/assets/gare-de-lyon-extract.osm +0 -174
  58. package/assets/geovelo-montpellier.json +0 -1144
  59. package/assets/horizontal-elevator.osm +0 -12
  60. package/assets/itinerary-deutsche-bahn-1.json +0 -368
  61. package/assets/itinerary-grenoble-otp-1.json +0 -1536
  62. package/assets/itinerary-grenoble-otp-2.json +0 -1092
  63. package/assets/itinerary-info-two-points-proj.osm +0 -39
  64. package/assets/itinerary-info-two-points.osm +0 -24
  65. package/assets/itinerary-lehavre-cityway-1.json +0 -6799
  66. package/assets/itinerary-lehavre-cityway-2.json +0 -2133
  67. package/assets/itinerary-lehavre-cityway-3.json +0 -12577
  68. package/assets/itinerary-lehavre-cityway-4.json +0 -1451
  69. package/assets/itinerary-lehavre-cityway-5.json +0 -5925
  70. package/assets/itinerary-lemans-navitia.json +0 -7768
  71. package/assets/itinerary-montpellier-osrm-3.json +0 -185
  72. package/assets/itinerary-montpellier-outdoor-without-steps.json +0 -110
  73. package/assets/itinerary-montpellier-outdoor.json +0 -513
  74. package/assets/itinerary-paris-idfm-2.json +0 -1838
  75. package/assets/itinerary-paris-idfm.json +0 -27727
  76. package/assets/itinerary-step-not-on-path-osrm.json +0 -457
  77. package/assets/itinerary-with-duplicate-nodes.json +0 -110
  78. package/assets/network-conveying-backward.osm +0 -74
  79. package/assets/network-elevator.osm +0 -48
  80. package/assets/network-escalators.osm +0 -50
  81. package/assets/network-simple.osm +0 -27
  82. package/assets/network-steps-same-level.osm +0 -283
  83. package/assets/network-with-modifiers.osm +0 -39
  84. package/assets/one-way.osm +0 -46
  85. package/assets/report-map-1.osm +0 -36
  86. package/assets/report-map-2.osm +0 -29
  87. package/assets/report-map-3.osm +0 -15
  88. package/assets/rr-wemap-multi-indoor-outdoor-indoor.json +0 -1352
  89. package/assets/rr-wemap-multi-indoor-outdoor.json +0 -145
  90. package/assets/rr-wemap-multi-multi-level.json +0 -262
  91. package/assets/rr-wemap-multi-outdoor-indoor.json +0 -145
  92. package/assets/rr-wemap-multi-outdoor-outdoor.json +0 -207
  93. package/assets/rr-wemap-multi-remote-indoor-indoor.json +0 -155
  94. package/assets/rr-wemap-multi-remote-indoor-outdoor-indoor.json +0 -668
  95. package/assets/rr-wemap-multi-remote-indoor-outdoor.json +0 -154
  96. package/assets/rr-wemap-multi-remote-outdoor-indoor.json +0 -179
  97. package/assets/rr-wemap-multi-remote-outdoor-outdoor.json +0 -109
  98. package/assets/stairs-and-exit.osm +0 -47
  99. package/helpers/InstructionManager.ts +0 -184
  100. package/helpers/InstructionManagerV1.ts +0 -95
  101. package/src/ItineraryInfoManager.spec.ts +0 -183
  102. package/src/ItineraryInfoManager.ts +0 -181
  103. package/src/RoutingError.ts +0 -60
  104. package/src/Utils.ts +0 -8
  105. package/src/graph/Edge.spec.ts +0 -32
  106. package/src/graph/Edge.ts +0 -64
  107. package/src/graph/Graph.spec.ts +0 -509
  108. package/src/graph/Graph.ts +0 -272
  109. package/src/graph/GraphProjection.ts +0 -15
  110. package/src/graph/GraphProjectionOptions.ts +0 -8
  111. package/src/graph/GraphRoute.spec.ts +0 -15
  112. package/src/graph/GraphRoute.ts +0 -43
  113. package/src/graph/GraphRouter.spec.ts +0 -317
  114. package/src/graph/GraphRouter.ts +0 -229
  115. package/src/graph/GraphRouterEngine.ts +0 -248
  116. package/src/graph/GraphRouterOptionsBuilder.ts +0 -98
  117. package/src/graph/NoRouteFoundError.ts +0 -39
  118. package/src/graph/Vertex.spec.ts +0 -42
  119. package/src/graph/Vertex.ts +0 -45
  120. package/src/model/Itinerary.spec.ts +0 -134
  121. package/src/model/Itinerary.ts +0 -370
  122. package/src/model/Leg.spec.ts +0 -107
  123. package/src/model/Leg.ts +0 -224
  124. package/src/model/LevelChange.spec.ts +0 -50
  125. package/src/model/LevelChange.ts +0 -14
  126. package/src/model/RouterRequest.ts +0 -33
  127. package/src/model/Step.spec.ts +0 -99
  128. package/src/model/Step.ts +0 -90
  129. package/src/model/StepExtra.ts +0 -1
  130. package/src/model/StepsBuilder.ts +0 -242
  131. package/src/model/TransitMode.spec.ts +0 -31
  132. package/src/model/TransitMode.ts +0 -28
  133. package/src/model/generateSteps.ts +0 -102
  134. package/src/remote/RemoteRouterManager.spec.ts +0 -178
  135. package/src/remote/RemoteRouterManager.ts +0 -72
  136. package/src/remote/RemoteRouterUtils.ts +0 -25
  137. package/src/remote/cityway/CitywayRemoteRouter.spec.ts +0 -122
  138. package/src/remote/cityway/CitywayRemoteRouter.ts +0 -435
  139. package/src/remote/deutsche-bahn/DeutscheBahnRemoteRouter.spec.ts +0 -52
  140. package/src/remote/deutsche-bahn/DeutscheBahnRemoteRouter.ts +0 -85
  141. package/src/remote/geovelo/GeoveloRemoteRouter.spec.ts +0 -54
  142. package/src/remote/geovelo/GeoveloRemoteRouter.ts +0 -293
  143. package/src/remote/idfm/IdfmRemoteRouter.spec.ts +0 -102
  144. package/src/remote/idfm/IdfmRemoteRouter.ts +0 -523
  145. package/src/remote/navitia/NavitiaRemoteRouter.spec.ts +0 -116
  146. package/src/remote/navitia/NavitiaRemoteRouter.ts +0 -445
  147. package/src/remote/navitia/types.ts +0 -73
  148. package/src/remote/osrm/OsrmRemoteRouter.spec.ts +0 -127
  149. package/src/remote/osrm/OsrmRemoteRouter.ts +0 -303
  150. package/src/remote/otp/OtpRemoteRouter.spec.ts +0 -103
  151. package/src/remote/otp/OtpRemoteRouter.ts +0 -223
  152. package/src/remote/wemap-multi/WemapMultiRemoteRouter.spec.ts +0 -103
  153. package/src/remote/wemap-multi/WemapMultiRemoteRouter.ts +0 -56
  154. package/src/types.ts +0 -32
  155. package/src/wemap-multi/CustomGraphMap.spec.ts +0 -40
  156. package/src/wemap-multi/CustomGraphMap.ts +0 -213
  157. package/src/wemap-multi/CustomGraphMapTester.spec.ts +0 -48
  158. package/src/wemap-multi/CustomGraphMapTester.ts +0 -90
  159. package/src/wemap-multi/WemapMultiRouter.spec.ts +0 -138
  160. package/src/wemap-multi/WemapMultiRouter.ts +0 -329
  161. package/src/wemap-osm/OsmGraphUtils.spec.ts +0 -165
  162. package/src/wemap-osm/OsmGraphUtils.ts +0 -173
  163. package/src/wemap-osm/OsmRouter.elevators.spec.ts +0 -106
  164. package/src/wemap-osm/OsmRouter.spec.ts +0 -292
  165. package/tests/CommonTest.ts +0 -78
  166. package/tsconfig.json +0 -3
  167. package/vite.config.ts +0 -4
@@ -1,445 +0,0 @@
1
- import { Coordinates, Utils as GeoUtils } from '@wemap/geo';
2
- import Logger from '@wemap/logger';
3
-
4
- import RemoteRouter from '../RemoteRouter.js';
5
- import Itinerary from '../../model/Itinerary.js';
6
- import Leg, { TransportInfo } from '../../model/Leg.js';
7
- import { dateWithTimeZone } from '../RemoteRouterUtils.js';
8
- import { TransitMode, areTransitAndTravelModeConsistent } from '../../model/TransitMode.js';
9
- import StepsBuilder from '../../model/StepsBuilder.js';
10
- import { type MinStepInfo } from '../../model/Step.js';
11
- import { type RouterRequest } from '../../model/RouterRequest.js';
12
- import { RemoteRoutingError } from '../../RoutingError.js';
13
- import { NavitiaJson, NavitiaCoordinates, NavitiaSection, NavitiaIntermediateStep } from './types';
14
-
15
- /**
16
- * List of all modes supported by the API
17
- * http://doc.navitia.io/#physical-mode
18
- */
19
-
20
- const transitModeCorrespondance = new Map<string, TransitMode>();
21
- transitModeCorrespondance.set('Air', 'AIRPLANE');
22
- transitModeCorrespondance.set('Boat', 'BOAT');
23
- transitModeCorrespondance.set('Bus', 'BUS');
24
- transitModeCorrespondance.set('BusRapidTransit', 'BUS');
25
- transitModeCorrespondance.set('Coach', 'BUS');
26
- transitModeCorrespondance.set('Ferry', 'FERRY');
27
- transitModeCorrespondance.set('Funicular', 'FUNICULAR');
28
- transitModeCorrespondance.set('LocalTrain', 'TRAIN');
29
- transitModeCorrespondance.set('LongDistanceTrain', 'TRAIN');
30
- transitModeCorrespondance.set('Metro', 'METRO');
31
- transitModeCorrespondance.set('Métro', 'METRO');
32
- transitModeCorrespondance.set('RailShuttle', 'TRAIN');
33
- transitModeCorrespondance.set('RapidTransit', 'BUS');
34
- transitModeCorrespondance.set('Shuttle', 'BUS');
35
- transitModeCorrespondance.set('SuspendedCableCar', 'FUNICULAR');
36
- transitModeCorrespondance.set('Taxi', 'TAXI');
37
- transitModeCorrespondance.set('Train', 'TRAIN');
38
- transitModeCorrespondance.set('RER', 'TRAIN');
39
- transitModeCorrespondance.set('Tramway', 'TRAM');
40
- transitModeCorrespondance.set('walking', 'WALK');
41
- transitModeCorrespondance.set('bike', 'BIKE');
42
-
43
- /**
44
- * List of transports modes
45
- */
46
- const TRANSPORT_IDS = [
47
- 'physical_mode:Air',
48
- 'physical_mode:Boat',
49
- 'physical_mode:Bus',
50
- 'physical_mode:BusRapidTransit',
51
- 'physical_mode:Coach',
52
- 'physical_mode:Ferry',
53
- 'physical_mode:Funicular',
54
- 'physical_mode:LocalTrain',
55
- 'physical_mode:LongDistanceTrain',
56
- 'physical_mode:Metro',
57
- 'physical_mode:RailShuttle',
58
- 'physical_mode:RapidTransit',
59
- 'physical_mode:Shuttle',
60
- 'physical_mode:SuspendedCableCar',
61
- 'physical_mode:Taxi',
62
- 'physical_mode:Train',
63
- 'physical_mode:Tramway'
64
- ];
65
-
66
- function jsonToCoordinates(json: NavitiaCoordinates) {
67
- return new Coordinates(Number(json.lat), Number(json.lon));
68
- }
69
-
70
- function last<T>(array: T[]) {
71
- return array[array.length - 1];
72
- }
73
-
74
- /**
75
- * stringDate (e.g. 20211117T104516)
76
- */
77
- function dateStringToTimestamp(stringDate: string, timeZone: string) {
78
- const yearStr = stringDate.substr(0, 4);
79
- const monthStr = stringDate.substr(4, 2);
80
- const dayStr = stringDate.substr(6, 2);
81
- const hoursStr = stringDate.substr(9, 2);
82
- const minutesStr = stringDate.substr(11, 2);
83
- const secondsStr = stringDate.substr(13, 2);
84
-
85
- return dateWithTimeZone(
86
- Number(yearStr),
87
- Number(monthStr) - 1,
88
- Number(dayStr),
89
- Number(hoursStr),
90
- Number(minutesStr),
91
- Number(secondsStr),
92
- timeZone
93
- ).getTime();
94
- }
95
-
96
- // The api key should be defined in the routingurl as api_key=XXXXXXXX
97
-
98
- /**
99
- * Singleton.
100
- */
101
- class NavitiaRemoteRouter extends RemoteRouter {
102
-
103
- get rname() { return 'navitia' as const; }
104
-
105
- async getItineraries(endpointUrl: string, routerRequest: RouterRequest) {
106
- const url = this.getURL(endpointUrl, routerRequest);
107
-
108
- // The api key should be defined in the routingurl as api_key=XXXXXXXX
109
- const api_key = url.searchParams.get('api_key');
110
- if (!api_key) {
111
- throw RemoteRoutingError.missingApiKey(this.rname);
112
- }
113
-
114
- const res = await (fetch(url, {
115
- method: 'GET',
116
- headers: {
117
- 'Authorization': api_key,
118
- }
119
- }).catch(() => {
120
- throw RemoteRoutingError.unreachableServer(this.rname, url.toString());
121
- }));
122
-
123
-
124
- const jsonResponse: NavitiaJson = await res.json().catch(() => {
125
- throw RemoteRoutingError.responseNotParsing(this.rname, url.toString());
126
- });
127
-
128
- // When Navitia failed to calculate an itinerary (ie. start or end
129
- // point is far from network), it respond a 404 with an error message
130
- // or a 200 with an error message
131
- if (jsonResponse && jsonResponse.error) {
132
- throw RemoteRoutingError.notFound(this.rname, jsonResponse.error.message);
133
- }
134
-
135
- const itineraries = this.parseResponse(jsonResponse);
136
-
137
- const sameModeFound = itineraries.some((itinerary) => areTransitAndTravelModeConsistent(itinerary.transitMode, routerRequest.travelMode));
138
-
139
- if (!sameModeFound) {
140
- throw RemoteRoutingError.notFound(
141
- this.rname,
142
- 'Selected mode of transport was not found for this itinerary.'
143
- )
144
- }
145
-
146
- return itineraries;
147
- }
148
-
149
- getURL(endpointUrl: string, routerRequest: RouterRequest) {
150
- const { origin, destination, waypoints, travelMode } = routerRequest;
151
-
152
- if ((waypoints || []).length > 0) {
153
- Logger.warn(`${this.rname} router uses only the first 2 waypoints (asked ${waypoints?.length})`);
154
- }
155
-
156
- const url = new URL(endpointUrl);
157
-
158
- const coreParams = new URLSearchParams();
159
- coreParams.set('from', `${origin.longitude};${origin.latitude}`);
160
- coreParams.set('to', `${destination.longitude};${destination.latitude}`);
161
- coreParams.set('data_freshness', 'realtime');
162
-
163
- if (routerRequest.itineraryModifiers?.avoidStairs) {
164
- coreParams.set('wheelchair', 'true')
165
- }
166
-
167
- let queryParams: URLSearchParams = new URLSearchParams();
168
- switch (travelMode) {
169
- case 'WALK':
170
- queryParams = this.getWalkingQuery();
171
- break;
172
- case 'BIKE':
173
- queryParams = this.getBikeQuery();
174
- break;
175
- case 'CAR':
176
- queryParams = this.getCarQuery();
177
- break;
178
- default:
179
- break;
180
- }
181
-
182
- [coreParams, queryParams].map(params => {
183
- for (const pair of params.entries()) {
184
- url.searchParams.append(pair[0], pair[1]);
185
- }
186
- });
187
-
188
- return url;
189
- }
190
-
191
- getCarQuery() {
192
- const urlSearchParams = new URLSearchParams();
193
-
194
- TRANSPORT_IDS.forEach((id) => {
195
- urlSearchParams.append('forbidden_uris[]', id);
196
- });
197
-
198
- urlSearchParams.append('first_section_mode[]', 'walking');
199
- urlSearchParams.append('first_section_mode[]', 'car');
200
- urlSearchParams.append('last_section_mode[]', 'walking');
201
- urlSearchParams.append('last_section_mode[]', 'car');
202
-
203
- return urlSearchParams;
204
- }
205
-
206
- getWalkingQuery() {
207
- const urlSearchParams = new URLSearchParams();
208
-
209
- TRANSPORT_IDS.forEach((id) => {
210
- urlSearchParams.append('forbidden_uris[]', id);
211
- });
212
-
213
- urlSearchParams.append('first_section_mode[]', 'walking');
214
- urlSearchParams.append('last_section_mode[]', 'walking');
215
-
216
- return urlSearchParams;
217
- }
218
-
219
- getBikeQuery() {
220
- const urlSearchParams = new URLSearchParams();
221
-
222
- TRANSPORT_IDS.forEach((id) => {
223
- urlSearchParams.append('forbidden_uris[]', id);
224
- });
225
-
226
- urlSearchParams.append('first_section_mode[]', 'bike');
227
- urlSearchParams.append('last_section_mode[]', 'bike');
228
-
229
- return urlSearchParams;
230
- }
231
-
232
-
233
- getSectionCoords(section: NavitiaSection) {
234
- let from: NavitiaCoordinates | undefined;
235
- let to: NavitiaCoordinates | undefined;
236
-
237
- if ('stop_point' in section.from) {
238
- from = section.from.stop_point.coord;
239
- } else if ('address' in section.from) {
240
- from = section.from.address.coord;
241
- } else {
242
- from = section.from.poi.coord;
243
- }
244
-
245
- if ('stop_point' in section.to) {
246
- to = section.to.stop_point.coord;
247
- } else if ('address' in section.to) {
248
- to = section.to.address.coord;
249
- } else {
250
- to = section.to.poi.coord;
251
- }
252
-
253
- return {
254
- from: jsonToCoordinates(from),
255
- to: jsonToCoordinates(to)
256
- };
257
- }
258
-
259
- /**
260
- * Since the navitia API does not provide coords for each step, we need to compute them
261
- * We trim the coordinates of the leg with the distance of each step and keep the last result as the coords of the step
262
- * @param {Leg} leg
263
- */
264
- findStepsCoord(legCoords: Coordinates[], steps: NavitiaIntermediateStep[]) {
265
- const coords = legCoords;
266
-
267
- const duplicatedCoords = [...coords];
268
- let previousStep = steps[0];
269
- let accumulatedIndex = 0;
270
- const outputSteps = [];
271
-
272
- for (const [idx, step] of steps.entries()) {
273
- let newCoords: Coordinates;
274
-
275
- let _idCoordsInLeg;
276
-
277
- if (idx === 0) {
278
- _idCoordsInLeg = 0;
279
- newCoords = coords[0];
280
- } else if (idx === steps.length - 1) {
281
- _idCoordsInLeg = coords.length - 1;
282
- newCoords = last(coords);
283
- } else if (duplicatedCoords.length === 1) {
284
- accumulatedIndex++;
285
-
286
- _idCoordsInLeg = accumulatedIndex;
287
-
288
- newCoords = duplicatedCoords[0];
289
-
290
- coords[_idCoordsInLeg] = newCoords;
291
- } else {
292
- const result = GeoUtils.trimRoute(duplicatedCoords, duplicatedCoords[0], previousStep.distance);
293
- accumulatedIndex += result.length - 1;
294
-
295
- duplicatedCoords.splice(0, result.length - 1);
296
-
297
- _idCoordsInLeg = accumulatedIndex;
298
-
299
- newCoords = last(result);
300
-
301
- coords[_idCoordsInLeg] = newCoords;
302
- }
303
-
304
- outputSteps.push({
305
- ...step,
306
- coords: newCoords
307
- });
308
-
309
- previousStep = step;
310
- }
311
-
312
- return outputSteps;
313
- }
314
-
315
- findStepCoords(step: NavitiaSection['path'][number], section: NavitiaSection) {
316
- if ('instruction_start_coordinate' in step) {
317
- return jsonToCoordinates(step.instruction_start_coordinate);
318
- }
319
-
320
- const via = section.vias?.find(via => via.id === step.via_uri);
321
- if (via) {
322
- return jsonToCoordinates(via.access_point.coord);
323
- }
324
- }
325
-
326
- parseResponse(json: NavitiaJson) {
327
-
328
- if (!json || !json.journeys) {
329
- throw RemoteRoutingError.notFound(this.rname, json.error?.message);
330
- }
331
-
332
- const itineraries = [];
333
-
334
- const timeZone = json.context.timezone;
335
-
336
- for (const jsonItinerary of json.journeys) {
337
-
338
- const legs = [];
339
-
340
- for (const jsonSection of jsonItinerary.sections) {
341
-
342
- if (jsonSection.type === 'waiting' || jsonSection.type === 'transfer') {
343
- continue;
344
- }
345
-
346
- const { from: startSection, to: endSection } = this.getSectionCoords(jsonSection);
347
-
348
- // A section can have multiple same coordinates, we need to remove them
349
- let existingCoords: string[] = [];
350
- const legCoords = jsonSection.geojson.coordinates.reduce((acc, [lon, lat]) => {
351
- if (!existingCoords.includes(`${lon}-${lat}`)) {
352
- existingCoords = existingCoords.concat(`${lon}-${lat}`);
353
- acc.push(new Coordinates(lat, lon));
354
- }
355
- return acc;
356
- }, [] as Coordinates[]);
357
-
358
- const stepsBuilder = new StepsBuilder().setStart(startSection).setEnd(endSection).setPathCoords(legCoords);
359
- let transportInfo: TransportInfo | undefined;
360
- let transitMode = transitModeCorrespondance.get(jsonSection.mode) as TransitMode;
361
-
362
- if (jsonSection.path) {
363
- const useNavitiaSteps = jsonSection.path.every(step => 'instruction_start_coordinate' in step || step.via_uri);
364
- const navitiaIntermediateSteps = [];
365
-
366
- for (const jsonPathLink of jsonSection.path) {
367
- let coords: Coordinates;
368
- if (useNavitiaSteps) {
369
- coords = this.findStepCoords(jsonPathLink, jsonSection)!;
370
-
371
- const intermediateStep = {
372
- name: jsonPathLink.name,
373
- distance: jsonPathLink.length,
374
- coords
375
- };
376
-
377
- stepsBuilder.addStepInfo(intermediateStep);
378
- } else {
379
- navitiaIntermediateSteps.push({
380
- name: jsonPathLink.name,
381
- distance: jsonPathLink.length,
382
- });
383
- }
384
- }
385
-
386
- if (!useNavitiaSteps) {
387
- stepsBuilder.setStepsInfo(this.findStepsCoord(legCoords, navitiaIntermediateSteps));
388
- }
389
- }
390
-
391
- if (jsonSection.type === 'public_transport') {
392
- transportInfo = {
393
- name: jsonSection.display_informations.code,
394
- routeColor: jsonSection.display_informations.color,
395
- routeTextColor: jsonSection.display_informations.text_color,
396
- directionName: jsonSection.display_informations.direction
397
- };
398
-
399
- transitMode = transitModeCorrespondance.get(jsonSection.display_informations.physical_mode) as TransitMode;
400
-
401
- const legStep: MinStepInfo = {
402
- coords: legCoords[0],
403
- name: transportInfo.directionName,
404
- distance: jsonSection.geojson.properties[0].length
405
- };
406
- stepsBuilder.setStepsInfo([legStep]);
407
- }
408
-
409
- const leg = new Leg({
410
- transitMode,
411
- duration: jsonSection.duration,
412
- startTime: dateStringToTimestamp(jsonSection.departure_date_time, timeZone),
413
- endTime: dateStringToTimestamp(jsonSection.arrival_date_time, timeZone),
414
- start: {
415
- name: jsonSection.from.name,
416
- coords: startSection
417
- },
418
- end: {
419
- name: jsonSection.to.name,
420
- coords: endSection
421
- },
422
- coords: legCoords,
423
- transportInfo,
424
- steps: stepsBuilder.build()
425
- });
426
- legs.push(leg);
427
- }
428
-
429
- const itinerary = new Itinerary({
430
- duration: jsonItinerary.duration,
431
- startTime: dateStringToTimestamp(jsonItinerary.departure_date_time, timeZone),
432
- endTime: dateStringToTimestamp(jsonItinerary.arrival_date_time, timeZone),
433
- origin: this.getSectionCoords(jsonItinerary.sections[0]).from,
434
- destination: this.getSectionCoords(last(jsonItinerary.sections)).to,
435
- legs
436
- });
437
-
438
- itineraries.push(itinerary);
439
- }
440
-
441
- return itineraries;
442
- }
443
- }
444
-
445
- export default new NavitiaRemoteRouter();
@@ -1,73 +0,0 @@
1
-
2
- export type NavitiaCoordinates = { lat: number | string, lon: number | string };
3
- export type NavitiaPath = {
4
- name: string,
5
- length: number
6
- } & ({ instruction_start_coordinate: NavitiaCoordinates } | { via_uri: string });
7
-
8
- export type NavitiaWaypoint = { name: string }
9
- & (
10
- { stop_point: { coord: NavitiaCoordinates } } |
11
- { address: { coord: NavitiaCoordinates } } |
12
- { poi: { coord: NavitiaCoordinates } }
13
- )
14
-
15
- export type NavitiaSection = {
16
- id: string;
17
- type: 'waiting' | 'transfer' | string,
18
- mode: string,
19
- departure_date_time: string,
20
- arrival_date_time: string,
21
- duration: number,
22
- geojson: {
23
- coordinates: [number, number][],
24
- properties: { length: number }[]
25
- },
26
- path: NavitiaPath[],
27
- display_informations: {
28
- code: string,
29
- color: string,
30
- text_color: string,
31
- direction: string,
32
- physical_mode: string
33
- },
34
- from: NavitiaWaypoint,
35
- to: NavitiaWaypoint,
36
- vias?: {
37
- id: string;
38
- name: string;
39
- access_point: {
40
- id: string;
41
- name: string;
42
- coord: {
43
- lon: string;
44
- lat: string;
45
- },
46
- embedded_type: string;
47
- },
48
- is_entrance: boolean,
49
- is_exit: boolean,
50
- length: number,
51
- traversal_time: number,
52
- pathway_mode: number
53
- }[]
54
- }
55
- export type NavitiaJson = {
56
- journeys: {
57
- duration: number,
58
- departure_date_time: string,
59
- arrival_date_time: string,
60
- sections: NavitiaSection[]
61
- }[],
62
- context: {
63
- timezone: string
64
- };
65
- error: {
66
- message?: string;
67
- }
68
- };
69
-
70
- export type NavitiaIntermediateStep = {
71
- name: string,
72
- distance: number
73
- };
@@ -1,127 +0,0 @@
1
- /* eslint-disable max-statements */
2
- import chai from 'chai';
3
- import chaiAlmost from 'chai-almost';
4
- import fs from 'fs';
5
- import path from 'path';
6
- import { fileURLToPath } from 'url';
7
-
8
- import { Coordinates } from '@wemap/geo';
9
-
10
- import OsrmRemoteRouter from './OsrmRemoteRouter.js';
11
- import { verifyStepsCoherence } from '../../model/Itinerary.spec.js';
12
- import { areTransitAndTravelModeConsistent } from '../../model/TransitMode.js';
13
-
14
-
15
- const { expect } = chai;
16
- chai.use(chaiAlmost(0.1));
17
-
18
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
19
- const assetsPath = path.resolve(__dirname, '../../../assets');
20
-
21
-
22
- describe('OsrmRemoteRouter - parseResponse', () => {
23
-
24
- it('Itineraries - 1', () => {
25
-
26
- const filePath = path.resolve(assetsPath, 'itinerary-montpellier-outdoor.json');
27
- const fileString = fs.readFileSync(filePath, 'utf8');
28
- const json = JSON.parse(fileString);
29
-
30
- const origin = new Coordinates(43.6007871, 3.8757218000000004);
31
- const destination = new Coordinates(43.598877, 3.873866);
32
- const itineraries = OsrmRemoteRouter.parseResponse(json, origin, destination, 'WALK');
33
- itineraries.forEach(verifyStepsCoherence);
34
-
35
- expect(itineraries.length).equal(1);
36
-
37
- const itinerary1 = itineraries[0];
38
- expect(itinerary1.origin.equals(origin)).true;
39
- expect(itinerary1.destination.equals(destination)).true;
40
- expect(itinerary1.distance).closeTo(400, 1);
41
- expect(itinerary1.duration).equal(287.8);
42
- expect(itinerary1.startTime).is.null;
43
- expect(itinerary1.endTime).is.null;
44
- expect(itinerary1.legs.length).equal(1);
45
- expect(itinerary1.coords.length).equal(19);
46
- expect(itinerary1.transitMode).equal('WALK');
47
- expect(areTransitAndTravelModeConsistent(itinerary1.transitMode, 'WALK')).is.true;
48
-
49
- const itinerary1leg1 = itinerary1.legs[0];
50
- expect(itinerary1leg1.startTime).is.null;
51
- expect(itinerary1leg1.endTime).is.null;
52
- expect(itinerary1leg1.distance).closeTo(400, 1);
53
- expect(itinerary1leg1.duration).equal(287.8);
54
- expect(itinerary1leg1.transitMode).equal('WALK');
55
- expect(itinerary1leg1.transportInfo).is.null;
56
- expect(itinerary1leg1.start.name).is.null;
57
- expect(itinerary1leg1.start.coords.equals(new Coordinates(43.600777, 3.875607))).true;
58
- expect(itinerary1leg1.end.name).is.null;
59
- expect(itinerary1leg1.end.coords.equals(new Coordinates(43.59906, 3.873865))).true;
60
- expect(itinerary1leg1.coords.length).equal(19);
61
- expect(itinerary1leg1.coords).deep.equal(itinerary1.coords);
62
-
63
- });
64
-
65
-
66
- it('Itineraries - 2', () => {
67
-
68
- const filePath = path.resolve(assetsPath, 'itinerary-montpellier-osrm-3.json');
69
- const fileString = fs.readFileSync(filePath, 'utf8');
70
- const json = JSON.parse(fileString);
71
-
72
- const origin = new Coordinates(43.605663, 3.887244);
73
- const destination = new Coordinates(43.6054106, 3.8878106);
74
- const itineraries = OsrmRemoteRouter.parseResponse(json, origin, destination, 'WALK');
75
- itineraries.forEach(verifyStepsCoherence);
76
-
77
- expect(itineraries.length).equal(1);
78
- expect(itineraries[0].transitMode).equal('WALK');
79
- expect(itineraries[0].origin.equals(origin)).true;
80
- expect(itineraries[0].destination.equals(destination)).true;
81
- expect(areTransitAndTravelModeConsistent(itineraries[0].transitMode, 'WALK')).is.true;
82
-
83
- const steps = itineraries[0].steps;
84
- expect(steps.length).equal(2);
85
- expect(steps[1].angle).almost.equal(1.575);
86
-
87
- });
88
-
89
-
90
- it('Itineraries - 2 - should return CAR itinerary', () => {
91
-
92
- const filePath = path.resolve(assetsPath, 'itinerary-montpellier-osrm-3.json');
93
- const fileString = fs.readFileSync(filePath, 'utf8');
94
- const json = JSON.parse(fileString);
95
-
96
- const origin = new Coordinates(43.605663, 3.887244);
97
- const destination = new Coordinates(43.6054106, 3.8878106);
98
- const itineraries = OsrmRemoteRouter.parseResponse(json, origin, destination, 'CAR');
99
- itineraries.forEach(verifyStepsCoherence);
100
-
101
- expect(itineraries.length).equal(1);
102
- expect(itineraries[0].transitMode).equal('CAR');
103
- expect(itineraries[0].origin.equals(origin)).true;
104
- expect(itineraries[0].destination.equals(destination)).true;
105
- expect(areTransitAndTravelModeConsistent(itineraries[0].transitMode, 'CAR')).is.true;
106
-
107
- const steps = itineraries[0].steps;
108
- expect(steps.length).equal(2);
109
- expect(steps[1].angle).almost.equal(1.575);
110
-
111
- });
112
-
113
-
114
- it('Itineraries - 3', () => {
115
-
116
- const filePath = path.resolve(assetsPath, 'itinerary-step-not-on-path-osrm.json');
117
- const fileString = fs.readFileSync(filePath, 'utf8');
118
- const json = JSON.parse(fileString);
119
-
120
- const from = new Coordinates(48.880506, 2.353747);
121
- const to = new Coordinates(48.879921, 2.354741);
122
- const itineraries = OsrmRemoteRouter.parseResponse(json, from, to, 'WALK');
123
- itineraries.forEach(verifyStepsCoherence);
124
-
125
- });
126
-
127
- });