@wemap/providers 9.2.0 → 10.0.0-alpha.1

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/index.d.ts CHANGED
@@ -1,23 +1,82 @@
1
1
  import { Calibration } from "@wemap/camera";
2
- import { Coordinates } from "@wemap/geo";
2
+ import {
3
+ Attitude, AttitudeJson,
4
+ UserPosition, UserPositionJson
5
+ } from "@wemap/geo";
3
6
  import { Quaternion_t } from "@wemap/maths";
7
+ import { UserAgentWithDetails } from "@wemap/utils";
4
8
 
5
9
  declare module '@wemap/providers' {
6
10
 
11
+ export type CoarsePoseJson = {
12
+ attitude?: AttitudeJson,
13
+ position?: UserPositionJson,
14
+ };
15
+
16
+ export type CoarsePose = {
17
+ attitude?: Attitude,
18
+ position?: UserPosition,
19
+ };
20
+
21
+ export type VpsMetadataJson = {
22
+ size: [number, number], // [width, height]
23
+ calibration?: Calibration,
24
+ time?: number,
25
+ coarse?: CoarsePoseJson,
26
+ userAgent?: UserAgentWithDetails
27
+ }
28
+
7
29
  export class VpsMetadata {
8
30
 
9
31
  size: { width: number, height: number };
10
32
  calibration?: Calibration;
11
33
  time?: number;
12
- coarse: {
13
- attitude?: Quaternion_t,
14
- position: Coordinates,
15
- positionAccuracy: number
16
- }
17
-
18
- toJson(): object;
19
- static fromJson(json: object): VpsMetadata;
34
+ coarse?: CoarsePose;
35
+ userAgent?: UserAgentWithDetails;
36
+
37
+ toJson(): VpsMetadataJson;
38
+ static fromJson(json: VpsMetadataJson): VpsMetadata;
39
+ }
40
+
41
+ export type VpsRequestJson = VpsMetadataJson & {
42
+ image: string
43
+ }
44
+
45
+ export class VpsRequest {
46
+ image: string;
47
+ metadata: VpsMetadata;
48
+
49
+ toJson(): VpsRequestJson;
50
+ static fromJson(json: VpsRequestJson): VpsRequest
20
51
  }
21
52
 
53
+ export type VpsResponseJson = {
54
+ attitude: AttitudeJson,
55
+ coordinates: UserPositionJson
56
+ }
57
+
58
+ export class VpsResponse {
59
+ attitude: Attitude;
60
+ coordinates: UserPosition;
61
+
62
+ toJson(): VpsResponseJson;
63
+ static fromJson(json: VpsResponseJson): VpsResponse;
64
+ }
65
+
66
+ export class ImageRelocalization {
67
+
68
+ static _prepareRequest(
69
+ imageCanvas: HTMLCanvasElement,
70
+ calibration?: Calibration,
71
+ coarsePose?: CoarsePose
72
+ ): VpsRequest
73
+
74
+ static relocalize(
75
+ endpointUrl: string, imageCanvas: HTMLCanvasElement,
76
+ calibration?: Calibration, coarsePose?: CoarsePose
77
+ ): Promise<VpsResponse>;
78
+
79
+ static getHeadingFromQuaternion(quaternion: Quaternion_t): number;
80
+ }
22
81
  }
23
82
 
package/index.js CHANGED
@@ -9,7 +9,9 @@ export { default as MapMatchingHandler } from './src/mapmatching/MapMatchingHand
9
9
  export { default as PositionSmoother } from './src/smoothers/PositionSmoother.js';
10
10
  export { default as AttitudeSmoother } from './src/smoothers/AttitudeSmoother.js';
11
11
 
12
- export { default as VpsMetadata } from './src/providers/vision/VpsMetadata.js';
12
+ export { default as VpsMetadata } from './src/providers/vision/vps/VpsMetadata.js';
13
+ export { default as VpsRequest } from './src/providers/vision/vps/VpsRequest.js';
14
+ export { default as VpsResponse } from './src/providers/vision/vps/VpsResponse.js';
13
15
 
14
16
  export { default as ProvidersLoggerOld } from './src/events/ProvidersLoggerOld.js';
