@wemap/routers 12.7.1 → 12.7.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.
package/dist/index.js CHANGED
@@ -4359,6 +4359,148 @@ class ItineraryInfoManager {
4359
4359
  return itineraryInfo;
4360
4360
  }
4361
4361
  }
4362
+ const _InstructionManager = class _InstructionManager {
4363
+ static getTurnInfoFromAngle(_angle) {
4364
+ let direction, directionExtra;
4365
+ const directionAngle = maths.rad2deg(maths.diffAngle(_angle, Math.PI));
4366
+ const directionAngleAbs = Math.abs(directionAngle);
4367
+ if (directionAngleAbs <= 20) {
4368
+ direction = "straight";
4369
+ } else {
4370
+ direction = directionAngle > 0 ? "left" : "right";
4371
+ if (directionAngleAbs < 55) {
4372
+ directionExtra = "slight";
4373
+ } else if (directionAngleAbs > 120) {
4374
+ directionExtra = "sharp";
4375
+ }
4376
+ }
4377
+ return { direction, directionExtra };
4378
+ }
4379
+ static getInfoFromStep(step) {
4380
+ let type, direction, directionExtra, levelChange;
4381
+ if (step.levelChange) {
4382
+ type = "level-change";
4383
+ levelChange = step.levelChange;
4384
+ } else {
4385
+ type = "turn";
4386
+ const turnInfo = _InstructionManager.getTurnInfoFromAngle(step.angle);
4387
+ direction = turnInfo.direction;
4388
+ directionExtra = turnInfo.directionExtra;
4389
+ }
4390
+ return {
4391
+ type,
4392
+ direction,
4393
+ directionExtra,
4394
+ levelChange,
4395
+ name: step.name,
4396
+ indoor: step.coords.level !== null
4397
+ };
4398
+ }
4399
+ // eslint-disable-next-line max-statements, complexity
4400
+ static getInstructionFromStep(step) {
4401
+ var _a, _b;
4402
+ const { direction, directionExtra } = _InstructionManager.getTurnInfoFromAngle(step.angle);
4403
+ const isTurn = direction !== "straight";
4404
+ if (step.lastStep) {
4405
+ if (isTurn && direction === "left") {
4406
+ return "Your destination is on your left";
4407
+ } else if (isTurn && direction === "right") {
4408
+ return "Your destination is on your right";
4409
+ }
4410
+ }
4411
+ let suffix = "";
4412
+ if ((_a = step.extras) == null ? void 0 : _a.isGate) {
4413
+ suffix = ` on gate ${step.name}`;
4414
+ } else if (step.name) {
4415
+ suffix = ` on ${step.name}`;
4416
+ }
4417
+ if (step.levelChange) {
4418
+ if (step.levelChange.direction === "up") {
4419
+ if (step.levelChange.type === "stairs") {
4420
+ return "Go up the stairs";
4421
+ }
4422
+ if (step.levelChange.type === "escalator") {
4423
+ return "Go up the escalator";
4424
+ }
4425
+ if (step.levelChange.type === "elevator") {
4426
+ return "Go up the elevator";
4427
+ }
4428
+ if (step.levelChange.type === "moving walkway") {
4429
+ return "Go up the moving walkway";
4430
+ }
4431
+ return "Go up" + suffix;
4432
+ }
4433
+ if (step.levelChange.direction === "down") {
4434
+ if (step.levelChange.type === "stairs") {
4435
+ return "Go down the stairs";
4436
+ }
4437
+ if (step.levelChange.type === "escalator") {
4438
+ return "Go down the escalator";
4439
+ }
4440
+ if (step.levelChange.type === "elevator") {
4441
+ return "Go down the elevator";
4442
+ }
4443
+ if (step.levelChange.type === "moving walkway") {
4444
+ return "Go down the moving walkway";
4445
+ }
4446
+ return "Go down" + suffix;
4447
+ }
4448
+ if ((_b = step.extras) == null ? void 0 : _b.subwayEntrance) {
4449
+ return `Take exit ${step.extras.subwayEntranceRef}`;
4450
+ }
4451
+ }
4452
+ if (isTurn) {
4453
+ if (direction === "left") {
4454
+ if (directionExtra === "slight") {
4455
+ return "Turn slightly left" + suffix;
4456
+ }
4457
+ return "Turn left" + suffix;
4458
+ }
4459
+ if (direction === "right") {
4460
+ if (directionExtra === "slight") {
4461
+ return "Turn slightly right" + suffix;
4462
+ }
4463
+ return "Turn right" + suffix;
4464
+ }
4465
+ }
4466
+ return "Continue straight";
4467
+ }
4468
+ static getInstructionFromPosition(itineraryInfoManager, position) {
4469
+ const itineraryInfo = itineraryInfoManager.getInfo(position);
4470
+ if (!itineraryInfo) {
4471
+ return null;
4472
+ }
4473
+ if (this.useProposals && itineraryInfo.projection.distanceFromNearestElement > 15) {
4474
+ return "It seems that we are a little bit lost, please start again the localization process";
4475
+ }
4476
+ const { nextStep } = itineraryInfo;
4477
+ if (!nextStep) {
4478
+ return "You are arrived";
4479
+ }
4480
+ const distNextStep = position.distanceTo(nextStep.coords);
4481
+ const distRounded = maths.roundFactor(distNextStep, 5);
4482
+ if (this.useProposals && distNextStep > 10) {
4483
+ return `Continue straight for ${distRounded}m`;
4484
+ }
4485
+ let instruction = _InstructionManager.getInstructionFromStep(nextStep);
4486
+ const stepWithImportantInfo = itineraryInfoManager._steps.find(
4487
+ (step) => step.levelChange && step.number > nextStep.number && step.coords.distanceTo(nextStep.coords) < 10
4488
+ ) || null;
4489
+ if (stepWithImportantInfo && stepWithImportantInfo.levelChange) {
4490
+ const nextBearing = nextStep.coords.bearingTo(stepWithImportantInfo.coords);
4491
+ const { direction } = _InstructionManager.getTurnInfoFromAngle(nextBearing - nextStep.previousBearing);
4492
+ instruction = direction === "straight" ? "Continue straight" : `Turn ${direction}`;
4493
+ const { direction: levelDirection, type: levelType } = stepWithImportantInfo.levelChange;
4494
+ instruction += ` and take the ${levelType} going ${levelDirection}`;
4495
+ }
4496
+ if (distNextStep >= 5) {
4497
+ instruction += ` in ${distRounded}m`;
4498
+ }
4499
+ return instruction;
4500
+ }
4501
+ };
4502
+ __publicField(_InstructionManager, "useProposals", false);
4503
+ let InstructionManager = _InstructionManager;
4362
4504
  exports.CitywayRemoteRouter = CitywayRemoteRouter$1;
4363
4505
  exports.CustomGraphMap = CustomGraphMap;
4364
4506
  exports.CustomGraphMapTester = CustomGraphMapTester;
@@ -4370,6 +4512,7 @@ exports.GraphRoute = GraphRoute;
4370
4512
  exports.GraphRouter = GraphRouter;
4371
4513
  exports.GraphRouterOptionsBuilder = GraphRouterOptionsBuilder;
4372
4514
  exports.IdfmRemoteRouter = IdfmRemoteRouter$1;
4515
+ exports.InstructionManager = InstructionManager;
4373
4516
  exports.Itinerary = Itinerary;
4374
4517
  exports.ItineraryInfoManager = ItineraryInfoManager;
4375
4518
  exports.Leg = Leg;