@wemap/routers 12.7.4 → 12.7.6
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/assets/itinerary-paris-idfm-2.json +1032 -26921
- package/assets/itinerary-paris-idfm.json +25421 -7140
- package/dist/index.js +45 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/graph/Graph.ts +17 -4
- package/src/model/TransitMode.spec.ts +1 -1
- package/src/model/TransitMode.ts +10 -1
- package/src/remote/idfm/IdfmRemoteRouter.spec.ts +46 -34
- package/src/remote/idfm/IdfmRemoteRouter.ts +61 -11
package/dist/index.mjs
CHANGED
|
@@ -139,6 +139,18 @@ class Graph {
|
|
|
139
139
|
const useAcceptEdgeFn = "acceptEdgeFn" in options;
|
|
140
140
|
const useMultiLevelSegments = !("useMultiLevelSegments" in options) || options.useMultiLevelSegments;
|
|
141
141
|
let bestProjection = null;
|
|
142
|
+
const adaptProjectionCoords = (projCoords) => {
|
|
143
|
+
if (!(origin instanceof UserPosition))
|
|
144
|
+
return projCoords;
|
|
145
|
+
const p = origin.clone();
|
|
146
|
+
p.lat = projCoords.lat;
|
|
147
|
+
p.lng = projCoords.lng;
|
|
148
|
+
p.level = projCoords.level;
|
|
149
|
+
p.alt = projCoords.alt;
|
|
150
|
+
p.heightFromFloor = projCoords.heightFromFloor;
|
|
151
|
+
p.heightFromGround = projCoords.heightFromGround;
|
|
152
|
+
return p;
|
|
153
|
+
};
|
|
142
154
|
this.edges.forEach((edge) => {
|
|
143
155
|
if (useAcceptEdgeFn && !options.acceptEdgeFn(edge))
|
|
144
156
|
return;
|
|
@@ -157,7 +169,7 @@ class Graph {
|
|
|
157
169
|
if (useMaxDistance && distanceToSegment > maxDistance)
|
|
158
170
|
return;
|
|
159
171
|
if (distanceToSegment < ((bestProjection == null ? void 0 : bestProjection.distanceFromNearestElement) ?? Number.MAX_VALUE)) {
|
|
160
|
-
bestProjection = new GraphProjection(origin, distanceToSegment, segmentProjection, edge);
|
|
172
|
+
bestProjection = new GraphProjection(origin, distanceToSegment, adaptProjectionCoords(segmentProjection), edge);
|
|
161
173
|
}
|
|
162
174
|
});
|
|
163
175
|
if (useMaxBearingAngle) {
|
|
@@ -175,13 +187,13 @@ class Graph {
|
|
|
175
187
|
return;
|
|
176
188
|
const distanceToVertex = vertexCoords.distanceTo(origin);
|
|
177
189
|
if (distanceToVertex < Constants.EPS_MM) {
|
|
178
|
-
bestProjection = new GraphProjection(origin, 0, vertexCoords, vertex);
|
|
190
|
+
bestProjection = new GraphProjection(origin, 0, adaptProjectionCoords(vertexCoords), vertex);
|
|
179
191
|
return;
|
|
180
192
|
}
|
|
181
193
|
if (useMaxDistance && distanceToVertex > maxDistance)
|
|
182
194
|
return;
|
|
183
195
|
if (distanceToVertex < ((bestProjection == null ? void 0 : bestProjection.distanceFromNearestElement) ?? Number.MAX_VALUE)) {
|
|
184
|
-
bestProjection = new GraphProjection(origin, distanceToVertex, vertexCoords, vertex);
|
|
196
|
+
bestProjection = new GraphProjection(origin, distanceToVertex, adaptProjectionCoords(vertexCoords), vertex);
|
|
185
197
|
}
|
|
186
198
|
});
|
|
187
199
|
return bestProjection;
|
|
@@ -308,7 +320,7 @@ function isTransitModePublicTransport(transitMode) {
|
|
|
308
320
|
].includes(transitMode);
|
|
309
321
|
}
|
|
310
322
|
function areTransitAndTravelModeConsistent(transitMode, travelMode) {
|
|
311
|
-
return transitMode === travelMode || isTransitModePublicTransport(transitMode) && travelMode === "TRANSIT";
|
|
323
|
+
return transitMode === travelMode || isTransitModePublicTransport(transitMode) && travelMode === "TRANSIT" || transitMode === "WALK" && travelMode === "TRANSIT";
|
|
312
324
|
}
|
|
313
325
|
function stepToJson(step) {
|
|
314
326
|
return {
|
|
@@ -3420,6 +3432,16 @@ class IdfmRemoteRouter extends RemoteRouter {
|
|
|
3420
3432
|
}
|
|
3421
3433
|
return outputSteps;
|
|
3422
3434
|
}
|
|
3435
|
+
findStepCoords(step, section) {
|
|
3436
|
+
var _a;
|
|
3437
|
+
if ("instruction_start_coordinate" in step) {
|
|
3438
|
+
return jsonToCoordinates$1(step.instruction_start_coordinate);
|
|
3439
|
+
}
|
|
3440
|
+
const via = (_a = section.vias) == null ? void 0 : _a.find((via2) => via2.id === step.via_uri);
|
|
3441
|
+
if (via) {
|
|
3442
|
+
return jsonToCoordinates$1(via.access_point.coord);
|
|
3443
|
+
}
|
|
3444
|
+
}
|
|
3423
3445
|
parseResponse(json) {
|
|
3424
3446
|
var _a;
|
|
3425
3447
|
if (!json || !json.journeys) {
|
|
@@ -3446,14 +3468,28 @@ class IdfmRemoteRouter extends RemoteRouter {
|
|
|
3446
3468
|
let transportInfo;
|
|
3447
3469
|
let transitMode = transitModeCorrespondance.get(jsonSection.mode);
|
|
3448
3470
|
if (jsonSection.path) {
|
|
3471
|
+
const useIDFMSteps = jsonSection.path.every((step) => "instruction_start_coordinate" in step || step.via_uri);
|
|
3449
3472
|
const idfmIntermediateSteps = [];
|
|
3450
3473
|
for (const jsonPathLink of jsonSection.path) {
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3474
|
+
let coords;
|
|
3475
|
+
if (useIDFMSteps) {
|
|
3476
|
+
coords = this.findStepCoords(jsonPathLink, jsonSection);
|
|
3477
|
+
const intermediateStep = {
|
|
3478
|
+
name: jsonPathLink.name,
|
|
3479
|
+
distance: jsonPathLink.length,
|
|
3480
|
+
coords
|
|
3481
|
+
};
|
|
3482
|
+
stepsBuilder.addStepInfo(intermediateStep);
|
|
3483
|
+
} else {
|
|
3484
|
+
idfmIntermediateSteps.push({
|
|
3485
|
+
name: jsonPathLink.name,
|
|
3486
|
+
distance: jsonPathLink.length
|
|
3487
|
+
});
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
if (!useIDFMSteps) {
|
|
3491
|
+
stepsBuilder.setStepsInfo(this.findStepsCoord(legCoords, idfmIntermediateSteps));
|
|
3455
3492
|
}
|
|
3456
|
-
stepsBuilder.setStepsInfo(this.findStepsCoord(legCoords, idfmIntermediateSteps));
|
|
3457
3493
|
}
|
|
3458
3494
|
if (jsonSection.type === "public_transport") {
|
|
3459
3495
|
transportInfo = {
|