15
17
 
@@ -35,8 +37,6 @@ export { default as Inclination } from './src/providers/inclination/Inclination.
35
37
 
36
38
  export { default as StepDetector } from './src/providers/steps/StepDetector.js';
37
39
  export { default as StraightLineDetector } from './src/providers/steps/StraightLineDetector.js';
38
- export { default as StepDetectionMinMaxPeaks2 } from './src/providers/steps/StepDetectionMinMaxPeaks2.js';
39
- export { default as StepDetectionMinMaxPeaks3 } from './src/providers/steps/StepDetectionMinMaxPeaks3.js';
40
40
 
41
41
  export { default as Pdr } from './src/providers/position/relative/Pdr.js';
42
42
  export { default as GeoRelativePositionFromArCore } from './src/providers/position/relative/GeoRelativePositionFromArCore.js';
@@ -48,8 +48,8 @@ export { default as Ip } from './src/providers/position/absolute/Ip.js';
48
48
  export { default as AbsolutePosition } from './src/providers/position/absolute/AbsolutePosition.js';
49
49
 
50
50
  export { default as ArCore } from './src/providers/vision/ArCore.js';
51
- export { default as ImageRelocalization } from './src/providers/vision/ImageRelocalization.js';
52
- export { default as Vps } from './src/providers/vision/Vps.js';
51
+ export { default as ImageRelocalization } from './src/providers/vision/vps/ImageRelocalization.js';
52
+ export { default as Vps } from './src/providers/vision/vps/Vps.js';
53
53
  export { default as Barcode } from './src/providers/vision/Barcode.js';
54
54
 
55
55
  export { default as CameraNative } from './src/providers/others/CameraNative.js';
package/package.json CHANGED
@@ -8,15 +8,15 @@
8
8
  "Guillaume Pannetier <guillaume.pannetier@getwemap.com>"
9
9
  ],
10
10
  "dependencies": {
11
- "@wemap/camera": "^9.2.0",
12
- "@wemap/geo": "^9.2.0",
11
+ "@wemap/camera": "^10.0.0-alpha.0",
12
+ "@wemap/geo": "^10.0.0-alpha.1",
13
13
  "@wemap/geomagnetism": "^0.1.1",
14
- "@wemap/logger": "^9.2.0",
15
- "@wemap/map": "^9.2.0",
14
+ "@wemap/logger": "^9.0.0",
15
+ "@wemap/map": "^10.0.0-alpha.1",
16
16
  "@wemap/maths": "^9.0.0",
17
- "@wemap/osm": "^9.2.0",
18
- "@wemap/routers": "^9.2.0",
19
- "@wemap/utils": "^9.0.0"
17
+ "@wemap/osm": "^10.0.0-alpha.1",
18
+ "@wemap/routers": "^10.0.0-alpha.1",
19
+ "@wemap/utils": "^10.0.0-alpha.0"
20
20
  },
21
21
  "description": "A package using different geoloc systems",
22
22
  "devDependencies": {
@@ -42,6 +42,6 @@
42
42
  "url": "git+https://github.com/wemap/wemap-modules-js.git"
43
43
  },
44
44
  "type": "module",
45
- "version": "9.2.0",
46
- "gitHead": "9eee407fadd76fc5cbfbeeb13be0d74391ca5d9e"
45
+ "version": "10.0.0-alpha.1",
46
+ "gitHead": "21ba33bd03930c68e3f358534ba95936ad965e34"
47
47
  }
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable max-statements */
2
2
  import {
3
- AbsoluteHeading, GraphEdge, Level, MapMatching, Network, GraphProjection, UserPosition
3
+ AbsoluteHeading, GraphEdge, MapMatching, Network, GraphProjection, UserPosition
4
4
  } from '@wemap/geo';
5
5
  import { deg2rad, diffAngle, diffAngleLines } from '@wemap/maths';
6
6
  import { Itinerary } from '@wemap/routers';
