@wemap/routers 11.0.0-alpha.0 → 11.0.0-alpha.10
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/package.json +14 -8
- package/src/ItineraryInfoManager.ts +2 -2
- package/src/model/Itinerary.spec.ts +9 -6
- package/src/model/Itinerary.ts +2 -7
- package/src/model/Leg.spec.ts +4 -4
- package/src/model/Leg.ts +11 -2
- package/src/model/Step.ts +0 -4
- package/src/remote/cityway/CitywayRemoteRouter.ts +2 -1
- package/src/remote/idfm/IdfmRemoteRouter.ts +2 -2
- package/src/wemap-multi/CustomNetworkMap.ts +7 -7
- package/src/wemap-osm/WemapOsmRouter.spec.ts +9 -9
- package/src/wemap-osm/WemapOsmRouter.ts +12 -12
- package/src/wemap-osm/WemapOsmRouterOptions.ts +5 -5
- package/dist/index.js +0 -5908
- package/dist/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"Thibaud Michel <thibaud@getwemap.com>"
|
|
5
5
|
],
|
|
6
6
|
"description": "Wemap Routers utils package",
|
|
7
|
-
"
|
|
7
|
+
"main": "dist/index.js",
|
|
8
8
|
"types": "index.ts",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/routers"
|
|
13
13
|
},
|
|
14
14
|
"name": "@wemap/routers",
|
|
15
|
-
"version": "11.0.0-alpha.
|
|
15
|
+
"version": "11.0.0-alpha.10",
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
18
18
|
},
|
|
@@ -33,16 +33,22 @@
|
|
|
33
33
|
"@turf/boolean-point-in-polygon": "^6.5.0",
|
|
34
34
|
"@turf/convex": "^6.5.0",
|
|
35
35
|
"@turf/helpers": "^6.5.0",
|
|
36
|
-
"@
|
|
37
|
-
"@wemap/
|
|
38
|
-
"@wemap/
|
|
39
|
-
"@wemap/
|
|
36
|
+
"@types/mapbox__polyline": "^1.0.2",
|
|
37
|
+
"@wemap/geo": "^11.0.0-alpha.10",
|
|
38
|
+
"@wemap/logger": "^11.0.0-alpha.4",
|
|
39
|
+
"@wemap/maths": "^11.0.0-alpha.10",
|
|
40
|
+
"@wemap/osm": "^11.0.0-alpha.10"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@types/fetch-mock": "^7.3.5",
|
|
43
|
-
"@types/mapbox__polyline": "^1.0.2",
|
|
44
44
|
"fetch-mock": "^9.11.0",
|
|
45
45
|
"geojson": "^0.5.0"
|
|
46
46
|
},
|
|
47
|
-
"
|
|
47
|
+
"exports": {
|
|
48
|
+
".": {
|
|
49
|
+
"import": "./dist/index.mjs",
|
|
50
|
+
"require": "./dist/index.js"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "ae6bf2f3ae6e6e49242a03c38b4295f77d5b3ba4"
|
|
48
54
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Coordinates, GraphEdge, GraphNode, GraphProjection, MapMatching
|
|
1
|
+
import { Coordinates, GraphEdge, GraphNode, GraphProjection, MapMatching } from '@wemap/geo';
|
|
2
2
|
|
|
3
3
|
import Itinerary from './model/Itinerary.js';
|
|
4
4
|
import Leg from './model/Leg.js';
|
|
@@ -7,7 +7,7 @@ import { Step } from './model/Step.js';
|
|
|
7
7
|
export type ItineraryInfo<U extends Coordinates = Coordinates> = {
|
|
8
8
|
nextStep: Step | null;
|
|
9
9
|
previousStep: Step | null;
|
|
10
|
-
projection: GraphProjection<unknown, U>;
|
|
10
|
+
projection: GraphProjection<unknown, unknown, U>;
|
|
11
11
|
leg: Leg;
|
|
12
12
|
traveledDistance: number;
|
|
13
13
|
remainingDistance: number;
|
|
@@ -68,11 +68,14 @@ export const verifyStepsCoherence = (itinerary: Itinerary) => {
|
|
|
68
68
|
expect(step.previousBearing).equals(coordsBeforeStep.bearingTo(step.coords));
|
|
69
69
|
expect(step.nextBearing).equals(step.coords.bearingTo(coordsAfterStep));
|
|
70
70
|
expect(step.angle).almost.equals(diffAngle(step.previousBearing, step.nextBearing + Math.PI));
|
|
71
|
-
expect(step.previousStep).equals(stepId !== 0 ? steps[stepId - 1] : null);
|
|
72
|
-
expect(step.nextStep).equals(stepId !== steps.length - 1 ? steps[stepId + 1] : null);
|
|
73
71
|
expect(step.firstStep).equals(stepId === 0);
|
|
74
72
|
expect(step.lastStep).equals(stepId === steps.length - 1);
|
|
75
73
|
});
|
|
74
|
+
itinerary.legs.forEach(leg => {
|
|
75
|
+
const legSteps = leg.getSteps(steps);
|
|
76
|
+
expect(legSteps.length).not.equals(0);
|
|
77
|
+
legSteps.forEach(step => expect(step).is.not.undefined);
|
|
78
|
+
});
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
describe('Itinerary', () => {
|
|
@@ -89,11 +92,11 @@ describe('Itinerary', () => {
|
|
|
89
92
|
});
|
|
90
93
|
|
|
91
94
|
it('steps coherence', () => {
|
|
92
|
-
|
|
95
|
+
verifyStepsCoherence(itinerary1);
|
|
93
96
|
verifyStepsCoherence(itinerary2);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
verifyStepsCoherence(itinerary3);
|
|
98
|
+
verifyStepsCoherence(itinerary4);
|
|
99
|
+
verifyStepsCoherence(itinerary5);
|
|
97
100
|
});
|
|
98
101
|
|
|
99
102
|
it('from / to JSON', () => {
|
package/src/model/Itinerary.ts
CHANGED
|
@@ -143,11 +143,6 @@ export default class Itinerary {
|
|
|
143
143
|
}
|
|
144
144
|
});
|
|
145
145
|
|
|
146
|
-
for (let i = 0; i < steps.length; i++) {
|
|
147
|
-
steps[i].previousStep = i !== 0 ? steps[i - 1] : null;
|
|
148
|
-
steps[i].nextStep = i !== steps.length - 1 ? steps[i + 1] : null;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
146
|
return steps;
|
|
152
147
|
}
|
|
153
148
|
|
|
@@ -196,8 +191,8 @@ export default class Itinerary {
|
|
|
196
191
|
// return this.legs.reduce((dist, leg) => dist + leg.distance, 0);
|
|
197
192
|
}
|
|
198
193
|
|
|
199
|
-
toNetwork<
|
|
200
|
-
return Network.fromCoordinates<
|
|
194
|
+
toNetwork<N = unknown, E = unknown>() {
|
|
195
|
+
return Network.fromCoordinates<N, E>([this.coords]);
|
|
201
196
|
}
|
|
202
197
|
|
|
203
198
|
static fromItineraries(...itineraries: Itinerary[]) {
|
package/src/model/Leg.spec.ts
CHANGED
|
@@ -40,18 +40,18 @@ const leg3 = new Leg({
|
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
const leg4 = new Leg({
|
|
43
|
-
from: { coords: new Coordinates(
|
|
43
|
+
from: { coords: new Coordinates(0, 0) },
|
|
44
44
|
to: { coords: new Coordinates(4, 0) },
|
|
45
|
-
coords: [new Coordinates(
|
|
45
|
+
coords: [new Coordinates(0, 0), new Coordinates(4, 0)],
|
|
46
46
|
mode: 'BOAT',
|
|
47
47
|
duration: 2000,
|
|
48
48
|
stepsInfo: [step1, step2, step3, step4]
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
const leg5 = new Leg({
|
|
52
|
-
from: { coords: new Coordinates(
|
|
52
|
+
from: { coords: new Coordinates(0, 0) },
|
|
53
53
|
to: { coords: new Coordinates(4, 0) },
|
|
54
|
-
coords: [new Coordinates(
|
|
54
|
+
coords: [new Coordinates(0, 0), new Coordinates(4, 0)],
|
|
55
55
|
mode: 'BOAT',
|
|
56
56
|
duration: 2000,
|
|
57
57
|
stepsInfo: [step1, step2, step3, step4]
|
package/src/model/Leg.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { getDurationFromLength } from '../Utils.js';
|
|
|
6
6
|
import generateSteps, { StepsGenerationRules } from './generateSteps.js';
|
|
7
7
|
import { RoutingMode, isRoutingModePublicTransport } from './RoutingMode.js';
|
|
8
8
|
|
|
9
|
+
import { Step } from './Step.js'
|
|
9
10
|
import StepInfo, { StepInfoJson } from './StepInfo.js';
|
|
10
11
|
|
|
11
12
|
export type Destination = {
|
|
@@ -101,8 +102,8 @@ export default class Leg {
|
|
|
101
102
|
return isRoutingModePublicTransport(this.mode);
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
toNetwork<
|
|
105
|
-
return Network.fromCoordinates<
|
|
105
|
+
toNetwork<N, E>() {
|
|
106
|
+
return Network.fromCoordinates<N, E>([this.coords]);
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
static equals(obj1: Leg, obj2: Leg) {
|
|
@@ -224,4 +225,12 @@ export default class Leg {
|
|
|
224
225
|
step.coords.level = Level.multiplyBy(step.coords.level, levelFactor);
|
|
225
226
|
});
|
|
226
227
|
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Get leg steps from itinerary steps
|
|
231
|
+
* Steps cannot be retrieved directly from stepsInfo due to nextBearing/previousBearing
|
|
232
|
+
*/
|
|
233
|
+
getSteps(itinerarySteps: Step[]) {
|
|
234
|
+
return this.stepsInfo.map(stepInfo => itinerarySteps.find(_step => _step.coords.equals(stepInfo.coords)));
|
|
235
|
+
}
|
|
227
236
|
}
|
package/src/model/Step.ts
CHANGED
|
@@ -300,10 +300,10 @@ class IdfmRemoteRouter extends RemoteRouter {
|
|
|
300
300
|
coords[_idCoordsInLeg] = newCoords;
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
-
outputSteps.push({
|
|
303
|
+
outputSteps.push(new StepInfo({
|
|
304
304
|
...step,
|
|
305
305
|
coords: newCoords
|
|
306
|
-
}
|
|
306
|
+
}));
|
|
307
307
|
|
|
308
308
|
previousStep = step;
|
|
309
309
|
}
|
|
@@ -2,8 +2,8 @@ import pointInPolygon from '@turf/boolean-point-in-polygon';
|
|
|
2
2
|
import convexHullFn from '@turf/convex';
|
|
3
3
|
import { Feature, Polygon, polygon as turfPolygon, Position } from '@turf/helpers';
|
|
4
4
|
|
|
5
|
-
import { Coordinates,
|
|
6
|
-
import { OsmParser, OsmNetworkUtils,
|
|
5
|
+
import { Coordinates, NoRouteFoundError } from '@wemap/geo';
|
|
6
|
+
import { OsmParser, OsmNetworkUtils, OsmNetwork, OsmGraphNode } from '@wemap/osm';
|
|
7
7
|
|
|
8
8
|
import WemapOsmRouter from '../wemap-osm/WemapOsmRouter.js';
|
|
9
9
|
import WemapOsmRouterOptions from '../wemap-osm/WemapOsmRouterOptions.js';
|
|
@@ -11,15 +11,15 @@ import WemapOsmRouterOptions from '../wemap-osm/WemapOsmRouterOptions.js';
|
|
|
11
11
|
class CustomNetworkMap {
|
|
12
12
|
|
|
13
13
|
name: string | null;
|
|
14
|
-
network:
|
|
14
|
+
network: OsmNetwork;
|
|
15
15
|
router: WemapOsmRouter;
|
|
16
16
|
bounds: Feature<Polygon>;
|
|
17
|
-
entryPoints:
|
|
17
|
+
entryPoints: OsmGraphNode[];
|
|
18
18
|
disabledWays = new Set<number>();
|
|
19
19
|
|
|
20
20
|
constructor(
|
|
21
|
-
network:
|
|
22
|
-
entryPoints:
|
|
21
|
+
network: OsmNetwork,
|
|
22
|
+
entryPoints: OsmGraphNode[],
|
|
23
23
|
bounds: Coordinates[] | null = null,
|
|
24
24
|
name: string | null = null) {
|
|
25
25
|
|
|
@@ -56,7 +56,7 @@ class CustomNetworkMap {
|
|
|
56
56
|
|
|
57
57
|
const entryPoints = osmModel.nodes
|
|
58
58
|
.filter(({ tags }) => tags && tags['wemap:routing-io'])
|
|
59
|
-
.map(osmNode => network.getNodeByCoords(osmNode.coords) as
|
|
59
|
+
.map(osmNode => network.getNodeByCoords(osmNode.coords) as OsmGraphNode);
|
|
60
60
|
if (entryPoints.some(el => el === null)
|
|
61
61
|
|| new Set(entryPoints).size !== entryPoints.length
|
|
62
62
|
) {
|
|
@@ -4,8 +4,8 @@ import fs from 'fs';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
6
|
|
|
7
|
-
import { Coordinates,
|
|
8
|
-
import { OsmElement, OsmParser, OsmNetworkUtils } from '@wemap/osm';
|
|
7
|
+
import { Coordinates, GraphItinerary } from '@wemap/geo';
|
|
8
|
+
import { OsmElement, OsmParser, OsmNetworkUtils, OsmGraphNode } from '@wemap/osm';
|
|
9
9
|
|
|
10
10
|
import WemapOsmRouter from './WemapOsmRouter.js';
|
|
11
11
|
import WemapOsmRouterOptions from './WemapOsmRouterOptions.js';
|
|
@@ -44,18 +44,18 @@ describe('WemapOsmRouter - Multi-level itinerary', () => {
|
|
|
44
44
|
const graphItinerary = router.getShortestPath(itineraryStart, itineraryEnd);
|
|
45
45
|
const itinerary = router.getItinerary(itineraryStart, itineraryEnd);
|
|
46
46
|
|
|
47
|
-
const p:
|
|
47
|
+
const p: OsmGraphNode[] = [];
|
|
48
48
|
|
|
49
49
|
it('Search for nodes', () => {
|
|
50
50
|
for (let i = 1; i <= 16; i++) {
|
|
51
|
-
p[i] = getNodeByName(networkModel, 'p' + i) as
|
|
52
|
-
expect(p[i]).instanceOf(
|
|
51
|
+
p[i] = getNodeByName(networkModel, 'p' + i) as OsmGraphNode;
|
|
52
|
+
expect(p[i]).instanceOf(OsmGraphNode);
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
it('Router return shortest path', () => {
|
|
57
57
|
expect(getNodesNames(graphItinerary)).deep.equals(
|
|
58
|
-
[
|
|
58
|
+
[null, ...generateNodeNames(7, 16)]
|
|
59
59
|
);
|
|
60
60
|
});
|
|
61
61
|
|
|
@@ -115,7 +115,7 @@ describe('WemapOsmRouter - Multi-level itinerary', () => {
|
|
|
115
115
|
const end = new Coordinates(43.60917216742, 3.8842355275, null, 2);
|
|
116
116
|
const itinerary2 = router.getShortestPath(start, end);
|
|
117
117
|
|
|
118
|
-
expect(getNodesNames(itinerary2)).deep.equals([
|
|
118
|
+
expect(getNodesNames(itinerary2)).deep.equals([null, 'p6', 'p5']);
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
it('do not use stairs', () => {
|
|
@@ -191,8 +191,8 @@ describe('WemapOsmRouter - Conveying - backward', () => {
|
|
|
191
191
|
|
|
192
192
|
it('do not use oneway conveying', () => {
|
|
193
193
|
|
|
194
|
-
const start = getNodeByName(networkModel, 'p6') as
|
|
195
|
-
const end = getNodeByName(networkModel, 'p13') as
|
|
194
|
+
const start = getNodeByName(networkModel, 'p6') as OsmGraphNode;
|
|
195
|
+
const end = getNodeByName(networkModel, 'p13') as OsmGraphNode;
|
|
196
196
|
|
|
197
197
|
const itinerary = router.getShortestPath(start, end);
|
|
198
198
|
expect(itinerary).is.not.undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Coordinates,
|
|
2
|
-
import {
|
|
1
|
+
import { Coordinates, GraphUtils } from '@wemap/geo';
|
|
2
|
+
import { OsmGraphItinerary, OsmGraphNode, OsmGraphRouter, OsmNetwork, OsmNode, OsmWay } from '@wemap/osm';
|
|
3
3
|
|
|
4
4
|
import { StepsGenerationRules } from '../model/generateSteps.js';
|
|
5
5
|
import Itinerary from '../model/Itinerary.js';
|
|
@@ -7,7 +7,7 @@ import { LevelChangeType } from '../model/LevelChange.js';
|
|
|
7
7
|
import WemapOsmRouterOptions from './WemapOsmRouterOptions.js';
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
const buildStepsRules = (graphItinerary:
|
|
10
|
+
const buildStepsRules = (graphItinerary: OsmGraphItinerary): StepsGenerationRules => (
|
|
11
11
|
currentCoords: Coordinates,
|
|
12
12
|
nextCoords: Coordinates
|
|
13
13
|
) => {
|
|
@@ -24,11 +24,11 @@ const buildStepsRules = (graphItinerary: GraphItinerary<OsmElement>): StepsGener
|
|
|
24
24
|
const isGate = node ? (node.builtFrom?.tags.barrier === 'gate' || node.builtFrom?.tags.aeroway === 'gate') : false;
|
|
25
25
|
|
|
26
26
|
let levelChangeType: LevelChangeType | null = null;
|
|
27
|
-
if (edge.builtFrom
|
|
27
|
+
if (edge.builtFrom?.isElevator) {
|
|
28
28
|
levelChangeType = 'elevator';
|
|
29
29
|
} else if (
|
|
30
|
-
edge.builtFrom instanceof OsmNode
|
|
31
|
-
|
|
30
|
+
(edge.builtFrom instanceof OsmNode || edge.builtFrom instanceof OsmWay)
|
|
31
|
+
&& edge.builtFrom.isConveying
|
|
32
32
|
) {
|
|
33
33
|
levelChangeType = 'conveyor';
|
|
34
34
|
} else if (edge.builtFrom instanceof OsmWay && edge.builtFrom.areStairs) {
|
|
@@ -48,9 +48,9 @@ const buildStepsRules = (graphItinerary: GraphItinerary<OsmElement>): StepsGener
|
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
class WemapOsmRouter extends
|
|
51
|
+
class WemapOsmRouter extends OsmGraphRouter {
|
|
52
52
|
|
|
53
|
-
constructor(network:
|
|
53
|
+
constructor(network: OsmNetwork) {
|
|
54
54
|
super(network);
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -59,16 +59,16 @@ class WemapOsmRouter extends GraphRouter<OsmElement> {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
getShortestPath(
|
|
62
|
-
start:
|
|
63
|
-
end:
|
|
62
|
+
start: OsmGraphNode | Coordinates,
|
|
63
|
+
end: OsmGraphNode | Coordinates,
|
|
64
64
|
options = new WemapOsmRouterOptions()
|
|
65
65
|
) {
|
|
66
66
|
return super.getShortestPath(start, end, options);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
getItinerary(
|
|
70
|
-
start:
|
|
71
|
-
end:
|
|
70
|
+
start: OsmGraphNode | Coordinates,
|
|
71
|
+
end: OsmGraphNode | Coordinates,
|
|
72
72
|
options = new WemapOsmRouterOptions()
|
|
73
73
|
) {
|
|
74
74
|
const graphItinerary = this.getShortestPath(start, end, options);
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { GraphEdge
|
|
2
|
-
import {
|
|
1
|
+
import { GraphEdge } from '@wemap/geo';
|
|
2
|
+
import { OsmNode, OsmGraphRouterOptions, OsmGraphEdge } from '@wemap/osm';
|
|
3
3
|
|
|
4
4
|
import { getDurationFromLength } from '../Utils.js';
|
|
5
5
|
|
|
6
|
-
class WemapOsmRouterOptions extends
|
|
6
|
+
class WemapOsmRouterOptions extends OsmGraphRouterOptions {
|
|
7
7
|
|
|
8
8
|
static DEFAULT = new WemapOsmRouterOptions();
|
|
9
9
|
|
|
10
10
|
static get WITHOUT_STAIRS() {
|
|
11
11
|
const options = new WemapOsmRouterOptions();
|
|
12
|
-
options.acceptEdgeFn = (edge:
|
|
12
|
+
options.acceptEdgeFn = (edge: OsmGraphEdge) => edge.builtFrom?.tags.highway !== 'steps';
|
|
13
13
|
return options;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
weightEdgeFn = (edge: GraphEdge
|
|
16
|
+
weightEdgeFn = (edge: GraphEdge) =>
|
|
17
17
|
edge.builtFrom instanceof OsmNode && edge.builtFrom.isElevator
|
|
18
18
|
? 30
|
|
19
19
|
: getDurationFromLength(edge.length);
|