@wemap/positioning 2.3.5 → 2.3.7

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 (32) hide show
  1. package/package.json +1 -1
  2. package/src/PositioningHandler.js +58 -43
  3. package/src/PositioningHandler.spec.js +47 -27
  4. package/src/components/AbsoluteAttitudeComponent.jsx +2 -6
  5. package/src/components/ArCoreAbsoluteComponent.jsx +4 -11
  6. package/src/components/ArCoreComponent.jsx +4 -11
  7. package/src/components/GnssWifiComponent.jsx +2 -6
  8. package/src/components/GnssWifiPdrComponent.jsx +4 -11
  9. package/src/components/ImuComponent.jsx +4 -12
  10. package/src/components/InclinationComponent.jsx +2 -6
  11. package/src/components/PdrComponent.jsx +5 -12
  12. package/src/components/PoseComponent.jsx +4 -11
  13. package/src/components/PositioningInclinationComponent.jsx +5 -8
  14. package/src/components/PositioningPoseComponent.jsx +10 -15
  15. package/src/components/RelativeAttitudeComponent.jsx +3 -6
  16. package/src/errors/ContainsIgnoredProviderError.js +9 -0
  17. package/src/events/Availability.js +30 -0
  18. package/src/providers/Provider.js +50 -50
  19. package/src/providers/attitude/AbsoluteAttitudeProvider.js +11 -27
  20. package/src/providers/attitude/RelativeAttitudeProvider.js +2 -17
  21. package/src/providers/others/ImuProvider.js +11 -25
  22. package/src/providers/others/InclinationProvider.js +2 -17
  23. package/src/providers/pose/ArCoreAbsoluteProvider.js +4 -30
  24. package/src/providers/pose/ArCoreProvider.js +11 -8
  25. package/src/providers/pose/GnssWifiPdrProvider.js +4 -26
  26. package/src/providers/pose/PoseProvider.js +3 -29
  27. package/src/providers/pose/pdr/PdrProvider.js +20 -33
  28. package/src/providers/position/GnssWifiProvider.js +9 -16
  29. package/src/providers/position/IpProvider.js +1 -11
  30. package/fix_gnsswifipdr_stop.patch +0 -13
  31. package/src/events/ProviderError.js +0 -52
  32. package/src/providers/FakeAbsolutePositionProvider.js +0 -56
@@ -1,7 +1,7 @@
1
1
  import noop from 'lodash.noop';
2
2
 
3
3
  import {
4
- Constants as GeoConstants, Itinerary, WGS84UserPosition
4
+ Constants as GeoConstants, Itinerary, WGS84UserPosition, WGS84
5
5
  } from '@wemap/geo';
