@wemap/routers 6.2.2 → 7.0.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.
- package/assets/biocbon-bergere-rdc-network.osm +163 -0
- package/assets/gare-de-lest-network-pp-bounds.osm +1615 -0
- package/dist/wemap-routers.es.js +1811 -695
- package/dist/wemap-routers.es.js.map +1 -1
- package/index.js +13 -5
- package/package.json +9 -6
- package/src/Constants.js +4 -2
- package/src/ItineraryInfoManager.spec.js +2 -2
- package/src/Utils.js +0 -77
- package/src/model/Itinerary.js +41 -5
- package/src/model/Itinerary.spec.js +91 -0
- package/src/model/Itinerary.type.spec.js +3 -78
- package/src/model/Leg.js +89 -19
- package/src/model/Leg.spec.js +110 -0
- package/src/model/Leg.type.spec.js +48 -0
- package/src/model/LevelChange.js +14 -24
- package/src/model/LevelChange.spec.js +78 -0
- package/src/model/LevelChange.type.spec.js +26 -0
- package/src/model/RouterResponse.js +70 -1
- package/src/model/RouterResponse.spec.js +85 -0
- package/src/model/RouterResponse.type.spec.js +7 -4
- package/src/model/Step.js +45 -6
- package/src/model/Step.spec.js +100 -0
- package/src/model/Step.type.spec.js +52 -0
- package/src/remote/RemoteRouter.js +31 -0
- package/src/remote/RemoteRouterManager.js +84 -0
- package/src/remote/RemoteRouterOptions.js +25 -0
- package/src/remote/RemoteRouterServerUnreachable.js +10 -0
- package/src/remote/RemoteRouterUtils.js +78 -0
- package/src/remote/RoutingModeCorrespondanceNotFound.js +18 -0
- package/src/remote/cityway/CitywayRemoteRouter.js +386 -0
- package/src/{cityway/CitywayUtils.spec.js → remote/cityway/CitywayRemoteRouter.spec.js} +19 -18
- package/src/remote/deutsche-bahn/DeutscheBahnRemoteRouter.js +143 -0
- package/src/{deutsche-bahn/DeutscheBahnRouterUtils.spec.js → remote/deutsche-bahn/DeutscheBahnRemoteRouter.spec.js} +7 -6
- package/src/remote/idfm/IdfmRemoteRouter.js +432 -0
- package/src/{idfm/IdfmUtils.spec.js → remote/idfm/IdfmRemoteRouter.spec.js} +7 -6
- package/src/remote/idfm/IdfmRemoteRouterTokenError.js +6 -0
- package/src/remote/osrm/OsrmRemoteRouter.js +331 -0
- package/src/{osrm/OsrmUtils.spec.js → remote/osrm/OsrmRemoteRouter.spec.js} +9 -15
- package/src/remote/otp/OtpRemoteRouter.js +222 -0
- package/src/{otp/OtpUtils.spec.js → remote/otp/OtpRemoteRouter.spec.js} +10 -9
- package/src/remote/wemap-meta/WemapMetaRemoteRouter.js +57 -0
- package/src/remote/wemap-meta/WemapMetaRemoteRouter.spec.js +22 -0
- package/src/remote/wemap-meta/WemapMetaRemoteRouterOptions.js +36 -0
- package/src/remote/wemap-meta/WemapMetaRemoteRouterPayload.js +44 -0
- package/src/wemap/WemapRouter.js +6 -0
- package/src/wemap/WemapRouterUtils.js +10 -4
- package/src/wemap/WemapStepsGeneration.js +36 -9
- package/src/wemap-meta/IOMap.js +191 -0
- package/src/wemap-meta/WemapMetaRouter.js +314 -0
- package/src/wemap-meta/WemapMetaRouter.spec.js +119 -0
- package/src/wemap-meta/WemapMetaRouterOptions.js +20 -0
- package/src/cityway/CitywayUtils.js +0 -252
- package/src/deutsche-bahn/DeutscheBahnRouterUtils.js +0 -91
- package/src/idfm/IdfmUtils.js +0 -247
- package/src/osrm/OsrmUtils.js +0 -269
- package/src/otp/OtpUtils.js +0 -150
|
@@ -6,25 +6,26 @@ import { fileURLToPath } from 'url';
|
|
|
6
6
|
|
|
7
7
|
import { Coordinates } from '@wemap/geo';
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import CitywayRemoteRouter from './CitywayRemoteRouter.js';
|
|
10
10
|
|
|
11
|
-
import
|
|
11
|
+
import checkRouterResponseType from '../../model/RouterResponse.type.spec.js';
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
const { expect } = chai;
|
|
15
15
|
|
|
16
16
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
const assetsPath = path.resolve(__dirname, '../../../assets');
|
|
17
18
|
|
|
18
|
-
describe('
|
|
19
|
+
describe('CitywayRemoteRouter - createRouterResponseFromJson', () => {
|
|
19
20
|
|
|
20
21
|
it('RouterResponse - 1', () => {
|
|
21
22
|
|
|
22
|
-
const filePath = path.resolve(
|
|
23
|
+
const filePath = path.resolve(assetsPath, 'itinerary-lehavre-cityway-1.json');
|
|
23
24
|
const fileString = fs.readFileSync(filePath, 'utf8');
|
|
24
25
|
const json = JSON.parse(fileString);
|
|
25
26
|
|
|
26
|
-
const routerResponse = createRouterResponseFromJson(json);
|
|
27
|
-
|
|
27
|
+
const routerResponse = CitywayRemoteRouter.createRouterResponseFromJson(json);
|
|
28
|
+
checkRouterResponseType(routerResponse);
|
|
28
29
|
|
|
29
30
|
expect(routerResponse.routerName).equal('cityway');
|
|
30
31
|
expect(routerResponse.itineraries.length).equal(3);
|
|
@@ -62,48 +63,48 @@ describe('CitywayUtils - createRouterResponseFromJson', () => {
|
|
|
62
63
|
});
|
|
63
64
|
|
|
64
65
|
it('RouterResponse - 2', () => {
|
|
65
|
-
const filePath = path.resolve(
|
|
66
|
+
const filePath = path.resolve(assetsPath, 'itinerary-lehavre-cityway-2.json');
|
|
66
67
|
const fileString = fs.readFileSync(filePath, 'utf8');
|
|
67
68
|
const json = JSON.parse(fileString);
|
|
68
69
|
|
|
69
|
-
const routerResponse = createRouterResponseFromJson(json);
|
|
70
|
-
|
|
70
|
+
const routerResponse = CitywayRemoteRouter.createRouterResponseFromJson(json);
|
|
71
|
+
checkRouterResponseType(routerResponse);
|
|
71
72
|
|
|
72
73
|
expect(routerResponse.itineraries.length).equal(1);
|
|
73
74
|
expect(routerResponse.itineraries[0].mode).equal('WALK');
|
|
74
75
|
});
|
|
75
76
|
|
|
76
77
|
it('RouterResponse - 3', () => {
|
|
77
|
-
const filePath = path.resolve(
|
|
78
|
+
const filePath = path.resolve(assetsPath, 'itinerary-lehavre-cityway-3.json');
|
|
78
79
|
const fileString = fs.readFileSync(filePath, 'utf8');
|
|
79
80
|
const json = JSON.parse(fileString);
|
|
80
81
|
|
|
81
|
-
const routerResponse = createRouterResponseFromJson(json);
|
|
82
|
-
|
|
82
|
+
const routerResponse = CitywayRemoteRouter.createRouterResponseFromJson(json);
|
|
83
|
+
checkRouterResponseType(routerResponse);
|
|
83
84
|
|
|
84
85
|
expect(routerResponse.itineraries[0].mode).equal('PT');
|
|
85
86
|
expect(routerResponse.itineraries[0].legs[1].mode).equal('FUNICULAR');
|
|
86
87
|
});
|
|
87
88
|
|
|
88
89
|
it('RouterResponse - 4', () => {
|
|
89
|
-
const filePath = path.resolve(
|
|
90
|
+
const filePath = path.resolve(assetsPath, 'itinerary-lehavre-cityway-4.json');
|
|
90
91
|
const fileString = fs.readFileSync(filePath, 'utf8');
|
|
91
92
|
const json = JSON.parse(fileString);
|
|
92
93
|
|
|
93
|
-
const routerResponse = createRouterResponseFromJson(json);
|
|
94
|
-
|
|
94
|
+
const routerResponse = CitywayRemoteRouter.createRouterResponseFromJson(json);
|
|
95
|
+
checkRouterResponseType(routerResponse);
|
|
95
96
|
|
|
96
97
|
expect(routerResponse.itineraries[0].mode).equal('BIKE');
|
|
97
98
|
expect(routerResponse.itineraries[0].legs[0].mode).equal('BIKE');
|
|
98
99
|
});
|
|
99
100
|
|
|
100
101
|
it('RouterResponse - 5', () => {
|
|
101
|
-
const filePath = path.resolve(
|
|
102
|
+
const filePath = path.resolve(assetsPath, 'itinerary-lehavre-cityway-5.json');
|
|
102
103
|
const fileString = fs.readFileSync(filePath, 'utf8');
|
|
103
104
|
const json = JSON.parse(fileString);
|
|
104
105
|
|
|
105
|
-
const routerResponse = createRouterResponseFromJson(json);
|
|
106
|
-
|
|
106
|
+
const routerResponse = CitywayRemoteRouter.createRouterResponseFromJson(json);
|
|
107
|
+
checkRouterResponseType(routerResponse);
|
|
107
108
|
|
|
108
109
|
expect(routerResponse.itineraries[1].mode).equal('PT');
|
|
109
110
|
expect(routerResponse.itineraries[1].legs[1].mode).equal('TRAM');
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/* eslint-disable max-statements */
|
|
2
|
+
|
|
3
|
+
import { Coordinates, GraphEdge, GraphItinerary, GraphNode, Level } from '@wemap/geo';
|
|
4
|
+
import { OsmElement, OsmNode, OsmWay } from '@wemap/osm';
|
|
5
|
+
|
|
6
|
+
import RemoteRouter from '../RemoteRouter.js';
|
|
7
|
+
import Itinerary from '../../model/Itinerary.js';
|
|
8
|
+
import RouterResponse from '../../model/RouterResponse.js';
|
|
9
|
+
import { generateStepsMetadata } from '../RemoteRouterUtils.js';
|
|
10
|
+
import StepsGeneration from '../../wemap/WemapStepsGeneration.js';
|
|
11
|
+
import RemoteRouterServerUnreachable from '../RemoteRouterServerUnreachable.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Singleton.
|
|
15
|
+
*/
|
|
16
|
+
class DeutscheBahnRemoteRouter extends RemoteRouter {
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @override
|
|
20
|
+
*/
|
|
21
|
+
get rname() {
|
|
22
|
+
return 'deutsche-bahn';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @override
|
|
27
|
+
* @throws {RemoteRouterServerUnreachable}
|
|
28
|
+
*/
|
|
29
|
+
async getItineraries(endpointUrl, mode, waypoints) {
|
|
30
|
+
const url = this.getURL(endpointUrl, mode, waypoints);
|
|
31
|
+
const res = await fetch(url);
|
|
32
|
+
if (res.status !== 200) {
|
|
33
|
+
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
34
|
+
}
|
|
35
|
+
const response = await res.json();
|
|
36
|
+
return this.createRouterResponseFromJson(response, waypoints[0], waypoints[1]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {string} endpointUrl
|
|
41
|
+
* @param {string} mode
|
|
42
|
+
* @param {Array<Coordinates>} waypoints
|
|
43
|
+
*/
|
|
44
|
+
getURL(endpointUrl, mode, waypoints) {
|
|
45
|
+
let url = endpointUrl + '/route/v1/walking/';
|
|
46
|
+
|
|
47
|
+
url += waypoints.map(waypoint => {
|
|
48
|
+
if (waypoint.level) {
|
|
49
|
+
const altitude = waypoint.level.isRange ? waypoint.level.low : waypoint.level.val;
|
|
50
|
+
|
|
51
|
+
return waypoint.longitude + ',' + waypoint.latitude + ',' + altitude;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return waypoint.longitude + ',' + waypoint.latitude;
|
|
55
|
+
}).join(';');
|
|
56
|
+
|
|
57
|
+
url += '?geometries=geojson&overview=full&steps=true';
|
|
58
|
+
|
|
59
|
+
return url;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Generate multi itineraries from the DB JSON
|
|
64
|
+
* @param {object} json JSON file provided by the DB.
|
|
65
|
+
* @param {Coordinates} from itinerary start
|
|
66
|
+
* @param {Coordinates} to itinerary end
|
|
67
|
+
* @returns {?RouterResponse}
|
|
68
|
+
*/
|
|
69
|
+
createRouterResponseFromJson(json, from, to) {
|
|
70
|
+
|
|
71
|
+
const { segments: jsonSegments } = json;
|
|
72
|
+
|
|
73
|
+
if (!jsonSegments) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const routerResponse = new RouterResponse();
|
|
78
|
+
routerResponse.routerName = this.rname;
|
|
79
|
+
|
|
80
|
+
routerResponse.from = from;
|
|
81
|
+
routerResponse.to = to;
|
|
82
|
+
|
|
83
|
+
/** @type {GraphEdge<OsmElement>[]} */
|
|
84
|
+
const edges = [];
|
|
85
|
+
|
|
86
|
+
/** @type {GraphNode<OsmElement>[]} */
|
|
87
|
+
const nodes = [];
|
|
88
|
+
|
|
89
|
+
/** @type {number[]} */
|
|
90
|
+
const edgesWeights = [];
|
|
91
|
+
|
|
92
|
+
let id = 1;
|
|
93
|
+
for (const jsonSegment of jsonSegments) {
|
|
94
|
+
|
|
95
|
+
const level = new Level(jsonSegment.fromLevel, jsonSegment.toLevel);
|
|
96
|
+
const osmWay = new OsmWay(id++, null, level);
|
|
97
|
+
|
|
98
|
+
for (const jsonPoint of jsonSegment.polyline) {
|
|
99
|
+
const coord = new Coordinates(jsonPoint.lat, jsonPoint.lon, null, level);
|
|
100
|
+
|
|
101
|
+
if (nodes.length !== 0
|
|
102
|
+
&& nodes[nodes.length - 1].coords.equalsTo(coord)) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const osmNode = new OsmNode(id++, coord);
|
|
107
|
+
const node = new GraphNode(osmNode.coords, osmNode);
|
|
108
|
+
|
|
109
|
+
if (nodes.length !== 0) {
|
|
110
|
+
const prevNode = nodes[nodes.length - 1];
|
|
111
|
+
const edge = new GraphEdge(prevNode, node, level, osmWay);
|
|
112
|
+
edges.push(edge);
|
|
113
|
+
edgesWeights.push(prevNode.coords.distanceTo(osmNode));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
nodes.push(node);
|
|
117
|
+
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** @type {GraphItinerary<OsmElement>} */
|
|
122
|
+
const graphItinerary = new GraphItinerary();
|
|
123
|
+
graphItinerary.nodes = nodes;
|
|
124
|
+
graphItinerary.edges = edges;
|
|
125
|
+
graphItinerary.edgesWeights = edgesWeights;
|
|
126
|
+
graphItinerary.start = nodes[0].coords;
|
|
127
|
+
graphItinerary.end = nodes[nodes.length - 1].coords;
|
|
128
|
+
|
|
129
|
+
const points = nodes.map(node => node.coords);
|
|
130
|
+
const itinerary = Itinerary.fromOrderedCoordinates(points, from, to);
|
|
131
|
+
itinerary.legs[0].steps = StepsGeneration.fromGraphItinerary(graphItinerary);
|
|
132
|
+
itinerary.legs[0].steps.map((step, idx) => (step._idCoordsInLeg = idx));
|
|
133
|
+
|
|
134
|
+
// All legs have to be parsed before computing steps metadata
|
|
135
|
+
generateStepsMetadata(itinerary);
|
|
136
|
+
|
|
137
|
+
routerResponse.itineraries.push(itinerary);
|
|
138
|
+
|
|
139
|
+
return routerResponse;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export default new DeutscheBahnRemoteRouter();
|
|
@@ -7,29 +7,30 @@ import { fileURLToPath } from 'url';
|
|
|
7
7
|
|
|
8
8
|
import { Coordinates, Level } from '@wemap/geo';
|
|
9
9
|
|
|
10
|
-
import
|
|
10
|
+
import DeutscheBahnRemoteRouter from './DeutscheBahnRemoteRouter.js';
|
|
11
11
|
|
|
12
|
-
import
|
|
12
|
+
import checkRouterResponseType from '../../model/RouterResponse.type.spec.js';
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
const { expect } = chai;
|
|
16
16
|
chai.use(chaiAlmost(0.1));
|
|
17
17
|
|
|
18
18
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
const assetsPath = path.resolve(__dirname, '../../../assets');
|
|
19
20
|
|
|
20
|
-
describe('
|
|
21
|
+
describe('DeutscheBahnRemoteRouter - createRouterResponseFromJson', () => {
|
|
21
22
|
|
|
22
23
|
it('RouterResponse - 1', () => {
|
|
23
24
|
|
|
24
|
-
const filePath = path.resolve(
|
|
25
|
+
const filePath = path.resolve(assetsPath, 'itinerary-deutsche-bahn-1.json');
|
|
25
26
|
const fileString = fs.readFileSync(filePath, 'utf8');
|
|
26
27
|
const json = JSON.parse(fileString);
|
|
27
28
|
|
|
28
29
|
const from = new Coordinates(52.5258473, 13.3683657, null, new Level(-10));
|
|
29
30
|
const to = new Coordinates(52.52499085853664, 13.369467296949914, null, new Level(0));
|
|
30
31
|
|
|
31
|
-
const routerResponse = createRouterResponseFromJson(json, from, to);
|
|
32
|
-
|
|
32
|
+
const routerResponse = DeutscheBahnRemoteRouter.createRouterResponseFromJson(json, from, to);
|
|
33
|
+
checkRouterResponseType(routerResponse);
|
|
33
34
|
|
|
34
35
|
expect(routerResponse.routerName).equal('deutsche-bahn');
|
|
35
36
|
expect(routerResponse.itineraries.length).equal(1);
|