@wemap/providers 4.0.0 → 4.0.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.
Files changed (66) hide show
  1. package/debug/dist/index.html +1 -0
  2. package/debug/dist/turn-detection.html +19 -0
  3. package/debug/index.js +2 -0
  4. package/debug/src/AbsoluteAttitudeComponent.jsx +3 -10
  5. package/debug/src/StepDetectionComponent.jsx +3 -3
  6. package/debug/src/TurnDetectionComponent.jsx +47 -0
  7. package/debug/src/Utils.js +20 -0
  8. package/package.json +7 -9
  9. package/src/Providers.js +26 -81
  10. package/src/ProvidersInterface.js +5 -6
  11. package/src/errors/AskImuOnDesktopError.js +4 -3
  12. package/src/errors/ContainsIgnoredProviderError.js +4 -3
  13. package/src/errors/GeolocationApiMissingError.js +4 -3
  14. package/src/errors/GeolocationPermissionDeniedError.js +4 -3
  15. package/src/errors/GeolocationPositionUnavailableError.js +4 -3
  16. package/src/errors/IpResolveServerError.js +4 -3
  17. package/src/errors/MissingAccelerometerError.js +3 -3
  18. package/src/errors/MissingArCoreError.js +4 -3
  19. package/src/errors/MissingGyroscopeError.js +3 -3
  20. package/src/errors/MissingNativeInterfaceError.js +4 -3
  21. package/src/errors/MissingSensorError.js +4 -3
  22. package/src/errors/NoProviderFoundError.js +4 -3
  23. package/src/events/EventType.js +5 -1
  24. package/src/events/ProviderEvent.js +7 -0
  25. package/src/events/ProvidersLoggerOld.js +35 -34
  26. package/src/mapmatching/MapMatchingHandler.js +335 -69
  27. package/src/providers/FakeProvider.spec.js +15 -15
  28. package/src/providers/Provider.js +44 -27
  29. package/src/providers/Provider.spec.js +18 -29
  30. package/src/providers/attitude/TurnDectector.js +71 -0
  31. package/src/providers/attitude/absolute/AbsoluteAttitude.js +232 -0
  32. package/src/providers/attitude/absolute/{AbsoluteAttitudeFromBrowserProvider.js → AbsoluteAttitudeFromBrowser.js} +4 -4
  33. package/src/providers/attitude/relative/{RelativeAttitudeProvider.js → RelativeAttitude.js} +5 -8
  34. package/src/providers/attitude/relative/{RelativeAttitudeFromBrowserProvider.js → RelativeAttitudeFromBrowser.js} +4 -5
  35. package/src/providers/attitude/relative/{RelativeAttitudeFromEkfProvider.js → RelativeAttitudeFromEkf.js} +7 -8
  36. package/src/providers/attitude/relative/{RelativeAttitudeFromInertialProvider.js → RelativeAttitudeFromInertial.js} +24 -7
  37. package/src/providers/imu/{AccelerometerProvider.js → Accelerometer.js} +3 -3
  38. package/src/providers/imu/{GyroscopeProvider.js → Gyroscope.js} +3 -3
  39. package/src/providers/imu/HighRotationsDetector.js +62 -0
  40. package/src/providers/imu/{ImuProvider.js → Imu.js} +3 -3
  41. package/src/providers/inclination/{InclinationProvider.js → Inclination.js} +5 -6
  42. package/src/providers/inclination/{InclinationFromAccProvider.js → InclinationFromAcc.js} +4 -3
  43. package/src/providers/inclination/{InclinationFromRelativeAttitudeProvider.js → InclinationFromRelativeAttitude.js} +4 -3
  44. package/src/providers/legacy/helpers/ThugDetector.js +7 -7
  45. package/src/providers/others/{BarcodeProvider.js → Barcode.js} +3 -3
  46. package/src/providers/others/{CameraNativeProvider.js → CameraNative.js} +3 -3
  47. package/src/providers/others/{CameraProjectionMatrixProvider.js → CameraProjectionMatrix.js} +4 -4
  48. package/src/providers/position/absolute/AbsolutePosition.js +217 -0
  49. package/src/providers/position/absolute/{GnssWifiProvider.js → GnssWifi.js} +9 -8
  50. package/src/providers/position/absolute/{IpProvider.js → Ip.js} +2 -2
  51. package/src/providers/position/relative/{ArCoreProvider.js → ArCore.js} +28 -30
  52. package/src/providers/position/relative/{GeoRelativePositionProvider.js → GeoRelativePosition.js} +6 -6
  53. package/src/providers/position/relative/{GeoRelativePositionFromArCoreProvider.js → GeoRelativePositionFromArCore.js} +4 -5
  54. package/src/providers/position/relative/{PdrProvider.js → Pdr.js} +8 -8
  55. package/src/providers/steps/StepDetectionLadetto.js +12 -13
  56. package/src/providers/steps/StepDetectionMinMaxPeaks.js +19 -17
  57. package/src/providers/steps/StepDetectionMinMaxPeaks2.js +17 -18
  58. package/src/providers/steps/{StepDetectionProvider.js → StepDetector.js} +8 -7
  59. package/src/providers/steps/StraightLineDetector.js +80 -0
  60. package/src/smoothers/AttitudeSmoother.js +94 -59
  61. package/src/providers/MetaProvider.js +0 -44
  62. package/src/providers/attitude/absolute/AbsoluteAttitudeFromRelAttProvider.js +0 -132
  63. package/src/providers/attitude/absolute/AbsoluteAttitudeFusedProvider.js +0 -166
  64. package/src/providers/attitude/absolute/AbsoluteAttitudeProvider.js +0 -175
  65. package/src/providers/position/absolute/AbsolutePositionFromRelProvider.js +0 -107
  66. package/src/providers/position/absolute/AbsolutePositionProvider.js +0 -189