6
6
  import {
7
7
  rad2deg, Quaternion
@@ -15,7 +15,6 @@ import RelativeAttitudeProvider from '../../attitude/RelativeAttitudeProvider';
15
15
  import ImuProvider from '../../others/ImuProvider';
16
16
  import EventType from '../../../events/EventType';
17
17
  import MapMatchingProvider from '../../others/MapMatchingProvider';
18
- import ProviderError from '../../../events/ProviderError';
19
18
 
20
19
 
21
20
  const MM_PDR_ANGLE = 20;
@@ -41,18 +40,20 @@ class PdrProvider extends MapMatchingProvider {
41
40
  * @override
42
41
  */
43
42
  constructor(onEvent, onError, options) {
44
- super(onEvent, onError, Object.assign(DEFAULT_OPTIONS, options || {}));
43
+ super(onEvent, onError, Object.assign({}, DEFAULT_OPTIONS, options));
45
44
 
46
45
  // Input data providers
47
46
  this.relativeAttitudeProvider = new RelativeAttitudeProvider(
48
47
  e => this.onRelativeAttitudeEvent(e),
49
- e => this.onProviderError(e),
50
- options
48
+ onError,
49
+ this.options
51
50
  );
52
51
  this.imuProvider = new ImuProvider(
53
52
  e => this.onImuEvent(e),
54
- e => this.onProviderError(e),
55
- Object.assign(options || {}, { require: [EventType.Acceleration, EventType.AngularRate] })
53
+ onError,
54
+ Object.assign({}, this.options,
55
+ { require: [EventType.Acceleration, EventType.AngularRate] }
56
+ )
56
57
  );
57
58
 
58
59
  // Helpers for PDR
@@ -84,7 +85,7 @@ class PdrProvider extends MapMatchingProvider {
84
85
  /**
85
86
  * @override
86
87
  */
87
- static get requiredProviders() {
88
+ static getRequiredProviders() {
88
89
  return [ImuProvider, RelativeAttitudeProvider];
89
90
  }
90
91
 
@@ -128,14 +129,21 @@ class PdrProvider extends MapMatchingProvider {
128
129
  }
129
130
 
130
131
  setPosition(position) {
131
- this.pdrPosition = position;
132
+ if (position instanceof WGS84) {
133
+ this.pdrPosition = WGS84UserPosition.fromWGS84(position);
134
+ if (window && window.performance) {
135
+ this.pdrPosition.time = window.performance / 1e3;
136
+ }
137
+ } else {
138
+ this.pdrPosition = position;
139
+ }
132
140
 
133
141
  if (this.options.smoother) {
134
- this.smoother.generateNextPositions(position, true);
142
+ this.smoother.generateNextPositions(this.pdrPosition, true);
135
143
  // this.smoother.pullPosition(position.time) should never return null
136
- this.position = this.smoother.pullPosition(position.time);
144
+ this.position = this.smoother.pullPosition(this.pdrPosition.time);
137
145
  } else {
138
- this.position = position.clone();
146
+ this.position = this.pdrPosition.clone();
139
147
  }
140
148
 
141
149
  this.notify(this.createEvent(EventType.AbsolutePosition, this.position));
@@ -233,27 +241,6 @@ class PdrProvider extends MapMatchingProvider {
233
241
  this.notify(this.createEvent(EventType.AbsolutePosition, this.position));
234
242
  }
235
243
 
236
- onProviderError(errors) {
237
- this.notifyError(...ProviderError.modifyArrayDataType(errors, EventType.AbsoluteAttitude));
238
- this.notifyError(...ProviderError.modifyArrayDataType(errors, EventType.AbsolutePosition));
239
- }
240
-
241
- /**
242
- * @override
243
- */
244
- static checkAvailabilityErrors() {
245
- const errors = super.checkAvailabilityErrors();
246
- return ProviderError.modifyArrayDataType(
247
- errors,
248
- EventType.AbsolutePosition
249
- ).concat(
250
- ProviderError.modifyArrayDataType(
251
- errors,
252
- EventType.AbsoluteAttitude
253
- )
254
- );
255
- }
256
-
257
244
  calculateNewPosition(previousPosition, timestamp, heading, stepSize) {
258
245
 
259
246
  /**
@@ -7,6 +7,7 @@ import GeolocationApiMissingError from '../../errors/GeolocationApiMissingError'
7
7
  import Provider from '../Provider';
8
8
  import GeolocationPermissionDeniedError from '../../errors/GeolocationPermissionDeniedError';
9
9
  import GeolocationPositionUnavailableError from '../../errors/GeolocationPositionUnavailableError';
10
+ import Availability from '../../events/Availability';
10
11
 
11
12
  const POSITION_OPTIONS = {
12
13
  enableHighAccuracy: true,
@@ -39,18 +40,13 @@ class GnssWifiProvider extends Provider {
39
40
  /**
40
41
  * @override
41
42
  */
42
- static checkAvailabilityErrors() {
43
-
44
- if (navigator && navigator.geolocation) {
45
- return [];
46
- }
47
-
48
- return [
49
- GnssWifiProvider.createError(
50
- EventType.AbsolutePosition,
51
- new GeolocationApiMissingError()
52
- )
53
- ];
43
+ static checkAvailability(options) {
44
+ return Availability.merge(
45
+ super.checkAvailability(options),
46
+ navigator && navigator.geolocation
47
+ ? Availability.yes()
48
+ : Availability.no(new GeolocationApiMissingError())
49
+ );
54
50
  }
55
51
 
56
52
  /**
@@ -118,10 +114,7 @@ class GnssWifiProvider extends Provider {
118
114
  }
119
115
 
120
116
  if (customError) {
121
- this.notifyError(this.createError(
122
- EventType.AbsolutePosition,
123
- customError
124
- ));
117
+ this.notifyError(customError);
125
118
  }
126
119
  };
127
120
  }
@@ -26,13 +26,6 @@ class IpProvider extends Provider {
26
26
  return [EventType.AbsolutePosition];
27
27
  }
28
28
 
29
- /**
30
- * @override
31
- */
32
- static checkAvailabilityErrors() {
33
- return [];
34
- }
35
-
36
29
  /**
37
30
  * @override
38
31
  */
@@ -41,10 +34,7 @@ class IpProvider extends Provider {
41
34
  fetch('https://ipinfo.io/geo?token=24a7ca2f3b489d')
42
35
  .then((response) => {
43
36
  if (!response) {
44
- this.notifyError(this.createError(
45
- EventType.AbsolutePosition,
46
- new IpResolveServerError()
47
- ));
37
+ this.notifyError(new IpResolveServerError());
48
38
  return;
49
39
  }
50
40
 
@@ -1,13 +0,0 @@
1
- diff --git a/src/providers/pose/GnssWifiPdrProvider.js b/src/providers/pose/GnssWifiPdrProvider.js
2
- index c35d429..901d8d3 100644
3
- --- a/src/providers/pose/GnssWifiPdrProvider.js
4
- +++ b/src/providers/pose/GnssWifiPdrProvider.js
5
- @@ -73,7 +73,7 @@ class GnssWifiPdrProvider extends MapMatchingProvider {
6
- * @override
7
- */
8
- stop() {
9
- - this.imuProvider.stop();
10
- + this.pdrProvider.stop();
11
- this.gnssWifiProvider.stop();
12
- this.absoluteAttitudeProvider.stop();
13
- }
@@ -1,52 +0,0 @@
1
- import EventType from './EventType';
2
- import ProviderEvent from './ProviderEvent';
3
-
4
- /**
5
- * A provider error is an error event which is triggered by device sensors
6
- * in case of problem
7
- */
8
- class ProviderError extends ProviderEvent {
9
-
10
- error = null;
11
-
12
- /**
13
- * Create a Provider Error with the minimum information
14
- * @param {String} providerName the provider name
15
- * @param {EventType} dataType the type of event
16
- * @param {Error} error the event error
17
- */
18
- constructor(providerName, dataType, error) {
19
- super(providerName, dataType, null);
20
- this.error = error;
21
- }
22
-
23
- clone() {
24
- const evt = new ProviderError(this.providerName, this.dataType, this.error);
25
- evt.timestamp = this.timestamp;
26
- evt.isFromNative = this.isFromNative;
27
- return evt;
28
- }
29
-
30
- /**
31
- * Remove the same error in array
32
- * @param {ProviderError[]} errorsArray
33
- */
34
- static removeArrayDuplicates(errorsArray) {
35
- return errorsArray.reduce((acc, current) => {
36
- const found = acc.find(item => typeof item.error === typeof current.error && item.dataType === current.dataType);
37
- return !found ? acc.concat([current]) : acc;
38
- }, []);
39
- }
40
-
41
- static modifyArrayDataType(errorsArray, newDataType) {
42
- const output = [];
43
- errorsArray.forEach(error => {
44
- const newError = error.clone();
45
- newError.dataType = newDataType;
46
- output.push(newError);
47
- });
48
- return ProviderError.removeArrayDuplicates(output);
49
- }
50
- }
51
-
52
- export default ProviderError;
@@ -1,56 +0,0 @@
1
- import {
2
- WGS84, Attitude
3
- } from '@wemap/geo';
4
- import Provider from './Provider';
5
- import EventType from '../events/EventType';
6
-
7
-
8
- /**
9
- * @private
10
- */
11
- class FakeAbsolutePositionProvider extends Provider {
12
-
13
- /**
14
- * @override
15
- */
16
- static get displayName() {
17
- return 'FakeAbsolutePosition';
18
- }
19
-
20
- /**
21
- * @override
22
- */
23
- static get eventsType() {
24
- return [EventType.AbsoluteAttitude, EventType.AbsolutePosition];
25
- }
26
-
27
- /**
28
- * @override
29
- */
30
- startInternal() {
31
-
32
- this.interval = setInterval(() => {
33
- this.notify(
34
- this.createEvent(EventType.AbsoluteAttitude, new Attitude([1, 0, 0, 0])),
35
- this.createEvent(EventType.AbsolutePosition, new WGS84(45, 5))
36
- );
37
- }, 1000);
38
-
39
- return Promise.resolve();
40
- }
41
-
42
- /**
43
- * @override
44
- */
45
- stopInternal() {
46
-
47
- if (this.interval) {
48
- clearInterval(this.interval);
49
- this.interval = null;
50
- }
51
- return Promise.resolve();
52
- }
53
-
54
- }
55
-
56
- export default FakeAbsolutePositionProvider;