@wemap/providers 10.0.0 → 10.2.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,4 +1,5 @@
1
1
  import { Evented } from 'mapbox-gl';
2
+ import Logger from '@wemap/logger';
2
3
  import {
3
4
  PositionSmoother, AbsoluteAttitude, AbsolutePosition
4
5
  } from '@wemap/providers';
@@ -22,7 +23,8 @@ export default class CustomMapProvider extends Evented {
22
23
  * Attitude
23
24
  */
24
25
  this.attitudeProviderId = AbsoluteAttitude.addEventListener(
25
- events => this.fire('heading.changed', { heading: events[0].data.headingDegrees })
26
+ events => this.fire('heading.changed', { heading: events[0].data.headingDegrees }),
27
+ Logger.warn
26
28
  );
27
29
 
28
30
  // There is no sense to show the last known attitude on the map
@@ -38,7 +40,8 @@ export default class CustomMapProvider extends Evented {
38
40
  });
39
41
 
40
42
  this.positionProviderId = AbsolutePosition.addEventListener(
41
- events => this.smoother.feed(events[0].data)
43
+ events => this.smoother.feed(events[0].data),
44
+ Logger.warn
42
45
  );
43
46
 
44
47
  const lastKnownPosition = AbsolutePosition.lastEvent ? AbsolutePosition.lastEvent.data : null;
package/package.json CHANGED
@@ -8,15 +8,15 @@
8
8
  "Guillaume Pannetier <guillaume.pannetier@getwemap.com>"
9
9
  ],
10
10
  "dependencies": {
11
- "@wemap/camera": "^10.0.0",
12
- "@wemap/geo": "^10.0.0",
11
+ "@wemap/camera": "^10.1.0",
12
+ "@wemap/geo": "^10.1.0",
13
13
  "@wemap/geomagnetism": "^0.1.1",
14
14
  "@wemap/logger": "^10.0.0",
15
- "@wemap/map": "^10.0.0",
15
+ "@wemap/map": "^10.1.0",
16
16
  "@wemap/maths": "^10.0.0",
17
- "@wemap/osm": "^10.0.0",
18
- "@wemap/routers": "^10.0.0",
19
- "@wemap/utils": "^10.0.0"
17
+ "@wemap/osm": "^10.1.0",
18
+ "@wemap/routers": "^10.1.0",
19
+ "@wemap/utils": "^10.1.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": "10.0.0",
46
- "gitHead": "dabdfdf7dbb6dcdf507ec148160ef228457b0519"
45
+ "version": "10.2.0",
46
+ "gitHead": "c90d603fbed21b566a197eb5ad3a30c54921bf54"
47
47
  }
@@ -94,7 +94,6 @@ class ProvidersInterface {
94
94
  return AbsoluteAttitude;
95
95
 
96
96
  case EventType.AbsolutePosition:
97
- case EventType.ForceVps:
98
97
  return AbsolutePosition;
99
98
 
100
99
  case EventType.RelativeAttitude:
@@ -150,8 +149,6 @@ class ProvidersInterface {
150
149
  throw errorFn('Itinerary');
151
150
  }
152
151
  break;
153
- case EventType.ForceVps:
154
- break;
155
152
  default:
156
153
  throw new Error(`Unable to deal with this event type: ${eventType}`);
157
154
  }