@@ -3,10 +3,10 @@ import { Attitude } from '@wemap/geo';
3
3
  import Provider from '../../Provider.js';
4
4
  import EventType from '../../../events/EventType.js';
5
5
  import EkfAttitude from '../EkfAttitude.js';
6
- import RelativeAttitudeFromInertialProvider from './RelativeAttitudeFromInertialProvider.js';
7
- import {
8
- Accelerometer, Gyroscope
9
- } from '../../../Providers.js';
6
+ import RelativeAttitudeFromInertial from './RelativeAttitudeFromInertial.js';
7
+
8
+ import Accelerometer from '../../imu/Accelerometer.js';
9
+ import Gyroscope from '../../imu/Gyroscope.js';
10
10
 
11
11
 
12
12
  /**
@@ -14,7 +14,7 @@ import {
14
14
  * browser deviceorientation
15
15
  * The provider does not work until an offset is given.
16
16
  */
17
- class RelativeAttitudeFromEkfProvider extends Provider {
17
+ class RelativeAttitudeFromEkf extends Provider {
18
18
 
19
19
  lastTimestamp = 0;
20
20
 
@@ -99,8 +99,7 @@ class RelativeAttitudeFromEkfProvider extends Provider {
99
99
  if (quaternion) {
100
100
  const attitude = new Attitude(quaternion,
101
101
  timestamp,
102
- RelativeAttitudeFromInertialProvider.DEFAULT_DRIFT,
103
- this.pname
102
+ RelativeAttitudeFromInertial.DEFAULT_DRIFT
104
103
  );
105
104
  this.notify(this.createEvent(
106
105
  EventType.RelativeAttitude,
@@ -110,4 +109,4 @@ class RelativeAttitudeFromEkfProvider extends Provider {
110
109
  };
111
110
  }
112
111
 
113
- export default RelativeAttitudeFromEkfProvider;
112
+ export default new RelativeAttitudeFromEkf();
@@ -1,18 +1,21 @@
1
+ import { Attitude } from '@wemap/geo';
1
2
  import { deg2rad } from '@wemap/maths';
2
3
  import { PromiseUtils } from '@wemap/utils';
3
4
 
4
5
  import Provider from '../../Provider.js';
6
+ import ProviderEvent from '../../../events/ProviderEvent.js';
5
7
  import EventType from '../../../events/EventType.js';
6
- import {
7
- RelativeAttitudeFromEkf, RelativeAttitudeFromBrowser
8
- } from '../../../Providers.js';
8
+ import RelativeAttitudeFromEkf from './RelativeAttitudeFromEkf.js';
9
+ import RelativeAttitudeFromBrowser from './RelativeAttitudeFromBrowser.js';
10
+ import HighRotationsDetector from '../../imu/HighRotationsDetector.js';
9
11
 
10
- class RelativeAttitudeFromInertialProvider extends Provider {
12
+
13
+ class RelativeAttitudeFromInertial extends Provider {
11
14
 
12
15
  /**
13
16
  * default relative attitude drift in rad.second-1
14
17
  */
15
- static DEFAULT_DRIFT = deg2rad(5) / 60;
18
+ DEFAULT_DRIFT = deg2rad(5) / 60;
16
19
 
17
20
 
18
21
  /**
@@ -49,11 +52,24 @@ class RelativeAttitudeFromInertialProvider extends Provider {
49
52
  .catch(() => (this.provider = RelativeAttitudeFromBrowser))
50
53
  .finally(() => {
51
54
  this.listenerId = this.provider.addEventListener(
52
- events => this.notify(events[0].clone()),
55
+ events => this._parseEvent(events[0]),
53
56
  error => this.notifyError(error)
54
57
  );
58
+ this._highRotationsDetector = HighRotationsDetector.addEventListener();
55
59
  });
60
+ }
56
61
 
62
+ /**
63
+ * @param {ProviderEvent<Attitude>} event
64
+ */
65
+ _parseEvent(event) {
66
+ const relativeAttitudeEvent = event.clone();
67
+ if (HighRotationsDetector.isInProgress()) {
68
+ let accuracy = relativeAttitudeEvent.data.accuracy + (this.DEFAULT_DRIFT * 100);
69
+ accuracy = Math.min(accuracy, Math.PI);
70
+ relativeAttitudeEvent.data.accuracy = accuracy;
71
+ }
72
+ this.notify(relativeAttitudeEvent);
57
73
  }
58
74
 
59
75
  /**
@@ -64,7 +80,8 @@ class RelativeAttitudeFromInertialProvider extends Provider {
64
80
  this.provider.removeEventListener(this.listenerId);
65
81
  this.provider = null;
66
82
  }
83
+ HighRotationsDetector.removeEventListener(this._highRotationsDetector);
67
84
  }
68
85
  }
69
86
 
70
- export default RelativeAttitudeFromInertialProvider;
87
+ export default new RelativeAttitudeFromInertial();
@@ -1,9 +1,9 @@
1
1
  import Provider from '../Provider.js';
2
2
  import EventType from '../../events/EventType.js';
3
3
  import MissingAccelerometerError from '../../errors/MissingAccelerometerError.js';
4
- import { Imu } from '../../Providers.js';
4
+ import Imu from './Imu.js';
5
5
 
6
- class AccelerometerProvider extends Provider {
6
+ class Accelerometer extends Provider {
7
7
 
8
8
  /**
9
9
  * @override
@@ -58,4 +58,4 @@ class AccelerometerProvider extends Provider {
58
58
 
59
59
  }
60
60
 
61
- export default AccelerometerProvider;
61
+ export default new Accelerometer();
@@ -1,9 +1,9 @@
1
1
  import Provider from '../Provider.js';
2
2
  import EventType from '../../events/EventType.js';
3
3
  import MissingGyroscopeError from '../../errors/MissingGyroscopeError.js';
4
- import { Imu } from '../../Providers.js';
4
+ import Imu from './Imu.js';
5
5
 
6
- class GyroscopeProvider extends Provider {
6
+ class Gyroscope extends Provider {
7
7
 
8
8
  /**
9
9
  * @override
@@ -58,4 +58,4 @@ class GyroscopeProvider extends Provider {
58
58
 
59
59
  }
60
60
 
61
- export default GyroscopeProvider;
61
+ export default new Gyroscope();
@@ -0,0 +1,62 @@
1
+ import { Vector3 } from '@wemap/maths';
2
+
3
+ import EventType from '../../events/EventType.js';
4
+ import Provider from '../Provider.js';
5
+ import Gyroscope from './Gyroscope.js';
6
+
7
+ class HighRotationsDetector extends Provider {
8
+
9
+ // in radians by second
10
+ static THRESHOLD = 10;
11
+
12
+ /** @type {number} in seconds */
13
+ static DELAY_CONSIDERATION = 3;
14
+
15
+ /**
16
+ * @override
17
+ */
18
+ static get pname() {
19
+ return 'HighRotationsDetector';
20
+ }
21
+
22
+ /**
23
+ * @override
24
+ */
25
+ start() {
26
+ this.providerId = Gyroscope.addEventListener(
27
+ events => this._parseGyroscopeEvent(events[0]),
28
+ error => this.notifyError(error)
29
+ );
30
+ }
31
+
32
+ /**
33
+ * @override
34
+ */
35
+ stop() {
36
+ Gyroscope.removeEventListener(this.providerId);
37
+ }
38
+
39
+ isInProgress() {
40
+ if (!this.lastEvent || !Gyroscope.lastEvent) {
41
+ return false;
42
+ }
43
+
44
+ const diffTime = Gyroscope.lastEvent.data.timestamp - this.lastEvent.data.timestamp;
45
+ return diffTime < HighRotationsDetector.DELAY_CONSIDERATION;
46
+ }
47
+
48
+ /**
49
+ * @private
50
+ */
51
+ _parseGyroscopeEvent = gyroscopeEvent => {
52
+
53
+ const { values, timestamp } = gyroscopeEvent.data;
54
+ const speed = Vector3.norm(values);
55
+ if (speed > HighRotationsDetector.THRESHOLD) {
56
+ this.notify(this.createEvent(EventType.HighRotation, { timestamp }, [gyroscopeEvent]));
57
+ }
58
+
59
+ }
60
+ }
61
+
62
+ export default new HighRotationsDetector();
@@ -22,7 +22,7 @@ import AskImuOnDesktopError from '../../errors/AskImuOnDesktopError.js';
22
22
  *
23
23
  * -----------------------------------
24
24
  */
25
- class ImuProvider extends Provider {
25
+ class Imu extends Provider {
26
26
 
27
27
  /**
28
28
  * @override
@@ -41,7 +41,7 @@ class ImuProvider extends Provider {
41
41
  /**
42
42
  * @override
43
43
  */
44
- get _availability() {
44
+ static get _availability() {
45
45
  return BrowserUtils.isMobile
46
46
  ? Promise.resolve()
47
47
  : Promise.reject(new AskImuOnDesktopError());
@@ -136,4 +136,4 @@ class ImuProvider extends Provider {
136
136
 
137
137
  }
138
138
 
139
- export default ImuProvider;
139
+ export default new Imu();
@@ -1,10 +1,9 @@
1
1
  import { PromiseUtils } from '@wemap/utils';
2
2
 
3
- import MetaProvider from '../MetaProvider.js';
3
+ import Provider from '../Provider.js';
4
4
  import EventType from '../../events/EventType.js';
5
- import {
6
- InclinationFromRelativeAttitude, InclinationFromAcc
7
- } from '../../Providers.js';
5
+ import InclinationFromAcc from './InclinationFromAcc.js';
6
+ import InclinationFromRelativeAttitude from './InclinationFromRelativeAttitude.js';
8
7
 
9
8
  /**
10
9
  * Inclination provider gives the inclination of the device using Imu Sensor
@@ -12,7 +11,7 @@ import {
12
11
  * when the device is layed on a table, inclination = 0
13
12
  * This provider use window.orientation to return a result in function of screen orientation
14
13
  */
15
- class InclinationProvider extends MetaProvider {
14
+ class Inclination extends Provider {
16
15
 
17
16
  /**
18
17
  * @override
@@ -75,4 +74,4 @@ class InclinationProvider extends MetaProvider {
75
74
  }
76
75
  }
77
76
 
78
- export default InclinationProvider;
77
+ export default new Inclination();
@@ -1,6 +1,7 @@
1
1
  import Provider from '../Provider.js';
2
2
  import EventType from '../../events/EventType.js';
3
- import { Accelerometer } from '../../Providers.js';
3
+
4
+ import Accelerometer from '../imu/Accelerometer.js';
4
5
 
5
6
  /**
6
7
  * Inclination provider gives the inclination of the device using Imu Sensor
@@ -8,7 +9,7 @@ import { Accelerometer } from '../../Providers.js';
8
9
  * when the device is layed on a table, inclination = 0
9
10
  * This provider use window.orientation to return a result in function of screen orientation
10
11
  */
11
- class InclinationFromAccProvider extends Provider {
12
+ class InclinationFromAcc extends Provider {
12
13
 
13
14
 
14
15
  /**
@@ -83,4 +84,4 @@ class InclinationFromAccProvider extends Provider {
83
84
  };
84
85
  }
85
86
 
86
- export default InclinationFromAccProvider;
87
+ export default new InclinationFromAcc();
@@ -1,6 +1,7 @@
1
1
  import Provider from '../Provider.js';
2
2
  import EventType from '../../events/EventType.js';
3
- import { RelativeAttitudeFromInertial } from '../../Providers.js';
3
+ import RelativeAttitudeFromInertial from '../attitude/relative/RelativeAttitudeFromInertial.js';
4
+
4
5
 
5
6
  /**
6
7
  * Inclination provider gives the inclination of the device using Relative Attitude
@@ -8,7 +9,7 @@ import { RelativeAttitudeFromInertial } from '../../Providers.js';
8
9
  * when the device is layed on a table, inclination = 0
9
10
  * This provider use window.orientation to return a result in function of screen orientation
10
11
  */
11
- class InclinationFromRelativeAttitudeProvider extends Provider {
12
+ class InclinationFromRelativeAttitude extends Provider {
12
13
 
13
14
  /**
14
15
  * @override
@@ -73,4 +74,4 @@ class InclinationFromRelativeAttitudeProvider extends Provider {
73
74
  }
74
75
  }
75
76
 
76
- export default InclinationFromRelativeAttitudeProvider;
77
+ export default new InclinationFromRelativeAttitude();
@@ -1,14 +1,14 @@
1
1
  import { Constants as GeoConstants } from '@wemap/geo';
2
2
  import { Vector3 } from '@wemap/maths';
3
3
 
4
- // in seconds
5
- const MIN_TIME_BETWEEN_DETECTIONS = 0.5;
6
4
 
7
- // in m.s^-2
8
- const EXT_ACC_NORM_THRESHOLD = 4;
5
+ class ThugDetector {
9
6
 
7
+ // in seconds
8
+ static MIN_TIME_BETWEEN_DETECTIONS = 0.5;
10
9
 
11
- class ThugDetector {
10
+ // in m.s^-2
11
+ static EXT_ACC_NORM_THRESHOLD = 4;
12
12
 
13
13
  constructor() {
14
14
  this.lastDetectionTimestamp = 0;
@@ -18,12 +18,12 @@ class ThugDetector {
18
18
 
19
19
  let detection = false;
20
20
 
21
- if (timestamp - this.lastDetectionTimestamp < MIN_TIME_BETWEEN_DETECTIONS) {
21
+ if (timestamp - this.lastDetectionTimestamp < ThugDetector.MIN_TIME_BETWEEN_DETECTIONS) {
22
22
  return detection;
23
23
  }
24
24
 
25
25
  const extAccNorm = Vector3.norm(acceleration) - GeoConstants.EARTH_GRAVITY;
26
- if (Math.abs(extAccNorm) > EXT_ACC_NORM_THRESHOLD) {
26
+ if (Math.abs(extAccNorm) > ThugDetector.EXT_ACC_NORM_THRESHOLD) {
27
27
  detection = true;
28
28
  this.lastDetectionTimestamp = timestamp;
29
29
  }
@@ -1,8 +1,8 @@
1
1
  import Provider from '../Provider.js';
2
2
  import EventType from '../../events/EventType.js';
3
- import { ArCore } from '../../Providers.js';
3
+ import ArCore from '../position/relative/ArCore.js';
4
4
 
5
- class BarcodeProvider extends Provider {
5
+ class Barcode extends Provider {
6
6
 
7
7
  /**
8
8
  * @override
@@ -51,4 +51,4 @@ class BarcodeProvider extends Provider {
51
51
  }
52
52
  }
53
53
 
54
- export default BarcodeProvider;
54
+ export default new Barcode();
@@ -1,9 +1,9 @@
1
- import MetaProvider from '../MetaProvider.js';
1
+ import Provider from '../Provider.js';
2
2
  import EventType from '../../events/EventType.js';
3
3
  import { ArCore } from '../../Providers.js';
4
4
  import ProviderState from '../ProviderState.js';
5
5
 
6
- class CameraNativeProvider extends MetaProvider {
6
+ class CameraNative extends Provider {
7
7
 
8
8
  /**
9
9
  * @override
@@ -52,4 +52,4 @@ class CameraNativeProvider extends MetaProvider {
52
52
  }
53
53
  }
54
54
 
55
- export default CameraNativeProvider;
55
+ export default new CameraNative();
@@ -1,8 +1,8 @@
1
- import MetaProvider from '../MetaProvider.js';
1
+ import Provider from '../Provider.js';
2
2
  import EventType from '../../events/EventType.js';
3
- import { ArCore } from '../../Providers.js';
3
+ import ArCore from '../position/relative/ArCore.js';
4
4
 
5
- class CameraProjectionMatrixProvider extends MetaProvider {
5
+ class CameraProjectionMatrix extends Provider {
6
6
 
7
7
  /**
8
8
  * @override
@@ -48,4 +48,4 @@ class CameraProjectionMatrixProvider extends MetaProvider {
48
48
  }
49
49
  }
50
50
 
51
- export default CameraProjectionMatrixProvider;
51
+ export default new CameraProjectionMatrix();
@@ -0,0 +1,217 @@
1
+ import { UserPosition, GeoRelativePosition } from '@wemap/geo';
2
+ import { PromiseUtils } from '@wemap/utils';
3
+
4
+ import Provider from '../../Provider.js';
5
+ import EventType from '../../../events/EventType.js';
6
+ import ProviderEvent from '../../../events/ProviderEvent.js';
7
+ import MapMatchingHandler from '../../../mapmatching/MapMatchingHandler.js';
8
+ import GnssWifi from './GnssWifi.js';
9
+ import { default as GeoRelativePositionProvider } from '../relative/GeoRelativePosition.js';
10
+
11
+ class AbsolutePosition extends Provider {
12
+
13
+ // Use the new absolute position if its accuracy is at least x times better than the last one.
14
+ static ACCURACY_RELOC_RATIO = 1.5;
15
+
16
+ /** @type {boolean} */
17
+ static USE_MM_FOR_FEED = true;
18
+
19
+
20
+ /** @type {number?} */
21
+ _gnssWifiProviderId;
22
+
23
+ /** @type {number?} */
24
+ _relativePositionProviderId;
25
+
26
+ /** @type {number?} */
27
+ _mapMatchingHandlerId
28
+
29
+ /**
30
+ * @override
31
+ */
32
+ static get pname() {
33
+ return 'AbsolutePosition';
34
+ }
35
+
36
+ /**
37
+ * @override
38
+ */
39
+ static get eventsType() {
40
+ return [EventType.AbsolutePosition];
41
+ }
42
+
43
+ /**
44
+ * @override
45
+ */
46
+ get _availability() {
47
+ return PromiseUtils.any([
48
+ GeoRelativePositionProvider.availability,
49
+ GnssWifi.availability
50
+ ]);
51
+ }
52
+
53
+
54
+ /**
55
+ * @override
56
+ */
57
+ start() {
58
+ GeoRelativePositionProvider.availability
59
+ .then(() => {
60
+ this._relativePositionProviderId = GeoRelativePositionProvider.addEventListener(
61
+ events => this._onRelativePosition(events[0])
62
+ );
63
+ })
64
+ .catch(() => {
65
+ // do nothing
66
+ });
67
+
68
+ this._gnssWifiProviderId = GnssWifi.addEventListener(
69
+ events => {
70
+ // bearing from GnssWifi is not reliable for our usecase
71
+ events[0].data.bearing = null;
72
+ this._onAbsolutePosition(events[0], false);
73
+ }
74
+ );
75
+
76
+ this._mapMatchingHandlerId = MapMatchingHandler.addEventListener();
77
+ }
78
+
79
+
80
+ /**
81
+ * @override
82
+ */
83
+ stop() {
84
+ if (this._relativePositionProviderId) {
85
+ GeoRelativePositionProvider.removeEventListener(this._relativePositionProviderId);
86
+ }
87
+ GnssWifi.removeEventListener(this._gnssWifiProviderId);
88
+
89
+ MapMatchingHandler.removeEventListener(this._mapMatchingHandlerId);
90
+ }
91
+
92
+ /**
93
+ * @param {ProviderEvent<UserPosition>} positionEvent
94
+ * @param {boolean} canContainLevel
95
+ */
96
+ _onAbsolutePosition(positionEvent, canContainLevel = true) {
97
+
98
+ const newPosition = positionEvent.data.clone();
99
+ const lastPosition = this.lastEvent ? this.lastEvent.data : null;
100
+
101
+ if (lastPosition) {
102
+
103
+ // Reject if the new position accuracy is not twice better than the last position accuracy
104
+ if (newPosition.accuracy * AbsolutePosition.ACCURACY_RELOC_RATIO > lastPosition.accuracy) {
105
+ return;
106
+ }
107
+
108
+ if (!canContainLevel) {
109
+ newPosition.level = lastPosition.level;
110
+ }
111
+
112
+ // If the new position does not have a bearing, retrieve the bearing from the last position
113
+ if (newPosition.bearing === null) {
114
+ newPosition.bearing = lastPosition.bearing;
115
+ }
116
+ }
117
+
118
+
119
+ const newPositionEvent = this.createEvent(
120
+ EventType.AbsolutePosition,
121
+ newPosition,
122
+ [positionEvent]
123
+ );
124
+
125
+ // If the MM is disable or the network is not set yet, use the new position as it is.
126
+ // If the position bearing is null, do not use MM, it is too dangerous.
127
+ if (!MapMatchingHandler.canUseMapMatching()) {
128
+ this.notify(newPositionEvent);
129
+ return;
130
+ }
131
+
132
+ MapMatchingHandler.notifyPositionFromAbsolute(newPositionEvent);
133
+ }
134
+
135
+ /**
136
+ * @param {ProviderEvent<GeoRelativePosition>} relativeEvent
137
+ */
138
+ _onRelativePosition(relativeEvent) {
139
+
140
+ if (!this.lastEvent) {
141
+ return;
142
+ }
143
+
144
+ const lastPosition = this.lastEvent.data;
145
+
146
+ const offsetPos = relativeEvent.data;
147
+
148
+ const dist = Math.sqrt(offsetPos.x ** 2 + offsetPos.y ** 2);
149
+ const bearing = Math.atan2(offsetPos.x, offsetPos.y);
150
+ const alt = lastPosition.alt !== null ? offsetPos.z : null;
151
+
152
+ const newPosition = lastPosition.destinationPoint(dist, bearing, alt);
153
+ newPosition.bearing = offsetPos.bearing;
154
+ newPosition.time = offsetPos.time;
155
+ newPosition.accuracy += offsetPos.accuracy;
156
+
157
+
158
+ const newPositionEvent = this.createEvent(
159
+ EventType.AbsolutePosition,
160
+ newPosition,
161
+ [relativeEvent]
162
+ );
163
+
164
+
165
+ if (!MapMatchingHandler.canUseMapMatching()) {
166
+ this.notify(newPositionEvent);
167
+ return;
168
+ }
169
+
170
+ MapMatchingHandler.notifyPositionFromRelative(newPositionEvent);
171
+ }
172
+
173
+
174
+ /**
175
+ * @override
176
+ * @param {UserPosition|ProviderEvent} data
177
+ */
178
+ feed(data) {
179
+
180
+ /** @type {ProviderEvent<UserPosition>} */
181
+ let newPositionEvent;
182
+
183
+ if (data instanceof UserPosition) {
184
+
185
+ if (data.time === null) {
186
+ throw Error('the time of the position is not defined');
187
+ }
188
+ if (data.accuracy === null) {
189
+ throw Error('the accuracy of the position is not defined');
190
+ }
191
+
192
+ newPositionEvent = new ProviderEvent(EventType.AbsolutePosition, data);
193
+
194
+ } else if (data instanceof ProviderEvent) {
195
+
196
+ if (data.dataType !== EventType.AbsolutePosition
197
+ || !(data.data instanceof UserPosition)) {
198
+ throw Error('the provider event is not an UserPosition');
199
+ }
200
+
201
+ newPositionEvent = data;
202
+
203
+ } else {
204
+ throw new Error('data is nor an UserPosition or a ProviderEvent');
205
+ }
206
+
207
+ // If the MM is disable or the network is not set yet, use the new position as it is.
208
+ if (!AbsolutePosition.USE_MM_FOR_FEED || !MapMatchingHandler.canUseMapMatching()) {
209
+ this.notify(newPositionEvent);
210
+ return;
211
+ }
212
+
213
+ MapMatchingHandler.notifyPositionFromFeed(newPositionEvent);
214
+ }
215
+ }
216
+
217
+ export default new AbsolutePosition();
@@ -10,11 +10,6 @@ import GeolocationPermissionDeniedError from '../../../errors/GeolocationPermiss
10
10
  import GeolocationPositionUnavailableError from '../../../errors/GeolocationPositionUnavailableError.js';
11
11
  import Constants from '../../Constants.js';
12
12
 
13
- const POSITION_OPTIONS = {
14
- enableHighAccuracy: true,
15
- timeout: Infinity,
16
- maximumAge: 0
17
- };
18
13
 
19
14
  /**
20
15
  * GnssWifiProvider is a provider based on navigator.geolocation.
@@ -22,7 +17,13 @@ const POSITION_OPTIONS = {
22
17
  * by Wifi Fingerprinting algorithms or by GNSS. That is why the name is
23
18
  * "GnssWifi".
24
19
  */
25
- class GnssWifiProvider extends Provider {
20
+ class GnssWifi extends Provider {
21
+
22
+ static POSITION_OPTIONS = {
23
+ enableHighAccuracy: true,
24
+ timeout: Infinity,
25
+ maximumAge: 0
26
+ };
26
27
 
27
28
  /**
28
29
  * @override
@@ -55,7 +56,7 @@ class GnssWifiProvider extends Provider {
55
56
  this.geoLocationId = navigator.geolocation.watchPosition(
56
57
  this.onNewPosition,
57
58
  this.onPositionError,
58
- POSITION_OPTIONS
59
+ GnssWifi.POSITION_OPTIONS
59
60
  );
60
61
 
61
62
  }
@@ -122,4 +123,4 @@ class GnssWifiProvider extends Provider {
122
123
  };
123
124
  }
124
125
 
125
- export default GnssWifiProvider;
126
+ export default new GnssWifi();
@@ -11,7 +11,7 @@ import IpResolveServerError from '../../../errors/IpResolveServerError.js';
11
11
  * by Wifi Fingerprinting algorithms or by GNSS. That is why the name is
12
12
  * "GnssWifi".
13
13
  */
14
- class IpProvider extends Provider {
14
+ class Ip extends Provider {
15
15
 
16
16
  /**
17
17
  * @override
@@ -63,4 +63,4 @@ class IpProvider extends Provider {
63
63
 
64
64
  }
65
65
 
66
- export default IpProvider;
66
+ export default new Ip();