@wemap/routers 13.2.3 → 14.2.0

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 (113) hide show
  1. package/README.md +2 -0
  2. package/dist/index.d.ts +45 -37
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +9924 -11
  5. package/dist/src/ItineraryInfoManager.d.ts +14 -14
  6. package/dist/src/ItineraryInfoManager.d.ts.map +1 -0
  7. package/dist/src/RoutingError.d.ts +7 -7
  8. package/dist/src/RoutingError.d.ts.map +1 -0
  9. package/dist/src/StatusCode.d.ts +13 -11
  10. package/dist/src/StatusCode.d.ts.map +1 -0
  11. package/dist/src/Utils.d.ts +1 -0
  12. package/dist/src/Utils.d.ts.map +1 -0
  13. package/dist/src/graph/Edge.d.ts +7 -12
  14. package/dist/src/graph/Edge.d.ts.map +1 -0
  15. package/dist/src/graph/Graph.d.ts +12 -11
  16. package/dist/src/graph/Graph.d.ts.map +1 -0
  17. package/dist/src/graph/GraphProjection.d.ts +4 -3
  18. package/dist/src/graph/GraphProjection.d.ts.map +1 -0
  19. package/dist/src/graph/{GraphProjectionOptions.d.ts → GraphProjectionRules.d.ts} +2 -1
  20. package/dist/src/graph/GraphProjectionRules.d.ts.map +1 -0
  21. package/dist/src/graph/GraphRoute.d.ts +4 -3
  22. package/dist/src/graph/GraphRoute.d.ts.map +1 -0
  23. package/dist/src/graph/GraphRouter.d.ts +9 -8
  24. package/dist/src/graph/GraphRouter.d.ts.map +1 -0
  25. package/dist/src/graph/GraphRouterEngine.d.ts +19 -26
  26. package/dist/src/graph/GraphRouterEngine.d.ts.map +1 -0
  27. package/dist/src/graph/GraphRouterRules.d.ts +32 -0
  28. package/dist/src/graph/GraphRouterRules.d.ts.map +1 -0
  29. package/dist/src/graph/GraphRouterRulesBuilder.d.ts +19 -0
  30. package/dist/src/graph/GraphRouterRulesBuilder.d.ts.map +1 -0
  31. package/dist/src/graph/GraphRouterRulesMerger.d.ts +4 -0
  32. package/dist/src/graph/GraphRouterRulesMerger.d.ts.map +1 -0
  33. package/dist/src/graph/GraphRouterRulesTyping.d.ts +26 -0
  34. package/dist/src/graph/GraphRouterRulesTyping.d.ts.map +1 -0
  35. package/dist/src/graph/NoRouteFoundError.d.ts +3 -2
  36. package/dist/src/graph/NoRouteFoundError.d.ts.map +1 -0
  37. package/dist/src/graph/Vertex.d.ts +6 -8
  38. package/dist/src/graph/Vertex.d.ts.map +1 -0
  39. package/dist/src/import/geojson/GeoJsonGraphUtils.d.ts +5 -4
  40. package/dist/src/import/geojson/GeoJsonGraphUtils.d.ts.map +1 -0
  41. package/dist/src/import/geojson/GeoJsonUtils.d.ts +1 -0
  42. package/dist/src/import/geojson/GeoJsonUtils.d.ts.map +1 -0
  43. package/dist/src/import/osm/OsmGraphUtils.d.ts +5 -4
  44. package/dist/src/import/osm/OsmGraphUtils.d.ts.map +1 -0
  45. package/dist/src/model/Itinerary.d.ts +8 -7
  46. package/dist/src/model/Itinerary.d.ts.map +1 -0
  47. package/dist/src/model/Leg.d.ts +6 -5
  48. package/dist/src/model/Leg.d.ts.map +1 -0
  49. package/dist/src/model/RouterRequest.d.ts +18 -19
  50. package/dist/src/model/RouterRequest.d.ts.map +1 -0
  51. package/dist/src/model/Step.d.ts +2 -1
  52. package/dist/src/model/Step.d.ts.map +1 -0
  53. package/dist/src/model/StepExtra.d.ts +1 -0
  54. package/dist/src/model/StepExtra.d.ts.map +1 -0
  55. package/dist/src/model/StepsBuilder.d.ts +4 -3
  56. package/dist/src/model/StepsBuilder.d.ts.map +1 -0
  57. package/dist/src/model/TransitMode.d.ts +1 -0
  58. package/dist/src/model/TransitMode.d.ts.map +1 -0
  59. package/dist/src/model/TravelMode.d.ts +1 -0
  60. package/dist/src/model/TravelMode.d.ts.map +1 -0
  61. package/dist/src/model/generateSteps.d.ts +2 -0
  62. package/dist/src/model/generateSteps.d.ts.map +1 -0
  63. package/dist/src/remote/RemoteRouter.d.ts +3 -2
  64. package/dist/src/remote/RemoteRouter.d.ts.map +1 -0
  65. package/dist/src/remote/RemoteRouterManager.d.ts +120 -119
  66. package/dist/src/remote/RemoteRouterManager.d.ts.map +1 -0
  67. package/dist/src/remote/RemoteRouterUtils.d.ts +1 -0
  68. package/dist/src/remote/RemoteRouterUtils.d.ts.map +1 -0
  69. package/dist/src/remote/cityway/CitywayRemoteRouter.d.ts +4 -3
  70. package/dist/src/remote/cityway/CitywayRemoteRouter.d.ts.map +1 -0
  71. package/dist/src/remote/deutsche-bahn/DeutscheBahnRemoteRouter.d.ts +5 -4
  72. package/dist/src/remote/deutsche-bahn/DeutscheBahnRemoteRouter.d.ts.map +1 -0
  73. package/dist/src/remote/geovelo/GeoveloRemoteRouter.d.ts +4 -3
  74. package/dist/src/remote/geovelo/GeoveloRemoteRouter.d.ts.map +1 -0
  75. package/dist/src/remote/idfm/IdfmRemoteRouter.d.ts +5 -4
  76. package/dist/src/remote/idfm/IdfmRemoteRouter.d.ts.map +1 -0
  77. package/dist/src/remote/navitia/NavitiaRemoteRouter.d.ts +5 -4
  78. package/dist/src/remote/navitia/NavitiaRemoteRouter.d.ts.map +1 -0
  79. package/dist/src/remote/navitia/types.d.ts +1 -0
  80. package/dist/src/remote/navitia/types.d.ts.map +1 -0
  81. package/dist/src/remote/osrm/OsrmRemoteRouter.d.ts +7 -6
  82. package/dist/src/remote/osrm/OsrmRemoteRouter.d.ts.map +1 -0
  83. package/dist/src/remote/otp/OtpRemoteRouter.d.ts +4 -3
  84. package/dist/src/remote/otp/OtpRemoteRouter.d.ts.map +1 -0
  85. package/dist/src/remote/tictactrip/TictactripRemoteRouter.d.ts +6 -5
  86. package/dist/src/remote/tictactrip/TictactripRemoteRouter.d.ts.map +1 -0
  87. package/dist/src/remote/tictactrip/type.d.ts +1 -0
  88. package/dist/src/remote/tictactrip/type.d.ts.map +1 -0
  89. package/dist/src/remote/wemap-multi/WemapMultiRemoteRouter.d.ts +5 -4
  90. package/dist/src/remote/wemap-multi/WemapMultiRemoteRouter.d.ts.map +1 -0
  91. package/dist/src/types.d.ts +4 -3
  92. package/dist/src/types.d.ts.map +1 -0
  93. package/dist/src/wemap-multi/CustomGraphMap.d.ts +16 -13
  94. package/dist/src/wemap-multi/CustomGraphMap.d.ts.map +1 -0
  95. package/dist/src/wemap-multi/CustomGraphMapTester.d.ts +4 -3
  96. package/dist/src/wemap-multi/CustomGraphMapTester.d.ts.map +1 -0
  97. package/dist/src/wemap-multi/WemapMultiRouter.d.ts +5 -4
  98. package/dist/src/wemap-multi/WemapMultiRouter.d.ts.map +1 -0
  99. package/dist/tests/CommonTest.d.ts +4 -3
  100. package/dist/tests/CommonTest.d.ts.map +1 -0
  101. package/dist/vitest.config.d.ts +3 -0
  102. package/dist/vitest.config.d.ts.map +1 -0
  103. package/package.json +39 -64
  104. package/dist/helpers/InstructionManager.d.ts +0 -19
  105. package/dist/helpers/InstructionManagerV1.d.ts +0 -6
  106. package/dist/index.js.map +0 -1
  107. package/dist/index.mjs +0 -14184
  108. package/dist/index.mjs.map +0 -1
  109. package/dist/src/graph/GraphRouterOptions.d.ts +0 -19
  110. package/dist/src/graph/GraphRouterOptionsBuilder.d.ts +0 -23
  111. package/dist/src/graph/GraphRouterOptionsFactors.d.ts +0 -8
  112. package/helpers/InstructionManager.ts +0 -184
  113. package/helpers/InstructionManagerV1.ts +0 -93
