@wemap/providers 12.10.8 → 12.10.9
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/dist/helpers/CustomMapProvider.d.ts +10 -0
- package/{index.ts → dist/index.d.ts} +0 -14
- package/dist/index.js +1 -3446
- package/dist/index.js.map +1 -1
- package/{src/ProvidersOptions.ts → dist/src/ProvidersOptions.d.ts} +7 -16
- package/dist/src/errors/AskImuOnDesktopError.d.ts +5 -0
- package/dist/src/errors/ContainsIgnoredProviderError.d.ts +5 -0
- package/dist/src/errors/GeolocationApiMissingError.d.ts +5 -0
- package/dist/src/errors/GeolocationPermissionDeniedError.d.ts +5 -0
- package/dist/src/errors/GeolocationPositionUnavailableError.d.ts +5 -0
- package/dist/src/errors/IpResolveServerError.d.ts +5 -0
- package/dist/src/errors/MissingAccelerometerError.d.ts +6 -0
- package/dist/src/errors/MissingArCoreError.d.ts +5 -0
- package/dist/src/errors/MissingGyroscopeError.d.ts +6 -0
- package/dist/src/errors/MissingMagnetometerError.d.ts +5 -0
- package/dist/src/errors/MissingNativeInterfaceError.d.ts +5 -0
- package/dist/src/errors/MissingPoleStarError.d.ts +5 -0
- package/dist/src/errors/MissingSensorError.d.ts +6 -0
- package/dist/src/errors/NoProviderFoundError.d.ts +5 -0
- package/dist/src/events/AvailabilityHelper.d.ts +5 -0
- package/dist/src/events/ProvidersLoggerOld.d.ts +24 -0
- package/dist/src/events/Types.d.ts +34 -0
- package/dist/src/mapmatching/MapMatchingHandler.d.ts +93 -0
- package/dist/src/providers/Constants.d.ts +4 -0
- package/{src/providers/NativeProviders.ts → dist/src/providers/NativeProviders.d.ts} +2 -23
- package/dist/src/providers/Provider.d.ts +64 -0
- package/dist/src/providers/attitude/EkfAttitude.d.ts +41 -0
- package/dist/src/providers/attitude/TurnProvider.d.ts +17 -0
- package/dist/src/providers/attitude/absolute/AbsoluteAttitudeFromBrowserProvider.d.ts +60 -0
- package/dist/src/providers/attitude/absolute/AbsoluteAttitudeProvider.d.ts +44 -0
- package/dist/src/providers/attitude/relative/RelativeAttitudeFromBrowserProvider.d.ts +31 -0
- package/dist/src/providers/attitude/relative/RelativeAttitudeFromEkfProvider.d.ts +26 -0
- package/dist/src/providers/attitude/relative/RelativeAttitudeFromInertialProvider.d.ts +18 -0
- package/dist/src/providers/attitude/relative/RelativeAttitudeProvider.d.ts +25 -0
- package/dist/src/providers/imu/AccelerometerProvider.d.ts +11 -0
- package/dist/src/providers/imu/GyroscopeProvider.d.ts +11 -0
- package/dist/src/providers/imu/HighRotationsProvider.d.ts +15 -0
- package/dist/src/providers/imu/ImuProvider.d.ts +34 -0
- package/dist/src/providers/imu/MagnetometerCalibrationProvider.d.ts +11 -0
- package/dist/src/providers/inclination/InclinationFromAccProvider.d.ts +18 -0
- package/dist/src/providers/inclination/InclinationFromRelativeAttitudeProvider.d.ts +19 -0
- package/dist/src/providers/inclination/InclinationProvider.d.ts +18 -0
- package/dist/src/providers/legacy/helpers/HeadingUnlocker.d.ts +12 -0
- package/dist/src/providers/legacy/helpers/ThugDetector.d.ts +8 -0
- package/dist/src/providers/others/CameraNativeProvider.d.ts +11 -0
- package/dist/src/providers/others/CameraProjectionMatrixProvider.d.ts +11 -0
- package/dist/src/providers/position/absolute/AbsolutePositionProvider.d.ts +35 -0
- package/dist/src/providers/position/absolute/GnssWifiProvider.d.ts +28 -0
- package/dist/src/providers/position/absolute/IpProvider.d.ts +16 -0
- package/dist/src/providers/position/absolute/PoleStarProvider.d.ts +14 -0
- package/dist/src/providers/position/relative/GeoRelativePositionFromArCoreProvider.d.ts +17 -0
- package/dist/src/providers/position/relative/GeoRelativePositionProvider.d.ts +12 -0
- package/dist/src/providers/position/relative/PdrProvider.d.ts +15 -0
- package/dist/src/providers/steps/StepDetectionLadetto.d.ts +15 -0
- package/dist/src/providers/steps/StepDetectionMinMaxPeaks.d.ts +19 -0
- package/dist/src/providers/steps/StepDetectionMinMaxPeaks2.d.ts +27 -0
- package/dist/src/providers/steps/StepDetectionMinMaxPeaks3.d.ts +24 -0
- package/dist/src/providers/steps/StepProvider.d.ts +36 -0
- package/dist/src/providers/steps/StraightLineProvider.d.ts +21 -0
- package/dist/src/providers/vision/ArCoreProvider.d.ts +50 -0
- package/dist/src/providers/vision/BarcodeProvider.d.ts +11 -0
- package/dist/src/providers/vision/vps/ImageRelocalization.d.ts +11 -0
- package/dist/src/providers/vision/vps/RelativeRotationCalc.d.ts +10 -0
- package/dist/src/providers/vision/vps/VpsMetadata.d.ts +33 -0
- package/dist/src/providers/vision/vps/VpsProvider.d.ts +45 -0
- package/dist/src/providers/vision/vps/VpsRequest.d.ts +18 -0
- package/dist/src/providers/vision/vps/VpsResponse.d.ts +15 -0
- package/dist/src/smoothers/AttitudeSmoother.d.ts +23 -0
- package/dist/src/smoothers/PositionSmoother.d.ts +21 -0
- package/package.json +16 -12
- package/src/errors/AskImuOnDesktopError.ts +0 -10
- package/src/errors/ContainsIgnoredProviderError.ts +0 -10
- package/src/errors/GeolocationApiMissingError.ts +0 -10
- package/src/errors/GeolocationPermissionDeniedError.ts +0 -10
- package/src/errors/GeolocationPositionUnavailableError.ts +0 -10
- package/src/errors/IpResolveServerError.ts +0 -10
- package/src/errors/MissingAccelerometerError.ts +0 -11
- package/src/errors/MissingArCoreError.ts +0 -10
- package/src/errors/MissingGyroscopeError.ts +0 -11
- package/src/errors/MissingMagnetometerError.ts +0 -9
- package/src/errors/MissingNativeInterfaceError.ts +0 -11
- package/src/errors/MissingPoleStarError.ts +0 -10
- package/src/errors/MissingSensorError.ts +0 -15
- package/src/errors/NoProviderFoundError.ts +0 -10
- package/src/events/AvailabilityHelper.spec.ts +0 -30
- package/src/events/AvailabilityHelper.ts +0 -28
- package/src/events/ProvidersLoggerOld.ts +0 -87
- package/src/events/Types.ts +0 -18
- package/src/mapmatching/MapMatchingHandler.spec.ts +0 -142
- package/src/mapmatching/MapMatchingHandler.ts +0 -540
- package/src/providers/Constants.ts +0 -5
- package/src/providers/FakeProvider.spec.ts +0 -49
- package/src/providers/Provider.spec.ts +0 -113
- package/src/providers/Provider.ts +0 -244
- package/src/providers/attitude/EkfAttitude.spec.ts +0 -115
- package/src/providers/attitude/EkfAttitude.ts +0 -233
- package/src/providers/attitude/TurnProvider.ts +0 -58
- package/src/providers/attitude/absolute/AbsoluteAttitudeFromBrowserProvider.ts +0 -267
- package/src/providers/attitude/absolute/AbsoluteAttitudeProvider.ts +0 -268
- package/src/providers/attitude/relative/RelativeAttitudeFromBrowserProvider.ts +0 -84
- package/src/providers/attitude/relative/RelativeAttitudeFromEkfProvider.ts +0 -89
- package/src/providers/attitude/relative/RelativeAttitudeFromInertialProvider.ts +0 -66
- package/src/providers/attitude/relative/RelativeAttitudeProvider.ts +0 -70
- package/src/providers/imu/AccelerometerProvider.ts +0 -28
- package/src/providers/imu/GyroscopeProvider.ts +0 -27
- package/src/providers/imu/HighRotationsProvider.ts +0 -49
- package/src/providers/imu/ImuProvider.ts +0 -110
- package/src/providers/imu/MagnetometerCalibrationProvider.ts +0 -21
- package/src/providers/inclination/InclinationFromAccProvider.ts +0 -57
- package/src/providers/inclination/InclinationFromRelativeAttitudeProvider.ts +0 -51
- package/src/providers/inclination/InclinationProvider.ts +0 -59
- package/src/providers/legacy/helpers/HeadingUnlocker.spec.ts +0 -53
- package/src/providers/legacy/helpers/HeadingUnlocker.ts +0 -44
- package/src/providers/legacy/helpers/ThugDetector.ts +0 -30
- package/src/providers/others/CameraNativeProvider.ts +0 -29
- package/src/providers/others/CameraProjectionMatrixProvider.ts +0 -25
- package/src/providers/position/absolute/AbsolutePositionProvider.spec.ts +0 -31
- package/src/providers/position/absolute/AbsolutePositionProvider.ts +0 -277
- package/src/providers/position/absolute/GnssWifiProvider.ts +0 -126
- package/src/providers/position/absolute/GnssWifiProviders.spec.ts +0 -90
- package/src/providers/position/absolute/IpProvider.ts +0 -47
- package/src/providers/position/absolute/PoleStarProvider.ts +0 -88
- package/src/providers/position/relative/GeoRelativePositionFromArCoreProvider.ts +0 -82
- package/src/providers/position/relative/GeoRelativePositionProvider.ts +0 -35
- package/src/providers/position/relative/PdrProvider.ts +0 -107
- package/src/providers/steps/StepDetectionLadetto.ts +0 -67
- package/src/providers/steps/StepDetectionMinMaxPeaks.ts +0 -70
- package/src/providers/steps/StepDetectionMinMaxPeaks2.ts +0 -99
- package/src/providers/steps/StepDetectionMinMaxPeaks3.ts +0 -192
- package/src/providers/steps/StepProvider.ts +0 -151
- package/src/providers/steps/StraightLineProvider.ts +0 -69
- package/src/providers/vision/ArCoreProvider.ts +0 -184
- package/src/providers/vision/BarcodeProvider.ts +0 -28
- package/src/providers/vision/vps/ImageRelocalization.ts +0 -98
- package/src/providers/vision/vps/RelativeRotationCalc.ts +0 -58
- package/src/providers/vision/vps/VpsMetadata.ts +0 -63
- package/src/providers/vision/vps/VpsProvider.ts +0 -251
- package/src/providers/vision/vps/VpsRequest.ts +0 -29
- package/src/providers/vision/vps/VpsResponse.ts +0 -43
- package/src/providers/vision/vps/VpsSchema.json +0 -90
- package/src/smoothers/AttitudeSmoother.ts +0 -110
- package/src/smoothers/PositionSmoother.spec.ts +0 -53
- package/src/smoothers/PositionSmoother.ts +0 -96
- package/tsconfig.json +0 -3
- package/vite.config.ts +0 -4
- /package/{src/providers/ProviderState.ts → dist/src/providers/ProviderState.d.ts} +0 -0
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
import { Level, GeoRelativePosition, UserPosition } from '@wemap/geo';
|
|
2
|
-
import { TimeUtils } from '@wemap/utils';
|
|
3
|
-
|
|
4
|
-
import Provider from '../../Provider.js';
|
|
5
|
-
import AvailabilityHelper from '../../../events/AvailabilityHelper.js';
|
|
6
|
-
import MapMatchingHandler from '../../../mapmatching/MapMatchingHandler.js';
|
|
7
|
-
import GnssWifiProvider from './GnssWifiProvider.js';
|
|
8
|
-
import GeoRelativePositionProvider from '../relative/GeoRelativePositionProvider.js';
|
|
9
|
-
import ProvidersOptions from '../../../ProvidersOptions.js';
|
|
10
|
-
import VpsProvider from '../../vision/vps/VpsProvider.js';
|
|
11
|
-
import PoleStarProvider from './PoleStarProvider.js';
|
|
12
|
-
import { AbsolutePosition } from '../../../events/Types.js';
|
|
13
|
-
|
|
14
|
-
class AbsolutePositionProvider extends Provider<AbsolutePosition> {
|
|
15
|
-
|
|
16
|
-
// Use the new absolute position if its accuracy is at least x times better than the last one.
|
|
17
|
-
static ACCURACY_RELOC_RATIO = 1; // or 1.5
|
|
18
|
-
static USE_MM_FOR_FEED = true;
|
|
19
|
-
|
|
20
|
-
_polestarProviderId?: number;
|
|
21
|
-
_vpsProviderId?: number;
|
|
22
|
-
_gnssWifiProviderId?: number;
|
|
23
|
-
_relativePositionProviderId?: number;
|
|
24
|
-
_mapMatchingHandlerId?: number;
|
|
25
|
-
|
|
26
|
-
useAllAbsolutePositions = false;
|
|
27
|
-
_waitUntilNextVpsPosition = false;
|
|
28
|
-
_lastPolestarFix: number | null = null;
|
|
29
|
-
|
|
30
|
-
getName = () => 'AbsolutePosition';
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
availability() {
|
|
34
|
-
return AvailabilityHelper.some([
|
|
35
|
-
GeoRelativePositionProvider.getAvailability(),
|
|
36
|
-
GnssWifiProvider.getAvailability(),
|
|
37
|
-
...(ProvidersOptions.hasPoleStar ? [PoleStarProvider.getAvailability()] : []),
|
|
38
|
-
VpsProvider.getAvailability()
|
|
39
|
-
]);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
start() {
|
|
44
|
-
GeoRelativePositionProvider.getAvailability()
|
|
45
|
-
.then((error) => {
|
|
46
|
-
if (!error) {
|
|
47
|
-
this._relativePositionProviderId = GeoRelativePositionProvider.addEventListener(
|
|
48
|
-
e => this._onRelativePosition(e)
|
|
49
|
-
);
|
|
50
|
-
} else {
|
|
51
|
-
// do nothing
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// GnssWifi
|
|
56
|
-
this._gnssWifiProviderId = GnssWifiProvider.addEventListener(
|
|
57
|
-
event => {
|
|
58
|
-
const clone = event.clone();
|
|
59
|
-
clone.bearing = null;
|
|
60
|
-
this._onAbsolutePosition(clone, false);
|
|
61
|
-
}
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
// Vps
|
|
65
|
-
this._vpsProviderId = VpsProvider.addEventListener(
|
|
66
|
-
event => this._onAbsolutePosition(event.absolutePosition),
|
|
67
|
-
this.notifyError,
|
|
68
|
-
false
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
// PoleStar
|
|
72
|
-
if (ProvidersOptions.hasPoleStar) {
|
|
73
|
-
this._polestarProviderId = PoleStarProvider.addEventListener(polestarPositionEvent => {
|
|
74
|
-
|
|
75
|
-
this._lastPolestarFix = TimeUtils.preciseTime();
|
|
76
|
-
const psPositionUsed = this._onAbsolutePosition(polestarPositionEvent);
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* In the case of a degraded position from PoleStar and a good position from GnssWifi,
|
|
80
|
-
* we still need to retrieve the level from PoleStar.
|
|
81
|
-
* To do so, we duplicate lastEvent and add the level from PoleStar to the current
|
|
82
|
-
* position, then we notify with the new position.
|
|
83
|
-
*/
|
|
84
|
-
if (!psPositionUsed && this.lastEvent?.level === null) {
|
|
85
|
-
const lastPositionWithLevel = this.lastEvent.clone();
|
|
86
|
-
lastPositionWithLevel.level = polestarPositionEvent.level;
|
|
87
|
-
this.notify(lastPositionWithLevel);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
this._mapMatchingHandlerId = MapMatchingHandler.addEventListener();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* @override
|
|
98
|
-
*/
|
|
99
|
-
stop() {
|
|
100
|
-
if (this._relativePositionProviderId) {
|
|
101
|
-
GeoRelativePositionProvider.removeEventListener(this._relativePositionProviderId);
|
|
102
|
-
delete this._relativePositionProviderId;
|
|
103
|
-
}
|
|
104
|
-
if (this._gnssWifiProviderId) {
|
|
105
|
-
GnssWifiProvider.removeEventListener(this._gnssWifiProviderId);
|
|
106
|
-
delete this._gnssWifiProviderId;
|
|
107
|
-
}
|
|
108
|
-
if (this._vpsProviderId) {
|
|
109
|
-
VpsProvider.removeEventListener(this._vpsProviderId);
|
|
110
|
-
delete this._vpsProviderId;
|
|
111
|
-
}
|
|
112
|
-
if (this._polestarProviderId) {
|
|
113
|
-
PoleStarProvider.removeEventListener(this._polestarProviderId);
|
|
114
|
-
delete this._polestarProviderId;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
MapMatchingHandler.removeEventListener(this._mapMatchingHandlerId);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
private _shouldTakeIntoAccountNewAbsolutePosition(newPositionEvent: AbsolutePosition, canContainLevel = true) {
|
|
122
|
-
|
|
123
|
-
const newPosition = newPositionEvent;
|
|
124
|
-
const lastPosition = this.lastEvent || null;
|
|
125
|
-
|
|
126
|
-
// 1. Verifiy if it is the first known absolute position
|
|
127
|
-
if (!lastPosition) {
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// 2. Is the new position accuracy is better enough than the last position accuracy
|
|
132
|
-
const isBetterEnough = newPosition.accuracy! * AbsolutePositionProvider.ACCURACY_RELOC_RATIO <= lastPosition.accuracy!;
|
|
133
|
-
if (isBetterEnough) {
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// 3.a. Is the new position is far from the new one (regarding accuracy)
|
|
138
|
-
// This condition return true if the two positions accuracy circles does not intersect.
|
|
139
|
-
// This is important if the person put the current page in the background during a while. But,
|
|
140
|
-
// could be dangerous if two providers do not provide close positions (ping-pong effect). This
|
|
141
|
-
// is why the 3.b. condition has been added.
|
|
142
|
-
// TODO: add a routine to augment the current position accuracy when the page is in background
|
|
143
|
-
const isFarEnough = lastPosition.distanceTo(newPosition) > lastPosition.accuracy! + newPosition.accuracy!;
|
|
144
|
-
if (isFarEnough) {
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// 3.b. Added on 16/06/22
|
|
149
|
-
// The goal of this condition is to avoid continuous jumps between positions from two providers
|
|
150
|
-
// (i.e. GnssWifi and PoleStar)
|
|
151
|
-
const isFarEnoughAndAccuracyIsBetter = isFarEnough && newPosition.accuracy! <= lastPosition.accuracy!;
|
|
152
|
-
|
|
153
|
-
if (isBetterEnough && isFarEnoughAndAccuracyIsBetter) {
|
|
154
|
-
return true;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// 4. Added on 23/06/22
|
|
158
|
-
// The goal of this condition is to take into account levels change when map-matching is not enabled / set
|
|
159
|
-
const isChangingLevel = canContainLevel && !Level.equals(newPosition.level, lastPosition.level);
|
|
160
|
-
if (isChangingLevel) {
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* @returns if input position is used by the system (true = used, false = discarded)
|
|
169
|
-
*/
|
|
170
|
-
private _onAbsolutePosition(positionEvent: AbsolutePosition, canContainLevel = true) {
|
|
171
|
-
|
|
172
|
-
if (!this._shouldTakeIntoAccountNewAbsolutePosition(positionEvent, canContainLevel)
|
|
173
|
-
&& !this.useAllAbsolutePositions) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const newPosition = positionEvent.clone();
|
|
178
|
-
const lastPosition = this.lastEvent ? this.lastEvent : null;
|
|
179
|
-
|
|
180
|
-
if (lastPosition) {
|
|
181
|
-
if (!canContainLevel) {
|
|
182
|
-
newPosition.level = lastPosition.level;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// If the new position does not have a bearing, retrieve the bearing from the last position
|
|
186
|
-
if (newPosition.bearing === null) {
|
|
187
|
-
newPosition.bearing = lastPosition.bearing;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// If the MM is disable or the network is not set yet, use the new position as it is.
|
|
192
|
-
// If the position bearing is null, do not use MM, it is too dangerous.
|
|
193
|
-
if (!MapMatchingHandler.canUseMapMatching()) {
|
|
194
|
-
this.notify(newPosition);
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return MapMatchingHandler.notifyPositionFromAbsolute(newPosition);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* @returns if input position is used by the system (true = used, false = discarded)
|
|
203
|
-
*/
|
|
204
|
-
_onRelativePosition(relativeEvent: GeoRelativePosition) {
|
|
205
|
-
|
|
206
|
-
if (!this.lastEvent || this._waitUntilNextVpsPosition) {
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const lastPosition = this.lastEvent;
|
|
211
|
-
|
|
212
|
-
const offsetPos = relativeEvent;
|
|
213
|
-
|
|
214
|
-
const dist = Math.sqrt(offsetPos.x ** 2 + offsetPos.y ** 2);
|
|
215
|
-
const bearing = Math.atan2(offsetPos.x, offsetPos.y);
|
|
216
|
-
const alt = lastPosition.alt !== null ? offsetPos.z : null;
|
|
217
|
-
|
|
218
|
-
const newPosition = lastPosition.destinationPoint(dist, bearing, alt);
|
|
219
|
-
newPosition.bearing = offsetPos.bearing;
|
|
220
|
-
newPosition.time = offsetPos.time;
|
|
221
|
-
newPosition.accuracy! += offsetPos.accuracy!;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (!MapMatchingHandler.canUseMapMatching()) {
|
|
225
|
-
this.notify(newPosition);
|
|
226
|
-
return true;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return MapMatchingHandler.notifyPositionFromRelative(newPosition);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
feed(data: AbsolutePosition) {
|
|
234
|
-
|
|
235
|
-
let newPositionEvent: AbsolutePosition;
|
|
236
|
-
|
|
237
|
-
if (data instanceof UserPosition) {
|
|
238
|
-
|
|
239
|
-
if (data.time === null) {
|
|
240
|
-
throw Error('the time of the position is not defined');
|
|
241
|
-
}
|
|
242
|
-
if (data.accuracy === null) {
|
|
243
|
-
throw Error('the accuracy of the position is not defined');
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
newPositionEvent = data;
|
|
247
|
-
|
|
248
|
-
} else {
|
|
249
|
-
throw new Error('data is nor an UserPosition or an AbsolutePositionEvent');
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// If the MM is disable or the network is not set yet, use the new position as it is.
|
|
253
|
-
if (!AbsolutePositionProvider.USE_MM_FOR_FEED || !MapMatchingHandler.canUseMapMatching()) {
|
|
254
|
-
this.notify(newPositionEvent);
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
MapMatchingHandler.notifyPositionFromFeed(newPositionEvent);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
getBestPositionEvent(...absolutePositionEvents: (AbsolutePosition | null)[]) {
|
|
262
|
-
return absolutePositionEvents.reduce((best, value) => {
|
|
263
|
-
if (!best) {
|
|
264
|
-
return value;
|
|
265
|
-
}
|
|
266
|
-
if (!value || value.accuracy === null || value.time === null) {
|
|
267
|
-
return best;
|
|
268
|
-
}
|
|
269
|
-
const { accuracy: curAccuracy, time: curTime } = value;
|
|
270
|
-
const { accuracy: bestAccuracy, time: bestTime } = best;
|
|
271
|
-
// 1.3888 corresponds to 1.3888 m/s (5 km/h)
|
|
272
|
-
return curAccuracy < (bestAccuracy! + 1.3888 * (curTime - bestTime!)) ? value : best;
|
|
273
|
-
}, null as null | AbsolutePosition);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
export default new AbsolutePositionProvider();
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { UserPosition } from '@wemap/geo';
|
|
2
|
-
import Logger from '@wemap/logger';
|
|
3
|
-
import { deg2rad } from '@wemap/maths';
|
|
4
|
-
import { TimeUtils } from '@wemap/utils';
|
|
5
|
-
|
|
6
|
-
import GeolocationApiMissingError from '../../../errors/GeolocationApiMissingError.js';
|
|
7
|
-
import Provider from '../../Provider.js';
|
|
8
|
-
import GeolocationPermissionDeniedError from '../../../errors/GeolocationPermissionDeniedError.js';
|
|
9
|
-
import GeolocationPositionUnavailableError from '../../../errors/GeolocationPositionUnavailableError.js';
|
|
10
|
-
import Constants from '../../Constants.js';
|
|
11
|
-
import { AbsolutePosition } from '../../../events/Types.js';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* GnssWifiProvider is a provider based on navigator.geolocation.
|
|
16
|
-
* This API does not allow us to know if the position returned is provided
|
|
17
|
-
* by Wifi Fingerprinting algorithms or by GNSS. That is why the name is
|
|
18
|
-
* "GnssWifi".
|
|
19
|
-
*/
|
|
20
|
-
class GnssWifiProvider extends Provider<AbsolutePosition> {
|
|
21
|
-
|
|
22
|
-
static DEFAULT_DISCARD_POSITIONS_ABOVE = 50;
|
|
23
|
-
|
|
24
|
-
discardPositionsAbove = GnssWifiProvider.DEFAULT_DISCARD_POSITIONS_ABOVE;
|
|
25
|
-
|
|
26
|
-
enableHighAccuracy = true;
|
|
27
|
-
|
|
28
|
-
geoLocationId?: number;
|
|
29
|
-
|
|
30
|
-
getName = () => 'GnssWifi';
|
|
31
|
-
|
|
32
|
-
get positionOptions() {
|
|
33
|
-
return {
|
|
34
|
-
enableHighAccuracy: this.enableHighAccuracy,
|
|
35
|
-
timeout: Infinity,
|
|
36
|
-
maximumAge: 0
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
availability() {
|
|
41
|
-
return typeof (navigator) === 'object' && navigator.geolocation
|
|
42
|
-
? Promise.resolve()
|
|
43
|
-
: Promise.resolve(new GeolocationApiMissingError());
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
start() {
|
|
47
|
-
// Trigger last known position
|
|
48
|
-
navigator.geolocation.getCurrentPosition(
|
|
49
|
-
this.onNewPosition,
|
|
50
|
-
this.onPositionError,
|
|
51
|
-
this.positionOptions
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
// Note: added timeout for a workaround on Safari/iOS when user disabled geolocation:
|
|
55
|
-
// watchPosition does not send the error callback without the "setTimeout"
|
|
56
|
-
setTimeout(() => {
|
|
57
|
-
this.geoLocationId = navigator.geolocation.watchPosition(
|
|
58
|
-
this.onNewPosition,
|
|
59
|
-
this.onPositionError,
|
|
60
|
-
this.positionOptions
|
|
61
|
-
);
|
|
62
|
-
}, 150);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
stop() {
|
|
66
|
-
if (typeof this.geoLocationId !== 'undefined') {
|
|
67
|
-
navigator.geolocation.clearWatch(this.geoLocationId);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private onNewPosition = (geolocation: GeolocationPosition) => {
|
|
72
|
-
|
|
73
|
-
const { coords } = geolocation;
|
|
74
|
-
if (!coords) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
let bearing;
|
|
79
|
-
if (coords.heading) {
|
|
80
|
-
bearing = deg2rad(coords.heading);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const timestamp = TimeUtils.unixTimestampToPreciseTime(geolocation.timestamp) / 1e3;
|
|
84
|
-
|
|
85
|
-
const position = new UserPosition(
|
|
86
|
-
coords.latitude,
|
|
87
|
-
coords.longitude,
|
|
88
|
-
Constants.DEFAULT_ALTITUDE,
|
|
89
|
-
null,
|
|
90
|
-
timestamp,
|
|
91
|
-
coords.accuracy,
|
|
92
|
-
bearing);
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
this.enableHighAccuracy &&
|
|
96
|
-
typeof this.discardPositionsAbove === 'number'
|
|
97
|
-
&& coords.accuracy > this.discardPositionsAbove
|
|
98
|
-
) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
this.notify(position);
|
|
103
|
-
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
onPositionError = (error: GeolocationPositionError) => {
|
|
107
|
-
|
|
108
|
-
Logger.warn(`[Providers] watchPosition error: [${error.code}] ${error.message}`);
|
|
109
|
-
|
|
110
|
-
let customError;
|
|
111
|
-
switch (error.code) {
|
|
112
|
-
case 1:
|
|
113
|
-
customError = new GeolocationPermissionDeniedError(error.message);
|
|
114
|
-
break;
|
|
115
|
-
case 2:
|
|
116
|
-
customError = new GeolocationPositionUnavailableError(error.message);
|
|
117
|
-
break;
|
|
118
|
-
default:
|
|
119
|
-
customError = new Error(error.message);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
this.notifyError(customError);
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export default new GnssWifiProvider();
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import chai from 'chai';
|
|
2
|
-
import sinon from 'sinon';
|
|
3
|
-
|
|
4
|
-
import GnssWifiProvider from './GnssWifiProvider.js';
|
|
5
|
-
|
|
6
|
-
const { expect } = chai;
|
|
7
|
-
|
|
8
|
-
describe('GnssWifiProvider', () => {
|
|
9
|
-
it('onNewPosition - should notify when accuracy is low', async () => {
|
|
10
|
-
|
|
11
|
-
const fakePositionEvent = {
|
|
12
|
-
coords: {
|
|
13
|
-
latitude: 43,
|
|
14
|
-
longitude: 3,
|
|
15
|
-
accuracy: 10,
|
|
16
|
-
altitude: 0,
|
|
17
|
-
altitudeAccuracy: 0,
|
|
18
|
-
heading: 0,
|
|
19
|
-
speed: 0
|
|
20
|
-
},
|
|
21
|
-
timestamp: Date.now()
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const notifySpy = sinon.spy();
|
|
25
|
-
|
|
26
|
-
const callbackId = GnssWifiProvider.addEventListener(notifySpy);
|
|
27
|
-
|
|
28
|
-
(GnssWifiProvider as any).onNewPosition(fakePositionEvent);
|
|
29
|
-
|
|
30
|
-
expect(notifySpy.callCount).to.equal(1);
|
|
31
|
-
|
|
32
|
-
GnssWifiProvider.removeEventListener(callbackId);
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('onNewPosition - should not notify when accuracy is greater than options', async () => {
|
|
37
|
-
|
|
38
|
-
const fakePositionEvent = {
|
|
39
|
-
coords: {
|
|
40
|
-
latitude: 43,
|
|
41
|
-
longitude: 3,
|
|
42
|
-
accuracy: 100,
|
|
43
|
-
altitude: 0,
|
|
44
|
-
altitudeAccuracy: 0,
|
|
45
|
-
heading: 0,
|
|
46
|
-
speed: 0
|
|
47
|
-
},
|
|
48
|
-
timestamp: Date.now()
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const notifySpy = sinon.spy();
|
|
52
|
-
|
|
53
|
-
const callbackId = GnssWifiProvider.addEventListener(notifySpy);
|
|
54
|
-
|
|
55
|
-
(GnssWifiProvider as any).onNewPosition(fakePositionEvent);
|
|
56
|
-
|
|
57
|
-
expect(notifySpy.callCount).to.equal(0);
|
|
58
|
-
|
|
59
|
-
GnssWifiProvider.removeEventListener(callbackId);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('onNewPosition - should notify when accuracy is high and enableHighAccuracy false', async () => {
|
|
63
|
-
|
|
64
|
-
const fakePositionEvent = {
|
|
65
|
-
coords: {
|
|
66
|
-
latitude: 43,
|
|
67
|
-
longitude: 3,
|
|
68
|
-
accuracy: 100,
|
|
69
|
-
altitude: 0,
|
|
70
|
-
altitudeAccuracy: 0,
|
|
71
|
-
heading: 0,
|
|
72
|
-
speed: 0
|
|
73
|
-
},
|
|
74
|
-
timestamp: Date.now()
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const notifySpy = sinon.spy();
|
|
78
|
-
GnssWifiProvider.enableHighAccuracy = false;
|
|
79
|
-
|
|
80
|
-
const callbackId = GnssWifiProvider.addEventListener(notifySpy);
|
|
81
|
-
|
|
82
|
-
(GnssWifiProvider as any).onNewPosition(fakePositionEvent);
|
|
83
|
-
|
|
84
|
-
expect(notifySpy.callCount).to.equal(1);
|
|
85
|
-
|
|
86
|
-
// Reset
|
|
87
|
-
GnssWifiProvider.enableHighAccuracy = true;
|
|
88
|
-
GnssWifiProvider.removeEventListener(callbackId);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { UserPosition } from '@wemap/geo';
|
|
2
|
-
import { TimeUtils } from '@wemap/utils';
|
|
3
|
-
|
|
4
|
-
import Provider from '../../Provider.js';
|
|
5
|
-
import IpResolveServerError from '../../../errors/IpResolveServerError.js';
|
|
6
|
-
import { AbsolutePosition } from '../../../events/Types.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* GnssWifiProvider is a provider based on navigator.geolocation.
|
|
10
|
-
* This API does not allow us to know if the position returned is provided
|
|
11
|
-
* by Wifi Fingerprinting algorithms or by GNSS. That is why the name is
|
|
12
|
-
* "GnssWifi".
|
|
13
|
-
*/
|
|
14
|
-
class IpProvider extends Provider<AbsolutePosition> {
|
|
15
|
-
|
|
16
|
-
getName = () => 'Ip';
|
|
17
|
-
|
|
18
|
-
availability = () => Promise.resolve();
|
|
19
|
-
|
|
20
|
-
async start() {
|
|
21
|
-
|
|
22
|
-
const response = await fetch('https://ipinfo.io/geo?token=24a7ca2f3b489d');
|
|
23
|
-
if (!response) {
|
|
24
|
-
this.notifyError(new IpResolveServerError());
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const timestamp = TimeUtils.preciseTime() / 1e3;
|
|
29
|
-
|
|
30
|
-
const latLngStr = (await response.json()).loc.split(',');
|
|
31
|
-
const position = new UserPosition(
|
|
32
|
-
parseFloat(latLngStr[0]),
|
|
33
|
-
parseFloat(latLngStr[1]),
|
|
34
|
-
null,
|
|
35
|
-
null,
|
|
36
|
-
timestamp,
|
|
37
|
-
100000
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
this.notify(position);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
stop() { /* do nothing */ }
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export default new IpProvider();
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { deg2rad } from '@wemap/maths';
|
|
2
|
-
import { TimeUtils } from '@wemap/utils';
|
|
3
|
-
|
|
4
|
-
import Provider from '../../Provider.js';
|
|
5
|
-
import MissingPoleStarError from '../../../errors/MissingPoleStarError.js';
|
|
6
|
-
import MissingNativeInterfaceError from '../../../errors/MissingNativeInterfaceError.js';
|
|
7
|
-
import Constants from '../../Constants.js';
|
|
8
|
-
import { AbsolutePosition } from '../../../events/Types.js';
|
|
9
|
-
import { NativePolestarPosition } from '../../NativeProviders.js';
|
|
10
|
-
|
|
11
|
-
class PoleStarProvider extends Provider<AbsolutePosition> {
|
|
12
|
-
|
|
13
|
-
getName = () => 'PoleStar';
|
|
14
|
-
|
|
15
|
-
constructor() {
|
|
16
|
-
super();
|
|
17
|
-
this.addMethodsToNativeJsProvider();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
availability() {
|
|
21
|
-
try {
|
|
22
|
-
this.nativeProvider.checkAvailability();
|
|
23
|
-
return Promise.resolve();
|
|
24
|
-
} catch (e) {
|
|
25
|
-
return Promise.resolve(e as Error);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
setApiKey(apiKey: string) {
|
|
30
|
-
this.nativeProvider.setApiKey(apiKey);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
start() {
|
|
34
|
-
this.nativeProvider.start();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
stop() {
|
|
38
|
-
this.nativeProvider.stop();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get nativeProvider() {
|
|
42
|
-
|
|
43
|
-
if (!this.nativeInterface) {
|
|
44
|
-
throw new MissingNativeInterfaceError();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const nativeProvider = this.nativeInterface.getPoleStarProvider();
|
|
48
|
-
if (!nativeProvider) {
|
|
49
|
-
throw new MissingPoleStarError();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return nativeProvider;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
addMethodsToNativeJsProvider() {
|
|
58
|
-
|
|
59
|
-
if (!this.nativeJsInterface) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
this.nativeJsInterface.polestar = {
|
|
64
|
-
callbackError: (errorMessage: string) => this.notifyError(new Error(errorMessage)),
|
|
65
|
-
callbackPosition: (jsonString: string) => {
|
|
66
|
-
|
|
67
|
-
const json: NativePolestarPosition = JSON.parse(jsonString);
|
|
68
|
-
|
|
69
|
-
const timestamp = TimeUtils.unixTimestampToPreciseTime(json.time) / 1e3;
|
|
70
|
-
|
|
71
|
-
const position = new AbsolutePosition(
|
|
72
|
-
json.lat,
|
|
73
|
-
json.lng,
|
|
74
|
-
Constants.DEFAULT_ALTITUDE,
|
|
75
|
-
json.alt / 5,
|
|
76
|
-
timestamp,
|
|
77
|
-
json.accuracy,
|
|
78
|
-
deg2rad(json.bearing)
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
this.notify(position);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export default new PoleStarProvider();
|