mobility-toolbox-js 1.7.5-beta.1 → 1.7.5-beta.2
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.
|
@@ -30,6 +30,8 @@ const REGEX_VIA_POINT_COORD = /^([\d.]+),([\d.]+)$/;
|
|
|
30
30
|
// !8596126$4 a station with id 8596126
|
|
31
31
|
const REGEX_VIA_POINT_STATION_ID = /^!([^$]*)(\$?([a-zA-Z0-9]{0,2}))$/;
|
|
32
32
|
|
|
33
|
+
const STOP_FETCH_ABORT_CONTROLLER_KEY = 'stop-fetch';
|
|
34
|
+
|
|
33
35
|
const getFlatCoordinatesFromSegments = (segmentArray) => {
|
|
34
36
|
const coords = [];
|
|
35
37
|
segmentArray.forEach((seg) => {
|
|
@@ -255,7 +257,7 @@ class RoutingControl extends Control {
|
|
|
255
257
|
*/
|
|
256
258
|
reset() {
|
|
257
259
|
// Clear viaPoints and source
|
|
258
|
-
this.
|
|
260
|
+
this.abortRequests();
|
|
259
261
|
this.viaPoints = [];
|
|
260
262
|
this.routingLayer.olLayer.getSource().clear();
|
|
261
263
|
this.dispatchEvent({
|
|
@@ -265,17 +267,24 @@ class RoutingControl extends Control {
|
|
|
265
267
|
}
|
|
266
268
|
|
|
267
269
|
/**
|
|
268
|
-
* Aborts
|
|
270
|
+
* Aborts viapoint and route requests
|
|
269
271
|
* @private
|
|
270
272
|
*/
|
|
271
|
-
|
|
272
|
-
|
|
273
|
+
abortRequests() {
|
|
274
|
+
// Abort Routing API requests
|
|
273
275
|
this.graphs.forEach(([graph]) => {
|
|
274
276
|
if (this.abortControllers[graph]) {
|
|
275
277
|
this.abortControllers[graph].abort();
|
|
276
278
|
}
|
|
277
279
|
this.abortControllers[graph] = new AbortController();
|
|
278
280
|
});
|
|
281
|
+
|
|
282
|
+
// Abort Stops API requests
|
|
283
|
+
this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]?.abort();
|
|
284
|
+
this.abortControllers[
|
|
285
|
+
STOP_FETCH_ABORT_CONTROLLER_KEY
|
|
286
|
+
] = new AbortController();
|
|
287
|
+
|
|
279
288
|
this.loading = false;
|
|
280
289
|
}
|
|
281
290
|
|
|
@@ -288,7 +297,8 @@ class RoutingControl extends Control {
|
|
|
288
297
|
*/
|
|
289
298
|
drawRoute() {
|
|
290
299
|
/* Calls RoutingAPI to draw a route using the viaPoints array */
|
|
291
|
-
this.
|
|
300
|
+
this.abortRequests();
|
|
301
|
+
this.routingLayer.olLayer.getSource().clear();
|
|
292
302
|
|
|
293
303
|
if (!this.viaPoints.length) {
|
|
294
304
|
return null;
|
|
@@ -296,7 +306,11 @@ class RoutingControl extends Control {
|
|
|
296
306
|
|
|
297
307
|
if (this.viaPoints.length === 1) {
|
|
298
308
|
// Add point for first node
|
|
299
|
-
return this.drawViaPoint(
|
|
309
|
+
return this.drawViaPoint(
|
|
310
|
+
this.viaPoints[0],
|
|
311
|
+
0,
|
|
312
|
+
this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY],
|
|
313
|
+
);
|
|
300
314
|
}
|
|
301
315
|
|
|
302
316
|
const formattedViaPoints = this.viaPoints.map((viaPoint) => {
|
|
@@ -318,7 +332,13 @@ class RoutingControl extends Control {
|
|
|
318
332
|
this.routingLayer.olLayer.getSource().clear();
|
|
319
333
|
|
|
320
334
|
// Create point features for the viaPoints
|
|
321
|
-
this.viaPoints.forEach((viaPoint, idx) =>
|
|
335
|
+
this.viaPoints.forEach((viaPoint, idx) =>
|
|
336
|
+
this.drawViaPoint(
|
|
337
|
+
viaPoint,
|
|
338
|
+
idx,
|
|
339
|
+
this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY],
|
|
340
|
+
),
|
|
341
|
+
);
|
|
322
342
|
|
|
323
343
|
return Promise.all(
|
|
324
344
|
this.graphs.map(([graph], index) => {
|
|
@@ -403,7 +423,7 @@ class RoutingControl extends Control {
|
|
|
403
423
|
*
|
|
404
424
|
* @private
|
|
405
425
|
*/
|
|
406
|
-
drawViaPoint(viaPoint, idx) {
|
|
426
|
+
drawViaPoint(viaPoint, idx, abortController) {
|
|
407
427
|
const pointFeature = new Feature();
|
|
408
428
|
pointFeature.set('viaPointIdx', idx);
|
|
409
429
|
|
|
@@ -429,6 +449,7 @@ class RoutingControl extends Control {
|
|
|
429
449
|
|
|
430
450
|
return fetch(
|
|
431
451
|
`${this.stopsApiUrl}lookup/${stationId}?key=${this.stopsApiKey}`,
|
|
452
|
+
{ signal: abortController.signal },
|
|
432
453
|
)
|
|
433
454
|
.then((res) => res.json())
|
|
434
455
|
.then((stationData) => {
|
|
@@ -440,6 +461,10 @@ class RoutingControl extends Control {
|
|
|
440
461
|
return pointFeature;
|
|
441
462
|
})
|
|
442
463
|
.catch((error) => {
|
|
464
|
+
if (error.name === 'AbortError') {
|
|
465
|
+
// Ignore abort error
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
443
468
|
// Dispatch error event and execute error function
|
|
444
469
|
this.dispatchEvent({
|
|
445
470
|
type: 'error',
|
|
@@ -489,6 +514,7 @@ class RoutingControl extends Control {
|
|
|
489
514
|
if (stationName) {
|
|
490
515
|
return fetch(
|
|
491
516
|
`${this.stopsApiUrl}?key=${this.stopsApiKey}&q=${stationName}&limit=1`,
|
|
517
|
+
{ signal: abortController.signal },
|
|
492
518
|
)
|
|
493
519
|
.then((res) => res.json())
|
|
494
520
|
.then((stationData) => {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "mobility-toolbox-js",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"description": "Toolbox for JavaScript applications in the domains of mobility and logistics.",
|
|
5
|
-
"version": "1.7.5-beta.
|
|
5
|
+
"version": "1.7.5-beta.2",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"module": "module.js",
|
|
8
8
|
"dependencies": {
|