@@ -1,19 +0,0 @@
1
- import { default as Edge } from './Edge.js';
2
- import { default as Vertex } from './Vertex.js';
3
- export type GraphRouterOptions = {
4
- input: GraphRouterOptionsJson;
5
- projectionMaxDistance?: number;
6
- weightEdgeFn?: (edge: Edge) => number;
7
- weightVertexFn?: (vertex: Vertex) => number;
8
- acceptEdgeFn?: (edge: Edge) => boolean;
9
- useMultiLevelSegments?: boolean;
10
- };
11
- export type GraphRouterOptionsJson = {
12
- avoidStairs?: boolean;
13
- avoidEscalators?: boolean;
14
- avoidElevators?: boolean;
15
- avoidMovingWalkways?: boolean;
16
- avoidTicketRestrictedAreas?: boolean;
17
- isWheelchair?: boolean;
18
- projectionMaxDistance?: number;
19
- };
@@ -1,23 +0,0 @@
1
- import { GraphRouterOptionsJson, GraphRouterOptions } from './GraphRouterOptions.js';
2
- export default class GraphRouterOptionsBuilder {
3
- avoidStairs: boolean;
4
- avoidEscalators: boolean;
5
- avoidElevators: boolean;
6
- avoidMovingWalkways: boolean;
7
- avoidTicketRestrictedAreas: boolean;
8
- useMultiLevelSegments: boolean;
9
- projectionMaxDistance?: number;
10
- isWheelchair: boolean;
11
- static DEFAULT: GraphRouterOptions;
12
- static WITHOUT_STAIRS: GraphRouterOptions;
13
- static WHEELCHAIR: GraphRouterOptions;
14
- setAvoidStairs(avoidStairs: boolean): this;
15
- setAvoidEscalators(avoidEscalators: boolean): this;
16
- setAvoidElevators(avoidElevators: boolean): this;
17
- setAvoidMovingWalkways(avoidMovingWalkways: boolean): this;
18
- setAvoidTicketRestrictedAreas(avoidTicketRestrictedAreas: boolean): this;
19
- setUseMultiLevelSegments(useMultiLevelSegments: boolean): this;
20
- setIsWheelchair(isWheelchair: boolean): this;
21
- static fromJson(options: GraphRouterOptionsJson): GraphRouterOptions;
22
- build(): GraphRouterOptions;
23
- }
@@ -1,8 +0,0 @@
1
- import { EdgeSmoothness, EdgeSurface } from './Edge.js';
2
- export type ProfileType = 'wheelchair' | 'default';
3
- export declare const SPEEDS: {
4
- readonly DEFAULT: 4;
5
- readonly WHEELCHAIR: 3;
6
- };
7
- export declare const SMOOTHNESS_FACTORS: Record<ProfileType, Record<EdgeSmoothness, number>>;
8
- export declare const SURFACE_FACTORS: Record<ProfileType, Record<EdgeSurface, number>>;
@@ -1,184 +0,0 @@
1
- import { Coordinates } from '@wemap/geo';
2
- import { diffAngle, rad2deg, roundFactor } from '@wemap/maths';
3
- import { ItineraryInfoManager, Step, isStepLevelChange } from '@wemap/routers';
4
-
5
- export default class InstructionManager {
6
-
7
- static useProposals = false;
8
-
9
- static getTurnInfoFromAngle(_angle: number) {
10
-
11
- let direction, directionExtra;
12
-
13
- const directionAngle = rad2deg(diffAngle(_angle, Math.PI));
14
- const directionAngleAbs = Math.abs(directionAngle);
15
- if (directionAngleAbs <= 20) {
16
- direction = 'straight';
17
- } else {
18
- direction = directionAngle > 0 ? 'left' : 'right';
19
- if (directionAngleAbs < 55) {
20
- directionExtra = 'slight';
21
- } else if (directionAngleAbs > 120) {
22
- directionExtra = 'sharp';
23
- }
24
- }
25
-
26
- return { direction, directionExtra };
27
- }
28
-
29
- static getInfoFromStep(step: Step) {
30
-
31
- let type, direction, directionExtra, levelChange;
32
-
33
- if (isStepLevelChange(step)) {
34
- type = 'level-change';
35
- levelChange = step.levelDifference;
36
- } else {
37
- type = 'turn';
38
- const turnInfo = InstructionManager.getTurnInfoFromAngle(step.angle);
39
- direction = turnInfo.direction;
40
- directionExtra = turnInfo.directionExtra;
41
- }
42
-
43
- return {
44
- type,
45
- direction,
46
- directionExtra,
47
- levelChange,
48
- name: step.name,
49
- indoor: step.coords.level !== null
50
- };
51
- }
52
-
53
- // eslint-disable-next-line max-statements, complexity
54
- static getInstructionFromStep(step: Step) {
55
-
56
- const { direction, directionExtra } = InstructionManager.getTurnInfoFromAngle(step.angle);
57
- const isTurn = direction !== 'straight';
58
-
59
- if (step.lastStep) {
60
- if (isTurn && direction === 'left') {
61
- return 'Your destination is on your left';
62
- } else if (isTurn && direction === 'right') {
63
- return 'Your destination is on your right';
64
- }
65
- }
66
-
67
- let suffix = '';
68
- if (step.type === 'gate') {
69
- suffix = ` on gate ${step.name}`;
70
- } else if (step.name) {
71
- suffix = ` on ${step.name}`;
72
- }
73
-
74
- if (isStepLevelChange(step)) {
75
- if (step.direction === 'up') {
76
- if (step.type === 'stairs') {
77
- return 'Go up the stairs';
78
- }
79
- if (step.type === 'escalator') {
80
- return 'Go up the escalator';
81
- }
82
- if (step.type === 'elevator') {
83
- return 'Go up the elevator';
84
- }
85
- if (step.type === 'moving-walkway') {
86
- return 'Go up the moving walkway';
87
- }
88
- if (step.type === 'incline-plane') {
89
- return 'Go up the incline plane';
90
- }
91
- return 'Go up' + suffix;
92
- }
93
- if (step.direction === 'down') {
94
- if (step.type === 'stairs') {
95
- return 'Go down the stairs';
96
- }
97
- if (step.type === 'escalator') {
98
- return 'Go down the escalator';
99
- }
100
- if (step.type === 'elevator') {
101
- return 'Go down the elevator';
102
- }
103
- if (step.type === 'moving-walkway') {
104
- return 'Go down the moving walkway';
105
- }
106
- if (step.type === 'incline-plane') {
107
- return 'Go down the incline plane';
108
- }
109
- return 'Go down' + suffix;
110
- }
111
- }
112
-
113
- if (step.type === 'subway-entrance') {
114
- return `Take exit ${step.name}`;
115
- }
116
-
117
- if (isTurn) {
118
- if (direction === 'left') {
119
- if (directionExtra === 'slight') {
120
- return 'Turn slightly left' + suffix;
121
- }
122
- return 'Turn left' + suffix;
123
- }
124
- if (direction === 'right') {
125
- if (directionExtra === 'slight') {
126
- return 'Turn slightly right' + suffix;
127
- }
128
- return 'Turn right' + suffix;
129
- }
130
- }
131
-
132
- return 'Continue straight';
133
- }
134
-
135
-
136
-
137
- static getInstructionFromPosition(itineraryInfoManager: ItineraryInfoManager, position: Coordinates) {
138
- const itineraryInfo = itineraryInfoManager.getInfo(position);
139
- if (!itineraryInfo) {
140
- return null;
141
- }
142
-
143
- // If distance between itinerary and position is too far,
144
- // something went wrong. (mapmatching.maxDistance)
145
- if (this.useProposals && itineraryInfo.projection.distanceFromNearestElement > 15) {
146
- return 'It seems that we are a little bit lost, please start again the localization process';
147
- }
148
-
149
- const { nextStep } = itineraryInfo;
150
- if (!nextStep) {
151
- return 'You are arrived';
152
- }
153
-
154
- const distNextStep = position.distanceTo(nextStep.coords);
155
- const distRounded = roundFactor(distNextStep, 5);
156
-
157
- if (this.useProposals && distNextStep > 10) {
158
- return `Continue straight for ${distRounded}m`;
159
- }
160
-
161
-
162
- let instruction = InstructionManager.getInstructionFromStep(nextStep);
163
-
164
- const stepWithImportantInfo = itineraryInfoManager._steps.find(step => isStepLevelChange(step)
165
- && step.number > nextStep.number
166
- && step.coords.distanceTo(nextStep.coords) < 10
167
- ) || null;
168
-
169
- if (stepWithImportantInfo && isStepLevelChange(stepWithImportantInfo)) {
170
- const nextBearing = nextStep.coords.bearingTo(stepWithImportantInfo.coords);
171
- const { direction } = InstructionManager.getTurnInfoFromAngle(nextBearing - nextStep.previousBearing);
172
- instruction = direction === 'straight' ? 'Continue straight' : `Turn ${direction}`;
173
- const { direction: levelDirection, type: levelType } = stepWithImportantInfo;
174
- instruction += ` and take the ${levelType} going ${levelDirection}`;
175
- }
176
-
177
- if (distNextStep >= 5) {
178
- instruction += ` in ${distRounded}m`;
179
- }
180
-
181
- return instruction;
182
- }
183
-
184
- }
@@ -1,93 +0,0 @@
1
- import { Coordinates } from '@wemap/geo';
2
- import { ItineraryInfoManager, Step, OsrmRemoteRouter } from '@wemap/routers';
3
-
4
- export default class InstructionManagerV1 {
5
-
6
- // eslint-disable-next-line max-statements, complexity
7
- static getInstructionFromStep(step: Step) {
8
-
9
- const modifier = OsrmRemoteRouter.getModifierFromAngle(step.angle);
10
- let direction, directionExtra;
11
- if (modifier.includes('left')) {
12
- direction = 'left';
13
- } else if (modifier.includes('right')) {
14
- direction = 'right';
15
- }
16
- if (modifier.includes('slight')) {
17
- directionExtra = 'slight';
18
- }
19
- const isTurn = modifier !== 'straight';
20
-
21
- if (step.lastStep) {
22
- if (isTurn && direction === 'left') {
23
- return 'Your destination is on your left';
24
- } else if (isTurn && direction === 'right') {
25
- return 'Your destination is on your right';
26
- }
27
- }
28
-
29
- const suffix = step.name ? ` on ${step.name}` : '';
30
-
31
- if (step.levelChange) {
32
- if (step.levelChange.direction === 'up') {
33
- if (step.levelChange.type === 'escalator') {
34
- return 'Go up the escalator';
35
- }
36
- if (step.levelChange.type === 'stairs') {
37
- return 'Go up the stairs';
38
- }
39
- return 'Go up' + suffix;
40
- }
41
- if (step.levelChange.direction === 'down') {
42
- if (step.levelChange.type === 'escalator') {
43
- return 'Go down the escalator';
44
- }
45
- if (step.levelChange.type === 'stairs') {
46
- return 'Go down the stairs';
47
- }
48
- return 'Go down' + suffix;
49
- }
50
- if (step.extras?.subwayEntrance) {
51
- return `Take exit ${step.extras.subwayEntranceRef}`;
52
- }
53
- }
54
-
55
- if (isTurn) {
56
- if (direction === 'left') {
57
- if (directionExtra === 'slight') {
58
- return 'Turn slightly left' + suffix;
59
- }
60
- return 'Turn left' + suffix;
61
- }
62
- if (direction === 'right') {
63
- if (directionExtra === 'slight') {
64
- return 'Turn slightly right' + suffix;
65
- }
66
- return 'Turn right' + suffix;
67
- }
68
- }
69
-
70
-
71
- return '';
72
- }
73
-
74
- static getInstructionFromPosition(itineraryInfoManager: ItineraryInfoManager, position: Coordinates) {
75
- const itineraryInfo = itineraryInfoManager.getInfo(position);
76
- if (!itineraryInfo) {
77
- return null;
78
- }
79
-
80
- const { nextStep } = itineraryInfo;
81
- if (!nextStep) {
82
- return null;
83
- }
84
-
85
- const distNextStep = position.distanceTo(nextStep.coords);
86
- const nextStep2 = itineraryInfoManager._steps.find(step => step.number > nextStep.number);
87
- if (distNextStep < 3 && nextStep2) {
88
- return InstructionManagerV1.getInstructionFromStep(nextStep2);
89
- }
90
-
91
- return InstructionManagerV1.getInstructionFromStep(nextStep);
92
- }
93
- }