@wemap/routers 7.1.0 → 7.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.
- package/assets/rr-wemap-meta-multi-level.json +256 -0
- package/index.js +1 -0
- package/package.json +4 -4
- package/src/Utils.js +55 -0
- package/src/Utils.spec.js +60 -0
- package/src/remote/RemoteRouterManager.js +3 -1
- package/src/wemap-meta/WemapMetaRouter.js +12 -4
- package/dist/wemap-routers.es.js +0 -3691
- package/dist/wemap-routers.es.js.map +0 -1
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
{
|
|
2
|
+
"routerName": [
|
|
3
|
+
"wemap-meta",
|
|
4
|
+
"wemap"
|
|
5
|
+
],
|
|
6
|
+
"from": [
|
|
7
|
+
43.6091851,
|
|
8
|
+
3.8841386,
|
|
9
|
+
1.5999999999999996,
|
|
10
|
+
"2"
|
|
11
|
+
],
|
|
12
|
+
"to": [
|
|
13
|
+
43.6093145,
|
|
14
|
+
3.8842585,
|
|
15
|
+
0,
|
|
16
|
+
"1"
|
|
17
|
+
],
|
|
18
|
+
"itineraries": [
|
|
19
|
+
{
|
|
20
|
+
"from": [
|
|
21
|
+
43.6091851,
|
|
22
|
+
3.8841386,
|
|
23
|
+
1.5999999999999996,
|
|
24
|
+
"2"
|
|
25
|
+
],
|
|
26
|
+
"to": [
|
|
27
|
+
43.6093145,
|
|
28
|
+
3.8842585,
|
|
29
|
+
0,
|
|
30
|
+
"1"
|
|
31
|
+
],
|
|
32
|
+
"distance": 42.54181917885857,
|
|
33
|
+
"duration": 30.630109808778165,
|
|
34
|
+
"mode": "WALK",
|
|
35
|
+
"legs": [
|
|
36
|
+
{
|
|
37
|
+
"mode": "WALK",
|
|
38
|
+
"from": {
|
|
39
|
+
"coords": [
|
|
40
|
+
43.6091851,
|
|
41
|
+
3.8841386,
|
|
42
|
+
1.5999999999999996,
|
|
43
|
+
"2"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"to": {
|
|
47
|
+
"coords": [
|
|
48
|
+
43.6093145,
|
|
49
|
+
3.8842585,
|
|
50
|
+
0,
|
|
51
|
+
"1"
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
"distance": 42.54181917885857,
|
|
55
|
+
"duration": 30.630109808778165,
|
|
56
|
+
"coords": [
|
|
57
|
+
[
|
|
58
|
+
43.60918687807148,
|
|
59
|
+
3.884139117496946,
|
|
60
|
+
1.5999999999999996,
|
|
61
|
+
"2"
|
|
62
|
+
],
|
|
63
|
+
[
|
|
64
|
+
43.60917494597,
|
|
65
|
+
3.88421731753,
|
|
66
|
+
null,
|
|
67
|
+
"2"
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
43.60927603206,
|
|
71
|
+
3.88424673798,
|
|
72
|
+
null,
|
|
73
|
+
"2"
|
|
74
|
+
],
|
|
75
|
+
[
|
|
76
|
+
43.60929353543,
|
|
77
|
+
3.88425183223,
|
|
78
|
+
null,
|
|
79
|
+
"2"
|
|
80
|
+
],
|
|
81
|
+
[
|
|
82
|
+
43.60930219142,
|
|
83
|
+
3.88427017086,
|
|
84
|
+
null,
|
|
85
|
+
"2"
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
43.60931231268,
|
|
89
|
+
3.8842731166,
|
|
90
|
+
null,
|
|
91
|
+
"2"
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
43.60932336323,
|
|
95
|
+
3.884200898,
|
|
96
|
+
null,
|
|
97
|
+
"2"
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
43.6093629216,
|
|
101
|
+
3.884212726,
|
|
102
|
+
null,
|
|
103
|
+
"1;2"
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
43.60935965678,
|
|
107
|
+
3.8842335535,
|
|
108
|
+
null,
|
|
109
|
+
"1;2"
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
43.60932022256,
|
|
113
|
+
3.88422176261,
|
|
114
|
+
null,
|
|
115
|
+
"1"
|
|
116
|
+
],
|
|
117
|
+
[
|
|
118
|
+
43.60931456597898,
|
|
119
|
+
3.884258519367876,
|
|
120
|
+
0,
|
|
121
|
+
"1"
|
|
122
|
+
]
|
|
123
|
+
],
|
|
124
|
+
"steps": [
|
|
125
|
+
{
|
|
126
|
+
"number": 1,
|
|
127
|
+
"coords": [
|
|
128
|
+
43.60918687807148,
|
|
129
|
+
3.884139117496946,
|
|
130
|
+
1.5999999999999996,
|
|
131
|
+
"2"
|
|
132
|
+
],
|
|
133
|
+
"angle": 1.570796452892035,
|
|
134
|
+
"previousBearing": 0.20769475566724294,
|
|
135
|
+
"nextBearing": 1.7784909563650013,
|
|
136
|
+
"distance": 6.441526226002801,
|
|
137
|
+
"_idCoordsInLeg": 0,
|
|
138
|
+
"firstStep": true,
|
|
139
|
+
"duration": 4.637898882722017
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"number": 2,
|
|
143
|
+
"coords": [
|
|
144
|
+
43.60917494597,
|
|
145
|
+
3.88421731753,
|
|
146
|
+
null,
|
|
147
|
+
"2"
|
|
148
|
+
],
|
|
149
|
+
"angle": -1.5707958396207153,
|
|
150
|
+
"previousBearing": 1.7784909563650013,
|
|
151
|
+
"nextBearing": 0.20769414239592354,
|
|
152
|
+
"distance": 13.491259592782844,
|
|
153
|
+
"_idCoordsInLeg": 1,
|
|
154
|
+
"duration": 9.71370690680365
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"number": 3,
|
|
158
|
+
"coords": [
|
|
159
|
+
43.60929353543,
|
|
160
|
+
3.88425183223,
|
|
161
|
+
null,
|
|
162
|
+
"2"
|
|
163
|
+
],
|
|
164
|
+
"angle": 2.3561946292270304,
|
|
165
|
+
"previousBearing": 0.20769440021825977,
|
|
166
|
+
"nextBearing": 0.9930924245810223,
|
|
167
|
+
"distance": 1.764470280281753,
|
|
168
|
+
"_idCoordsInLeg": 3,
|
|
169
|
+
"duration": 1.2704186018028611
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"number": 4,
|
|
173
|
+
"coords": [
|
|
174
|
+
43.60930219142,
|
|
175
|
+
3.88427017086,
|
|
176
|
+
null,
|
|
177
|
+
"2"
|
|
178
|
+
],
|
|
179
|
+
"angle": -2.35619514761237,
|
|
180
|
+
"previousBearing": 0.9930924245810223,
|
|
181
|
+
"nextBearing": 0.20769491860359898,
|
|
182
|
+
"distance": 1.1514392872995367,
|
|
183
|
+
"_idCoordsInLeg": 4,
|
|
184
|
+
"duration": 0.8290362868556649
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"number": 5,
|
|
188
|
+
"coords": [
|
|
189
|
+
43.60931231268,
|
|
190
|
+
3.8842731166,
|
|
191
|
+
null,
|
|
192
|
+
"2"
|
|
193
|
+
],
|
|
194
|
+
"angle": -1.571367193550253,
|
|
195
|
+
"previousBearing": 0.20769491860359898,
|
|
196
|
+
"nextBearing": -1.3625305414359412,
|
|
197
|
+
"distance": 5.9495234765598815,
|
|
198
|
+
"_idCoordsInLeg": 5,
|
|
199
|
+
"duration": 4.283656903123116
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
"number": 6,
|
|
203
|
+
"coords": [
|
|
204
|
+
43.60932336323,
|
|
205
|
+
3.884200898,
|
|
206
|
+
null,
|
|
207
|
+
"2"
|
|
208
|
+
],
|
|
209
|
+
"angle": 1.5658578729882155,
|
|
210
|
+
"previousBearing": -1.3625305414359412,
|
|
211
|
+
"nextBearing": 0.213204239165637,
|
|
212
|
+
"distance": 10.714755603461356,
|
|
213
|
+
"_idCoordsInLeg": 6,
|
|
214
|
+
"duration": 7.714624034492179,
|
|
215
|
+
"levelChange": {
|
|
216
|
+
"direction": "down",
|
|
217
|
+
"difference": -1,
|
|
218
|
+
"type": "stairs"
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"number": 7,
|
|
223
|
+
"coords": [
|
|
224
|
+
43.60932022256,
|
|
225
|
+
3.88422176261,
|
|
226
|
+
null,
|
|
227
|
+
"1"
|
|
228
|
+
],
|
|
229
|
+
"angle": -1.567016008190605,
|
|
230
|
+
"previousBearing": -2.928388068274625,
|
|
231
|
+
"nextBearing": 1.780220593505773,
|
|
232
|
+
"distance": 3.0288447124703852,
|
|
233
|
+
"_idCoordsInLeg": 9,
|
|
234
|
+
"duration": 2.180768192978679
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"number": 8,
|
|
238
|
+
"coords": [
|
|
239
|
+
43.60931456597898,
|
|
240
|
+
3.884258519367876,
|
|
241
|
+
0,
|
|
242
|
+
"1"
|
|
243
|
+
],
|
|
244
|
+
"angle": 1.570792167125268,
|
|
245
|
+
"previousBearing": 1.780220593505773,
|
|
246
|
+
"nextBearing": -2.932164227209288,
|
|
247
|
+
"distance": 0.007508814013397345,
|
|
248
|
+
"_idCoordsInLeg": 10,
|
|
249
|
+
"lastStep": true
|
|
250
|
+
}
|
|
251
|
+
]
|
|
252
|
+
}
|
|
253
|
+
]
|
|
254
|
+
}
|
|
255
|
+
]
|
|
256
|
+
}
|
package/index.js
CHANGED
|
@@ -26,6 +26,7 @@ export { default as IdfmRemoteRouter } from './src/remote/idfm/IdfmRemoteRouter.
|
|
|
26
26
|
export { default as WemapMetaRemoteRouter } from './src/remote/wemap-meta/WemapMetaRemoteRouter.js';
|
|
27
27
|
export { default as WemapMetaRemoteRouterOptions } from './src/remote/wemap-meta/WemapMetaRemoteRouterOptions.js';
|
|
28
28
|
export { default as WemapMetaRemoteRouterPayload } from './src/remote/wemap-meta/WemapMetaRemoteRouterPayload.js';
|
|
29
|
+
export { default as RemoteRouterManager } from './src/remote/RemoteRouterManager.js';
|
|
29
30
|
|
|
30
31
|
|
|
31
32
|
/* Others */
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"directory": "packages/routers"
|
|
12
12
|
},
|
|
13
13
|
"name": "@wemap/routers",
|
|
14
|
-
"version": "7.
|
|
14
|
+
"version": "7.2.0",
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
17
17
|
},
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"@turf/boolean-point-in-polygon": "^6.5.0",
|
|
30
30
|
"@turf/convex": "^6.5.0",
|
|
31
31
|
"@turf/helpers": "^6.5.0",
|
|
32
|
-
"@wemap/geo": "^7.
|
|
32
|
+
"@wemap/geo": "^7.2.0",
|
|
33
33
|
"@wemap/logger": "^7.0.0",
|
|
34
34
|
"@wemap/maths": "^7.0.0",
|
|
35
|
-
"@wemap/osm": "^7.
|
|
35
|
+
"@wemap/osm": "^7.2.0"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "a4a796c2870c6b1182a0c69fe753bc4012faf0c1"
|
|
38
38
|
}
|
package/src/Utils.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
|
|
2
|
+
import RouterResponse from './model/RouterResponse.js';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Get route duration
|
|
3
6
|
* @param {Number} speed in km/h
|
|
@@ -6,3 +9,55 @@
|
|
|
6
9
|
export function getDurationFromLength(length, speed = 5) {
|
|
7
10
|
return length / (speed * 1000 / 3600);
|
|
8
11
|
}
|
|
12
|
+
|
|
13
|
+
/* eslint-disable max-statements */
|
|
14
|
+
/* eslint-disable max-depth */
|
|
15
|
+
/**
|
|
16
|
+
* @param {RouterResponse} routerResponse
|
|
17
|
+
* @param {Number} levelFactor
|
|
18
|
+
*/
|
|
19
|
+
export function multiplyRouterResponseLevel(routerResponse, levelFactor) {
|
|
20
|
+
if (routerResponse.from.level) {
|
|
21
|
+
routerResponse.from.level.multiplyBy(levelFactor);
|
|
22
|
+
}
|
|
23
|
+
if (routerResponse.to.level) {
|
|
24
|
+
routerResponse.to.level.multiplyBy(levelFactor);
|
|
25
|
+
}
|
|
26
|
+
for (const itinerary of routerResponse.itineraries) {
|
|
27
|
+
if (itinerary.from.level) {
|
|
28
|
+
itinerary.from.level.multiplyBy(levelFactor);
|
|
29
|
+
}
|
|
30
|
+
if (itinerary.to.level) {
|
|
31
|
+
itinerary.to.level.multiplyBy(levelFactor);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
for (const leg of itinerary.legs) {
|
|
35
|
+
if (leg.from.coords.level) {
|
|
36
|
+
leg.from.coords.level.multiplyBy(levelFactor);
|
|
37
|
+
}
|
|
38
|
+
if (leg.to.coords.level) {
|
|
39
|
+
leg.to.coords.level.multiplyBy(levelFactor);
|
|
40
|
+
}
|
|
41
|
+
for (const coords of leg.coords) {
|
|
42
|
+
if (coords.level) {
|
|
43
|
+
coords.level.multiplyBy(levelFactor);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (leg.steps) {
|
|
47
|
+
for (const step of leg.steps) {
|
|
48
|
+
if (step.coords.level) {
|
|
49
|
+
step.coords.level.multiplyBy(levelFactor);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (itinerary._coords) {
|
|
56
|
+
for (const coords of itinerary._coords) {
|
|
57
|
+
if (coords.level) {
|
|
58
|
+
coords.level.multiplyBy(levelFactor);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* eslint-disable max-statements */
|
|
2
|
+
import chai from 'chai';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
|
|
7
|
+
import RouterResponse from './model/RouterResponse.js';
|
|
8
|
+
import { multiplyRouterResponseLevel } from './Utils.js';
|
|
9
|
+
|
|
10
|
+
const { expect } = chai;
|
|
11
|
+
|
|
12
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const assetsPath = path.resolve(__dirname, '../assets');
|
|
14
|
+
|
|
15
|
+
describe('Routers Utils', () => {
|
|
16
|
+
|
|
17
|
+
it('multiplyRouterResponseLevel', () => {
|
|
18
|
+
|
|
19
|
+
const filePath = path.resolve(assetsPath, 'rr-wemap-meta-multi-level.json');
|
|
20
|
+
const fileString = fs.readFileSync(filePath, 'utf8');
|
|
21
|
+
const json = JSON.parse(fileString);
|
|
22
|
+
|
|
23
|
+
const routerResponse = RouterResponse.fromJson(json);
|
|
24
|
+
multiplyRouterResponseLevel(routerResponse, 5);
|
|
25
|
+
|
|
26
|
+
expect(routerResponse.from.level.val).equal(10);
|
|
27
|
+
expect(routerResponse.to.level.val).equal(5);
|
|
28
|
+
|
|
29
|
+
const itinerary = routerResponse.itineraries[0];
|
|
30
|
+
expect(itinerary.from.level.val).equal(10);
|
|
31
|
+
expect(itinerary.to.level.val).equal(5);
|
|
32
|
+
|
|
33
|
+
const leg = itinerary.legs[0];
|
|
34
|
+
expect(leg.from.coords.level.val).equal(10);
|
|
35
|
+
expect(leg.to.coords.level.val).equal(5);
|
|
36
|
+
|
|
37
|
+
for (let i = 0; i < leg.coords.length; i++) {
|
|
38
|
+
if (i <= 6) {
|
|
39
|
+
expect(leg.coords[i].level.val).equal(10);
|
|
40
|
+
} else if (i <= 8) {
|
|
41
|
+
expect(leg.coords[i].level.up).equal(10);
|
|
42
|
+
expect(leg.coords[i].level.low).equal(5);
|
|
43
|
+
} else {
|
|
44
|
+
expect(leg.coords[i].level.val).equal(5);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const { steps } = leg;
|
|
49
|
+
for (let i = 0; i < steps.length; i++) {
|
|
50
|
+
if (i <= 5) {
|
|
51
|
+
expect(steps[i].coords.level.val).equal(10);
|
|
52
|
+
} else {
|
|
53
|
+
expect(steps[i].coords.level.val).equal(5);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
});
|
|
60
|
+
|
|
@@ -7,6 +7,7 @@ import DeutscheBahnRemoteRouter from './deutsche-bahn/DeutscheBahnRemoteRouter.j
|
|
|
7
7
|
import IdfmRemoteRouter from './idfm/IdfmRemoteRouter.js';
|
|
8
8
|
import OsrmRemoteRouter from './osrm/OsrmRemoteRouter.js';
|
|
9
9
|
import OtpRemoteRouter from './otp/OtpRemoteRouter.js';
|
|
10
|
+
import WemapMetaRemoteRouter from './wemap-meta/WemapMetaRemoteRouter.js';
|
|
10
11
|
import RemoteRouterOptions from './RemoteRouterOptions.js';
|
|
11
12
|
import RemoteRouterServerUnreachable from './RemoteRouterServerUnreachable.js';
|
|
12
13
|
import RoutingModeCorrespondanceNotFound from './RoutingModeCorrespondanceNotFound.js';
|
|
@@ -23,7 +24,8 @@ class RemoteRouterManager {
|
|
|
23
24
|
DeutscheBahnRemoteRouter,
|
|
24
25
|
IdfmRemoteRouter,
|
|
25
26
|
OsrmRemoteRouter,
|
|
26
|
-
OtpRemoteRouter
|
|
27
|
+
OtpRemoteRouter,
|
|
28
|
+
WemapMetaRemoteRouter
|
|
27
29
|
];
|
|
28
30
|
|
|
29
31
|
/**
|
|
@@ -118,6 +118,8 @@ class WemapMetaRouter {
|
|
|
118
118
|
routerResponse.from = start;
|
|
119
119
|
routerResponse.to = end;
|
|
120
120
|
|
|
121
|
+
/** @type {Itinerary} */
|
|
122
|
+
let ioMapItinerary;
|
|
121
123
|
|
|
122
124
|
// Find the first map where the "start" is inside.
|
|
123
125
|
const mapWithStart = ioMapsToTest.find(map => map.isPointInside(start));
|
|
@@ -134,9 +136,17 @@ class WemapMetaRouter {
|
|
|
134
136
|
*/
|
|
135
137
|
if (mapWithStart && mapWithStart.isPointInside(end)) {
|
|
136
138
|
|
|
137
|
-
|
|
139
|
+
try {
|
|
140
|
+
ioMapItinerary = mapWithStart.getItineraryInsideMap(start, end, wemapRouterOptions);
|
|
141
|
+
} catch (e) {
|
|
142
|
+
if (!(e instanceof NoRouteFoundError)) {
|
|
143
|
+
throw e;
|
|
144
|
+
}
|
|
145
|
+
routerResponse.error = `${e.message} - on map ${mapWithStart.name}.`;
|
|
146
|
+
return routerResponse;
|
|
147
|
+
}
|
|
138
148
|
|
|
139
|
-
routerResponse.itineraries.push(
|
|
149
|
+
routerResponse.itineraries.push(ioMapItinerary);
|
|
140
150
|
routerResponse.routerName = [this.rname, WemapRouter.rname];
|
|
141
151
|
|
|
142
152
|
return routerResponse;
|
|
@@ -158,8 +168,6 @@ class WemapMetaRouter {
|
|
|
158
168
|
/** @type {RouterResponse} */
|
|
159
169
|
let remoteRouterResponse;
|
|
160
170
|
|
|
161
|
-
/** @type {Itinerary} */
|
|
162
|
-
let ioMapItinerary;
|
|
163
171
|
|
|
164
172
|
/**
|
|
165
173
|
* Case 3
|