@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,242 +0,0 @@
1
- import { Coordinates, Level } from '@wemap/geo';
2
- import Logger from '@wemap/logger';
3
- import { diffAngle, deg2rad } from '@wemap/maths';
4
-
5
- import { type LevelChange, type LevelChangeType } from './LevelChange.js';
6
- import { type Step, type MinStepInfo } from './Step.js';
7
- import { getDurationFromLength } from '../Utils.js';
8
- import GraphRoute from '../graph/GraphRoute.js';
9
-
10
- const SKIP_STEP_ANGLE_MAX = deg2rad(20);
11
-
12
- export default class StepsBuilder {
13
-
14
- private start: Coordinates | null = null;
15
- private end: Coordinates | null = null;
16
- private pathCoords: Coordinates[] | null = null;
17
- private stepsInfo: MinStepInfo[] = [];
18
-
19
- setStart(start: Coordinates) {
20
- this.start = start;
21
- return this;
22
- }
23
-
24
- setEnd(end: Coordinates) {
25
- this.end = end;
26
- return this;
27
- }
28
-
29
- setPathCoords(pathCoords: Coordinates[]) {
30
- this.pathCoords = pathCoords;
31
- return this;
32
- }
33
-
34
- setStepsInfo(stepsInfo: MinStepInfo[]) {
35
- this.stepsInfo = stepsInfo;
36
- return this;
37
- }
38
-
39
- addStepInfo(stepInfo: MinStepInfo) {
40
- this.stepsInfo.push(stepInfo);
41
- return this;
42
- }
43
-
44
- setGraphRoute(graphRoute: GraphRoute) {
45
-
46
- const stepsInfo: MinStepInfo[] = [];
47
-
48
- const { start, end } = graphRoute;
49
-
50
- if (!graphRoute.hasRoute) { return this; }
51
-
52
- let currentStep: MinStepInfo | null = null;
53
- let previousBearing = start.bearingTo(graphRoute.vertices[0].coords);
54
-
55
- for (let i = 0; i < graphRoute.vertices.length - 1; i++) {
56
-
57
- const isFirstStep = i === 0;
58
-
59
- const vertex = graphRoute.vertices[i];
60
- const currentCoords = vertex.coords;
61
- const nextVertex = graphRoute.vertices[i + 1];
62
- const nextCoords = nextVertex.coords;
63
-
64
- const edge = graphRoute.edges[i];
65
-
66
- const nextBearing = vertex.bearingTo(nextVertex);
67
- const angle = diffAngle(previousBearing, nextBearing + Math.PI);
68
-
69
- const previousStep = stepsInfo.length ? stepsInfo[stepsInfo.length - 1] : null;
70
-
71
- const { isSubwayEntrance, isGate, subwayEntranceRef } = vertex.properties;
72
- const { isElevator, areEscalators, areStairs, isMovingWalkway, incline } = edge.properties;
73
-
74
- let levelChangeType: LevelChangeType | null = null;
75
- if (isElevator) {
76
- levelChangeType = 'elevator';
77
- } else if (areEscalators) {
78
- levelChangeType = 'escalator';
79
- } else if (areStairs) {
80
- levelChangeType = 'stairs';
81
- } else if (isMovingWalkway) {
82
- levelChangeType = 'moving walkway';
83
- } else {
84
- levelChangeType = 'incline plane';
85
- }
86
-
87
- // Handle stairs/elevators/escalators/moving walkway/incline plane without change in level coordinates
88
- let forceLevelChange: 'up' | 'down' | undefined;
89
- if (
90
- (areStairs || isElevator)
91
- && incline
92
- && !previousStep?.levelChange
93
- ) {
94
- forceLevelChange = incline;
95
- }
96
-
97
- const previousEdge = i > 0 ? graphRoute.edges[i - 1] : null;
98
- const previousEdgeProperties = previousEdge?.properties || {};
99
- const forceEndOfLevelChange = Boolean(
100
- previousEdgeProperties.incline && previousEdgeProperties.areStairs
101
- && (!incline || !areStairs)
102
- );
103
- const isEntrance = vertex.properties.isSubwayEntrance;
104
-
105
- const stepName = edge.properties.name || null;
106
- const duration = graphRoute.edgesWeights[i];
107
- const stepExtras = {
108
- ...(isSubwayEntrance && { isSubwayEntrance }),
109
- ...(subwayEntranceRef && { subwayEntranceRef }),
110
- ...(isGate && { isGate })
111
- };
112
-
113
- let splitByAngle = Math.abs(diffAngle(Math.PI, angle)) >= SKIP_STEP_ANGLE_MAX;
114
-
115
- const splitByLevel = Level.isRange(edge.level) && !Level.isRange(currentCoords.level) || forceLevelChange;
116
- splitByAngle = splitByAngle && !(currentCoords.level && Level.isRange(currentCoords.level));
117
-
118
-
119
- const splitByEndOfLevelChange = previousStep?.levelChange && !Level.isRange(currentCoords.level)
120
- || forceEndOfLevelChange;
121
-
122
- const splitStepCondition = splitByAngle || splitByLevel || splitByEndOfLevelChange || isEntrance;
123
-
124
- // New step creation
125
- if (isFirstStep || splitStepCondition) {
126
-
127
- let levelChange: LevelChange | undefined;
128
-
129
- if (splitByLevel) {
130
- const difference = Level.diff(currentCoords.level, nextCoords.level) || 0;
131
- let direction: 'up' | 'down' = difference > 0 ? 'up' : 'down';
132
- if (forceLevelChange) {
133
- direction = forceLevelChange;
134
- }
135
- levelChange = {
136
- difference, direction, ...(levelChangeType && { type: levelChangeType })
137
- };
138
- }
139
-
140
- currentStep = {
141
- coords: currentCoords,
142
- ...(stepName && { name: stepName }),
143
- extras: stepExtras,
144
- levelChange,
145
- distance: 0,
146
- duration: 0
147
- };
148
-
149
- stepsInfo.push(currentStep);
150
- }
151
-
152
- currentStep!.distance! += currentCoords.distanceTo(nextCoords);
153
- currentStep!.duration! += duration;
154
-
155
- previousBearing = nextBearing;
156
- }
157
-
158
- const lastCoords = graphRoute.vertices[graphRoute.vertices.length - 1].coords;
159
-
160
- // Create a last step if end is not on the graph
161
- if (!Coordinates.equals(lastCoords, end)) {
162
- stepsInfo.push({ coords: lastCoords });
163
- }
164
-
165
- this.setStart(start);
166
- this.setEnd(end);
167
- this.setPathCoords(graphRoute.vertices.map(v => v.coords));
168
- this.setStepsInfo(stepsInfo);
169
-
170
- return this;
171
- }
172
-
173
- build(): Step[] {
174
-
175
- const { pathCoords, start, end } = this;
176
-
177
- if (!pathCoords) {
178
- Logger.warn(`StepsBuilder: Missing "pathCoords" property to build steps`);
179
- return [];
180
- }
181
-
182
- if (!start) {
183
- Logger.warn(`StepsBuilder: Missing "from" property to build steps`);
184
- return [];
185
- }
186
-
187
- if (!end) {
188
- Logger.warn(`StepsBuilder: Missing "to" property to build steps`);
189
- return [];
190
- }
191
-
192
- if (this.stepsInfo.length === 0) {
193
- // If there is no steps info, steps coordinates are calculated using our steps calculation algorithm above.
194
- this.setGraphRoute(GraphRoute.fromCoordinates(start, end, pathCoords));
195
- }
196
-
197
- const { stepsInfo } = this;
198
-
199
- return stepsInfo.map((stepInfo, stepId) => {
200
- const coordsId = pathCoords.findIndex(coords => coords.equals(stepInfo.coords));
201
- if (coordsId === -1) {
202
- throw new Error('Cannot find step coordinates in itinerary coordinates.');
203
- }
204
-
205
- const coordsBeforeStep = coordsId === 0 ? start : pathCoords[coordsId - 1];
206
- const coordsAfterStep = coordsId === pathCoords.length - 1
207
- ? end
208
- : pathCoords[coordsId + 1];
209
-
210
- const previousBearing = coordsBeforeStep.bearingTo(stepInfo.coords);
211
- const nextBearing = stepInfo.coords.bearingTo(coordsAfterStep);
212
-
213
- let distance = 0;
214
- const isLastStep = stepId === stepsInfo.length - 1;
215
- const coordsToStopCalculation = isLastStep
216
- ? pathCoords[pathCoords.length - 1]
217
- : stepsInfo[stepId + 1].coords;
218
-
219
- let currentCoordsId = coordsId;
220
- while (!pathCoords[currentCoordsId].equals(coordsToStopCalculation)) {
221
- distance += pathCoords[currentCoordsId].distanceTo(pathCoords[currentCoordsId + 1]);
222
- currentCoordsId++;
223
- }
224
-
225
- return {
226
- coords: stepInfo.coords,
227
- name: stepInfo.name || null,
228
- number: stepId + 1,
229
- previousBearing,
230
- nextBearing,
231
- angle: diffAngle(previousBearing, nextBearing + Math.PI),
232
- firstStep: stepId === 0,
233
- lastStep: isLastStep,
234
- distance, // stepInfo.distance is overwritten
235
- duration: stepInfo.duration || getDurationFromLength(distance),
236
- levelChange: stepInfo.levelChange || null,
237
- extras: stepInfo.extras || null
238
- }
239
- });
240
- }
241
-
242
- }
@@ -1,31 +0,0 @@
1
- import chai from 'chai';
2
-
3
- import { isTransitModePublicTransport, areTransitAndTravelModeConsistent } from './TransitMode.js';
4
-
5
- const { expect } = chai;
6
-
7
- describe('TransitMode', () => {
8
-
9
- it('transit and travel mode consistent', () => {
10
- expect(areTransitAndTravelModeConsistent('AIRPLANE', 'TRANSIT')).is.true;
11
- expect(areTransitAndTravelModeConsistent('BOAT', 'TRANSIT' )).is.true;
12
- expect(areTransitAndTravelModeConsistent('BUS', 'TRANSIT' )).is.true;
13
- expect(areTransitAndTravelModeConsistent('FERRY', 'TRANSIT' )).is.true;
14
- expect(areTransitAndTravelModeConsistent('FUNICULAR', 'TRANSIT' )).is.true;
15
- expect(areTransitAndTravelModeConsistent('METRO', 'TRANSIT' )).is.true;
16
- expect(areTransitAndTravelModeConsistent('TRAIN', 'TRANSIT' )).is.true;
17
- expect(areTransitAndTravelModeConsistent('TRAM', 'TRANSIT' )).is.true;
18
- expect(areTransitAndTravelModeConsistent('MULTI', 'TRANSIT' )).is.true;
19
-
20
- expect(areTransitAndTravelModeConsistent('BIKE', 'TRANSIT')).is.false;
21
- expect(areTransitAndTravelModeConsistent('CAR', 'TRANSIT')).is.false;
22
- expect(areTransitAndTravelModeConsistent('MOTO', 'TRANSIT')).is.false;
23
- expect(areTransitAndTravelModeConsistent('TAXI', 'TRANSIT')).is.false;
24
-
25
- expect(areTransitAndTravelModeConsistent('WALK', 'TRANSIT')).is.true;
26
- expect(areTransitAndTravelModeConsistent('WALK', 'WALK')).is.true;
27
- expect(areTransitAndTravelModeConsistent('BIKE', 'BIKE')).is.true;
28
- expect(areTransitAndTravelModeConsistent('CAR', 'CAR')).is.true;
29
- });
30
-
31
- });
@@ -1,28 +0,0 @@
1
- import { TravelMode } from "./TravelMode";
2
-
3
- export type TransitMode = 'AIRPLANE' | 'BOAT' | 'BIKE' | 'BUS' | 'CAR' |
4
- 'FERRY' | 'FUNICULAR' | 'METRO' | 'MOTO' | 'TRAIN' | 'TAXI' |
5
- 'TRAM' | 'WALK' | 'MULTI' | 'UNKNOWN';
6
-
7
- export type PublicTransport = 'AIRPLANE' | 'BOAT' | 'BUS' |
8
- 'FERRY' | 'FUNICULAR' | 'METRO' | 'MULTI' | 'TRAIN' | 'TRAM';
9
-
10
- export function isTransitModePublicTransport(transitMode: TransitMode): transitMode is PublicTransport {
11
- return [
12
- 'AIRPLANE', 'BOAT', 'BUS', 'FERRY',
13
- 'FUNICULAR', 'METRO', 'MULTI', 'TRAIN', 'TRAM'
14
- ].includes(transitMode);
15
- }
16
-
17
- // Check if the transit mode and the travel mode are consistent
18
- // If they are strictly equal
19
- // Edge cases:
20
- // If the transit mode is public transport and the travel mode is 'TRANSIT'
21
- // If the transit mode is 'WALK' and the travel mode is 'TRANSIT'
22
- export function areTransitAndTravelModeConsistent(transitMode: TransitMode, travelMode: TravelMode): boolean {
23
- return (
24
- transitMode === travelMode
25
- || (isTransitModePublicTransport(transitMode) && travelMode === 'TRANSIT')
26
- || (transitMode === 'WALK' && travelMode === 'TRANSIT')
27
- );
28
- }
@@ -1,102 +0,0 @@
1
- // import { Coordinates, Level } from '@wemap/geo';
2
- // import { diffAngle, deg2rad } from '@wemap/maths';
3
- // import Leg from './Leg.js';
4
-
5
- // import { LevelChange, LevelChangeType } from './LevelChange.js';
6
- // import { MinStepInfo } from './Step.js';
7
- // import { StepExtra } from './StepExtra.js';
8
-
9
- // const SKIP_STEP_ANGLE_MAX = deg2rad(20);
10
-
11
- // export type StepsGenerationRules =
12
- // (currentCoords: Coordinates, nextCoords: Coordinates, previousStep: MinStepInfo | null) => {
13
- // createNewStep?: boolean;
14
- // duration?: number;
15
- // stepName?: string;
16
- // stepExtras?: StepExtra;
17
- // levelChangeType?: LevelChangeType;
18
- // forceLevelChange?: 'up' | 'down';
19
- // forceEndOfLevelChange?: boolean;
20
- // };
21
-
22
- // export default function generateSteps(leg: Leg, rules?: StepsGenerationRules) {
23
-
24
- // const steps: MinStepInfo[] = [];
25
-
26
- // const { from, to, coords: coordsArray } = leg;
27
-
28
- // let currentStep: MinStepInfo | null = null;
29
- // let previousBearing = from.coords.bearingTo(coordsArray[0]);
30
-
31
- // for (let i = 0; i < coordsArray.length - 1; i++) {
32
-
33
- // const isFirstStep = i === 0;
34
-
35
- // const currentCoords = coordsArray[i];
36
- // const nextCoords = coordsArray[i + 1];
37
- // const edgeLevel = Level.union(currentCoords.level, nextCoords.level);
38
-
39
- // const nextBearing = currentCoords.bearingTo(nextCoords);
40
- // const angle = diffAngle(previousBearing, nextBearing + Math.PI);
41
-
42
- // const previousStep = steps.length ? steps[steps.length - 1] : null;
43
- // const customRules = rules?.(currentCoords, nextCoords, previousStep);
44
-
45
- // let splitByAngle = Math.abs(diffAngle(Math.PI, angle)) >= SKIP_STEP_ANGLE_MAX;
46
-
47
- // const splitByLevel = Level.isRange(edgeLevel) && !Level.isRange(currentCoords.level) || customRules?.forceLevelChange;
48
- // splitByAngle = splitByAngle && !(currentCoords.level && Level.isRange(currentCoords.level));
49
-
50
-
51
- // const splitByEndOfLevelChange = previousStep?.levelChange && !Level.isRange(currentCoords.level)
52
- // || customRules?.forceEndOfLevelChange;
53
-
54
- // const splitStepCondition = splitByAngle || splitByLevel || splitByEndOfLevelChange || customRules?.createNewStep;
55
-
56
- // // New step creation
57
- // if (isFirstStep || splitStepCondition) {
58
-
59
- // let levelChange: LevelChange | undefined;
60
-
61
- // if (splitByLevel) {
62
- // const difference = Level.diff(currentCoords.level, nextCoords.level) || 0;
63
- // let direction: 'up' | 'down' = difference > 0 ? 'up' : 'down';
64
- // if (customRules?.forceLevelChange) {
65
- // direction = customRules?.forceLevelChange;
66
- // }
67
- // levelChange = { difference, direction, type: customRules?.levelChangeType };
68
- // }
69
-
70
- // // Remove duration in the case of rules do not provide duration.
71
- // if (currentStep && currentStep.duration === 0) {
72
- // delete currentStep.duration;
73
- // }
74
-
75
- // currentStep = {
76
- // coords: currentCoords,
77
- // name: customRules?.stepName,
78
- // extras: customRules?.stepExtras,
79
- // levelChange,
80
- // distance: 0,
81
- // duration: 0
82
- // };
83
-
84
- // steps.push(currentStep);
85
- // }
86
-
87
- // currentStep!.distance! += currentCoords.distanceTo(nextCoords);
88
- // if (customRules?.duration) {
89
- // currentStep!.duration! += customRules?.duration;
90
- // }
91
- // previousBearing = nextBearing;
92
- // }
93
-
94
- // const lastCoords = coordsArray[coordsArray.length - 1];
95
-
96
- // // Create a last step if end is not on the network
97
- // if (!Coordinates.equals(lastCoords, to.coords)) {
98
- // steps.push({ coords: lastCoords });
99
- // }
100
-
101
- // return steps;
102
- // }
@@ -1,178 +0,0 @@
1
- import chai from 'chai';
2
- import chaiAlmost from 'chai-almost';
3
- import fs from 'fs';
4
- import path from 'path';
5
- import { fileURLToPath } from 'url';
6
- import fetchMock from 'fetch-mock';
7
-
8
- import { Coordinates } from '@wemap/geo';
9
-
10
- import RemoteRouterManager, { RoutingFallbackStrategy } from './RemoteRouterManager.js';
11
- import { RemoteRoutingError } from '../RoutingError.js';
12
-
13
- type MockAny = any;
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
- const osrmPath = path.resolve(assetsPath, 'itinerary-montpellier-outdoor.json');
21
- const osrmJson = JSON.parse(fs.readFileSync(osrmPath, 'utf8'));
22
-
23
- describe('RemoteRouterManager', () => {
24
- afterEach(() => {
25
- fetchMock.restore();
26
- });
27
-
28
- describe('getRouterByName', () => {
29
- it('should return the router', () => {
30
- const router = RemoteRouterManager.getRouterByName('osrm');
31
- expect(router).not.null;
32
- });
33
-
34
- it('should return undefined if router is unknown', () => {
35
- const router = RemoteRouterManager.getRouterByName('unknown' as MockAny);
36
-
37
- expect(router).to.be.undefined;
38
- });
39
- });
40
-
41
- describe('getItineraries', () => {
42
- it('should return itineraries', async () => {
43
- fetchMock.mock('*', (() => {
44
- return osrmJson;
45
- })())
46
-
47
- const routerRequest = {
48
- origin: new Coordinates(48.8725992, 2.343431),
49
- destination: new Coordinates(48.8725694, 2.3433),
50
- travelMode: 'WALK'
51
- } as const;
52
-
53
- const itineraries = await RemoteRouterManager.getItineraries('osrm', 'http://localhost:3001', routerRequest);
54
- expect(itineraries).not.empty;
55
- });
56
-
57
- it('should throw an error if router is unknown', (done) => {
58
- const routerRequest = {
59
- origin: new Coordinates(48.8725992, 2.343431),
60
- destination: new Coordinates(48.8725694, 2.3433),
61
- travelMode: 'WALK'
62
- } as const;
63
-
64
- RemoteRouterManager.getItineraries('unknown' as MockAny, 'http://localhost:3001', routerRequest)
65
- .then(() => done('should throw an error'))
66
- .catch(() => done());
67
- });
68
-
69
- it('should throw an error on server error', (done) => {
70
- fetchMock.mock('*', (() => {
71
- return new Response(null, { status: 404 });
72
- })())
73
-
74
- const routerRequest = {
75
- origin: new Coordinates(48.8725992, 2.343431),
76
- destination: new Coordinates(48.8725694, 2.3433),
77
- travelMode: 'WALK'
78
- } as const;
79
-
80
- RemoteRouterManager.getItineraries('unknown' as MockAny, 'http://localhost:3001', routerRequest)
81
- .then(() => done('should throw an error'))
82
- .catch(() => done());
83
- });
84
- });
85
-
86
- describe('getItinerariesWithFallback', () => {
87
- it('should return itineraries', async () => {
88
- fetchMock.mock('*', (() => {
89
- return osrmJson;
90
- })())
91
-
92
- const routerRequest = {
93
- origin: new Coordinates(48.8725992, 2.343431),
94
- destination: new Coordinates(48.8725694, 2.3433),
95
- travelMode: 'WALK'
96
- } as const;
97
-
98
- const fallbackStrategy: RoutingFallbackStrategy = [
99
- { name: 'osrm', endpointUrl: 'http://localhost:3001' }
100
- ];
101
-
102
- const itineraries = await RemoteRouterManager.getItinerariesWithFallback(routerRequest, fallbackStrategy);
103
- expect(itineraries).not.empty;
104
- });
105
-
106
- it('should throw an error if all routers are unknown', (done) => {
107
- const routerRequest = {
108
- origin: new Coordinates(48.8725992, 2.343431),
109
- destination: new Coordinates(48.8725694, 2.3433),
110
- travelMode: 'WALK'
111
- } as const;
112
-
113
- const fallbackStrategy = [
114
- { name: 'unknown' as MockAny, endpointUrl: 'http://localhost:3001/unknown' }
115
- ];
116
-
117
- RemoteRouterManager.getItinerariesWithFallback(routerRequest, fallbackStrategy)
118
- .then(() => done('should throw an error'))
119
- .catch((error) => {
120
- expect(error instanceof RemoteRoutingError).to.be.true;
121
- expect((error as RemoteRoutingError).routerName).equal('unknown');
122
- expect((error as RemoteRoutingError).message).to.contains('http://localhost:3001/unknown');
123
-
124
- done();
125
- });
126
- });
127
-
128
- it('should throw an error if all routers are unreachable and return all errors', (done) => {
129
- fetchMock.mock('*', (() => {
130
- return new Response(null, { status: 404 });
131
- })())
132
-
133
- const routerRequest = {
134
- origin: new Coordinates(48.8725992, 2.343431),
135
- destination: new Coordinates(48.8725694, 2.3433),
136
- travelMode: 'WALK'
137
- } as const;
138
-
139
- const fallbackStrategy = [
140
- { name: 'osrm', endpointUrl: 'http://localhost:3001/osrm' },
141
- { name: 'unknown' as MockAny, endpointUrl: 'http://localhost:3001/unknown' }
142
- ];
143
-
144
- RemoteRouterManager.getItinerariesWithFallback(routerRequest, fallbackStrategy)
145
- .then(() => done('should throw an error'))
146
- .catch((error) => {
147
- expect(error instanceof RemoteRoutingError).to.be.true;
148
- expect((error as RemoteRoutingError).routerName).equal('osrm, unknown');
149
- expect((error as RemoteRoutingError).message).to.contains('http://localhost:3001/osrm');
150
- expect((error as RemoteRoutingError).message).to.contains('http://localhost:3001/unknown');
151
-
152
- done();
153
- });
154
- });
155
-
156
- it('should return itineraries and use fallback router if previous one fails', async () => {
157
- fetchMock.mock('*', (() => {
158
- return osrmJson;
159
- })())
160
-
161
- const routerRequest = {
162
- origin: new Coordinates(48.8725992, 2.343431),
163
- destination: new Coordinates(48.8725694, 2.3433),
164
- travelMode: 'WALK'
165
- } as const;
166
-
167
- const fallbackStrategy = [
168
- { name: 'unknown' as MockAny, endpointUrl: 'http://localhost:3001/unknown' },
169
- { name: 'osrm', endpointUrl: 'http://localhost:3001/osrm' }
170
- ];
171
-
172
- const itineraries = await RemoteRouterManager.getItinerariesWithFallback(routerRequest, fallbackStrategy);
173
- expect(itineraries).not.empty;
174
- });
175
-
176
- });
177
-
178
- });
@@ -1,72 +0,0 @@
1
- import RemoteRouter from './RemoteRouter.js';
2
- import CitywayRemoteRouter from './cityway/CitywayRemoteRouter.js';
3
- import NavitiaRemoteRouter from './navitia/NavitiaRemoteRouter.js';
4
- import DeutscheBahnRemoteRouter from './deutsche-bahn/DeutscheBahnRemoteRouter.js';
5
- import IdfmRemoteRouter from './idfm/IdfmRemoteRouter.js';
6
- import OsrmRemoteRouter from './osrm/OsrmRemoteRouter.js';
7
- import OtpRemoteRouter from './otp/OtpRemoteRouter.js';
8
- import WemapMultiRemoteRouter from './wemap-multi/WemapMultiRemoteRouter.js';
9
- import { RouterRequest } from '../model/RouterRequest.js';
10
- import { RemoteRoutingError } from '../RoutingError.js';
11
-
12
- const remoteRouters = [
13
- CitywayRemoteRouter,
14
- NavitiaRemoteRouter,
15
- DeutscheBahnRemoteRouter,
16
- IdfmRemoteRouter,
17
- OsrmRemoteRouter,
18
- OtpRemoteRouter,
19
- WemapMultiRemoteRouter
20
- ] as const;
21
-
22
- export type RemoteRouterName = typeof remoteRouters[number]['rname'];
23
-
24
- export type RoutingFallbackStrategy = { name: RemoteRouterName, endpointUrl: string }[];
25
-
26
- /**
27
- * Singleton
28
- */
29
- class RemoteRouterManager {
30
-
31
- getRouterByName(name: RemoteRouterName): RemoteRouter {
32
- return remoteRouters.find(remoteRouter => remoteRouter.rname === name) as RemoteRouter;
33
- }
34
-
35
- async getItineraries(name: RemoteRouterName, endpointUrl: string, routerRequest: RouterRequest) {
36
- const router = this.getRouterByName(name);
37
- if (!router) {
38
- throw RemoteRoutingError.notFound(name, `Unknown "${name}" remote router`);
39
- }
40
- return router.getItineraries(endpointUrl, routerRequest);
41
- }
42
-
43
- async getItinerariesWithFallback(routerRequest: RouterRequest, fallbackStrategy: RoutingFallbackStrategy) {
44
- let itineraries;
45
- const errors = [];
46
- for (const { name, endpointUrl } of fallbackStrategy) {
47
- try {
48
- itineraries = await this.getItineraries(name, endpointUrl, routerRequest);
49
- if (itineraries.length) {
50
- return itineraries;
51
- }
52
- } catch (error) {
53
- if (error instanceof RemoteRoutingError) {
54
- errors.push({
55
- name,
56
- endpointUrl,
57
- error
58
- });
59
- } else {
60
- throw error;
61
- }
62
- }
63
- }
64
-
65
- const routersNames = fallbackStrategy.map(({ name }) => name).join(', ');
66
- const errorsMessages = errors.map(routerError => `(${routerError.name}) Could not find an itinerary on endpoint: ${routerError.endpointUrl}. Details: ${routerError.error.message}`).join('\n');
67
-
68
- throw RemoteRoutingError.notFound(routersNames, errorsMessages)
69
- }
70
- }
71
-
72
- export default new RemoteRouterManager();
@@ -1,25 +0,0 @@
1
- import { RoutingError } from "../RoutingError";
2
-
3
- /**
4
- * Create and return a date with a given timezone
5
- * timeZone - timezone name (e.g. 'Europe/Paris')
6
- */
7
- export function dateWithTimeZone(
8
- year: number, month: number, day: number,
9
- hour: number, minute: number, second: number,
10
- timeZone = 'Europe/Paris'
11
- ) {
12
- const date = new Date(Date.UTC(year, month, day, hour, minute, second));
13
-
14
- const utcDate = new Date(date.toLocaleString('en-US', { timeZone: 'UTC' }));
15
- const tzDate = new Date(date.toLocaleString('en-US', { timeZone: timeZone }));
16
- const offset = utcDate.getTime() - tzDate.getTime();
17
-
18
- date.setTime(date.getTime() + offset);
19
-
20
- return date;
21
- }
22
-
23
- export function isRoutingError(e: unknown): e is Error {
24
- return e instanceof RoutingError;
25
- }