@wemap/routers 12.7.1 → 12.7.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 +162 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +163 -6
- package/dist/index.mjs.map +1 -1
- package/index.ts +1 -0
- package/package.json +2 -2
- package/src/remote/RemoteRouterManager.spec.ts +178 -0
- package/src/remote/RemoteRouterManager.ts +20 -5
package/dist/index.js
CHANGED
|
@@ -3887,14 +3887,28 @@ class RemoteRouterManager {
|
|
|
3887
3887
|
}
|
|
3888
3888
|
async getItinerariesWithFallback(routerRequest, fallbackStrategy) {
|
|
3889
3889
|
let itineraries;
|
|
3890
|
+
const errors = [];
|
|
3890
3891
|
for (const { name, endpointUrl } of fallbackStrategy) {
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3892
|
+
try {
|
|
3893
|
+
itineraries = await this.getItineraries(name, endpointUrl, routerRequest);
|
|
3894
|
+
if (itineraries.length) {
|
|
3895
|
+
return itineraries;
|
|
3896
|
+
}
|
|
3897
|
+
} catch (error) {
|
|
3898
|
+
if (error instanceof RemoteRoutingError) {
|
|
3899
|
+
errors.push({
|
|
3900
|
+
name,
|
|
3901
|
+
endpointUrl,
|
|
3902
|
+
error
|
|
3903
|
+
});
|
|
3904
|
+
} else {
|
|
3905
|
+
throw error;
|
|
3906
|
+
}
|
|
3894
3907
|
}
|
|
3895
3908
|
}
|
|
3896
|
-
const routersNames = fallbackStrategy.map(({ name }) => name).join(",");
|
|
3897
|
-
|
|
3909
|
+
const routersNames = fallbackStrategy.map(({ name }) => name).join(", ");
|
|
3910
|
+
const errorsMessages = errors.map((routerError) => `(${routerError.name}) Could not find an itinerary on endpoint: ${routerError.endpointUrl}. Details: ${routerError.error.message}`).join("\n");
|
|
3911
|
+
throw RemoteRoutingError.notFound(routersNames, errorsMessages);
|
|
3898
3912
|
}
|
|
3899
3913
|
}
|
|
3900
3914
|
const RemoteRouterManager$1 = new RemoteRouterManager();
|
|
@@ -4359,6 +4373,148 @@ class ItineraryInfoManager {
|
|
|
4359
4373
|
return itineraryInfo;
|
|
4360
4374
|
}
|
|
4361
4375
|
}
|
|
4376
|
+
const _InstructionManager = class _InstructionManager {
|
|
4377
|
+
static getTurnInfoFromAngle(_angle) {
|
|
4378
|
+
let direction, directionExtra;
|
|
4379
|
+
const directionAngle = maths.rad2deg(maths.diffAngle(_angle, Math.PI));
|
|
4380
|
+
const directionAngleAbs = Math.abs(directionAngle);
|
|
4381
|
+
if (directionAngleAbs <= 20) {
|
|
4382
|
+
direction = "straight";
|
|
4383
|
+
} else {
|
|
4384
|
+
direction = directionAngle > 0 ? "left" : "right";
|
|
4385
|
+
if (directionAngleAbs < 55) {
|
|
4386
|
+
directionExtra = "slight";
|
|
4387
|
+
} else if (directionAngleAbs > 120) {
|
|
4388
|
+
directionExtra = "sharp";
|
|
4389
|
+
}
|
|
4390
|
+
}
|
|
4391
|
+
return { direction, directionExtra };
|
|
4392
|
+
}
|
|
4393
|
+
static getInfoFromStep(step) {
|
|
4394
|
+
let type, direction, directionExtra, levelChange;
|
|
4395
|
+
if (step.levelChange) {
|
|
4396
|
+
type = "level-change";
|
|
4397
|
+
levelChange = step.levelChange;
|
|
4398
|
+
} else {
|
|
4399
|
+
type = "turn";
|
|
4400
|
+
const turnInfo = _InstructionManager.getTurnInfoFromAngle(step.angle);
|
|
4401
|
+
direction = turnInfo.direction;
|
|
4402
|
+
directionExtra = turnInfo.directionExtra;
|
|
4403
|
+
}
|
|
4404
|
+
return {
|
|
4405
|
+
type,
|
|
4406
|
+
direction,
|
|
4407
|
+
directionExtra,
|
|
4408
|
+
levelChange,
|
|
4409
|
+
name: step.name,
|
|
4410
|
+
indoor: step.coords.level !== null
|
|
4411
|
+
};
|
|
4412
|
+
}
|
|
4413
|
+
// eslint-disable-next-line max-statements, complexity
|
|
4414
|
+
static getInstructionFromStep(step) {
|
|
4415
|
+
var _a, _b;
|
|
4416
|
+
const { direction, directionExtra } = _InstructionManager.getTurnInfoFromAngle(step.angle);
|
|
4417
|
+
const isTurn = direction !== "straight";
|
|
4418
|
+
if (step.lastStep) {
|
|
4419
|
+
if (isTurn && direction === "left") {
|
|
4420
|
+
return "Your destination is on your left";
|
|
4421
|
+
} else if (isTurn && direction === "right") {
|
|
4422
|
+
return "Your destination is on your right";
|
|
4423
|
+
}
|
|
4424
|
+
}
|
|
4425
|
+
let suffix = "";
|
|
4426
|
+
if ((_a = step.extras) == null ? void 0 : _a.isGate) {
|
|
4427
|
+
suffix = ` on gate ${step.name}`;
|
|
4428
|
+
} else if (step.name) {
|
|
4429
|
+
suffix = ` on ${step.name}`;
|
|
4430
|
+
}
|
|
4431
|
+
if (step.levelChange) {
|
|
4432
|
+
if (step.levelChange.direction === "up") {
|
|
4433
|
+
if (step.levelChange.type === "stairs") {
|
|
4434
|
+
return "Go up the stairs";
|
|
4435
|
+
}
|
|
4436
|
+
if (step.levelChange.type === "escalator") {
|
|
4437
|
+
return "Go up the escalator";
|
|
4438
|
+
}
|
|
4439
|
+
if (step.levelChange.type === "elevator") {
|
|
4440
|
+
return "Go up the elevator";
|
|
4441
|
+
}
|
|
4442
|
+
if (step.levelChange.type === "moving walkway") {
|
|
4443
|
+
return "Go up the moving walkway";
|
|
4444
|
+
}
|
|
4445
|
+
return "Go up" + suffix;
|
|
4446
|
+
}
|
|
4447
|
+
if (step.levelChange.direction === "down") {
|
|
4448
|
+
if (step.levelChange.type === "stairs") {
|
|
4449
|
+
return "Go down the stairs";
|
|
4450
|
+
}
|
|
4451
|
+
if (step.levelChange.type === "escalator") {
|
|
4452
|
+
return "Go down the escalator";
|
|
4453
|
+
}
|
|
4454
|
+
if (step.levelChange.type === "elevator") {
|
|
4455
|
+
return "Go down the elevator";
|
|
4456
|
+
}
|
|
4457
|
+
if (step.levelChange.type === "moving walkway") {
|
|
4458
|
+
return "Go down the moving walkway";
|
|
4459
|
+
}
|
|
4460
|
+
return "Go down" + suffix;
|
|
4461
|
+
}
|
|
4462
|
+
if ((_b = step.extras) == null ? void 0 : _b.subwayEntrance) {
|
|
4463
|
+
return `Take exit ${step.extras.subwayEntranceRef}`;
|
|
4464
|
+
}
|
|
4465
|
+
}
|
|
4466
|
+
if (isTurn) {
|
|
4467
|
+
if (direction === "left") {
|
|
4468
|
+
if (directionExtra === "slight") {
|
|
4469
|
+
return "Turn slightly left" + suffix;
|
|
4470
|
+
}
|
|
4471
|
+
return "Turn left" + suffix;
|
|
4472
|
+
}
|
|
4473
|
+
if (direction === "right") {
|
|
4474
|
+
if (directionExtra === "slight") {
|
|
4475
|
+
return "Turn slightly right" + suffix;
|
|
4476
|
+
}
|
|
4477
|
+
return "Turn right" + suffix;
|
|
4478
|
+
}
|
|
4479
|
+
}
|
|
4480
|
+
return "Continue straight";
|
|
4481
|
+
}
|
|
4482
|
+
static getInstructionFromPosition(itineraryInfoManager, position) {
|
|
4483
|
+
const itineraryInfo = itineraryInfoManager.getInfo(position);
|
|
4484
|
+
if (!itineraryInfo) {
|
|
4485
|
+
return null;
|
|
4486
|
+
}
|
|
4487
|
+
if (this.useProposals && itineraryInfo.projection.distanceFromNearestElement > 15) {
|
|
4488
|
+
return "It seems that we are a little bit lost, please start again the localization process";
|
|
4489
|
+
}
|
|
4490
|
+
const { nextStep } = itineraryInfo;
|
|
4491
|
+
if (!nextStep) {
|
|
4492
|
+
return "You are arrived";
|
|
4493
|
+
}
|
|
4494
|
+
const distNextStep = position.distanceTo(nextStep.coords);
|
|
4495
|
+
const distRounded = maths.roundFactor(distNextStep, 5);
|
|
4496
|
+
if (this.useProposals && distNextStep > 10) {
|
|
4497
|
+
return `Continue straight for ${distRounded}m`;
|
|
4498
|
+
}
|
|
4499
|
+
let instruction = _InstructionManager.getInstructionFromStep(nextStep);
|
|
4500
|
+
const stepWithImportantInfo = itineraryInfoManager._steps.find(
|
|
4501
|
+
(step) => step.levelChange && step.number > nextStep.number && step.coords.distanceTo(nextStep.coords) < 10
|
|
4502
|
+
) || null;
|
|
4503
|
+
if (stepWithImportantInfo && stepWithImportantInfo.levelChange) {
|
|
4504
|
+
const nextBearing = nextStep.coords.bearingTo(stepWithImportantInfo.coords);
|
|
4505
|
+
const { direction } = _InstructionManager.getTurnInfoFromAngle(nextBearing - nextStep.previousBearing);
|
|
4506
|
+
instruction = direction === "straight" ? "Continue straight" : `Turn ${direction}`;
|
|
4507
|
+
const { direction: levelDirection, type: levelType } = stepWithImportantInfo.levelChange;
|
|
4508
|
+
instruction += ` and take the ${levelType} going ${levelDirection}`;
|
|
4509
|
+
}
|
|
4510
|
+
if (distNextStep >= 5) {
|
|
4511
|
+
instruction += ` in ${distRounded}m`;
|
|
4512
|
+
}
|
|
4513
|
+
return instruction;
|
|
4514
|
+
}
|
|
4515
|
+
};
|
|
4516
|
+
__publicField(_InstructionManager, "useProposals", false);
|
|
4517
|
+
let InstructionManager = _InstructionManager;
|
|
4362
4518
|
exports.CitywayRemoteRouter = CitywayRemoteRouter$1;
|
|
4363
4519
|
exports.CustomGraphMap = CustomGraphMap;
|
|
4364
4520
|
exports.CustomGraphMapTester = CustomGraphMapTester;
|
|
@@ -4370,6 +4526,7 @@ exports.GraphRoute = GraphRoute;
|
|
|
4370
4526
|
exports.GraphRouter = GraphRouter;
|
|
4371
4527
|
exports.GraphRouterOptionsBuilder = GraphRouterOptionsBuilder;
|
|
4372
4528
|
exports.IdfmRemoteRouter = IdfmRemoteRouter$1;
|
|
4529
|
+
exports.InstructionManager = InstructionManager;
|
|
4373
4530
|
exports.Itinerary = Itinerary;
|
|
4374
4531
|
exports.ItineraryInfoManager = ItineraryInfoManager;
|
|
4375
4532
|
exports.Leg = Leg;
|