proximiio-js-library 1.14.55 → 1.15.0

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.
@@ -1,5 +1,6 @@
1
1
  import { lineString, point } from '@turf/helpers';
2
2
  import pointToLineDistance from '@turf/point-to-line-distance';
3
+ import distance from '@turf/distance';
3
4
  /**
4
5
  * Find the most appropriate navigation step index based on user's current position.
5
6
  *
@@ -16,16 +17,22 @@ const getCurrentStepIndex = ({ userPosition, steps, lastKnownStepIndex = 0, thre
16
17
  // Only check steps ahead of current one to avoid regressions
17
18
  for (let i = lastKnownStepIndex; i < steps.length; i++) {
18
19
  const step = steps[i];
19
- if (step.navMode === 'mall' && !step.lineStringFeatureFromLastStep) {
20
+ const isStartOrLevelChanger = step.direction === 'START' || step.levelChangerId;
21
+ if (step.navMode === 'mall' && !step.lineStringFeatureFromLastStep && !isStartOrLevelChanger) {
20
22
  return;
21
23
  }
22
- const lineCoords = step.navMode === 'mall' ? step.lineStringFeatureFromLastStep.geometry.coordinates : step.geometry.coordinates;
23
- const line = lineString(lineCoords);
24
- // Calculate shortest distance from user to this step's path
25
- const distance = pointToLineDistance(userPoint, line, { units: 'meters' });
24
+ let pointDistance = 0;
25
+ if (isStartOrLevelChanger) {
26
+ pointDistance = distance(userPoint, point(step.coordinates), { units: 'meters' });
27
+ }
28
+ else {
29
+ const lineCoords = step.navMode === 'mall' ? step.lineStringFeatureFromLastStep.geometry.coordinates : step.geometry.coordinates;
30
+ const line = lineString(lineCoords);
31
+ pointDistance = pointToLineDistance(userPoint, line, { units: 'meters' });
32
+ }
26
33
  // If within threshold and closest so far, consider this as best candidate
27
- if (distance < thresholdMeters && distance < minDistance) {
28
- minDistance = distance;
34
+ if (pointDistance < thresholdMeters && pointDistance < minDistance) {
35
+ minDistance = pointDistance;
29
36
  closestStepIndex = i;
30
37
  }
31
38
  }
@@ -5,13 +5,15 @@ export default class GuidanceStepsGenerator {
5
5
  steps: GuidanceStep[];
6
6
  language: string;
7
7
  landMarkNav: boolean;
8
+ simplifiedTBT: boolean;
8
9
  pois?: Feature[];
9
10
  levelChangers?: Feature[];
10
11
  initialBearing: number;
11
- constructor({ points, language, landMarkNav, pois, levelChangers, initialBearing, }: {
12
+ constructor({ points, language, landMarkNav, simplifiedTBT, pois, levelChangers, initialBearing, }: {
12
13
  points: Feature[];
13
14
  language: string;
14
15
  landMarkNav: boolean;
16
+ simplifiedTBT: boolean;
15
17
  pois?: Feature[];
16
18
  levelChangers?: Feature[];
17
19
  initialBearing: number;
@@ -40,7 +40,7 @@ var LevelChangerTypes;
40
40
  LevelChangerTypes["ramp"] = "RAMP";
41
41
  })(LevelChangerTypes || (LevelChangerTypes = {}));
42
42
  export default class GuidanceStepsGenerator {
43
- constructor({ points, language, landMarkNav, pois, levelChangers, initialBearing, }) {
43
+ constructor({ points, language, landMarkNav, simplifiedTBT, pois, levelChangers, initialBearing, }) {
44
44
  this.capitalize = (s) => s && String(s[0]).toUpperCase() + String(s).slice(1);
45
45
  this.points = points;
46
46
  this.language = language;
@@ -50,6 +50,7 @@ export default class GuidanceStepsGenerator {
50
50
  this.levelChangers = levelChangers;
51
51
  this.initialBearing = initialBearing;
52
52
  }
53
+ this.simplifiedTBT = simplifiedTBT;
53
54
  if (this.points && this.points.length > 0) {
54
55
  this.generateStepsFromPoints();
55
56
  }
@@ -86,6 +87,16 @@ export default class GuidanceStepsGenerator {
86
87
  distanceFromLastStep === 0)) {
87
88
  return;
88
89
  }
90
+ if (!this.simplifiedTBT &&
91
+ (direction === Direction.Start ||
92
+ (direction === Direction.Finish && currentPoint.isPoi) ||
93
+ direction === Direction.TurnAround) /*||
94
+ direction === `${Direction.Down}_${LevelChangerTypes[currentPoint.properties.type]}` ||
95
+ direction === `${Direction.Up}_${LevelChangerTypes[currentPoint.properties.type]}` ||
96
+ direction === `${Direction.Exit}_${LevelChangerTypes[currentPoint.properties.type]}` ||
97
+ distanceFromLastStep === 0*/) {
98
+ return;
99
+ }
89
100
  return {
90
101
  bearingFromLastStep: this.getBearingFromLastStep(data),
91
102
  coordinates: [point.geometry.coordinates[0], point.geometry.coordinates[1]],
@@ -98,6 +98,7 @@ export interface Options {
98
98
  newFeatureModalEvent?: string;
99
99
  enableTBTNavigation?: boolean;
100
100
  landmarkTBTNavigation?: boolean;
101
+ useSimplifiedTBTNavigation?: boolean;
101
102
  mapboxOptions?: MapboxOptions;
102
103
  zoomIntoPlace?: boolean;
103
104
  defaultPlaceId?: string;
@@ -106,6 +106,7 @@ export class Map {
106
106
  newFeatureModalEvent: 'click',
107
107
  enableTBTNavigation: true,
108
108
  landmarkTBTNavigation: false,
109
+ useSimplifiedTBTNavigation: false,
109
110
  zoomIntoPlace: true,
110
111
  defaultFloorLevel: 0,
111
112
  isKiosk: false,
@@ -3550,7 +3551,9 @@ export class Map {
3550
3551
  ? this.routingSource.route[`path-part-${this.currentStep}`]
3551
3552
  : lineString(this.routingSource.levelPoints[this.state.floor.level].map((i) => i.geometry.coordinates), { level: this.state.floor.level });
3552
3553
  let routeUntilNextStep;
3553
- if (route.properties.source === 'cityRoute' || this.defaultOptions.landmarkTBTNavigation) {
3554
+ if (route.properties.source === 'cityRoute' ||
3555
+ this.defaultOptions.landmarkTBTNavigation ||
3556
+ !this.defaultOptions.useSimplifiedTBTNavigation) {
3554
3557
  // Step 1: Determine the current level to filter on
3555
3558
  const level = route.properties.source === 'cityRoute'
3556
3559
  ? route.properties.level // Use route level if it's a city route
@@ -3671,7 +3674,8 @@ export class Map {
3671
3674
  this.setNavStep('next');
3672
3675
  }
3673
3676
  if (this.defaultOptions.autoRestartAnimationAfterFloorChange &&
3674
- !this.defaultOptions.landmarkTBTNavigation) {
3677
+ !this.defaultOptions.landmarkTBTNavigation &&
3678
+ !this.defaultOptions.useSimplifiedTBTNavigation) {
3675
3679
  this.restartRouteAnimation({ delay: 0, recenter: true });
3676
3680
  }
3677
3681
  }, 2000);
@@ -3685,7 +3689,9 @@ export class Map {
3685
3689
  const currentPoint = along(route, currentDistance);
3686
3690
  const routeProgress = (this.currentStep / this.routingSource.steps.length) * 100;
3687
3691
  // cut the line at the point
3688
- const lineAlong = lineSplit(route.properties.source === 'cityRoute' || this.defaultOptions.landmarkTBTNavigation
3692
+ const lineAlong = lineSplit(route.properties.source === 'cityRoute' ||
3693
+ this.defaultOptions.landmarkTBTNavigation ||
3694
+ !this.defaultOptions.useSimplifiedTBTNavigation
3689
3695
  ? routeUntilNextStep
3690
3696
  : route, currentPoint).features[0];
3691
3697
  if (this.defaultOptions.routeAnimation.lineProgress) {
@@ -4962,6 +4968,11 @@ export class Map {
4962
4968
  }
4963
4969
  return step;
4964
4970
  }
4971
+ else if (this.routingSource && this.routingSource.points.length > 0 && this.routingSource.points[newStep]) {
4972
+ this.currentStep = newStep;
4973
+ this.onStepSetListener.next(this.currentStep);
4974
+ return step;
4975
+ }
4965
4976
  else {
4966
4977
  console.error(`Route not found`);
4967
4978
  }
@@ -11,11 +11,12 @@ export default class Routing {
11
11
  setData(collection: FeatureCollection): void;
12
12
  toggleOnlyAccessible(onlyAccessible: any): void;
13
13
  setConfig(config: WayfindingConfigModel): void;
14
- route({ start, finish, stops, landmarkTBT, priorityEntrance, }: {
14
+ route({ start, finish, stops, landmarkTBT, simplifiedTBT, priorityEntrance, }: {
15
15
  start: Feature;
16
16
  finish?: Feature;
17
17
  stops?: Feature[];
18
18
  landmarkTBT?: boolean;
19
+ simplifiedTBT?: boolean;
19
20
  priorityEntrance?: Feature;
20
21
  }): {
21
22
  paths: any;
@@ -61,7 +61,7 @@ export default class Routing {
61
61
  this.config = config;
62
62
  this.wayfinding.setConfiguration(config);
63
63
  }
64
- route({ start, finish, stops, landmarkTBT = false, priorityEntrance, }) {
64
+ route({ start, finish, stops, landmarkTBT = false, simplifiedTBT = false, priorityEntrance, }) {
65
65
  const isMultipoint = stops && stops.length > 1;
66
66
  let points = null;
67
67
  let details = null;
@@ -214,7 +214,7 @@ export default class Routing {
214
214
  }
215
215
  }
216
216
  }
217
- else {
217
+ else if (simplifiedTBT) {
218
218
  if (this.forceFloorLevel !== null && this.forceFloorLevel !== undefined) {
219
219
  if (typeof pathPoints['path-part-'.concat(pathPartIndex)] === 'undefined') {
220
220
  pathPoints['path-part-'.concat(pathPartIndex)] = [];
@@ -237,6 +237,21 @@ export default class Routing {
237
237
  }
238
238
  }
239
239
  }
240
+ else {
241
+ if (typeof pathPoints[`path-part-${pathPartIndex}`] === 'undefined') {
242
+ if (points[index + 1]) {
243
+ pathPoints[`path-part-${pathPartIndex}`] = [];
244
+ if (p.isLevelChanger && points[index + 1].isLevelChanger) {
245
+ const leveledPoint = Object.assign(Object.assign({}, p), { properties: Object.assign(Object.assign({}, p.properties), { level: points[index + 1].properties.level }) });
246
+ pathPoints[`path-part-${pathPartIndex}`].push(p, leveledPoint);
247
+ }
248
+ else {
249
+ pathPoints[`path-part-${pathPartIndex}`].push(p, points[index + 1]);
250
+ }
251
+ pathPartIndex++;
252
+ }
253
+ }
254
+ }
240
255
  });
241
256
  const paths = {};
242
257
  let stopIndex = 0;
@@ -36,6 +36,7 @@ export default class RoutingSource extends DataSource {
36
36
  fullPath?: Feature;
37
37
  isMultipoint: boolean;
38
38
  landmarkTBT: boolean;
39
+ simplifiedTBT: boolean;
39
40
  pois?: Feature[];
40
41
  levelChangers?: Feature[];
41
42
  initialBearing: number;
@@ -44,6 +45,7 @@ export default class RoutingSource extends DataSource {
44
45
  setConfig(config: WayfindingConfigModel): void;
45
46
  setNavigationType(type: 'mall' | 'city' | 'combined'): void;
46
47
  setLandmarkTBT(value: boolean): void;
48
+ setSimplifiedTBT(value: boolean): void;
47
49
  setInitialBearing(initialBearing: number): void;
48
50
  setPois(pois: Feature[]): void;
49
51
  setLevelChangers(levelChangers: Feature[]): void;
@@ -21,6 +21,7 @@ export default class RoutingSource extends DataSource {
21
21
  this.routing = new Routing();
22
22
  this.navigationType = 'mall';
23
23
  this.landmarkTBT = false;
24
+ this.simplifiedTBT = false;
24
25
  }
25
26
  toggleAccessible(value) {
26
27
  this.routing.toggleOnlyAccessible(value);
@@ -34,6 +35,9 @@ export default class RoutingSource extends DataSource {
34
35
  setLandmarkTBT(value) {
35
36
  this.landmarkTBT = value;
36
37
  }
38
+ setSimplifiedTBT(value) {
39
+ this.simplifiedTBT = value;
40
+ }
37
41
  setInitialBearing(initialBearing) {
38
42
  this.initialBearing = initialBearing;
39
43
  }
@@ -68,7 +72,13 @@ export default class RoutingSource extends DataSource {
68
72
  route = yield this.routing.cityRoute({ start, finish, language: this.language });
69
73
  }
70
74
  else if (this.navigationType === 'mall') {
71
- route = this.routing.route({ start, finish, stops, landmarkTBT: this.landmarkTBT });
75
+ route = this.routing.route({
76
+ start,
77
+ finish,
78
+ stops,
79
+ landmarkTBT: this.landmarkTBT,
80
+ simplifiedTBT: this.simplifiedTBT,
81
+ });
72
82
  }
73
83
  else if (this.navigationType === 'combined' && connectingPoint) {
74
84
  if (startAtMall) {
@@ -80,6 +90,7 @@ export default class RoutingSource extends DataSource {
80
90
  finish: connectingPoint,
81
91
  stops,
82
92
  landmarkTBT: this.landmarkTBT,
93
+ simplifiedTBT: this.simplifiedTBT,
83
94
  priorityEntrance: entranceFeature,
84
95
  });
85
96
  }
@@ -92,6 +103,7 @@ export default class RoutingSource extends DataSource {
92
103
  finish,
93
104
  stops,
94
105
  landmarkTBT: this.landmarkTBT,
106
+ simplifiedTBT: this.simplifiedTBT,
95
107
  priorityEntrance: entranceFeature,
96
108
  });
97
109
  }
@@ -111,6 +123,7 @@ export default class RoutingSource extends DataSource {
111
123
  points: route === null || route === void 0 ? void 0 : route.points,
112
124
  language: this.language,
113
125
  landMarkNav: this.landmarkTBT,
126
+ simplifiedTBT: this.simplifiedTBT,
114
127
  pois: this.pois,
115
128
  levelChangers: this.levelChangers,
116
129
  initialBearing: this.initialBearing,
@@ -168,6 +181,7 @@ export default class RoutingSource extends DataSource {
168
181
  points: mallRoute === null || mallRoute === void 0 ? void 0 : mallRoute.points,
169
182
  language: this.language,
170
183
  landMarkNav: this.landmarkTBT,
184
+ simplifiedTBT: this.simplifiedTBT,
171
185
  pois: this.pois,
172
186
  levelChangers: this.levelChangers,
173
187
  initialBearing: this.initialBearing,