@wemap/providers 9.0.8 → 9.0.10
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/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserPosition, GeoRelativePosition } from '@wemap/geo';
|
|
1
|
+
import { UserPosition, GeoRelativePosition, Level } from '@wemap/geo';
|
|
2
2
|
import { PromiseUtils, TimeUtils } from '@wemap/utils';
|
|
3
3
|
|
|
4
4
|
import Provider from '../../Provider.js';
|
|
@@ -20,6 +20,9 @@ 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
|
+
|
|
23
26
|
/** @type {number?} */
|
|
24
27
|
_gnssWifiProviderId;
|
|
25
28
|
|
|
@@ -50,10 +53,18 @@ class AbsolutePosition extends Provider {
|
|
|
50
53
|
* @override
|
|
51
54
|
*/
|
|
52
55
|
get _availability() {
|
|
53
|
-
|
|
56
|
+
|
|
57
|
+
const providersToCheck = [
|
|
54
58
|
GeoRelativePositionProvider.availability,
|
|
55
59
|
GnssWifi.availability
|
|
56
|
-
]
|
|
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);
|
|
57
68
|
}
|
|
58
69
|
|
|
59
70
|
|
|
@@ -146,6 +157,54 @@ class AbsolutePosition extends Provider {
|
|
|
146
157
|
MapMatchingHandler.removeEventListener(this._mapMatchingHandlerId);
|
|
147
158
|
}
|
|
148
159
|
|
|
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
|
+
|
|
149
208
|
/**
|
|
150
209
|
* @param {ProviderEvent<UserPosition>} positionEvent
|
|
151
210
|
* @param {boolean} canContainLevel
|
|
@@ -153,22 +212,15 @@ class AbsolutePosition extends Provider {
|
|
|
153
212
|
*/
|
|
154
213
|
_onAbsolutePosition(positionEvent, canContainLevel = true) {
|
|
155
214
|
|
|
215
|
+
if (!this._shouldTakeIntoAccountNewAbsolutePosition(positionEvent, canContainLevel)
|
|
216
|
+
&& !this.useAllAbsolutePositions) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
|
|
156
220
|
const newPosition = positionEvent.data.clone();
|
|
157
221
|
const lastPosition = this.lastEvent ? this.lastEvent.data : null;
|
|
158
222
|
|
|
159
223
|
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
|
-
|
|
172
224
|
if (!canContainLevel) {
|
|
173
225
|
newPosition.level = lastPosition.level;
|
|
174
226
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-bitwise */
|
|
2
2
|
|
|
3
3
|
import { UserPosition } from '@wemap/geo';
|
|
4
|
+
import { deg2rad } from '@wemap/maths';
|
|
4
5
|
import { TimeUtils } from '@wemap/utils';
|
|
5
6
|
|
|
6
7
|
import Provider from '../../Provider.js';
|
|
@@ -97,7 +98,7 @@ class PoleStar extends Provider {
|
|
|
97
98
|
json.alt / 5,
|
|
98
99
|
timestamp,
|
|
99
100
|
json.accuracy,
|
|
100
|
-
json.bearing,
|
|
101
|
+
deg2rad(json.bearing),
|
|
101
102
|
this.pname);
|
|
102
103
|
|
|
103
104
|
this.notify(this.createEvent(
|
|
@@ -163,6 +163,14 @@ class Vps extends Provider {
|
|
|
163
163
|
);
|
|
164
164
|
const attitude = new Attitude(deviceQuaternion, res.attitude.time, res.attitude.accuracy);
|
|
165
165
|
|
|
166
|
+
// [16/06/22] Force VPS accuracy to 5m if the information does not exist
|
|
167
|
+
// this allows to correctly fuse positions from different providers (VPS,
|
|
168
|
+
// GnssWifi, Pole Star...)
|
|
169
|
+
const devicePosition = res.userPosition.clone();
|
|
170
|
+
if (devicePosition.accuracy === null) {
|
|
171
|
+
devicePosition.accuracy = 5;
|
|
172
|
+
}
|
|
173
|
+
|
|
166
174
|
// 5. Finally, notify the listeners if the VPS is not stopped
|
|
167
175
|
if (this.state === ProviderState.STOPPED) {
|
|
168
176
|
break;
|
|
@@ -170,7 +178,7 @@ class Vps extends Provider {
|
|
|
170
178
|
|
|
171
179
|
this.notify(
|
|
172
180
|
this.createEvent(EventType.AbsoluteAttitude, attitude),
|
|
173
|
-
this.createEvent(EventType.AbsolutePosition,
|
|
181
|
+
this.createEvent(EventType.AbsolutePosition, devicePosition)
|
|
174
182
|
);
|
|
175
183
|
|
|
176
184
|
}
|