@wemap/routers 11.1.1 → 11.2.1

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 CHANGED
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/routers"
13
13
  },
14
14
  "name": "@wemap/routers",
15
- "version": "11.1.1",
15
+ "version": "11.2.1",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-modules-js/issues"
18
18
  },
@@ -52,5 +52,5 @@
52
52
  },
53
53
  "./helpers/*": "./helpers/*"
54
54
  },
55
- "gitHead": "1fe2ac803a61d5cdb1e3f26185aaeb431bfb482f"
55
+ "gitHead": "e8ba0bc0c26f2167896f7c5ce4b0ebfd39aa2f13"
56
56
  }
@@ -10,6 +10,7 @@ import RemoteRouter from '../RemoteRouter.js';
10
10
  import RemoteRouterServerUnreachable from '../RemoteRouterServerUnreachable.js';
11
11
  import { RoutingMode } from '../../model/RoutingMode.js';
12
12
  import { MinStepInfo } from '../../model/Step.js';
13
+ import { RemoteRouterOptions } from '../RemoteRouterOptions.js';
13
14
 
14
15
  type IdfmCoordinates = { lat: number, lon: number };
15
16
  type IdfmSection = {
@@ -160,8 +161,8 @@ class IdfmRemoteRouter extends RemoteRouter {
160
161
  * @throws {IdfmRemoteRouterTokenError}
161
162
  * @throws {RemoteRouterServerUnreachable}
162
163
  */
163
- async getItineraries(endpointUrl: string, mode: RoutingMode, waypoints: Coordinates[]) {
164
- const url = this.getURL(endpointUrl, mode, waypoints);
164
+ async getItineraries(endpointUrl: string, mode: RoutingMode, waypoints: Coordinates[], options: RemoteRouterOptions = {}) {
165
+ const url = this.getURL(endpointUrl, mode, waypoints, options);
165
166
 
166
167
  const res = await (fetch(url, {
167
168
  method: 'GET',
@@ -190,56 +191,85 @@ class IdfmRemoteRouter extends RemoteRouter {
190
191
  return this.createRouterResponseFromJson(jsonResponse, waypoints[0], waypoints[1]);
191
192
  }
192
193
 
193
- getURL(endpointUrl: string, mode: RoutingMode, waypoints: Coordinates[]) {
194
+ getURL(endpointUrl: string, mode: RoutingMode, waypoints: Coordinates[], options: RemoteRouterOptions) {
194
195
 
195
196
  if (waypoints.length > 2) {
196
197
  Logger.warn(`${this.rname} router uses only the first 2 waypoints (asked ${waypoints.length})`);
197
198
  }
198
199
 
199
- const fromPlace = `from=${waypoints[0].longitude};${waypoints[0].latitude}`;
200
- const toPlace = `to=${waypoints[1].longitude};${waypoints[1].latitude}`;
201
-
202
200
  const url = new URL(endpointUrl);
203
- let { search } = url;
204
- search = (search ? `${search}&` : '?') + `${fromPlace}&${toPlace}`;
205
201
 
206
- let query = '';
202
+ const coreParams = new URLSearchParams();
203
+ coreParams.set('from', `${waypoints[0].longitude};${waypoints[0].latitude}`);
204
+ coreParams.set('to', `${waypoints[1].longitude};${waypoints[1].latitude}`);
205
+
206
+ if ('useStairs' in options && !options.useStairs) {
207
+ coreParams.set('wheelchair', 'true')
208
+ }
209
+
210
+ let queryParams: URLSearchParams = new URLSearchParams();
207
211
  switch (mode) {
208
212
  case 'WALK':
209
- query = this.getWalkingQuery();
213
+ queryParams = this.getWalkingQuery();
210
214
  break;
211
215
  case 'BIKE':
212
- query = this.getBikeQuery();
216
+ queryParams = this.getBikeQuery();
213
217
  break;
214
218
  case 'CAR':
215
- query = this.getCarQuery();
219
+ queryParams = this.getCarQuery();
216
220
  break;
217
221
  default:
218
222
  break;
219
223
  }
220
224
 
221
- return `${url.origin}${url.pathname}${search}${query}`;
225
+ [coreParams, queryParams].map(params => {
226
+ for (const pair of params.entries()) {
227
+ url.searchParams.append(pair[0], pair[1]);
228
+ }
229
+ });
230
+
231
+ return url.toString();
222
232
  }
223
233
 
224
234
  getCarQuery() {
225
- const forbiddenTransport = TRANSPORT_IDS.map((id) => `forbidden_uris[]=${id}`).join('&');
226
- const allowCar = 'first_section_mode[]=walking&first_section_mode[]=car&last_section_mode[]=walking&last_section_mode[]=car';
235
+ const urlSearchParams = new URLSearchParams();
236
+
237
+ TRANSPORT_IDS.forEach((id) => {
238
+ urlSearchParams.append('forbidden_uris[]', id);
239
+ });
240
+
241
+ urlSearchParams.append('first_section_mode[]', 'walking');
242
+ urlSearchParams.append('first_section_mode[]', 'car');
243
+ urlSearchParams.append('last_section_mode[]', 'walking');
244
+ urlSearchParams.append('last_section_mode[]', 'car');
227
245
 
228
- return `&${forbiddenTransport}&${allowCar}`;
246
+ return urlSearchParams;
229
247
  }
230
248
 
231
249
  getWalkingQuery() {
232
- const forbiddenTransport = TRANSPORT_IDS.map((id) => `forbidden_uris[]=${id}`).join('&');
233
- const allowWalking = 'first_section_mode[]=walking&last_section_mode[]=walking';
250
+ const urlSearchParams = new URLSearchParams();
251
+
252
+ TRANSPORT_IDS.forEach((id) => {
253
+ urlSearchParams.append('forbidden_uris[]', id);
254
+ });
234
255
 
235
- return `&${forbiddenTransport}&${allowWalking}`;
256
+ urlSearchParams.append('first_section_mode[]', 'walking');
257
+ urlSearchParams.append('last_section_mode[]', 'walking');
258
+
259
+ return urlSearchParams;
236
260
  }
237
261
 
238
262
  getBikeQuery() {
239
- const forbiddenTransport = TRANSPORT_IDS.map((id) => `forbidden_uris[]=${id}`).join('&');
240
- const allowBike = 'first_section_mode[]=bike&last_section_mode[]=bike';
263
+ const urlSearchParams = new URLSearchParams();
264
+
265
+ TRANSPORT_IDS.forEach((id) => {
266
+ urlSearchParams.append('forbidden_uris[]', id);
267
+ });
268
+
269
+ urlSearchParams.append('first_section_mode[]', 'bike');
270
+ urlSearchParams.append('last_section_mode[]', 'bike');
241
271
 
242
- return `&${forbiddenTransport}&${allowBike}`;
272
+ return urlSearchParams;
243
273
  }
244
274
 
245
275