@wemap/routers 12.11.3 → 12.11.5
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.d.ts +0 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -230
- package/dist/index.mjs.map +1 -1
- package/helpers/InstructionManager.ts +184 -0
- package/helpers/InstructionManagerV1.ts +95 -0
- package/package.json +10 -5
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ var __publicField = (obj, key, value) => {
|
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
7
|
import { Level, Coordinates, BoundingBox, UserPosition, Constants, Utils } from "@wemap/geo";
|
|
8
|
-
import { diffAngleLines, deg2rad, diffAngle, positiveMod, rad2deg
|
|
8
|
+
import { diffAngleLines, deg2rad, diffAngle, positiveMod, rad2deg } from "@wemap/maths";
|
|
9
9
|
import Logger from "@wemap/logger";
|
|
10
10
|
import salesman from "@wemap/salesman.js";
|
|
11
11
|
import { OsmNode, OsmParser } from "@wemap/osm";
|
|
@@ -5032,233 +5032,6 @@ class ItineraryInfoManager {
|
|
|
5032
5032
|
return itineraryInfo;
|
|
5033
5033
|
}
|
|
5034
5034
|
}
|
|
5035
|
-
const _InstructionManager = class _InstructionManager {
|
|
5036
|
-
static getTurnInfoFromAngle(_angle) {
|
|
5037
|
-
let direction, directionExtra;
|
|
5038
|
-
const directionAngle = rad2deg(diffAngle(_angle, Math.PI));
|
|
5039
|
-
const directionAngleAbs = Math.abs(directionAngle);
|
|
5040
|
-
if (directionAngleAbs <= 20) {
|
|
5041
|
-
direction = "straight";
|
|
5042
|
-
} else {
|
|
5043
|
-
direction = directionAngle > 0 ? "left" : "right";
|
|
5044
|
-
if (directionAngleAbs < 55) {
|
|
5045
|
-
directionExtra = "slight";
|
|
5046
|
-
} else if (directionAngleAbs > 120) {
|
|
5047
|
-
directionExtra = "sharp";
|
|
5048
|
-
}
|
|
5049
|
-
}
|
|
5050
|
-
return { direction, directionExtra };
|
|
5051
|
-
}
|
|
5052
|
-
static getInfoFromStep(step) {
|
|
5053
|
-
let type, direction, directionExtra, levelChange;
|
|
5054
|
-
if (step.levelChange) {
|
|
5055
|
-
type = "level-change";
|
|
5056
|
-
levelChange = step.levelChange;
|
|
5057
|
-
} else {
|
|
5058
|
-
type = "turn";
|
|
5059
|
-
const turnInfo = _InstructionManager.getTurnInfoFromAngle(step.angle);
|
|
5060
|
-
direction = turnInfo.direction;
|
|
5061
|
-
directionExtra = turnInfo.directionExtra;
|
|
5062
|
-
}
|
|
5063
|
-
return {
|
|
5064
|
-
type,
|
|
5065
|
-
direction,
|
|
5066
|
-
directionExtra,
|
|
5067
|
-
levelChange,
|
|
5068
|
-
name: step.name,
|
|
5069
|
-
indoor: step.coords.level !== null
|
|
5070
|
-
};
|
|
5071
|
-
}
|
|
5072
|
-
// eslint-disable-next-line max-statements, complexity
|
|
5073
|
-
static getInstructionFromStep(step) {
|
|
5074
|
-
var _a, _b;
|
|
5075
|
-
const { direction, directionExtra } = _InstructionManager.getTurnInfoFromAngle(step.angle);
|
|
5076
|
-
const isTurn = direction !== "straight";
|
|
5077
|
-
if (step.lastStep) {
|
|
5078
|
-
if (isTurn && direction === "left") {
|
|
5079
|
-
return "Your destination is on your left";
|
|
5080
|
-
} else if (isTurn && direction === "right") {
|
|
5081
|
-
return "Your destination is on your right";
|
|
5082
|
-
}
|
|
5083
|
-
}
|
|
5084
|
-
let suffix = "";
|
|
5085
|
-
if ((_a = step.extras) == null ? void 0 : _a.isGate) {
|
|
5086
|
-
suffix = ` on gate ${step.name}`;
|
|
5087
|
-
} else if (step.name) {
|
|
5088
|
-
suffix = ` on ${step.name}`;
|
|
5089
|
-
}
|
|
5090
|
-
if (step.levelChange) {
|
|
5091
|
-
if (step.levelChange.direction === "up") {
|
|
5092
|
-
if (step.levelChange.type === "stairs") {
|
|
5093
|
-
return "Go up the stairs";
|
|
5094
|
-
}
|
|
5095
|
-
if (step.levelChange.type === "escalator") {
|
|
5096
|
-
return "Go up the escalator";
|
|
5097
|
-
}
|
|
5098
|
-
if (step.levelChange.type === "elevator") {
|
|
5099
|
-
return "Go up the elevator";
|
|
5100
|
-
}
|
|
5101
|
-
if (step.levelChange.type === "moving walkway") {
|
|
5102
|
-
return "Go up the moving walkway";
|
|
5103
|
-
}
|
|
5104
|
-
if (step.levelChange.type === "incline plane") {
|
|
5105
|
-
return "Go up the incline plane";
|
|
5106
|
-
}
|
|
5107
|
-
return "Go up" + suffix;
|
|
5108
|
-
}
|
|
5109
|
-
if (step.levelChange.direction === "down") {
|
|
5110
|
-
if (step.levelChange.type === "stairs") {
|
|
5111
|
-
return "Go down the stairs";
|
|
5112
|
-
}
|
|
5113
|
-
if (step.levelChange.type === "escalator") {
|
|
5114
|
-
return "Go down the escalator";
|
|
5115
|
-
}
|
|
5116
|
-
if (step.levelChange.type === "elevator") {
|
|
5117
|
-
return "Go down the elevator";
|
|
5118
|
-
}
|
|
5119
|
-
if (step.levelChange.type === "moving walkway") {
|
|
5120
|
-
return "Go down the moving walkway";
|
|
5121
|
-
}
|
|
5122
|
-
if (step.levelChange.type === "incline plane") {
|
|
5123
|
-
return "Go down the incline plane";
|
|
5124
|
-
}
|
|
5125
|
-
return "Go down" + suffix;
|
|
5126
|
-
}
|
|
5127
|
-
if ((_b = step.extras) == null ? void 0 : _b.subwayEntrance) {
|
|
5128
|
-
return `Take exit ${step.extras.subwayEntranceRef}`;
|
|
5129
|
-
}
|
|
5130
|
-
}
|
|
5131
|
-
if (isTurn) {
|
|
5132
|
-
if (direction === "left") {
|
|
5133
|
-
if (directionExtra === "slight") {
|
|
5134
|
-
return "Turn slightly left" + suffix;
|
|
5135
|
-
}
|
|
5136
|
-
return "Turn left" + suffix;
|
|
5137
|
-
}
|
|
5138
|
-
if (direction === "right") {
|
|
5139
|
-
if (directionExtra === "slight") {
|
|
5140
|
-
return "Turn slightly right" + suffix;
|
|
5141
|
-
}
|
|
5142
|
-
return "Turn right" + suffix;
|
|
5143
|
-
}
|
|
5144
|
-
}
|
|
5145
|
-
return "Continue straight";
|
|
5146
|
-
}
|
|
5147
|
-
static getInstructionFromPosition(itineraryInfoManager, position) {
|
|
5148
|
-
const itineraryInfo = itineraryInfoManager.getInfo(position);
|
|
5149
|
-
if (!itineraryInfo) {
|
|
5150
|
-
return null;
|
|
5151
|
-
}
|
|
5152
|
-
if (this.useProposals && itineraryInfo.projection.distanceFromNearestElement > 15) {
|
|
5153
|
-
return "It seems that we are a little bit lost, please start again the localization process";
|
|
5154
|
-
}
|
|
5155
|
-
const { nextStep } = itineraryInfo;
|
|
5156
|
-
if (!nextStep) {
|
|
5157
|
-
return "You are arrived";
|
|
5158
|
-
}
|
|
5159
|
-
const distNextStep = position.distanceTo(nextStep.coords);
|
|
5160
|
-
const distRounded = roundFactor(distNextStep, 5);
|
|
5161
|
-
if (this.useProposals && distNextStep > 10) {
|
|
5162
|
-
return `Continue straight for ${distRounded}m`;
|
|
5163
|
-
}
|
|
5164
|
-
let instruction = _InstructionManager.getInstructionFromStep(nextStep);
|
|
5165
|
-
const stepWithImportantInfo = itineraryInfoManager._steps.find(
|
|
5166
|
-
(step) => step.levelChange && step.number > nextStep.number && step.coords.distanceTo(nextStep.coords) < 10
|
|
5167
|
-
) || null;
|
|
5168
|
-
if (stepWithImportantInfo && stepWithImportantInfo.levelChange) {
|
|
5169
|
-
const nextBearing = nextStep.coords.bearingTo(stepWithImportantInfo.coords);
|
|
5170
|
-
const { direction } = _InstructionManager.getTurnInfoFromAngle(nextBearing - nextStep.previousBearing);
|
|
5171
|
-
instruction = direction === "straight" ? "Continue straight" : `Turn ${direction}`;
|
|
5172
|
-
const { direction: levelDirection, type: levelType } = stepWithImportantInfo.levelChange;
|
|
5173
|
-
instruction += ` and take the ${levelType} going ${levelDirection}`;
|
|
5174
|
-
}
|
|
5175
|
-
if (distNextStep >= 5) {
|
|
5176
|
-
instruction += ` in ${distRounded}m`;
|
|
5177
|
-
}
|
|
5178
|
-
return instruction;
|
|
5179
|
-
}
|
|
5180
|
-
};
|
|
5181
|
-
__publicField(_InstructionManager, "useProposals", false);
|
|
5182
|
-
let InstructionManager = _InstructionManager;
|
|
5183
|
-
class InstructionManagerV1 {
|
|
5184
|
-
// eslint-disable-next-line max-statements, complexity
|
|
5185
|
-
static getInstructionFromStep(step) {
|
|
5186
|
-
var _a;
|
|
5187
|
-
const modifier = OsrmRemoteRouter$1.getModifierFromAngle(step.angle);
|
|
5188
|
-
let direction, directionExtra;
|
|
5189
|
-
if (modifier.includes("left")) {
|
|
5190
|
-
direction = "left";
|
|
5191
|
-
} else if (modifier.includes("right")) {
|
|
5192
|
-
direction = "right";
|
|
5193
|
-
}
|
|
5194
|
-
if (modifier.includes("slight")) {
|
|
5195
|
-
directionExtra = "slight";
|
|
5196
|
-
}
|
|
5197
|
-
const isTurn = modifier !== "straight";
|
|
5198
|
-
if (step.lastStep) {
|
|
5199
|
-
if (isTurn && direction === "left") {
|
|
5200
|
-
return "Your destination is on your left";
|
|
5201
|
-
} else if (isTurn && direction === "right") {
|
|
5202
|
-
return "Your destination is on your right";
|
|
5203
|
-
}
|
|
5204
|
-
}
|
|
5205
|
-
const suffix = step.name ? ` on ${step.name}` : "";
|
|
5206
|
-
if (step.levelChange) {
|
|
5207
|
-
if (step.levelChange.direction === "up") {
|
|
5208
|
-
if (step.levelChange.type === "escalator") {
|
|
5209
|
-
return "Go up the escalator";
|
|
5210
|
-
}
|
|
5211
|
-
if (step.levelChange.type === "stairs") {
|
|
5212
|
-
return "Go up the stairs";
|
|
5213
|
-
}
|
|
5214
|
-
return "Go up" + suffix;
|
|
5215
|
-
}
|
|
5216
|
-
if (step.levelChange.direction === "down") {
|
|
5217
|
-
if (step.levelChange.type === "escalator") {
|
|
5218
|
-
return "Go down the escalator";
|
|
5219
|
-
}
|
|
5220
|
-
if (step.levelChange.type === "stairs") {
|
|
5221
|
-
return "Go down the stairs";
|
|
5222
|
-
}
|
|
5223
|
-
return "Go down" + suffix;
|
|
5224
|
-
}
|
|
5225
|
-
if ((_a = step.extras) == null ? void 0 : _a.subwayEntrance) {
|
|
5226
|
-
return `Take exit ${step.extras.subwayEntranceRef}`;
|
|
5227
|
-
}
|
|
5228
|
-
}
|
|
5229
|
-
if (isTurn) {
|
|
5230
|
-
if (direction === "left") {
|
|
5231
|
-
if (directionExtra === "slight") {
|
|
5232
|
-
return "Turn slightly left" + suffix;
|
|
5233
|
-
}
|
|
5234
|
-
return "Turn left" + suffix;
|
|
5235
|
-
}
|
|
5236
|
-
if (direction === "right") {
|
|
5237
|
-
if (directionExtra === "slight") {
|
|
5238
|
-
return "Turn slightly right" + suffix;
|
|
5239
|
-
}
|
|
5240
|
-
return "Turn right" + suffix;
|
|
5241
|
-
}
|
|
5242
|
-
}
|
|
5243
|
-
return "";
|
|
5244
|
-
}
|
|
5245
|
-
static getInstructionFromPosition(itineraryInfoManager, position) {
|
|
5246
|
-
const itineraryInfo = itineraryInfoManager.getInfo(position);
|
|
5247
|
-
if (!itineraryInfo) {
|
|
5248
|
-
return null;
|
|
5249
|
-
}
|
|
5250
|
-
const { nextStep } = itineraryInfo;
|
|
5251
|
-
if (!nextStep) {
|
|
5252
|
-
return null;
|
|
5253
|
-
}
|
|
5254
|
-
const distNextStep = position.distanceTo(nextStep.coords);
|
|
5255
|
-
const nextStep2 = itineraryInfoManager._steps.find((step) => step.number > nextStep.number);
|
|
5256
|
-
if (distNextStep < 3 && nextStep2) {
|
|
5257
|
-
return InstructionManagerV1.getInstructionFromStep(nextStep2);
|
|
5258
|
-
}
|
|
5259
|
-
return InstructionManagerV1.getInstructionFromStep(nextStep);
|
|
5260
|
-
}
|
|
5261
|
-
}
|
|
5262
5035
|
export {
|
|
5263
5036
|
CitywayRemoteRouter$1 as CitywayRemoteRouter,
|
|
5264
5037
|
CustomGraphMap,
|
|
@@ -5272,8 +5045,6 @@ export {
|
|
|
5272
5045
|
GraphRouter,
|
|
5273
5046
|
GraphRouterOptionsBuilder,
|
|
5274
5047
|
IdfmRemoteRouter$1 as IdfmRemoteRouter,
|
|
5275
|
-
InstructionManager,
|
|
5276
|
-
InstructionManagerV1,
|
|
5277
5048
|
Itinerary,
|
|
5278
5049
|
ItineraryInfoManager,
|
|
5279
5050
|
Leg,
|