@wemap/routers 7.2.2 → 7.3.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/package.json +4 -4
- 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 +4 -4
- package/src/remote/osrm/OsrmRemoteRouter.js +9 -5
- 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.
|
|
14
|
+
"version": "7.3.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.3.0",
|
|
33
33
|
"@wemap/logger": "^7.0.0",
|
|
34
34
|
"@wemap/maths": "^7.0.0",
|
|
35
|
-
"@wemap/osm": "^7.
|
|
35
|
+
"@wemap/osm": "^7.3.0"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "c79062ac53248f45aead5d4edd45b3efbc79755e"
|
|
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,23 +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
120
|
// or a 200 with an error message
|
|
121
|
-
if (
|
|
121
|
+
if (jsonResponse && jsonResponse.error) {
|
|
122
122
|
const routerResponse = new RouterResponse();
|
|
123
123
|
routerResponse.routerName = this.rname;
|
|
124
124
|
routerResponse.from = waypoints[0];
|
|
125
125
|
routerResponse.to = waypoints[1];
|
|
126
|
-
routerResponse.error =
|
|
126
|
+
routerResponse.error = jsonResponse.error.message || 'no details.';
|
|
127
127
|
return routerResponse;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
return this.createRouterResponseFromJson(
|
|
130
|
+
return this.createRouterResponseFromJson(jsonResponse);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
/**
|
|
@@ -44,12 +44,16 @@ 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
|
-
|
|
52
|
-
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
const jsonResponse = await res.json().catch(() => {
|
|
53
|
+
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return this.createRouterResponseFromJson(jsonResponse, waypoints[0], waypoints[1]);
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
/**
|
|
@@ -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
|
}
|