@@ -35,55 +35,28 @@ class MapMatchingHandler extends Provider {
35
35
  static DEFAULT_USE_ITINERARY_START_AS_POSITION = false;
36
36
 
37
37
  /** @type {boolean} */
38
- static DEFAULT_USE_ORIENTATION_MATCHING = true;
38
+ static ORIENTATION_MATCHING = true;
39
39
 
40
40
  /** @type {number} in meters */
41
- static DEFAULT_MM_HUGE_JUMP_DISTANCE = 3;
42
-
43
- /** @type {number} in meters */
44
- static DEFAULT_DISABLE_MM_CLOSE_TO_A_TURN_DISTANCE = 2;
41
+ static MM_HUGE_JUMP_DISTANCE = 3;
45
42
 
46
43
  /** @type {number} */
47
- static DEFAULT_MIN_STEPS_BETWEEN_ORIENTATION_MATCHING = 3;
44
+ static MIN_STEPS_BETWEEN_ORIENTATION_MATCHING = 3;
48
45
 
49
46
  /** @type {number} */
50
- static DEFAULT_MIN_STEPS_FOR_ORIENTATION_MATCHING = 5;
47
+ static MIN_STEPS_FOR_ORIENTATION_MATCHING = 5;
51
48
 
52
49
  /** @type {number} */
53
- static DEFAULT_LAST_PROJECTIONS_WINDOW_SIZE = 3;
50
+ static LAST_PROJECTIONS_WINDOW_SIZE = 3;
54
51
 
55
52
  /** @type {number} */
56
- static DEFAULT_LAST_PROJECTIONS_EDGE_ANGLE_THRESHOLD = deg2rad(3);
53
+ static LAST_PROJECTIONS_EDGE_ANGLE_THRESHOLD = deg2rad(3);
57
54
 
58
55
  /** @type {MapMatching} */
59
56
  _mapMatching;
60
57
 
61
58
  /** @type {number} */
62
- _mapMatchingMinDistance = MapMatchingHandler.DEFAULT_MM_MIN_DIST;
63
-
64
- /** @type {boolean} */
65
- _useItineraryStartAsPosition = MapMatchingHandler.DEFAULT_USE_ITINERARY_START_AS_POSITION;
66
-
67
- /** @type {boolean} */
68
- _useOrientationMatching = MapMatchingHandler.DEFAULT_USE_ORIENTATION_MATCHING;
69
-
70
- /** @type {number} */
71
- _hugeJumpDistance = MapMatchingHandler.DEFAULT_MM_HUGE_JUMP_DISTANCE;
72
-
73
- /** @type {number} */
74
- _disableMMCloseToATurnDistance = MapMatchingHandler.DEFAULT_DISABLE_MM_CLOSE_TO_A_TURN_DISTANCE;
75
-
76
- /** @type {number} */
77
- _minStepsBetweenOrientationMatching = MapMatchingHandler.DEFAULT_MIN_STEPS_BETWEEN_ORIENTATION_MATCHING;
78
-
79
- /** @type {number} */
80
- _minStepsForOrientationMatching = MapMatchingHandler.DEFAULT_MIN_STEPS_FOR_ORIENTATION_MATCHING;
81
-
82
- /** @type {number} */
83
- _lastProjectionsWindowSize = MapMatchingHandler.DEFAULT_LAST_PROJECTIONS_WINDOW_SIZE;
84
-
85
- /** @type {number} */
86
- _lastProjectionsEdgeAngleThreshold = MapMatchingHandler.DEFAULT_LAST_PROJECTIONS_EDGE_ANGLE_THRESHOLD;
59
+ _mapMatchingMinDistance;
87
60
 
88
61
  /** @type {boolean} */
89
62
  _internalProvidersStarted = false;
@@ -113,6 +86,8 @@ class MapMatchingHandler extends Provider {
113
86
  this._mapMatching = new MapMatching();
114
87
  this._mapMatching.maxDistance = MapMatchingHandler.DEFAULT_MM_MAX_DIST;
115
88
  this._mapMatching.maxAngleBearing = MapMatchingHandler.DEFAULT_MM_MAX_ANGLE;
89
+ this._mapMatchingMinDistance = MapMatchingHandler.DEFAULT_MM_MIN_DIST;
90
+ this._useItineraryStartAsPosition = MapMatchingHandler.DEFAULT_USE_ITINERARY_START_AS_POSITION;
116
91
  }
117
92
 
118
93
  /**
@@ -304,7 +279,7 @@ class MapMatchingHandler extends Provider {
304
279
 
305
280
  // newPosition must not be used after this line
306
281
 
307
- const thisWillBeAHugeJump = projectionWithBearing.distanceFromNearestElement > this._hugeJumpDistance;
282
+ const thisWillBeAHugeJump = projectionWithBearing.distanceFromNearestElement > MapMatchingHandler.MM_HUGE_JUMP_DISTANCE;
308
283
 
309
284
  // In case of a huge jump, be sure the user is in a straight line
310
285
  if (thisWillBeAHugeJump && !StraightLineDetector.isStraight()) {
@@ -346,11 +321,11 @@ class MapMatchingHandler extends Provider {
346
321
  if (projection) {
347
322
  this._projectionsWithAbsAndWithoutRelAttitudeInARow = [];
348
323
  this._lastProjections.push(projection);
349
- if (this._lastProjections.length > this._lastProjectionsWindowSize) {
324
+ if (this._lastProjections.length > MapMatchingHandler.LAST_PROJECTIONS_WINDOW_SIZE) {
350
325
  this._lastProjections.shift();
351
326
  }
352
327
 
353
- const thisWillBeAHugeJump = projection.distanceFromNearestElement > this._hugeJumpDistance;
328
+ const thisWillBeAHugeJump = projection.distanceFromNearestElement > MapMatchingHandler.MM_HUGE_JUMP_DISTANCE;
354
329
 
355
330
  // In case of a huge jump, be sure the user is in a straight line
356
331
  if (thisWillBeAHugeJump && !StraightLineDetector.isStraight()) {
@@ -370,13 +345,6 @@ class MapMatchingHandler extends Provider {
370
345
  return true;
371
346
  }
372
347
 
373
- // Detector to avoid map-matching close to network turns
374
- if (this._disableMMCloseToATurnDistance > 0
375
- && this._hasTurnInCircle(projection.projection, this._disableMMCloseToATurnDistance)) {
376
- AbsolutePosition.notify(positionEvent);
377
- return true;
378
- }
379
-
380
348
  AbsolutePosition.notify(this.createEvent(
381
349
  EventType.AbsolutePosition,
382
350
  projection.projection,
@@ -408,7 +376,7 @@ class MapMatchingHandler extends Provider {
408
376
  }
409
377
 
410
378
  this._lastProjections.push(projectionWithAbs);
411
- if (this._lastProjections.length > this._lastProjectionsWindowSize) {
379
+ if (this._lastProjections.length > MapMatchingHandler.LAST_PROJECTIONS_WINDOW_SIZE) {
412
380
  this._lastProjections.shift();
413
381
  }
414
382
 
@@ -473,57 +441,22 @@ class MapMatchingHandler extends Provider {
473
441
  return !this._lastProjections.some(projection =>
474
442
  !(projection.nearestElement instanceof GraphEdge)
475
443
  || (diffAngleLines(projection.nearestElement.bearing, firstProjection.nearestElement.bearing)
476
- > this._lastProjectionsEdgeAngleThreshold)
444
+ > MapMatchingHandler.LAST_PROJECTIONS_EDGE_ANGLE_THRESHOLD)
477
445
  );
478
446
  }
479
447
 
480
- /**
481
- * @param {GraphNode} node
482
- * @returns {boolean}
483
- */
484
- _nodeHasTurn(node) {
485
- const { edges } = node;
486
- for (let i = 0; i < edges.length; i++) {
487
- for (let j = i + 1; j < edges.length; j++) {
488
- const angle = diffAngleLines(edges[i].bearing, edges[j].bearing);
489
- if (angle > MapMatchingHandler.DEFAULT_MM_MAX_ANGLE) {
490
- return true;
491
- }
492
- }
493
- }
494
- return false;
495
- }
496
-
497
- /**
498
- * @param {Coordinates} center
499
- * @param {number} radius
500
- * @returns {boolean}
501
- */
502
- _hasTurnInCircle(center, radius) {
503
- /** @type {Network} */
504
- const network = this._mapMatching.network;
505
- if (!network) {
506
- return false;
507
- }
508
-
509
- return network.nodes.filter(node =>
510
- node.coords.distanceTo(center) <= radius
511
- && Level.intersect(node.coords.level, center.level)
512
- ).some(this._nodeHasTurn);
513
- }
514
-
515
448
  /**
516
449
  * @param {Projection} projection
517
450
  */
518
451
  tryOrientationMatching(projection) {
519
452
 
520
- if (!this._useOrientationMatching) {
453
+ if (!MapMatchingHandler.ORIENTATION_MATCHING) {
521
454
  return;
522
455
  }
523
456
 
524
457
  if (this.state !== ProviderState.STARTED
525
- || this._countStepsFromLastMatching < this._minStepsBetweenOrientationMatching
526
- || StraightLineDetector.numStepsDetectedFromLastTurn < this._minStepsForOrientationMatching) {
458
+ || this._countStepsFromLastMatching < MapMatchingHandler.MIN_STEPS_BETWEEN_ORIENTATION_MATCHING
459
+ || StraightLineDetector.numStepsDetectedFromLastTurn < MapMatchingHandler.MIN_STEPS_FOR_ORIENTATION_MATCHING) {
527
460
  return;
528
461
  }
529
462
 
@@ -591,70 +524,6 @@ class MapMatchingHandler extends Provider {
591
524
  set useItineraryStartAsPosition(useItineraryStartAsPosition) {
592
525
  this._useItineraryStartAsPosition = useItineraryStartAsPosition;
593
526
  }
594
-
595
- get useOrientationMatching() {
596
- return this._useOrientationMatching;
597
- }
598
-
599
- set useOrientationMatching(useOrientationMatching) {
600
- this._useOrientationMatching = useOrientationMatching;
601
- }
602
-
603
- get hugeJumpDistance() {
604
- return this._hugeJumpDistance;
605
- }
606
-
607
- set hugeJumpDistance(hugeJumpDistance) {
608
- this._hugeJumpDistance = hugeJumpDistance;
609
- }
610
-
611
- get disableMMCloseToATurnDistance() {
612
- return this._disableMMCloseToATurnDistance;
613
- }
614
-
615
- set disableMMCloseToATurnDistance(disableMMCloseToATurnDistance) {
616
- this._disableMMCloseToATurnDistance = disableMMCloseToATurnDistance;
617
- }
618
-
619
- get useOrientationMatching() {
620
- return this._useOrientationMatching;
621
- }
622
-
623
- set useOrientationMatching(useOrientationMatching) {
624
- this._useOrientationMatching = useOrientationMatching;
625
- }
626
-
627
- get minStepsBetweenOrientationMatching() {
628
- return this._minStepsBetweenOrientationMatching;
629
- }
630
-
631
- set minStepsBetweenOrientationMatching(minStepsBetweenOrientationMatching) {
632
- this._minStepsBetweenOrientationMatching = minStepsBetweenOrientationMatching;
633
- }
634
-
635
- get minStepsForOrientationMatching() {
636
- return this._minStepsForOrientationMatching;
637
- }
638
-
639
- set minStepsForOrientationMatching(minStepsForOrientationMatching) {
640
- this._minStepsForOrientationMatching = minStepsForOrientationMatching;
641
- }
642
-
643
- get lastProjectionsWindowSize() {
644
- return this._lastProjectionsWindowSize;
645
- }
646
-
647
- set lastProjectionsWindowSize(lastProjectionsWindowSize) {
648
- this._lastProjectionsWindowSize = lastProjectionsWindowSize;
649
- }
650
-
651
- get lastProjectionsEdgeAngleThreshold() {
652
- return this._lastProjectionsEdgeAngleThreshold;
653
- }
654
-
655
- set lastProjectionsEdgeAngleThreshold(lastProjectionsEdgeAngleThreshold) {
656
- this._lastProjectionsEdgeAngleThreshold = lastProjectionsEdgeAngleThreshold;
657
- }
658
527
  }
659
528
 
660
529
  export default new MapMatchingHandler();
@@ -1,4 +1,4 @@
1
- import { UserPosition, GeoRelativePosition, Level } from '@wemap/geo';
1
+ import { UserPosition, GeoRelativePosition } from '@wemap/geo';
2
2
  import { PromiseUtils, TimeUtils } from '@wemap/utils';
3
3
 
4
4
  import Provider from '../../Provider.js';
@@ -9,7 +9,7 @@ import GnssWifi from './GnssWifi.js';
9
9
  import { default as GeoRelativePositionProvider } from '../relative/GeoRelativePosition.js';
10
10
  import ProvidersOptions from '../../../ProvidersOptions.js';
11
11
  import ProviderState from '../../ProviderState.js';
12
- import Vps from '../../vision/Vps.js';
12
+ import Vps from '../../vision/vps/Vps.js';
13
13
  import PoleStar from './PoleStar.js';
14
14
 
15
15
  class AbsolutePosition extends Provider {
@@ -20,9 +20,6 @@ class AbsolutePosition extends Provider {
20
20
  /** @type {boolean} */
21
21
  static USE_MM_FOR_FEED = true;
22
22
 
23
- /** @type {boolean} */
24
- useAllAbsolutePositions = false;
25
-
26
23
  /** @type {number?} */
27
24
  _gnssWifiProviderId;
28
25
 
@@ -53,18 +50,10 @@ class AbsolutePosition extends Provider {
53
50
  * @override
54
51
  */
55
52
  get _availability() {
56
-
57
- const providersToCheck = [
53
+ return PromiseUtils.any([
58
54
  GeoRelativePositionProvider.availability,
59
55
  GnssWifi.availability
60
- ];
61
- if (ProvidersOptions.hasPoleStar) {
62
- providersToCheck.push(PoleStar.availability);
63
- }
64
- if (ProvidersOptions.hasVps) {
65
- providersToCheck.push(Vps.availability);
66
- }
67
- return PromiseUtils.any(providersToCheck);
56
+ ]);
68
57
  }
69
58
 
70
59
 
@@ -157,54 +146,6 @@ class AbsolutePosition extends Provider {
157
146
  MapMatchingHandler.removeEventListener(this._mapMatchingHandlerId);
158
147
  }
159
148
 
160
- /**
161
- * @param {ProviderEvent<UserPosition>} newPositionEvent
162
- * @param {boolean} canContainLevel
163
- * @returns {boolean}
164
- */
165
- _shouldTakeIntoAccountNewAbsolutePosition(newPositionEvent, canContainLevel = true) {
166
-
167
- const newPosition = newPositionEvent.data;
168
- const lastPosition = this.lastEvent ? this.lastEvent.data : null;
169
-
170
- // 1. Verifiy if it is the first known absolute position
171
- if (!lastPosition) {
172
- return true;
173
- }
174
-
175
- // 2. Is the new position accuracy is better enough than the last position accuracy
176
- const isBetterEnough = newPosition.accuracy * AbsolutePosition.ACCURACY_RELOC_RATIO <= lastPosition.accuracy;
177
- if (isBetterEnough) {
178
- return true;
179
- }
180
-
181
- // 3.a. Is the new position is far from the new one (regarding accuracy)
182
- // This condition return true if the two positions accuracy circles does not intersect.
183
- // This is important if the person put the current page in the background during a while. But,
184
- // could be dangerous if two providers do not provide close positions (ping-pong effect). This
185
- // is why the 3.b. condition has been added.
186
- // TODO: add a routine to augment the current position accuracy when the page is in background
187
- const isFarEnough = lastPosition.distanceTo(newPosition) > lastPosition.accuracy + newPosition.accuracy;
188
-
189
- // 3.b. Added on 16/06/22
190
- // The goal of this condition is to avoid continuous jumps between positions from two providers
191
- // (i.e. GnssWifi and PoleStar)
192
- const isFarEnoughAndAccuracyIsBetter = isFarEnough && newPosition.accuracy <= lastPosition.accuracy;
193
-
194
- if (isBetterEnough && isFarEnoughAndAccuracyIsBetter) {
195
- return true;
196
- }
197
-
198
- // 4. Added on 23/06/22
199
- // The goal of this condition is to take into account levels change when map-matching is not enabled / set
200
- const isChangingLevel = canContainLevel && !Level.equals(newPosition.level, lastPosition.level);
201
- if (isChangingLevel) {
202
- return true;
203
- }
204
-
205
- return false;
206
- }
207
-
208
149
  /**
209
150
  * @param {ProviderEvent<UserPosition>} positionEvent
210
151
  * @param {boolean} canContainLevel
@@ -212,15 +153,22 @@ class AbsolutePosition extends Provider {
212
153
  */
213
154
  _onAbsolutePosition(positionEvent, canContainLevel = true) {
214
155
 
215
- if (!this._shouldTakeIntoAccountNewAbsolutePosition(positionEvent, canContainLevel)
216
- && !this.useAllAbsolutePositions) {
217
- return false;
218
- }
219
-
220
156
  const newPosition = positionEvent.data.clone();
221
157
  const lastPosition = this.lastEvent ? this.lastEvent.data : null;
222
158
 
223
159
  if (lastPosition) {
160
+
161
+ // Is the new position accuracy is better enough than the last position accuracy
162
+ const isBetterEnough = newPosition.accuracy * AbsolutePosition.ACCURACY_RELOC_RATIO <= lastPosition.accuracy;
163
+
164
+ // Is the new position is far from the new one (regarding accuracy)
165
+ // This is important if the person put the current page in the background during a while
166
+ const isFarEnough = lastPosition.distanceTo(newPosition) > lastPosition.accuracy + newPosition.accuracy;
167
+
168
+ if (!isBetterEnough && !isFarEnough) {
169
+ return false;
170
+ }
171
+
224
172
  if (!canContainLevel) {
225
173
  newPosition.level = lastPosition.level;
226
174
  }
@@ -1,7 +1,6 @@
1
1
  /* eslint-disable no-bitwise */
2
2
 
3
3
  import { UserPosition } from '@wemap/geo';
4
- import { deg2rad } from '@wemap/maths';
5
4
  import { TimeUtils } from '@wemap/utils';
6
5
 
7
6
  import Provider from '../../Provider.js';
@@ -98,7 +97,7 @@ class PoleStar extends Provider {
98
97
  json.alt / 5,
99
98
  timestamp,
100
99
  json.accuracy,
101
- deg2rad(json.bearing),
100
+ json.bearing,
102
101
  this.pname);
103
102
 
104
103
  this.notify(this.createEvent(
@@ -6,30 +6,14 @@ import RelativeAttitudeFromInertial from '../attitude/relative/RelativeAttitudeF
6
6
  import Accelerometer from '../imu/Accelerometer.js';
7
7
  import Gyroscope from '../imu/Gyroscope.js';
8
8
  import Provider from '../Provider.js';
9
- import StepDetectionLadetto from './StepDetectionLadetto.js';
10
- import StepDetectionMinMaxPeaks from './StepDetectionMinMaxPeaks.js';
11
9
  import StepDetectionMinMaxPeaks2 from './StepDetectionMinMaxPeaks2.js';
12
- import StepDetectionMinMaxPeaks3 from './StepDetectionMinMaxPeaks3.js';
13
10
 
14
11
 
15
12
  class StepDetector extends Provider {
16
13
 
17
- /** @type {number} */
18
- static DEFAULT_STEP_SIZE_MULTIPLIER = 1;
19
-
20
- // ladetto, minMaxPeaks, minMaxPeaks2, minMaxPeaks3
21
- static DEFAULT_ALGORITHM = 'minMaxPeaks3';
22
-
23
- _stepSizeMultiplier = StepDetector.DEFAULT_STEP_SIZE_MULTIPLIER;
24
-
25
- /** @type {string} */
26
- _algorithm = StepDetector.DEFAULT_ALGORITHM;
27
-
28
- _accValues = [];
29
-
30
14
  constructor() {
31
15
  super();
32
- this.algorithm = this._algorithm;
16
+ this.stepDetector = new StepDetectionMinMaxPeaks2();
33
17
  }
34
18
 
35
19
  /**
@@ -100,7 +84,7 @@ class StepDetector extends Provider {
100
84
  const stepDetected = this.stepDetector.compute(timestamp, linearAcc, this.angularRateEvent.data.values);
101
85
 
102
86
  if (stepDetected) {
103
- const size = this.stepDetector.lastStepSize * this._stepSizeMultiplier;
87
+ const size = this.stepDetector.lastStepSize;
104
88
  this.numOfSteps++;
105
89
  this.notify(this.createEvent(
106
90
  EventType.Step, {
@@ -118,34 +102,6 @@ class StepDetector extends Provider {
118
102
  linearAcc[2] -= GeoConstants.EARTH_GRAVITY;
119
103
  return linearAcc;
120
104
  }
121
-
122
- set stepSizeMultiplier(stepSizeMultiplier) {
123
- this._stepSizeMultiplier = stepSizeMultiplier;
124
- }
125
-
126
- get stepSizeMultiplier() {
127
- return this._stepSizeMultiplier;
128
- }
129
-
130
- set algorithm(algorithm) {
131
- switch (algorithm) {
132
- case 'ladetto':
133
- this.stepDetector = new StepDetectionLadetto();
134
- break;
135
- case 'minMaxPeaks':
136
- this.stepDetector = new StepDetectionMinMaxPeaks();
137
- break;
138
- case 'minMaxPeaks2':
139
- this.stepDetector = new StepDetectionMinMaxPeaks2();
140
- break;
141
- case 'minMaxPeaks3':
142
- default:
143
- algorithm = 'minMaxPeaks3';
144
- this.stepDetector = new StepDetectionMinMaxPeaks3();
145
- break;
146
- }
147
- this._algorithm = algorithm;
148
- }
149
105
  }
150
106
 
151
107
  export default new StepDetector();
@@ -6,7 +6,7 @@ import EventType from '../../events/EventType.js';
6
6
  class StraightLineDetector extends Provider {
7
7
 
8
8
  /** @type {number} */
9
- static DEFAULT_STEPS_CONSIDERED_FOR_STRAIGHT_LINE = 2;
9
+ static STEPS_CONSIDERED_FOR_STRAIGHT_LINE = 2;
10
10
 
11
11
  /** @type {number?} */
12
12
  _turnDetectorProviderId = null;
@@ -17,9 +17,6 @@ class StraightLineDetector extends Provider {
17
17
  /** @type {number} */
18
18
  _countSteps = 0;
19
19
 
20
- /** @type {number} */
21
- _stepsConsideredForStraightLine = StraightLineDetector.DEFAULT_STEPS_CONSIDERED_FOR_STRAIGHT_LINE;
22
-
23
20
  /**
24
21
  * @override
25
22
  */
@@ -44,7 +41,7 @@ class StraightLineDetector extends Provider {
44
41
  }
45
42
 
46
43
  _onTurn = (event) => {
47
- if (this._countSteps >= this._stepsConsideredForStraightLine) {
44
+ if (this._countSteps >= StraightLineDetector.STEPS_CONSIDERED_FOR_STRAIGHT_LINE) {
48
45
 
49
46
  const fromEvents = [event];
50
47
  if (StepDetector.lastEvent !== null) {
@@ -60,7 +57,7 @@ class StraightLineDetector extends Provider {
60
57
  _onStep = (event) => {
61
58
  this._countSteps++;
62
59
 
63
- if (this._countSteps === this._stepsConsideredForStraightLine) {
60
+ if (this._countSteps === StraightLineDetector.STEPS_CONSIDERED_FOR_STRAIGHT_LINE) {
64
61
 
65
62
  const fromEvents = [event];
66
63
  if (TurnDectector.lastEvent !== null) {
@@ -82,14 +79,6 @@ class StraightLineDetector extends Provider {
82
79
  get numStepsDetectedFromLastTurn() {
83
80
  return this._countSteps;
84
81
  }
85
-
86
- get stepsConsideredForStraightLine() {
87
- return this._stepsConsideredForStraightLine;
88
- }
89
-
90
- set stepsConsideredForStraightLine(stepsConsideredForStraightLine) {
91
- this._stepsConsideredForStraightLine = stepsConsideredForStraightLine;
92
- }
93
82
  }
94
83
 
95
84
  export default new StraightLineDetector();