@@ -12,7 +12,7 @@ const ProvidersOptions = {
12
12
  ignoreProviders: [],
13
13
 
14
14
  /**
15
- * Some providers are not used by default (VPS, QRCodeScanner) because they
15
+ * Some providers are not used by default (i.e. PoleStar) because they
16
16
  * require data from an optional external service or because they drain more
17
17
  * battery. They can be added to this list to be used
18
18
  * List of {@link Provider#pname}
@@ -34,10 +34,6 @@ const ProvidersOptions = {
34
34
 
35
35
  smoother: true,
36
36
 
37
- get hasVps() {
38
- return this.optionalProviders.includes('Vps');
39
- },
40
-
41
37
  get hasPoleStar() {
42
38
  return this.optionalProviders.includes('PoleStar');
43
39
  }
@@ -34,7 +34,5 @@ export default {
34
34
  CameraNative: 'CAMERA_NATIVE',
35
35
 
36
36
  Itinerary: 'ITINERARY',
37
- Network: 'NETWORK',
38
-
39
- ForceVps: 'FORCE_VPS'
37
+ Network: 'NETWORK'
40
38
  };
@@ -623,14 +623,6 @@ class MapMatchingHandler extends Provider {
623
623
  this._disableMMCloseToATurnDistance = disableMMCloseToATurnDistance;
624
624
  }
625
625
 
626
- get useOrientationMatching() {
627
- return this._useOrientationMatching;
628
- }
629
-
630
- set useOrientationMatching(useOrientationMatching) {
631
- this._useOrientationMatching = useOrientationMatching;
632
- }
633
-
634
626
  get minStepsBetweenOrientationMatching() {
635
627
  return this._minStepsBetweenOrientationMatching;
636
628
  }
@@ -144,12 +144,12 @@ class Provider {
144
144
 
145
145
  /**
146
146
  *
147
- * @param {onEventsFunction} onEvents
148
- * @param {Function} onError
147
+ * @param {onEventsFunction|null|undefined} onEvents
148
+ * @param {Function|null|undefined} onError
149
149
  * @param {Boolean} startIfNecessary
150
150
  * @returns {Number}
151
151
  */
152
- addEventListener(onEvents = () => { }, onError = () => { }, startIfNecessary = true) {
152
+ addEventListener(onEvents = null, onError = null, startIfNecessary = true) {
153
153
  const id = ++Provider._callbackUniqueId;
154
154
 
155
155
  /**
@@ -157,8 +157,8 @@ class Provider {
157
157
  */
158
158
  this._eventsCallbacks.push({
159
159
  id,
160
- onEvents,
161
- onError,
160
+ onEvents: onEvents || (() => {}),
161
+ onError: onError || (() => {}),
162
162
  optional: !startIfNecessary
163
163
  });
164
164
 
@@ -9,7 +9,6 @@ import RelativeAttitude from '../relative/RelativeAttitude.js';
9
9
  import Inclination from '../../inclination/Inclination.js';
10
10
  import ProviderEvent from '../../../events/ProviderEvent.js';
11
11
  import HighRotationsDetector from '../../imu/HighRotationsDetector.js';
12
- import ProvidersOptions from '../../../ProvidersOptions.js';
13
12
  import Vps from '../../vision/vps/Vps.js';
14
13
  import AvailabilityHelper from '../../../events/AvailabilityHelper.js';
15
14
 
@@ -101,13 +100,11 @@ class AbsoluteAttitude extends Provider {
101
100
  );
102
101
 
103
102
  // Vps
104
- if (ProvidersOptions.hasVps) {
105
- this._vpsProviderId = Vps.addEventListener(
106
- events => this._onAttitudeFromVps(events.find(event => event.dataType === EventType.AbsoluteAttitude)),
107
- error => this.notifyError(error),
108
- false
109
- );
110
- }
103
+ this._vpsProviderId = Vps.addEventListener(
104
+ events => this._onAttitudeFromVps(events.find(event => event.dataType === EventType.AbsoluteAttitude)),
105
+ error => this.notifyError(error),
106
+ false
107
+ );
111
108
 
112
109
  this.relativeAttitudeProviderId = RelativeAttitude.addEventListener(
113
110
  events => this._onRelativeAttitudeEvent(events[0]),
@@ -8,7 +8,6 @@ import MapMatchingHandler from '../../../mapmatching/MapMatchingHandler.js';
8
8
  import GnssWifi from './GnssWifi.js';
9
9
  import { default as GeoRelativePositionProvider } from '../relative/GeoRelativePosition.js';
10
10
  import ProvidersOptions from '../../../ProvidersOptions.js';
11
- import ProviderState from '../../ProviderState.js';
12
11
  import Vps from '../../vision/vps/Vps.js';
13
12
  import PoleStar from './PoleStar.js';
14
13
  import AvailabilityHelper from '../../../events/AvailabilityHelper.js';
@@ -62,9 +61,7 @@ class AbsolutePosition extends Provider {
62
61
  if (ProvidersOptions.hasPoleStar) {
63
62
  providersToCheck.push(PoleStar.availability);
64
63
  }
65
- if (ProvidersOptions.hasVps) {
66
- providersToCheck.push(Vps.availability);
67
- }
64
+ providersToCheck.push(Vps.availability);
68
65
  return AvailabilityHelper.some(providersToCheck);
69
66
  }
70
67
 
@@ -94,13 +91,11 @@ class AbsolutePosition extends Provider {
94
91
  );
95
92
 
96
93
  // Vps
97
- if (ProvidersOptions.hasVps) {
98
- this._vpsProviderId = Vps.addEventListener(
99
- events => this._onAbsolutePosition(events.find(event => event.dataType === EventType.AbsolutePosition)),
100
- error => this.notifyError(error),
101
- false
102
- );
103
- }
94
+ this._vpsProviderId = Vps.addEventListener(
95
+ events => this._onAbsolutePosition(events.find(event => event.dataType === EventType.AbsolutePosition)),
96
+ error => this.notifyError(error),
97
+ false
98
+ );
104
99
 
105
100
  // PoleStar
106
101
  if (ProvidersOptions.hasPoleStar) {
@@ -292,28 +287,12 @@ class AbsolutePosition extends Provider {
292
287
  /**
293
288
  * @override
294
289
  * @param {UserPosition|ProviderEvent} data
295
- * @param {EventType} eventType
296
290
  */
297
- feed(data, eventType) {
291
+ feed(data) {
298
292
 
299
293
  /** @type {ProviderEvent<UserPosition>} */
300
294
  let newPositionEvent;
301
295
 
302
- if (eventType === EventType.ForceVps) {
303
- if (!this._vpsProviderId && this.state === ProviderState.STARTED) {
304
- this._waitUntilNextVpsPosition = true;
305
- this._vpsProviderId = Vps.addEventListener(events => {
306
- this._waitUntilNextVpsPosition = false;
307
- this._onAbsolutePosition(events.find(event => event.dataType === EventType.AbsolutePosition));
308
- Vps.removeEventListener(this._vpsProviderId);
309
- this._vpsProviderId = null;
310
- });
311
- }
312
-
313
- return;
314
-
315
- }
316
-
317
296
  if (data instanceof UserPosition) {
318
297
 
319
298
  if (data.time === null) {
@@ -346,6 +325,21 @@ class AbsolutePosition extends Provider {
346
325
 
347
326
  MapMatchingHandler.notifyPositionFromFeed(newPositionEvent);
348
327
  }
328
+
329
+ getBestPositionEvent(...absolutePositionEvents) {
330
+ return absolutePositionEvents.reduce((best, value) => {
331
+ if (!best) {
332
+ return value;
333
+ }
334
+ if (!value || value.data.accuracy === null || value.data.time === null) {
335
+ return best;
336
+ }
337
+ const {accuracy: curAccuracy, time: curTime} = value.data;
338
+ const {accuracy: bestAccuracy, time: bestTime} = best.data;
339
+ // 1.3888 corresponds to 1.3888 m/s (5 km/h)
340
+ return curAccuracy < (bestAccuracy + 1.3888 * (curTime - bestTime)) ? value : best;
341
+ }, null);
342
+ }
349
343
  }
350
344
 
351
345
  export default new AbsolutePosition();
@@ -0,0 +1,35 @@
1
+ /* eslint-disable max-nested-callbacks */
2
+ import { UserPosition } from '@wemap/geo';
3
+ import chai from 'chai';
4
+
5
+ import EventType from '../../../events/EventType.js';
6
+ import ProviderEvent from '../../../events/ProviderEvent.js';
7
+ import AbsolutePosition from './AbsolutePosition.js';
8
+
9
+ const { expect } = chai;
10
+
11
+
12
+ describe('AbsolutePosition', () => {
13
+
14
+ it('getBestPositionEvent', () => {
15
+
16
+ const createEvent = (time, accuracy) =>
17
+ new ProviderEvent(EventType.AbsolutePosition, new UserPosition(0, 0, null, null, time, accuracy));
18
+
19
+ const evt1 = createEvent(4, 1);
20
+ const evt2 = createEvent(4, 5);
21
+ const evt3 = createEvent(2, 1);
22
+ const evt4 = createEvent(2, 2);
23
+
24
+ expect(AbsolutePosition.getBestPositionEvent(evt1, evt2)).equals(evt1);
25
+ expect(AbsolutePosition.getBestPositionEvent(evt1, evt3)).equals(evt1);
26
+ expect(AbsolutePosition.getBestPositionEvent(evt2, evt4)).equals(evt4);
27
+ expect(AbsolutePosition.getBestPositionEvent(null, evt1)).equals(evt1);
28
+ expect(AbsolutePosition.getBestPositionEvent(null, evt1, null)).equals(evt1);
29
+ expect(AbsolutePosition.getBestPositionEvent(null, evt2, evt4)).equals(evt4);
30
+ expect(AbsolutePosition.getBestPositionEvent(null)).equals(null);
31
+ expect(AbsolutePosition.getBestPositionEvent(null, null)).equals(null);
32
+ expect(AbsolutePosition.getBestPositionEvent()).equals(null);
33
+ });
34
+
35
+ });
@@ -147,6 +147,10 @@ class StepDetector extends Provider {
147
147
  }
148
148
  this._algorithm = algorithm;
149
149
  }
150
+
151
+ get algorithm() {
152
+ return this._algorithm;
153
+ }
150
154
  }
151
155
 
152
156
  export default new StepDetector();
@@ -87,7 +87,7 @@ class StraightLineDetector extends Provider {
87
87
  * @returns {boolean}
88
88
  */
89
89
  isStraight() {
90
- return this._countSteps >= StraightLineDetector.STEPS_CONSIDERED_FOR_STRAIGHT_LINE;
90
+ return this._countSteps >= this._stepsConsideredForStraightLine;
91
91
  }
92
92
 
93
93
  get numStepsDetectedFromLastTurn() {
@@ -1,5 +1,6 @@
1
1
  import { CameraUtils } from '@wemap/camera';
2
2
  import { Attitude, Coordinates, UserPosition } from '@wemap/geo';
3
+ import Logger from '@wemap/logger';
3
4
  import { TimeUtils, UserAgentUtils } from '@wemap/utils';
4
5
 
5
6
  import VpsRequest from './VpsRequest.js';
@@ -48,25 +49,31 @@ class ImageRelocalization {
48
49
  // 2. Send the request
49
50
  let serverResponse;
50
51
  try {
52
+ const body = JSON.stringify(vpsRequest.toJson());
53
+ Logger.debug(`[VPS] Request (${(body.length / 1024).toFixed(0)} kB) sent to server ${endpointUrl}`);
51
54
  serverResponse = await fetch(endpointUrl, {
52
55
  method: 'POST',
53
- body: JSON.stringify(vpsRequest.toJson()),
56
+ body,
54
57
  headers: Object.assign(
55
58
  { 'Content-Type': 'application/json', 'Accept': 'application/json' },
56
59
  customHeaders ? customHeaders : {}
57
60
  )
58
61
  });
59
62
  } catch (e) {
63
+ Logger.debug('[VPS] Server respond error');
60
64
  return null;
61
65
  }
62
66
 
63
67
  if (serverResponse.status !== 200) {
68
+ Logger.debug('[VPS] Server respond error');
64
69
  return null;
65
70
  }
66
71
 
67
72
  // 3. Parse the response
68
73
  const json = await serverResponse.json();
69
- return VpsResponse.fromJson(json, timeBeforeRequest);
74
+ const res = VpsResponse.fromJson(json, timeBeforeRequest);
75
+ Logger.debug(`[VPS] Server respond ${res.success ? 'success' : 'not found'}`);
76
+ return res;
70
77
  }
71
78
 
72
79
  static getHeadingFromQuaternion(quaternion) {
@@ -11,9 +11,11 @@ import Inclination from '../../inclination/Inclination.js';
11
11
  import Provider from '../../Provider.js';
12
12
  import ProviderState from '../../ProviderState.js';
13
13
  import ImageRelocalization from './ImageRelocalization.js';
14
- import AbsolutePosition from '../../position/absolute/AbsolutePosition.js';
15
14
  import AbsoluteAttitude from '../../attitude/absolute/AbsoluteAttitude.js';
16
15
  import RelativeRotationCalc from './RelativeRotationCalc.js';
16
+ import GnssWifi from '../../position/absolute/GnssWifi.js';
17
+ import AbsolutePosition from '../../position/absolute/AbsolutePosition.js';
18
+ import PoleStar from '../../position/absolute/PoleStar.js';
17
19
 
18
20
  class Vps extends Provider {
19
21
 
@@ -179,20 +181,26 @@ class Vps extends Provider {
179
181
  }
180
182
 
181
183
  // 3. Get current image from camera and relocalize it.
184
+
185
+ // 3.a. Get current image and time it.
182
186
  this._relativeRotationCalc.tickStart();
183
187
  const image = await this._camera.currentImage;
188
+
189
+ // 3.b. Retrieve coarse position if necessary.
184
190
  let coarsePose = null;
185
- if (this._useCoarsePose && (AbsolutePosition.lastEvent || AbsoluteAttitude.lastEvent)) {
191
+ const bestCoarsePosition = AbsolutePosition.getBestPositionEvent(GnssWifi.lastEvent, PoleStar.lastEvent);
192
+ if (this._useCoarsePose && (bestCoarsePosition || AbsoluteAttitude.lastEvent)) {
186
193
  coarsePose = {};
187
- if (AbsolutePosition.lastEvent) {
188
- coarsePose.position = AbsolutePosition.lastEvent.data;
194
+ if (bestCoarsePosition) {
195
+ coarsePose.position = bestCoarsePosition.data;
189
196
  }
190
197
  if (AbsoluteAttitude.lastEvent) {
191
198
  coarsePose.attitude = AbsoluteAttitude.lastEvent.data;
192
199
  }
193
200
  }
194
- const res = await ImageRelocalization.relocalize(this._endpoint, image, null, coarsePose);
195
201
 
202
+ // 3.c. Send image and metadata.
203
+ const res = await ImageRelocalization.relocalize(this._endpoint, image, null, coarsePose);
196
204
  if (!res || !res.success) {
197
205
  continue;
198
206
  }