@wemap/routers 7.2.1 → 7.2.3
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 +2 -2
- package/src/remote/RemoteRouterOptions.js +4 -2
- package/src/remote/cityway/CitywayRemoteRouter.js +7 -5
- package/src/remote/deutsche-bahn/DeutscheBahnRemoteRouter.js +7 -5
- package/src/remote/idfm/IdfmRemoteRouter.js +16 -24
- package/src/remote/osrm/OsrmRemoteRouter.js +8 -4
- package/src/remote/otp/OtpRemoteRouter.js +7 -5
- package/src/remote/wemap-meta/WemapMetaRemoteRouter.js +8 -6
- package/src/remote/wemap-meta/WemapMetaRemoteRouterOptions.js +4 -2
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"directory": "packages/routers"
|
|
12
12
|
},
|
|
13
13
|
"name": "@wemap/routers",
|
|
14
|
-
"version": "7.2.
|
|
14
|
+
"version": "7.2.3",
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
17
17
|
},
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"@wemap/maths": "^7.0.0",
|
|
35
35
|
"@wemap/osm": "^7.2.1"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "a80867c434ebd266c2955a61dd2c662f1728aa3d"
|
|
38
38
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
class RemoteRouterOptions {
|
|
2
2
|
|
|
3
|
-
/** @type {boolean} */
|
|
3
|
+
/** @type {!boolean} */
|
|
4
4
|
useStairs = true;
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -16,7 +16,9 @@ class RemoteRouterOptions {
|
|
|
16
16
|
*/
|
|
17
17
|
static fromJson(json) {
|
|
18
18
|
const obj = new RemoteRouterOptions();
|
|
19
|
-
|
|
19
|
+
if ('useStairs' in json) {
|
|
20
|
+
obj.useStairs = json.useStairs;
|
|
21
|
+
}
|
|
20
22
|
return obj;
|
|
21
23
|
}
|
|
22
24
|
|
|
@@ -93,12 +93,14 @@ class CitywayRemoteRouter extends RemoteRouter {
|
|
|
93
93
|
*/
|
|
94
94
|
async getItineraries(endpointUrl, mode, waypoints) {
|
|
95
95
|
const url = this.getURL(endpointUrl, mode, waypoints);
|
|
96
|
-
const res = await fetch(url)
|
|
97
|
-
if (res.status !== 200) {
|
|
96
|
+
const res = await (fetch(url).catch(() => {
|
|
98
97
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
}));
|
|
99
|
+
|
|
100
|
+
const jsonResponse = await res.json().catch(() => {
|
|
101
|
+
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
102
|
+
});
|
|
103
|
+
return this.createRouterResponseFromJson(jsonResponse);
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
|
|
@@ -28,12 +28,14 @@ class DeutscheBahnRemoteRouter extends RemoteRouter {
|
|
|
28
28
|
*/
|
|
29
29
|
async getItineraries(endpointUrl, mode, waypoints) {
|
|
30
30
|
const url = this.getURL(endpointUrl, mode, waypoints);
|
|
31
|
-
const res = await fetch(url)
|
|
32
|
-
if (res.status !== 200) {
|
|
31
|
+
const res = await (fetch(url).catch(() => {
|
|
33
32
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
const jsonResponse = await res.json().catch(() => {
|
|
36
|
+
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
37
|
+
});
|
|
38
|
+
return this.createRouterResponseFromJson(jsonResponse, waypoints[0], waypoints[1]);
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
/**
|
|
@@ -111,31 +111,23 @@ class IdfmRemoteRouter extends RemoteRouter {
|
|
|
111
111
|
}));
|
|
112
112
|
|
|
113
113
|
|
|
114
|
-
const
|
|
114
|
+
const jsonResponse = await res.json().catch(() => {
|
|
115
115
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
116
116
|
});
|
|
117
117
|
|
|
118
118
|
// When IDFM failed to calculate an itinerary (ie. start or end
|
|
119
119
|
// point is far from network), it respond a 404 with an error message
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (response && 'error' in response && 'message' in response.error) {
|
|
123
|
-
errorMessage = response.error.message;
|
|
124
|
-
}
|
|
125
|
-
|
|
120
|
+
// or a 200 with an error message
|
|
121
|
+
if (jsonResponse && jsonResponse.error) {
|
|
126
122
|
const routerResponse = new RouterResponse();
|
|
127
123
|
routerResponse.routerName = this.rname;
|
|
128
124
|
routerResponse.from = waypoints[0];
|
|
129
125
|
routerResponse.to = waypoints[1];
|
|
130
|
-
routerResponse.error =
|
|
126
|
+
routerResponse.error = jsonResponse.error.message || 'no details.';
|
|
131
127
|
return routerResponse;
|
|
132
128
|
}
|
|
133
129
|
|
|
134
|
-
|
|
135
|
-
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return this.createRouterResponseFromJson(response);
|
|
130
|
+
return this.createRouterResponseFromJson(jsonResponse);
|
|
139
131
|
}
|
|
140
132
|
|
|
141
133
|
/**
|
|
@@ -204,17 +196,17 @@ class IdfmRemoteRouter extends RemoteRouter {
|
|
|
204
196
|
|
|
205
197
|
let query = '';
|
|
206
198
|
switch (mode) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
199
|
+
case Constants.ROUTING_MODE.WALK:
|
|
200
|
+
query = this.getWalkingQuery();
|
|
201
|
+
break;
|
|
202
|
+
case Constants.ROUTING_MODE.BIKE:
|
|
203
|
+
query = this.getBikeQuery();
|
|
204
|
+
break;
|
|
205
|
+
case Constants.ROUTING_MODE.CAR:
|
|
206
|
+
query = this.getCarQuery();
|
|
207
|
+
break;
|
|
208
|
+
default:
|
|
209
|
+
break;
|
|
218
210
|
}
|
|
219
211
|
|
|
220
212
|
url = `${url.origin}${url.pathname}${search}${query}`;
|
|
@@ -44,11 +44,15 @@ class OsrmRemoteRouter extends RemoteRouter {
|
|
|
44
44
|
*/
|
|
45
45
|
async getItineraries(endpointUrl, mode, waypoints) {
|
|
46
46
|
const url = this.getURL(endpointUrl, mode, waypoints);
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
|
|
48
|
+
const res = await (fetch(url).catch(() => {
|
|
49
49
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
50
|
-
}
|
|
51
|
-
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
const response = await res.json().catch(() => {
|
|
53
|
+
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
54
|
+
});
|
|
55
|
+
|
|
52
56
|
return this.createRouterResponseFromJson(response, waypoints[0], waypoints[1]);
|
|
53
57
|
}
|
|
54
58
|
|
|
@@ -43,12 +43,14 @@ class OtpRemoteRouter extends RemoteRouter {
|
|
|
43
43
|
*/
|
|
44
44
|
async getItineraries(endpointUrl, mode, waypoints) {
|
|
45
45
|
const url = this.getURL(endpointUrl, mode, waypoints);
|
|
46
|
-
const res = await fetch(url)
|
|
47
|
-
if (res.status !== 200) {
|
|
46
|
+
const res = await (fetch(url).catch(() => {
|
|
48
47
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
const jsonResponse = await res.json().catch(() => {
|
|
51
|
+
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
52
|
+
});
|
|
53
|
+
return this.createRouterResponseFromJson(jsonResponse);
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
/**
|
|
@@ -37,20 +37,22 @@ class WemapMetaRemoteRouter extends RemoteRouter {
|
|
|
37
37
|
payload.mode = mode;
|
|
38
38
|
payload.options = options;
|
|
39
39
|
|
|
40
|
-
const res = await fetch(endpointUrl, {
|
|
40
|
+
const res = await (fetch(endpointUrl, {
|
|
41
41
|
method: 'POST',
|
|
42
42
|
headers: {
|
|
43
43
|
'Accept': 'application/json',
|
|
44
44
|
'Content-Type': 'application/json'
|
|
45
45
|
},
|
|
46
46
|
body: JSON.stringify(payload.toJson())
|
|
47
|
-
})
|
|
47
|
+
}).catch(() => {
|
|
48
|
+
throw new RemoteRouterServerUnreachable(this.rname, endpointUrl);
|
|
49
|
+
}));
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
const jsonResponse = await res.json().catch(() => {
|
|
50
52
|
throw new RemoteRouterServerUnreachable(this.rname, endpointUrl);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return RouterResponse.fromJson(
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return RouterResponse.fromJson(jsonResponse);
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
}
|
|
@@ -28,8 +28,10 @@ class WemapMetaRemoteRouterOptions extends RemoteRouterOptions {
|
|
|
28
28
|
*/
|
|
29
29
|
static fromJson(json) {
|
|
30
30
|
const obj = new WemapMetaRemoteRouterOptions();
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
if ('useStairs' in json) {
|
|
32
|
+
obj.useStairs = json.useStairs;
|
|
33
|
+
}
|
|
34
|
+
obj.remoteRouters = json.remoteRouters ? json.remoteRouters : [];
|
|
33
35
|
obj.targetMaps = json.targetMaps ? json.targetMaps : null;
|
|
34
36
|
return obj;
|
|
35
37
|
}
|