@wemap/providers 9.0.9 → 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';
|
|
@@ -158,33 +158,69 @@ class AbsolutePosition extends Provider {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
/**
|
|
161
|
-
* @param {ProviderEvent<UserPosition>}
|
|
161
|
+
* @param {ProviderEvent<UserPosition>} newPositionEvent
|
|
162
162
|
* @param {boolean} canContainLevel
|
|
163
|
-
* @returns {boolean}
|
|
163
|
+
* @returns {boolean}
|
|
164
164
|
*/
|
|
165
|
-
|
|
165
|
+
_shouldTakeIntoAccountNewAbsolutePosition(newPositionEvent, canContainLevel = true) {
|
|
166
166
|
|
|
167
|
-
const newPosition =
|
|
167
|
+
const newPosition = newPositionEvent.data;
|
|
168
168
|
const lastPosition = this.lastEvent ? this.lastEvent.data : null;
|
|
169
169
|
|
|
170
|
-
if
|
|
170
|
+
// 1. Verifiy if it is the first known absolute position
|
|
171
|
+
if (!lastPosition) {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
171
174
|
|
|
172
|
-
|
|
173
|
-
|
|
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
|
+
}
|
|
174
180
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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;
|
|
178
188
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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;
|
|
183
193
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
+
/**
|
|
209
|
+
* @param {ProviderEvent<UserPosition>} positionEvent
|
|
210
|
+
* @param {boolean} canContainLevel
|
|
211
|
+
* @returns {boolean} if input position is used by the system (true = used, false = discarded)
|
|
212
|
+
*/
|
|
213
|
+
_onAbsolutePosition(positionEvent, canContainLevel = true) {
|
|
214
|
+
|
|
215
|
+
if (!this._shouldTakeIntoAccountNewAbsolutePosition(positionEvent, canContainLevel)
|
|
216
|
+
&& !this.useAllAbsolutePositions) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const newPosition = positionEvent.data.clone();
|
|
221
|
+
const lastPosition = this.lastEvent ? this.lastEvent.data : null;
|
|
187
222
|
|
|
223
|
+
if (lastPosition) {
|
|
188
224
|
if (!canContainLevel) {
|
|
189
225
|
newPosition.level = lastPosition.level;
|
|
190
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,9 +163,13 @@ class Vps extends Provider {
|
|
|
163
163
|
);
|
|
164
164
|
const attitude = new Attitude(deviceQuaternion, res.attitude.time, res.attitude.accuracy);
|
|
165
165
|
|
|
166
|
-
//
|
|
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...)
|
|
167
169
|
const devicePosition = res.userPosition.clone();
|
|
168
|
-
devicePosition.accuracy
|
|
170
|
+
if (devicePosition.accuracy === null) {
|
|
171
|
+
devicePosition.accuracy = 5;
|
|
172
|
+
}
|
|
169
173
|
|
|
170
174
|
// 5. Finally, notify the listeners if the VPS is not stopped
|
|
171
175
|
if (this.state === ProviderState.STOPPED) {
|