@wemap/routers 12.10.1 → 12.10.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/dist/index.js +4 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/ItineraryInfoManager.ts +1 -5
- package/src/model/Itinerary.ts +3 -25
- package/src/remote/cityway/CitywayRemoteRouter.spec.ts +1 -1
- package/src/remote/geovelo/GeoveloRemoteRouter.spec.ts +1 -1
- package/src/remote/osrm/OsrmRemoteRouter.spec.ts +1 -1
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/routers"
|
|
13
13
|
},
|
|
14
14
|
"name": "@wemap/routers",
|
|
15
|
-
"version": "12.10.
|
|
15
|
+
"version": "12.10.3",
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
18
18
|
},
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
},
|
|
54
54
|
"./helpers/*": "./helpers/*"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "910c64e846fe88b4e9c7a0b1f52fb3e2b96d4f46"
|
|
57
57
|
}
|
|
@@ -54,11 +54,7 @@ class ItineraryInfoManager {
|
|
|
54
54
|
this._coordsPreviousStep = new Array(itinerary.coords.length);
|
|
55
55
|
this._coordsDistanceTraveled = new Array(itinerary.coords.length);
|
|
56
56
|
this._coordsLeg = new Array(itinerary.coords.length);
|
|
57
|
-
|
|
58
|
-
const destinationProjectionDistance = this._itinerary.destination.distanceTo(this._itinerary.coords[this._itinerary.coords.length - 1]);
|
|
59
|
-
this._itineraryDistanceWithoutProjections = itinerary.distance
|
|
60
|
-
- originProjectionDistance
|
|
61
|
-
- destinationProjectionDistance;
|
|
57
|
+
this._itineraryDistanceWithoutProjections = itinerary.distance;
|
|
62
58
|
|
|
63
59
|
let stepId = 0;
|
|
64
60
|
let previousStep: Step | null = null;
|
package/src/model/Itinerary.ts
CHANGED
|
@@ -64,13 +64,7 @@ export default class Itinerary {
|
|
|
64
64
|
if (typeof duration === 'number') {
|
|
65
65
|
this.duration = duration;
|
|
66
66
|
} else {
|
|
67
|
-
|
|
68
|
-
const lastLeg = this.legs[this.legs.length - 1];
|
|
69
|
-
const lastCoords = lastLeg.coords[lastLeg.coords.length - 1];
|
|
70
|
-
// Projection duration is calculated using walking mode
|
|
71
|
-
const originProjectionDuration = getDurationFromLength(this.origin.distanceTo(firstCoords));
|
|
72
|
-
const destinationProjectionDuration = getDurationFromLength(this.destination.distanceTo(lastCoords));
|
|
73
|
-
this.duration = this.legs.reduce((dur, leg) => dur + leg.duration, originProjectionDuration + destinationProjectionDuration);
|
|
67
|
+
this.duration = this.legs.reduce((dur, leg) => dur + leg.duration, 0);
|
|
74
68
|
}
|
|
75
69
|
this.startTime = typeof startTime === 'number' ? startTime : null;
|
|
76
70
|
this.endTime = typeof endTime === 'number' ? endTime : null;
|
|
@@ -139,7 +133,7 @@ export default class Itinerary {
|
|
|
139
133
|
|
|
140
134
|
get distance() {
|
|
141
135
|
if (this._distance === null) {
|
|
142
|
-
this._distance = GeoUtils.calcDistance(
|
|
136
|
+
this._distance = GeoUtils.calcDistance(this.coords);
|
|
143
137
|
}
|
|
144
138
|
return this._distance;
|
|
145
139
|
|
|
@@ -338,12 +332,12 @@ export default class Itinerary {
|
|
|
338
332
|
}
|
|
339
333
|
|
|
340
334
|
/**
|
|
335
|
+
* TODO: Remove it in router v3
|
|
341
336
|
* Update steps info thanks to the coordinates of the whole itinerary.
|
|
342
337
|
* This method will update:
|
|
343
338
|
* - all steps number
|
|
344
339
|
* - first/last steps
|
|
345
340
|
* - previousBearing/nextBearing/angle of first and last step of each leg
|
|
346
|
-
* - distance/duration of first and last step of each leg
|
|
347
341
|
*/
|
|
348
342
|
updateStepsFromLegs() {
|
|
349
343
|
|
|
@@ -368,25 +362,9 @@ export default class Itinerary {
|
|
|
368
362
|
step.nextBearing = step.coords.bearingTo(coordsAfterStep);
|
|
369
363
|
step.angle = diffAngle(step.previousBearing, step.nextBearing + Math.PI);
|
|
370
364
|
|
|
371
|
-
const stepDistanceBefore = step.distance;
|
|
372
|
-
step.distance = 0;
|
|
373
|
-
const coordsToStopCalculation = stepId !== steps.length - 1
|
|
374
|
-
? steps[stepId + 1].coords
|
|
375
|
-
: itineraryCoords[itineraryCoords.length - 1];
|
|
376
|
-
let currentCoordsId = coordsId;
|
|
377
|
-
while (!itineraryCoords[currentCoordsId].equals(coordsToStopCalculation)) {
|
|
378
|
-
step.distance += itineraryCoords[currentCoordsId].distanceTo(itineraryCoords[currentCoordsId + 1]);
|
|
379
|
-
currentCoordsId++;
|
|
380
|
-
}
|
|
381
|
-
if (currentCoordsId === itineraryCoords.length - 1) {
|
|
382
|
-
step.distance += itineraryCoords[currentCoordsId].distanceTo(this.destination);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
365
|
step.number = stepId + 1;
|
|
386
366
|
step.firstStep = stepId === 0;
|
|
387
367
|
step.lastStep = stepId === steps.length - 1;
|
|
388
|
-
|
|
389
|
-
step.duration += getDurationFromLength(step.distance - stepDistanceBefore)
|
|
390
368
|
});
|
|
391
369
|
}
|
|
392
370
|
}
|
|
@@ -31,7 +31,7 @@ describe('CitywayRemoteRouter - parseResponse', () => {
|
|
|
31
31
|
const itinerary1 = itineraries[0];
|
|
32
32
|
expect(itinerary1.origin.equals(new Coordinates(49.515093882362159, 0.093417496193663158))).true;
|
|
33
33
|
expect(itinerary1.destination.equals(new Coordinates(49.5067090188444, 0.16948421154178309))).true;
|
|
34
|
-
expect(itinerary1.distance).to.be.closeTo(
|
|
34
|
+
expect(itinerary1.distance).to.be.closeTo(6887, 1);
|
|
35
35
|
expect(itinerary1.duration).equal(2379);
|
|
36
36
|
expect(itinerary1.transitMode).equal('BUS');
|
|
37
37
|
// Do not work because of the input time format
|
|
@@ -31,7 +31,7 @@ describe('GeoveloRouter - parseResponse', () => {
|
|
|
31
31
|
const itinerary1 = itineraries[0];
|
|
32
32
|
expect(itinerary1.origin.equals(new Coordinates(43.596949, 3.877772))).true;
|
|
33
33
|
expect(itinerary1.destination.equals(new Coordinates(43.609609, 3.914684))).true;
|
|
34
|
-
expect(itinerary1.distance).to.be.closeTo(
|
|
34
|
+
expect(itinerary1.distance).to.be.closeTo(4029, 1);
|
|
35
35
|
expect(itinerary1.duration).equal(1053);
|
|
36
36
|
expect(itinerary1.transitMode).equal('BIKE');
|
|
37
37
|
// Do not work because of the input time format
|
|
@@ -37,7 +37,7 @@ describe('OsrmRemoteRouter - parseResponse', () => {
|
|
|
37
37
|
const itinerary1 = itineraries[0];
|
|
38
38
|
expect(itinerary1.origin.equals(origin)).true;
|
|
39
39
|
expect(itinerary1.destination.equals(destination)).true;
|
|
40
|
-
expect(itinerary1.distance).closeTo(
|
|
40
|
+
expect(itinerary1.distance).closeTo(400, 1);
|
|
41
41
|
expect(itinerary1.duration).equal(287.8);
|
|
42
42
|
expect(itinerary1.startTime).is.null;
|
|
43
43
|
expect(itinerary1.endTime).is.null;
|