@wemap/routers 11.2.4 → 11.3.1
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/index.js +53 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -33
- package/dist/index.mjs.map +1 -1
- package/index.ts +1 -0
- package/package.json +4 -4
- package/src/model/LevelChange.spec.ts +1 -0
- package/src/model/LevelChange.ts +2 -1
- package/src/wemap-multi/CustomNetworkMap.ts +5 -5
- package/src/wemap-multi/WemapMultiRouter.ts +5 -8
- package/src/wemap-multi/WemapMultiRouterOptions.ts +2 -7
- package/src/wemap-osm/OsmRouter.ts +61 -33
- package/src/wemap-osm/OsmRouterOptions.ts +12 -0
package/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type { RoutingMode } from './src/model/RoutingMode.js';
|
|
|
12
12
|
/* Wemap Router */
|
|
13
13
|
export { default as OsmGraph, type OsmVertex, type OsmEdge, type OsmVertexData, type OsmEdgeData } from './src/wemap-osm/OsmGraph.js';
|
|
14
14
|
export { default as OsmRouter, type OsmItinerary } from './src/wemap-osm/OsmRouter.js';
|
|
15
|
+
export {type OsmRouterOptions } from './src/wemap-osm/OsmRouterOptions.js';
|
|
15
16
|
|
|
16
17
|
export { default as WemapMultiRouter } from './src/wemap-multi/WemapMultiRouter.js';
|
|
17
18
|
export { default as CustomNetworkMap } from './src/wemap-multi/CustomNetworkMap.js';
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/routers"
|
|
13
13
|
},
|
|
14
14
|
"name": "@wemap/routers",
|
|
15
|
-
"version": "11.
|
|
15
|
+
"version": "11.3.1",
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
18
18
|
},
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"@turf/convex": "^6.5.0",
|
|
35
35
|
"@turf/helpers": "^6.5.0",
|
|
36
36
|
"@types/mapbox__polyline": "^1.0.2",
|
|
37
|
-
"@wemap/geo": "^11.
|
|
37
|
+
"@wemap/geo": "^11.3.1",
|
|
38
38
|
"@wemap/logger": "^11.0.1",
|
|
39
39
|
"@wemap/maths": "^11.0.1",
|
|
40
|
-
"@wemap/osm": "^11.
|
|
40
|
+
"@wemap/osm": "^11.3.1",
|
|
41
41
|
"@wemap/salesman.js": "^2.1.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
},
|
|
53
53
|
"./helpers/*": "./helpers/*"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "d2e603fe3846cfb5b2944ca35c06e74bce6fd6d2"
|
|
56
56
|
}
|
package/src/model/LevelChange.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Position, MultiPolygon } from '@turf/helpers';
|
|
|
5
5
|
import { Coordinates, GeoGraphRouterOptions, Level, NoRouteFoundError } from '@wemap/geo';
|
|
6
6
|
import { OsmParser } from '@wemap/osm';
|
|
7
7
|
|
|
8
|
-
import OsmGraph, { OsmVertex } from '../wemap-osm/OsmGraph.js';
|
|
8
|
+
import OsmGraph, { OsmEdgeData, OsmVertex, OsmVertexData } from '../wemap-osm/OsmGraph.js';
|
|
9
9
|
import WemapOsmRouter from '../wemap-osm/OsmRouter.js';
|
|
10
10
|
|
|
11
11
|
class CustomNetworkMap {
|
|
@@ -129,7 +129,7 @@ class CustomNetworkMap {
|
|
|
129
129
|
* /!\ start is only used to sort the entry points (step 1).
|
|
130
130
|
*
|
|
131
131
|
*/
|
|
132
|
-
getBestItineraryFromEntryPointsToEnd(start: Coordinates, end: Coordinates, options: GeoGraphRouterOptions) {
|
|
132
|
+
getBestItineraryFromEntryPointsToEnd(start: Coordinates, end: Coordinates, options: GeoGraphRouterOptions<OsmVertexData, OsmEdgeData>) {
|
|
133
133
|
|
|
134
134
|
const sortedEntryPoints = this.getOrderedEntryPointsSortedByDistance(start, end);
|
|
135
135
|
for (const entryPoint of sortedEntryPoints) {
|
|
@@ -156,7 +156,7 @@ class CustomNetworkMap {
|
|
|
156
156
|
* /!\ end is only used to sort the entry points (step 1).
|
|
157
157
|
*
|
|
158
158
|
*/
|
|
159
|
-
getBestItineraryFromStartToEntryPoints(start: Coordinates, end: Coordinates, options: GeoGraphRouterOptions) {
|
|
159
|
+
getBestItineraryFromStartToEntryPoints(start: Coordinates, end: Coordinates, options: GeoGraphRouterOptions<OsmVertexData, OsmEdgeData>) {
|
|
160
160
|
|
|
161
161
|
const sortedEntryPoints = this.getOrderedEntryPointsSortedByDistance(start, end);
|
|
162
162
|
for (const entryPoint of sortedEntryPoints) {
|
|
@@ -171,12 +171,12 @@ class CustomNetworkMap {
|
|
|
171
171
|
);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
getItineraryInsideMap(start: Coordinates, end: Coordinates, options: GeoGraphRouterOptions) {
|
|
174
|
+
getItineraryInsideMap(start: Coordinates, end: Coordinates, options: GeoGraphRouterOptions<OsmVertexData, OsmEdgeData>) {
|
|
175
175
|
// Call the Wemap router to get the shortest path
|
|
176
176
|
return this.router.getItinerary(start, end, options);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
getTripInsideMap(waypoints: Coordinates[], options: GeoGraphRouterOptions) {
|
|
179
|
+
getTripInsideMap(waypoints: Coordinates[], options: GeoGraphRouterOptions<OsmVertexData, OsmEdgeData>) {
|
|
180
180
|
// Call the Wemap router to get the shortest trip itinerary
|
|
181
181
|
return this.router.getTripItinerary(waypoints, options);
|
|
182
182
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable complexity */
|
|
2
2
|
/* eslint-disable max-statements */
|
|
3
3
|
|
|
4
|
-
import { Coordinates, NoRouteFoundError
|
|
4
|
+
import { Coordinates, NoRouteFoundError } from '@wemap/geo';
|
|
5
5
|
import Logger from '@wemap/logger';
|
|
6
6
|
|
|
7
7
|
import CustomNetworkMap from './CustomNetworkMap.js';
|
|
@@ -9,7 +9,7 @@ import { WemapMultiRouterOptions } from './WemapMultiRouterOptions.js';
|
|
|
9
9
|
import RemoteRouterManager from '../remote/RemoteRouterManager.js';
|
|
10
10
|
import { isRoutingError } from '../remote/RemoteRouterUtils.js';
|
|
11
11
|
import RouterResponse from '../model/RouterResponse.js';
|
|
12
|
-
import WemapOsmRouter
|
|
12
|
+
import WemapOsmRouter from '../wemap-osm/OsmRouter.js';
|
|
13
13
|
import Itinerary from '../model/Itinerary.js';
|
|
14
14
|
import { RoutingMode } from '../model/RoutingMode.js';
|
|
15
15
|
import WemapMultiRemoteRouter from '../remote/wemap-multi/WemapMultiRemoteRouter.js';
|
|
@@ -57,14 +57,11 @@ class WemapMultiRouter {
|
|
|
57
57
|
return ioMapsToTest;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
private convertOptionsToWemapOsmOptions(options: WemapMultiRouterOptions | null) {
|
|
60
|
+
private convertOptionsToWemapOsmOptions(options: WemapMultiRouterOptions | null = null) {
|
|
61
61
|
// Create WemapOsmRouterOptions from WemapMultiRouterOptions
|
|
62
|
-
const outputOptions
|
|
63
|
-
= !options || !('useStairs' in options) || options.useStairs
|
|
64
|
-
? WemapOsmRouter.DEFAULT_OPTIONS
|
|
65
|
-
: WemapOsmRouter.WITHOUT_STAIRS_OPTIONS;
|
|
62
|
+
const outputOptions = WemapOsmRouter.buildOptions(options ? options : {});
|
|
66
63
|
|
|
67
|
-
if(typeof options?.tspTempCoeff !== 'undefined') {
|
|
64
|
+
if (typeof options?.tspTempCoeff !== 'undefined') {
|
|
68
65
|
(outputOptions as any).tspTempCoeff = options.tspTempCoeff;
|
|
69
66
|
}
|
|
70
67
|
return outputOptions;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { RemoteRouterName } from "../remote/RemoteRouterManager.js";
|
|
2
|
+
import { OsmRouterOptions } from "../wemap-osm/OsmRouterOptions.js";
|
|
2
3
|
|
|
3
|
-
export type WemapMultiRouterOptions = {
|
|
4
|
-
|
|
5
|
-
useStairs?: boolean;
|
|
4
|
+
export type WemapMultiRouterOptions = OsmRouterOptions & {
|
|
6
5
|
|
|
7
6
|
targetMaps?: string[] | null;
|
|
8
7
|
|
|
9
|
-
isTrip?: boolean;
|
|
10
|
-
|
|
11
|
-
tspTempCoeff?: number;
|
|
12
|
-
|
|
13
8
|
/**
|
|
14
9
|
* List of ordered remote routers (first of the list, first tested)
|
|
15
10
|
* Algorithm will try the first router and if it fails continue
|
|
@@ -11,39 +11,14 @@ import { getDurationFromLength } from '../Utils.js';
|
|
|
11
11
|
import OsmGraph, { OsmEdge, OsmEdgeData, OsmVertex, OsmVertexData } from './OsmGraph.js';
|
|
12
12
|
import Leg from '../model/Leg.js';
|
|
13
13
|
import { MinStepInfo } from '../model/Step.js';
|
|
14
|
+
import { OsmRouterOptions } from './OsmRouterOptions.js';
|
|
14
15
|
|
|
15
16
|
|
|
16
|
-
const DEFAULT_OPTIONS = Object.assign({}, GeoGraphRouter.DEFAULT_OPTIONS, {
|
|
17
|
-
weightEdgeFn: (edge: OsmEdge) => {
|
|
18
|
-
if (edge.data.isElevator) {
|
|
19
|
-
return 90;
|
|
20
|
-
}
|
|
21
|
-
let duration = getDurationFromLength(edge.length, 4);
|
|
22
|
-
if (edge.data instanceof OsmWay && edge.data.areStairs) {
|
|
23
|
-
duration *= 3;
|
|
24
|
-
}
|
|
25
|
-
return duration;
|
|
26
|
-
},
|
|
27
|
-
acceptEdgeFn: (edge: GeoGraphEdge) => {
|
|
28
|
-
const accessTag = (edge as OsmEdge).data.tags.access;
|
|
29
|
-
return typeof accessTag === 'undefined' || accessTag === 'yes';
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const WITHOUT_STAIRS_OPTIONS = Object.assign({}, DEFAULT_OPTIONS, {
|
|
34
|
-
acceptEdgeFn: (edge: GeoGraphEdge) => (edge as OsmEdge).data.tags.highway !== 'steps'
|
|
35
|
-
});
|
|
36
|
-
|
|
37
17
|
export type GeoGraphTripRouterOptions<VertexData = unknown, EdgeData = unknown> =
|
|
38
18
|
GeoGraphRouterOptions<VertexData, EdgeData> & {
|
|
39
19
|
tspTempCoeff?: number; // https://github.com/wemap/salesman.js/blob/master/salesman.js#L164
|
|
40
20
|
};
|
|
41
21
|
|
|
42
|
-
const DEFAULT_TRIP_OPTIONS = Object.assign({}, {
|
|
43
|
-
tspTempCoeff: 0.99
|
|
44
|
-
}, GeoGraphRouter.DEFAULT_OPTIONS);
|
|
45
|
-
|
|
46
|
-
|
|
47
22
|
const buildStepsRules = (graphItinerary: OsmItinerary): StepsGenerationRules => (
|
|
48
23
|
currentCoords: Coordinates,
|
|
49
24
|
nextCoords: Coordinates,
|
|
@@ -64,10 +39,14 @@ const buildStepsRules = (graphItinerary: OsmItinerary): StepsGenerationRules =>
|
|
|
64
39
|
let levelChangeType: LevelChangeType | null = null;
|
|
65
40
|
if (edge.data.isElevator) {
|
|
66
41
|
levelChangeType = 'elevator';
|
|
67
|
-
} else if (edge.data.isConveying) {
|
|
42
|
+
} else if (edge.data instanceof OsmWay && edge.data.isConveying && edge.data.areStairs) {
|
|
43
|
+
// TODO: change to escalator
|
|
68
44
|
levelChangeType = 'conveyor';
|
|
45
|
+
// levelChangeType = 'escalator';
|
|
69
46
|
} else if (edge.data instanceof OsmWay && edge.data.areStairs) {
|
|
70
47
|
levelChangeType = 'stairs';
|
|
48
|
+
} else if (edge.data instanceof OsmWay && edge.data.isConveying) {
|
|
49
|
+
levelChangeType = 'moving walkway';
|
|
71
50
|
}
|
|
72
51
|
|
|
73
52
|
// Handle stairs/elevator/conveyors without change in level coordinates
|
|
@@ -124,8 +103,9 @@ export class OsmItinerary extends GeoGraphItinerary<OsmVertexData, OsmEdgeData>
|
|
|
124
103
|
|
|
125
104
|
class WemapOsmRouter extends GeoGraphRouter<OsmVertexData, OsmEdgeData> {
|
|
126
105
|
|
|
127
|
-
static DEFAULT_OPTIONS =
|
|
128
|
-
static WITHOUT_STAIRS_OPTIONS =
|
|
106
|
+
static DEFAULT_OPTIONS = WemapOsmRouter.buildOptions();
|
|
107
|
+
static WITHOUT_STAIRS_OPTIONS = WemapOsmRouter.buildOptions({ useStairs: false });
|
|
108
|
+
static DEFAULT_TRIP_OPTIONS = WemapOsmRouter.buildTripOptions();
|
|
129
109
|
|
|
130
110
|
constructor(graph: OsmGraph) {
|
|
131
111
|
super(graph);
|
|
@@ -138,7 +118,7 @@ class WemapOsmRouter extends GeoGraphRouter<OsmVertexData, OsmEdgeData> {
|
|
|
138
118
|
getShortestPath(
|
|
139
119
|
start: OsmVertex | Coordinates,
|
|
140
120
|
end: OsmVertex | Coordinates,
|
|
141
|
-
options: GeoGraphRouterOptions<OsmVertexData, OsmEdgeData> = DEFAULT_OPTIONS
|
|
121
|
+
options: GeoGraphRouterOptions<OsmVertexData, OsmEdgeData> = WemapOsmRouter.DEFAULT_OPTIONS
|
|
142
122
|
) {
|
|
143
123
|
return super.getShortestPath(start, end, options) as OsmItinerary;
|
|
144
124
|
}
|
|
@@ -146,7 +126,7 @@ class WemapOsmRouter extends GeoGraphRouter<OsmVertexData, OsmEdgeData> {
|
|
|
146
126
|
getItinerary(
|
|
147
127
|
start: OsmVertex | Coordinates,
|
|
148
128
|
end: OsmVertex | Coordinates,
|
|
149
|
-
options: GeoGraphRouterOptions<OsmVertexData, OsmEdgeData> = DEFAULT_OPTIONS
|
|
129
|
+
options: GeoGraphRouterOptions<OsmVertexData, OsmEdgeData> = WemapOsmRouter.DEFAULT_OPTIONS
|
|
150
130
|
) {
|
|
151
131
|
const graphItinerary = this.getShortestPath(start, end, options);
|
|
152
132
|
|
|
@@ -177,7 +157,7 @@ class WemapOsmRouter extends GeoGraphRouter<OsmVertexData, OsmEdgeData> {
|
|
|
177
157
|
|
|
178
158
|
getShortestTrip(
|
|
179
159
|
waypoints: Coordinates[],
|
|
180
|
-
options: GeoGraphTripRouterOptions<OsmVertexData, OsmEdgeData> = DEFAULT_TRIP_OPTIONS
|
|
160
|
+
options: GeoGraphTripRouterOptions<OsmVertexData, OsmEdgeData> = WemapOsmRouter.DEFAULT_TRIP_OPTIONS
|
|
181
161
|
) {
|
|
182
162
|
type CustomPoint = salesman.Point & { coords: Coordinates };
|
|
183
163
|
|
|
@@ -221,7 +201,7 @@ class WemapOsmRouter extends GeoGraphRouter<OsmVertexData, OsmEdgeData> {
|
|
|
221
201
|
|
|
222
202
|
getTripItinerary(
|
|
223
203
|
waypoints: Coordinates[],
|
|
224
|
-
options: GeoGraphTripRouterOptions<OsmVertexData, OsmEdgeData> = DEFAULT_TRIP_OPTIONS
|
|
204
|
+
options: GeoGraphTripRouterOptions<OsmVertexData, OsmEdgeData> = WemapOsmRouter.DEFAULT_TRIP_OPTIONS
|
|
225
205
|
) {
|
|
226
206
|
const shortestTrip = this.getShortestTrip(waypoints, options);
|
|
227
207
|
return new Itinerary({
|
|
@@ -230,6 +210,54 @@ class WemapOsmRouter extends GeoGraphRouter<OsmVertexData, OsmEdgeData> {
|
|
|
230
210
|
legs: shortestTrip.map(graphItinerary => Leg.fromGraphItinerary(graphItinerary))
|
|
231
211
|
});
|
|
232
212
|
}
|
|
213
|
+
|
|
214
|
+
static buildOptions(options?: OsmRouterOptions): GeoGraphRouterOptions<OsmVertexData, OsmEdgeData> {
|
|
215
|
+
|
|
216
|
+
const weightEdgeFn = (edge: GeoGraphEdge<OsmVertexData, OsmEdgeData>) => {
|
|
217
|
+
if (edge.data?.isElevator) {
|
|
218
|
+
return 90;
|
|
219
|
+
}
|
|
220
|
+
let duration = getDurationFromLength(edge.length, 4);
|
|
221
|
+
if (edge.data instanceof OsmWay && edge.data.areStairs) {
|
|
222
|
+
duration *= 3;
|
|
223
|
+
}
|
|
224
|
+
return duration;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const acceptEdgeFn = (edge: GeoGraphEdge<OsmVertexData, OsmEdgeData>) => {
|
|
228
|
+
|
|
229
|
+
// Verify access
|
|
230
|
+
const accessTag = edge.data?.tags?.access;
|
|
231
|
+
if (typeof accessTag !== 'undefined' && accessTag !== 'yes') return false;
|
|
232
|
+
|
|
233
|
+
// Verify stairs
|
|
234
|
+
if (typeof options?.useStairs !== 'undefined' && !options?.useStairs
|
|
235
|
+
&& edge.data instanceof OsmWay && edge.data.areStairs && !edge.data.isConveying) return false;
|
|
236
|
+
|
|
237
|
+
// Verify escalators
|
|
238
|
+
if (typeof options?.useEscalator !== 'undefined' && !options?.useEscalator
|
|
239
|
+
&& edge.data instanceof OsmWay && edge.data.areStairs && edge.data.isConveying) return false;
|
|
240
|
+
|
|
241
|
+
// Verify elevator
|
|
242
|
+
if (typeof options?.useElevator !== 'undefined' && !options?.useElevator && edge.data?.isElevator) return false;
|
|
243
|
+
|
|
244
|
+
return true;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
weightEdgeFn,
|
|
249
|
+
acceptEdgeFn,
|
|
250
|
+
projectionMaxDistance: GeoGraphRouter.DEFAULT_OPTIONS.projectionMaxDistance
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
static buildTripOptions(options?: OsmRouterOptions): GeoGraphTripRouterOptions<OsmVertexData, OsmEdgeData> {
|
|
255
|
+
return Object.assign({},
|
|
256
|
+
WemapOsmRouter.buildOptions(options),
|
|
257
|
+
{ tspTempCoeff: 0.99 }
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
233
261
|
}
|
|
234
262
|
|
|
235
263
|
export default WemapOsmRouter;
|