@wemap/providers 3.1.4 → 3.1.6
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/debug/MainComponent.jsx +2 -15
- package/debug/details/DetailsAttitudeComponent.jsx +9 -2
- package/debug/details/DetailsComponent.jsx +1 -11
- package/debug/details/DetailsPositionComponent.jsx +10 -2
- package/debug/map/MapComponent.jsx +0 -7
- package/debug/map/helpers/UserOnMapHandler.js +7 -26
- package/package.json +6 -6
- package/src/providers/FakeProvider.spec.js +2 -7
- package/src/providers/Provider.js +19 -14
- package/src/providers/Provider.spec.js +21 -20
- package/src/providers/attitude/absolute/AbsoluteAttitudeFromBrowserProvider.js +2 -3
- package/src/providers/attitude/absolute/AbsoluteAttitudeProvider.js +3 -3
- package/src/providers/attitude/relative/RelativeAttitudeFromBrowserProvider.js +2 -3
- package/src/providers/attitude/relative/RelativeAttitudeFromEkfProvider.js +3 -4
- package/src/providers/attitude/relative/RelativeAttitudeFromInertialProvider.js +17 -11
- package/src/providers/imu/ImuProvider.js +2 -3
- package/src/providers/inclination/InclinationProvider.js +4 -3
- package/src/providers/position/absolute/AbsolutePositionProvider.js +14 -10
- package/src/providers/position/absolute/GnssWifiProvider.js +2 -3
- package/src/providers/position/relative/ArCoreProvider.js +3 -4
- package/src/providers/position/relative/GeoRelativePositionProvider.js +23 -20
- package/src/providers/position/relative/PdrProvider.js +2 -3
- package/src/providers/steps/StepDetectionProvider.js +2 -3
- package/src/events/Availability.js +0 -44
package/debug/MainComponent.jsx
CHANGED
|
@@ -15,20 +15,12 @@ class MainComponent extends React.Component {
|
|
|
15
15
|
super(props, context);
|
|
16
16
|
this.state = {
|
|
17
17
|
details: true,
|
|
18
|
-
locationEnabled: false,
|
|
19
18
|
mapHandler: null
|
|
20
19
|
};
|
|
21
20
|
|
|
22
|
-
ProvidersInterface.logger =
|
|
21
|
+
ProvidersInterface.logger = false;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
onStart = () => {
|
|
26
|
-
this.setState({ locationEnabled: true });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
onStop = () => {
|
|
30
|
-
this.setState({ locationEnabled: false });
|
|
31
|
-
}
|
|
32
24
|
|
|
33
25
|
render() {
|
|
34
26
|
return (
|
|
@@ -36,7 +28,6 @@ class MainComponent extends React.Component {
|
|
|
36
28
|
<div id='map-container'>
|
|
37
29
|
<MapComponent
|
|
38
30
|
ref={map => (this.map = map)}
|
|
39
|
-
locationEnabled={this.state.locationEnabled}
|
|
40
31
|
onMapLoaded={mapHandler => this.setState({ mapHandler })}
|
|
41
32
|
indoorMaps={['assets/indoor-maps/bureaux-wemap-montpellier.geojson']}
|
|
42
33
|
/>
|
|
@@ -48,11 +39,7 @@ class MainComponent extends React.Component {
|
|
|
48
39
|
</span>
|
|
49
40
|
{this.state.details ? (
|
|
50
41
|
<div id='details-container'>
|
|
51
|
-
<DetailsComponent
|
|
52
|
-
mapHandler={this.state.mapHandler}
|
|
53
|
-
onStart={this.onStart}
|
|
54
|
-
onStop={this.onStop}
|
|
55
|
-
/>
|
|
42
|
+
<DetailsComponent mapHandler={this.state.mapHandler} />
|
|
56
43
|
</div>
|
|
57
44
|
) : null}
|
|
58
45
|
</div>
|
|
@@ -22,6 +22,7 @@ const Orientations = [
|
|
|
22
22
|
}
|
|
23
23
|
];
|
|
24
24
|
|
|
25
|
+
const fps = 10;
|
|
25
26
|
|
|
26
27
|
class DetailsAttitudeComponent extends React.PureComponent {
|
|
27
28
|
|
|
@@ -46,13 +47,19 @@ class DetailsAttitudeComponent extends React.PureComponent {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
componentWillUnmount() {
|
|
49
|
-
|
|
50
|
+
if (this.timeoutLoopId) {
|
|
51
|
+
clearTimeout(this.timeoutLoopId);
|
|
52
|
+
}
|
|
53
|
+
cancelAnimationFrame(this.renderLoopId);
|
|
50
54
|
ProvidersInterface.removeEventListener(this.providersId);
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
renderLoop = () => {
|
|
54
58
|
this.renderAttitude();
|
|
55
|
-
this.
|
|
59
|
+
this.timeoutLoopId = setTimeout(() => {
|
|
60
|
+
this.timeoutLoopId = null;
|
|
61
|
+
this.renderLoopId = requestAnimationFrame(this.renderLoop);
|
|
62
|
+
}, 1000 / fps);
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
renderAttitude = () => {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import noop from 'lodash.noop';
|
|
2
1
|
import PropTypes from 'prop-types';
|
|
3
2
|
import React from 'react';
|
|
4
3
|
|
|
@@ -11,16 +10,7 @@ import ItineraryComponent from './ItineraryComponent';
|
|
|
11
10
|
|
|
12
11
|
class DetailsComponent extends React.Component {
|
|
13
12
|
|
|
14
|
-
static propTypes = {
|
|
15
|
-
mapHandler: PropTypes.instanceOf(MapHandler),
|
|
16
|
-
onStart: PropTypes.func,
|
|
17
|
-
onStop: PropTypes.func
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
static defaultProps = {
|
|
21
|
-
onStart: noop,
|
|
22
|
-
onStop: noop
|
|
23
|
-
};
|
|
13
|
+
static propTypes = { mapHandler: PropTypes.instanceOf(MapHandler) };
|
|
24
14
|
|
|
25
15
|
render() {
|
|
26
16
|
|
|
@@ -32,6 +32,8 @@ const Positions = [
|
|
|
32
32
|
}
|
|
33
33
|
];
|
|
34
34
|
|
|
35
|
+
const fps = 10;
|
|
36
|
+
|
|
35
37
|
class DetailsPositionComponent extends React.PureComponent {
|
|
36
38
|
|
|
37
39
|
position = null;
|
|
@@ -55,13 +57,19 @@ class DetailsPositionComponent extends React.PureComponent {
|
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
componentWillUnmount() {
|
|
58
|
-
|
|
60
|
+
if (this.timeoutLoopId) {
|
|
61
|
+
clearTimeout(this.timeoutLoopId);
|
|
62
|
+
}
|
|
63
|
+
cancelAnimationFrame(this.renderLoopId);
|
|
59
64
|
ProvidersInterface.removeEventListener(this.providersId);
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
renderLoop = () => {
|
|
63
68
|
this.renderPosition();
|
|
64
|
-
this.
|
|
69
|
+
this.timeoutLoopId = setTimeout(() => {
|
|
70
|
+
this.timeoutLoopId = null;
|
|
71
|
+
this.renderLoopId = requestAnimationFrame(this.renderLoop);
|
|
72
|
+
}, 1000 / fps);
|
|
65
73
|
}
|
|
66
74
|
|
|
67
75
|
renderPosition = () => {
|
|
@@ -13,7 +13,6 @@ const BELOW_LAYER_ID = 'housenum-label';
|
|
|
13
13
|
|
|
14
14
|
class MapComponent extends React.Component {
|
|
15
15
|
static propTypes = {
|
|
16
|
-
locationEnabled: PropTypes.bool.isRequired,
|
|
17
16
|
maxZoom: PropTypes.number,
|
|
18
17
|
onMapLoaded: PropTypes.func,
|
|
19
18
|
indoorMaps: PropTypes.array
|
|
@@ -55,12 +54,6 @@ class MapComponent extends React.Component {
|
|
|
55
54
|
this.map.remove();
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
componentDidUpdate(prevProps) {
|
|
59
|
-
if (prevProps.locationEnabled !== this.props.locationEnabled) {
|
|
60
|
-
this.mapHandler.locationEnabled = this.props.locationEnabled;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
57
|
loadIndoorMaps(mapsPaths) {
|
|
65
58
|
return Promise.all(
|
|
66
59
|
mapsPaths.map(mapPath =>
|
|
@@ -62,17 +62,11 @@ class UserOnMapHandler {
|
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
componentDidMount() {
|
|
65
|
-
this.
|
|
66
|
-
this.renderPositionAccuracyLoop();
|
|
67
|
-
this.renderOrientationLoop();
|
|
68
|
-
this.renderCameraCenterLoop();
|
|
65
|
+
this.renderLoop();
|
|
69
66
|
}
|
|
70
67
|
|
|
71
68
|
componentWillUnmount() {
|
|
72
|
-
cancelAnimationFrame(this.
|
|
73
|
-
cancelAnimationFrame(this.renderPositionAccuracyLoopId);
|
|
74
|
-
cancelAnimationFrame(this.renderOrientationLoopId);
|
|
75
|
-
cancelAnimationFrame(this.renderCameraCenterLoopId);
|
|
69
|
+
cancelAnimationFrame(this.renderLoopId);
|
|
76
70
|
}
|
|
77
71
|
|
|
78
72
|
|
|
@@ -243,9 +237,12 @@ class UserOnMapHandler {
|
|
|
243
237
|
* Render loops
|
|
244
238
|
*/
|
|
245
239
|
|
|
246
|
-
|
|
240
|
+
renderLoop = () => {
|
|
247
241
|
this.renderPosition();
|
|
248
|
-
this.
|
|
242
|
+
this.renderPositionAccuracy();
|
|
243
|
+
this.renderOrientation();
|
|
244
|
+
this.renderCameraCenter();
|
|
245
|
+
this.renderLoopId = requestAnimationFrame(this.renderLoop);
|
|
249
246
|
}
|
|
250
247
|
|
|
251
248
|
renderPosition() {
|
|
@@ -286,11 +283,6 @@ class UserOnMapHandler {
|
|
|
286
283
|
this.levelForPositionDirty = false;
|
|
287
284
|
}
|
|
288
285
|
|
|
289
|
-
renderPositionAccuracyLoop = () => {
|
|
290
|
-
this.renderPositionAccuracy();
|
|
291
|
-
this.renderPositionAccuracyLoopId = requestAnimationFrame(this.renderPositionAccuracyLoop);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
286
|
renderPositionAccuracy() {
|
|
295
287
|
|
|
296
288
|
if (!this.positionAccuracyDirty) {
|
|
@@ -327,11 +319,6 @@ class UserOnMapHandler {
|
|
|
327
319
|
this.positionAccuracyDirty = false;
|
|
328
320
|
}
|
|
329
321
|
|
|
330
|
-
renderOrientationLoop = () => {
|
|
331
|
-
this.renderOrientation();
|
|
332
|
-
this.renderOrientationLoopId = requestAnimationFrame(this.renderOrientationLoop);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
322
|
renderOrientation() {
|
|
336
323
|
|
|
337
324
|
if (!this.attitudeDirty || !this.positionIcon) {
|
|
@@ -352,12 +339,6 @@ class UserOnMapHandler {
|
|
|
352
339
|
this.attitudeDirty = false;
|
|
353
340
|
}
|
|
354
341
|
|
|
355
|
-
renderCameraCenterLoop = () => {
|
|
356
|
-
this.renderCameraCenter();
|
|
357
|
-
this.renderCameraCenterLoopId = requestAnimationFrame(this.renderCameraCenterLoop);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
|
|
361
342
|
renderCameraCenter() {
|
|
362
343
|
|
|
363
344
|
if (!this.positionForCameraDirty || !this.trackUserLocation || !this.position) {
|
package/package.json
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"Guillaume Pannetier <guillaume.pannetier@getwemap.com>"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@wemap/geo": "^3.1.
|
|
12
|
-
"@wemap/graph": "^3.1.
|
|
11
|
+
"@wemap/geo": "^3.1.6",
|
|
12
|
+
"@wemap/graph": "^3.1.6",
|
|
13
13
|
"@wemap/logger": "^3.0.0",
|
|
14
14
|
"@wemap/maths": "^3.0.0",
|
|
15
|
-
"@wemap/osm": "^3.1.
|
|
16
|
-
"@wemap/utils": "^3.1.
|
|
15
|
+
"@wemap/osm": "^3.1.6",
|
|
16
|
+
"@wemap/utils": "^3.1.5",
|
|
17
17
|
"geomagnetism": "^0.1.0",
|
|
18
18
|
"lodash.isempty": "^4.4.0",
|
|
19
19
|
"lodash.isnumber": "^3.0.3",
|
|
@@ -65,6 +65,6 @@
|
|
|
65
65
|
"lint": "eslint --ext .js,.jsx --quiet src",
|
|
66
66
|
"test": "mocha -r esm \"src/**/*.spec.js\""
|
|
67
67
|
},
|
|
68
|
-
"version": "3.1.
|
|
69
|
-
"gitHead": "
|
|
68
|
+
"version": "3.1.6",
|
|
69
|
+
"gitHead": "f7967fd5b465e1e2be1c575ef0f2150adde4825f"
|
|
70
70
|
}
|
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
import { UserPosition } from '@wemap/geo';
|
|
2
2
|
|
|
3
3
|
import Provider from './Provider';
|
|
4
|
-
import Availability from '../events/Availability';
|
|
5
4
|
|
|
6
5
|
import EventType from '../events/EventType';
|
|
7
6
|
import { TimeUtils } from '@wemap/utils';
|
|
8
7
|
|
|
9
8
|
class FakeProvider1 extends Provider { }
|
|
10
9
|
|
|
11
|
-
class FakeProvider5 extends Provider {
|
|
12
|
-
start() {}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
10
|
class FakeProvider2 extends Provider {
|
|
16
11
|
get _availability() {
|
|
17
|
-
return
|
|
12
|
+
return Promise.reject(new Error());
|
|
18
13
|
}
|
|
19
14
|
start() { }
|
|
20
15
|
stop() { }
|
|
@@ -53,5 +48,5 @@ class FakeProvider4 extends Provider {
|
|
|
53
48
|
}
|
|
54
49
|
|
|
55
50
|
export {
|
|
56
|
-
FakeProvider1, FakeProvider2, FakeProvider3, FakeProvider4
|
|
51
|
+
FakeProvider1, FakeProvider2, FakeProvider3, FakeProvider4
|
|
57
52
|
};
|
|
@@ -6,7 +6,6 @@ import { TimeUtils } from '@wemap/utils';
|
|
|
6
6
|
import EventType from '../events/EventType';
|
|
7
7
|
import ProviderEvent from '../events/ProviderEvent';
|
|
8
8
|
import ProvidersLogger from '../events/ProvidersLogger';
|
|
9
|
-
import Availability from '../events/Availability';
|
|
10
9
|
import ContainsIgnoredProviderError from '../errors/ContainsIgnoredProviderError';
|
|
11
10
|
import ProvidersOptions from '../ProvidersOptions';
|
|
12
11
|
import ProviderState from './ProviderState';
|
|
@@ -85,18 +84,18 @@ class Provider {
|
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
/**
|
|
88
|
-
* @returns {
|
|
87
|
+
* @returns {Promise} returns an availability promise
|
|
89
88
|
*/
|
|
90
89
|
get availability() {
|
|
91
90
|
if (ProvidersOptions.ignoreProviders.includes(this.name)) {
|
|
92
|
-
return
|
|
91
|
+
return Promise.reject(new ContainsIgnoredProviderError());
|
|
93
92
|
}
|
|
94
93
|
|
|
95
94
|
return this._availability;
|
|
96
95
|
}
|
|
97
96
|
|
|
98
97
|
get _availability() {
|
|
99
|
-
return
|
|
98
|
+
return Promise.resolve();
|
|
100
99
|
}
|
|
101
100
|
|
|
102
101
|
/**
|
|
@@ -177,22 +176,28 @@ class Provider {
|
|
|
177
176
|
}
|
|
178
177
|
|
|
179
178
|
// Check availability on start if defined in options
|
|
179
|
+
let availabilityPromise = Promise.resolve();
|
|
180
180
|
if (ProvidersOptions.checkAvailabilityOnStart) {
|
|
181
|
-
|
|
182
|
-
this.notifyError(this.availability.reason);
|
|
183
|
-
return id;
|
|
184
|
-
}
|
|
181
|
+
availabilityPromise = this.availability;
|
|
185
182
|
}
|
|
186
183
|
|
|
187
|
-
|
|
184
|
+
availabilityPromise
|
|
185
|
+
.then(() => {
|
|
186
|
+
this.state = ProviderState.STARTING;
|
|
188
187
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
188
|
+
ProvidersLogger.addEvent(this, 'start');
|
|
189
|
+
// Call the child start function
|
|
190
|
+
this.start();
|
|
192
191
|
|
|
193
|
-
|
|
192
|
+
this.state = ProviderState.STARTED;
|
|
194
193
|
|
|
195
|
-
|
|
194
|
+
this._monitoringCallbacks.forEach(({ onStarted }) => onStarted());
|
|
195
|
+
})
|
|
196
|
+
.catch(e => {
|
|
197
|
+
this.notifyError(e);
|
|
198
|
+
})
|
|
199
|
+
// notifyError can throw an error if onStop is not defined
|
|
200
|
+
.catch(() => noop);
|
|
196
201
|
|
|
197
202
|
return id;
|
|
198
203
|
}
|
|
@@ -10,7 +10,7 @@ import Provider from './Provider';
|
|
|
10
10
|
import ContainsIgnoredProviderError from '../errors/ContainsIgnoredProviderError';
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
|
-
FakeProvider1, FakeProvider2, FakeProvider3, FakeProvider4
|
|
13
|
+
FakeProvider1, FakeProvider2, FakeProvider3, FakeProvider4
|
|
14
14
|
} from './FakeProvider.spec';
|
|
15
15
|
import ProvidersOptions from '../ProvidersOptions';
|
|
16
16
|
import ProviderState from './ProviderState';
|
|
@@ -20,6 +20,7 @@ Logger.enable(false);
|
|
|
20
20
|
|
|
21
21
|
const { expect } = chai;
|
|
22
22
|
|
|
23
|
+
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
23
24
|
|
|
24
25
|
describe('Provider', () => {
|
|
25
26
|
|
|
@@ -45,23 +46,21 @@ describe('Provider', () => {
|
|
|
45
46
|
expect(provider.useCameraNatively).is.false;
|
|
46
47
|
});
|
|
47
48
|
|
|
48
|
-
it('availability', () => {
|
|
49
|
+
it('availability', async () => {
|
|
49
50
|
|
|
50
51
|
const fakeProvider1 = FakeProvider1.instance;
|
|
51
|
-
expect(fakeProvider1.availability
|
|
52
|
+
await expect(fakeProvider1.availability).to.be.fulfilled;
|
|
52
53
|
ProvidersOptions.ignoreProviders.push(FakeProvider1.name);
|
|
53
|
-
expect(fakeProvider1.availability
|
|
54
|
-
expect(fakeProvider1.availability.reason).instanceOf(ContainsIgnoredProviderError);
|
|
54
|
+
await expect(fakeProvider1.availability).to.be.rejectedWith(ContainsIgnoredProviderError);
|
|
55
55
|
ProvidersOptions.ignoreProviders = [];
|
|
56
56
|
|
|
57
|
-
expect(FakeProvider2.instance.availability
|
|
58
|
-
expect(FakeProvider2.instance.availability.reason).instanceOf(Error);
|
|
57
|
+
await expect(FakeProvider2.instance.availability).to.be.rejectedWith(Error);
|
|
59
58
|
|
|
60
|
-
expect(FakeProvider3.instance.availability
|
|
61
|
-
expect(FakeProvider4.instance.availability
|
|
59
|
+
await expect(FakeProvider3.instance.availability).to.be.fulfilled;
|
|
60
|
+
await expect(FakeProvider4.instance.availability).to.be.fulfilled;
|
|
62
61
|
});
|
|
63
62
|
|
|
64
|
-
it('checkAvailability on start', () => {
|
|
63
|
+
it('checkAvailability on start', async () => {
|
|
65
64
|
|
|
66
65
|
const fp2 = FakeProvider2.instance;
|
|
67
66
|
|
|
@@ -71,6 +70,8 @@ describe('Provider', () => {
|
|
|
71
70
|
let errored = false;
|
|
72
71
|
fp2.addEventListener(noop, () => (errored = true));
|
|
73
72
|
|
|
73
|
+
await sleep(2);
|
|
74
|
+
|
|
74
75
|
expect(errored).is.true;
|
|
75
76
|
expect(fp2.state).equals(ProviderState.STOPPPED);
|
|
76
77
|
expect(fp2._eventsCallbacks.length).equals(0);
|
|
@@ -83,6 +84,8 @@ describe('Provider', () => {
|
|
|
83
84
|
errored = false;
|
|
84
85
|
const id = fp2.addEventListener(noop, () => (errored = true));
|
|
85
86
|
|
|
87
|
+
await sleep(2);
|
|
88
|
+
|
|
86
89
|
expect(errored).is.false;
|
|
87
90
|
expect(fp2.state).equals(ProviderState.STARTED);
|
|
88
91
|
|
|
@@ -120,17 +123,15 @@ describe('Provider', () => {
|
|
|
120
123
|
};
|
|
121
124
|
|
|
122
125
|
|
|
123
|
-
it('start/stop', () => {
|
|
124
|
-
|
|
126
|
+
it('start/stop', async () => {
|
|
127
|
+
let errored = false;
|
|
128
|
+
FakeProvider1.instance.addEventListener(noop, (errored = true));
|
|
129
|
+
await sleep(2);
|
|
130
|
+
expect(errored).is.true;
|
|
125
131
|
|
|
126
|
-
|
|
127
|
-
expect((
|
|
132
|
+
await expect(startStop(FakeProvider2.instance)).to.be.fulfilled;
|
|
133
|
+
await expect(startStop(FakeProvider3.instance)).to.be.fulfilled;
|
|
134
|
+
await expect(startStop(FakeProvider4.instance)).to.be.fulfilled;
|
|
128
135
|
|
|
129
|
-
return Promise.all([
|
|
130
|
-
expect(startStop(FakeProvider2.instance)).to.be.fulfilled,
|
|
131
|
-
expect(startStop(FakeProvider3.instance)).to.be.fulfilled,
|
|
132
|
-
expect(startStop(FakeProvider4.instance)).to.be.fulfilled
|
|
133
|
-
]);
|
|
134
136
|
});
|
|
135
|
-
|
|
136
137
|
});
|
|
@@ -16,7 +16,6 @@ import EventType from '../../../events/EventType';
|
|
|
16
16
|
import AskImuOnDesktopError from '../../../errors/AskImuOnDesktopError';
|
|
17
17
|
import MissingMagnetometerError from '../../../errors/MissingMagnetometerError';
|
|
18
18
|
import MissingSensorError from '../../../errors/MissingSensorError';
|
|
19
|
-
import Availability from '../../../events/Availability';
|
|
20
19
|
import { AbsolutePosition } from '../../../Providers';
|
|
21
20
|
|
|
22
21
|
|
|
@@ -61,8 +60,8 @@ class AbsoluteAttitudeFromBrowserProvider extends Provider {
|
|
|
61
60
|
*/
|
|
62
61
|
get _availability() {
|
|
63
62
|
return BrowserUtils.isMobile
|
|
64
|
-
?
|
|
65
|
-
:
|
|
63
|
+
? Promise.resolve()
|
|
64
|
+
: Promise.reject(new AskImuOnDesktopError());
|
|
66
65
|
}
|
|
67
66
|
|
|
68
67
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AbsoluteHeading, Attitude
|
|
3
3
|
} from '@wemap/geo';
|
|
4
|
+
import { PromiseUtils } from '@wemap/utils';
|
|
4
5
|
|
|
5
6
|
import MetaProvider from '../../MetaProvider';
|
|
6
7
|
import EventType from '../../../events/EventType';
|
|
7
|
-
import Availability from '../../../events/Availability';
|
|
8
8
|
import {
|
|
9
9
|
AbsoluteAttitudeFromBrowser, AbsoluteAttitudeFromRelAtt
|
|
10
10
|
} from '../../../Providers';
|
|
@@ -40,10 +40,10 @@ class AbsoluteAttitudeProvider extends MetaProvider {
|
|
|
40
40
|
* @override
|
|
41
41
|
*/
|
|
42
42
|
get _availability() {
|
|
43
|
-
return
|
|
43
|
+
return PromiseUtils.any([
|
|
44
44
|
AbsoluteAttitudeFromBrowser.availability,
|
|
45
45
|
AbsoluteAttitudeFromRelAtt.availability
|
|
46
|
-
);
|
|
46
|
+
]);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
@@ -8,7 +8,6 @@ import Provider from '../../Provider';
|
|
|
8
8
|
import EventType from '../../../events/EventType';
|
|
9
9
|
import AskImuOnDesktopError from '../../../errors/AskImuOnDesktopError';
|
|
10
10
|
import MissingSensorError from '../../../errors/MissingSensorError';
|
|
11
|
-
import Availability from '../../../events/Availability';
|
|
12
11
|
import RelativeAttitudeFromInertialProvider from './RelativeAttitudeFromInertialProvider';
|
|
13
12
|
|
|
14
13
|
|
|
@@ -48,8 +47,8 @@ class RelativeAttitudeFromBrowserProvider extends Provider {
|
|
|
48
47
|
*/
|
|
49
48
|
get _availability() {
|
|
50
49
|
return BrowserUtils.isMobile
|
|
51
|
-
?
|
|
52
|
-
:
|
|
50
|
+
? Promise.resolve()
|
|
51
|
+
: Promise.reject(new AskImuOnDesktopError());
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
/**
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Attitude } from '@wemap/geo';
|
|
2
2
|
|
|
3
3
|
import Provider from '../../Provider';
|
|
4
|
-
import Availability from '../../../events/Availability';
|
|
5
4
|
import EventType from '../../../events/EventType';
|
|
6
5
|
import EkfAttitude from '../EkfAttitude';
|
|
7
6
|
import RelativeAttitudeFromInertialProvider from './RelativeAttitudeFromInertialProvider';
|
|
@@ -45,10 +44,10 @@ class RelativeAttitudeFromEkfProvider extends Provider {
|
|
|
45
44
|
* @override
|
|
46
45
|
*/
|
|
47
46
|
get _availability() {
|
|
48
|
-
return
|
|
47
|
+
return Promise.all([
|
|
49
48
|
Accelerometer.availability,
|
|
50
|
-
Gyroscope.availability
|
|
51
|
-
);
|
|
49
|
+
Gyroscope.availability
|
|
50
|
+
]);
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { deg2rad } from '@wemap/maths';
|
|
2
|
+
import { PromiseUtils } from '@wemap/utils';
|
|
2
3
|
|
|
3
4
|
import Provider from '../../Provider';
|
|
4
5
|
import EventType from '../../../events/EventType';
|
|
5
|
-
import Availability from '../../../events/Availability';
|
|
6
6
|
import {
|
|
7
7
|
RelativeAttitudeFromEkf, RelativeAttitudeFromBrowser
|
|
8
8
|
} from '../../../Providers';
|
|
@@ -33,31 +33,37 @@ class RelativeAttitudeFromInertialProvider extends Provider {
|
|
|
33
33
|
* @override
|
|
34
34
|
*/
|
|
35
35
|
get _availability() {
|
|
36
|
-
return
|
|
36
|
+
return PromiseUtils.any([
|
|
37
37
|
RelativeAttitudeFromEkf.availability,
|
|
38
38
|
RelativeAttitudeFromBrowser.availability
|
|
39
|
-
);
|
|
39
|
+
]);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* @override
|
|
44
44
|
*/
|
|
45
45
|
start() {
|
|
46
|
-
this.provider = RelativeAttitudeFromEkf.availability.isSupported
|
|
47
|
-
? RelativeAttitudeFromEkf
|
|
48
|
-
: RelativeAttitudeFromBrowser;
|
|
49
46
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
RelativeAttitudeFromEkf.availability
|
|
48
|
+
.then(() => (this.provider = RelativeAttitudeFromEkf))
|
|
49
|
+
.catch(() => (this.provider = RelativeAttitudeFromBrowser))
|
|
50
|
+
.finally(() => {
|
|
51
|
+
this.listenerId = this.provider.addEventListener(
|
|
52
|
+
events => this.notify(events[0].clone()),
|
|
53
|
+
error => this.notifyError(error),
|
|
54
|
+
this.name);
|
|
55
|
+
});
|
|
56
|
+
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
/**
|
|
57
60
|
* @override
|
|
58
61
|
*/
|
|
59
62
|
stop() {
|
|
60
|
-
this.provider
|
|
63
|
+
if (this.provider) {
|
|
64
|
+
this.provider.removeEventListener(this.listenerId);
|
|
65
|
+
this.provider = null;
|
|
66
|
+
}
|
|
61
67
|
}
|
|
62
68
|
}
|
|
63
69
|
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
import Provider from '../Provider';
|
|
9
9
|
import EventType from '../../events/EventType';
|
|
10
10
|
import AskImuOnDesktopError from '../../errors/AskImuOnDesktopError';
|
|
11
|
-
import Availability from '../../events/Availability';
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Imu (Inertial Measurement Unit) provider retrieve acceleration data
|
|
@@ -46,8 +45,8 @@ class ImuProvider extends Provider {
|
|
|
46
45
|
*/
|
|
47
46
|
get _availability() {
|
|
48
47
|
return BrowserUtils.isMobile
|
|
49
|
-
?
|
|
50
|
-
:
|
|
48
|
+
? Promise.resolve()
|
|
49
|
+
: Promise.reject(new AskImuOnDesktopError());
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { PromiseUtils } from '@wemap/utils';
|
|
2
|
+
|
|
1
3
|
import MetaProvider from '../MetaProvider';
|
|
2
4
|
import EventType from '../../events/EventType';
|
|
3
|
-
import Availability from '../../events/Availability';
|
|
4
5
|
import {
|
|
5
6
|
InclinationFromRelativeAttitude, InclinationFromAcc
|
|
6
7
|
} from '../../Providers';
|
|
@@ -24,10 +25,10 @@ class InclinationProvider extends MetaProvider {
|
|
|
24
25
|
* @override
|
|
25
26
|
*/
|
|
26
27
|
get _availability() {
|
|
27
|
-
return
|
|
28
|
+
return PromiseUtils.any([
|
|
28
29
|
InclinationFromAcc.availability,
|
|
29
30
|
InclinationFromRelativeAttitude.availability
|
|
30
|
-
);
|
|
31
|
+
]);
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
MapMatching, Network
|
|
6
6
|
} from '@wemap/graph';
|
|
7
7
|
import { deg2rad } from '@wemap/maths';
|
|
8
|
+
import { PromiseUtils } from '@wemap/utils';
|
|
8
9
|
|
|
9
10
|
import MetaProvider from '../../MetaProvider';
|
|
10
11
|
import EventType from '../../../events/EventType';
|
|
11
12
|
import ProviderEvent from '../../../events/ProviderEvent';
|
|
12
|
-
import Availability from '../../../events/Availability';
|
|
13
13
|
import {
|
|
14
14
|
AbsolutePositionFromRel, GnssWifi
|
|
15
15
|
} from '../../../Providers';
|
|
@@ -52,10 +52,10 @@ class AbsolutePositionProvider extends MetaProvider {
|
|
|
52
52
|
* @override
|
|
53
53
|
*/
|
|
54
54
|
get _availability() {
|
|
55
|
-
return
|
|
55
|
+
return PromiseUtils.any([
|
|
56
56
|
AbsolutePositionFromRel.availability,
|
|
57
57
|
GnssWifi.availability
|
|
58
|
-
);
|
|
58
|
+
]);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
|
|
@@ -63,13 +63,17 @@ class AbsolutePositionProvider extends MetaProvider {
|
|
|
63
63
|
* @override
|
|
64
64
|
*/
|
|
65
65
|
start() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
AbsolutePositionFromRel.availability
|
|
67
|
+
.then(() => {
|
|
68
|
+
this.fromRelPosProviderId = AbsolutePositionFromRel.addEventListener(
|
|
69
|
+
events => this.onAbsolutePositionFromRel(events[0]),
|
|
70
|
+
noop,
|
|
71
|
+
this.name
|
|
72
|
+
);
|
|
73
|
+
})
|
|
74
|
+
.catch(() => {
|
|
75
|
+
// do nothing
|
|
76
|
+
});
|
|
73
77
|
|
|
74
78
|
this.gnssWifiProviderId = GnssWifi.addEventListener(
|
|
75
79
|
events => this.onAbsolutePosition(events[0], false),
|
|
@@ -7,7 +7,6 @@ import GeolocationApiMissingError from '../../../errors/GeolocationApiMissingErr
|
|
|
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';
|
|
11
10
|
import Constants from '../../Constants';
|
|
12
11
|
|
|
13
12
|
const POSITION_OPTIONS = {
|
|
@@ -43,8 +42,8 @@ class GnssWifiProvider extends Provider {
|
|
|
43
42
|
*/
|
|
44
43
|
get _availability() {
|
|
45
44
|
return typeof(navigator) === 'object' && navigator.geolocation
|
|
46
|
-
?
|
|
47
|
-
:
|
|
45
|
+
? Promise.resolve()
|
|
46
|
+
: Promise.reject(new GeolocationApiMissingError());
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
/**
|
|
@@ -9,7 +9,6 @@ import Provider from '../../Provider';
|
|
|
9
9
|
import EventType from '../../../events/EventType';
|
|
10
10
|
import MissingArCoreError from '../../../errors/MissingArCoreError';
|
|
11
11
|
import MissingNativeInterfaceError from '../../../errors/MissingNativeInterfaceError';
|
|
12
|
-
import Availability from '../../../events/Availability';
|
|
13
12
|
import ProviderState from '../../ProviderState';
|
|
14
13
|
|
|
15
14
|
|
|
@@ -164,14 +163,14 @@ class ArCoreProvider extends Provider {
|
|
|
164
163
|
const nativeProvider = this.nativeProvider;
|
|
165
164
|
|
|
166
165
|
if (!nativeProvider.checkAvailability()) {
|
|
167
|
-
return
|
|
166
|
+
return Promise.reject(new MissingArCoreError());
|
|
168
167
|
}
|
|
169
168
|
|
|
170
169
|
} catch (e) {
|
|
171
|
-
return
|
|
170
|
+
return Promise.reject(e);
|
|
172
171
|
}
|
|
173
172
|
|
|
174
|
-
return
|
|
173
|
+
return Promise.resolve();
|
|
175
174
|
}
|
|
176
175
|
|
|
177
176
|
enableBarcodeScanner() {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { PromiseUtils } from '@wemap/utils';
|
|
2
|
+
|
|
1
3
|
import MetaProvider from '../../MetaProvider';
|
|
2
|
-
import Availability from '../../../events/Availability';
|
|
3
4
|
import EventType from '../../../events/EventType';
|
|
4
5
|
import {
|
|
5
6
|
Pdr, GeoRelativePositionFromArCore
|
|
@@ -25,10 +26,10 @@ class GeoRelativePositionProvider extends MetaProvider {
|
|
|
25
26
|
* @override
|
|
26
27
|
*/
|
|
27
28
|
get _availability() {
|
|
28
|
-
return
|
|
29
|
+
return PromiseUtils.any([
|
|
29
30
|
Pdr.availability,
|
|
30
31
|
GeoRelativePositionFromArCore.availability
|
|
31
|
-
);
|
|
32
|
+
]);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
|
|
@@ -37,29 +38,31 @@ class GeoRelativePositionProvider extends MetaProvider {
|
|
|
37
38
|
*/
|
|
38
39
|
start() {
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
this.geoRelativeProvider = GeoRelativePositionFromArCore
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
);
|
|
41
|
+
GeoRelativePositionFromArCore.availability
|
|
42
|
+
.then(() => (this.geoRelativeProvider = GeoRelativePositionFromArCore))
|
|
43
|
+
.catch(() => (this.geoRelativeProvider = Pdr))
|
|
44
|
+
.finally(() => {
|
|
45
|
+
this.providerId = this.geoRelativeProvider.addEventListener(
|
|
46
|
+
events => {
|
|
47
|
+
const event = events.find(_event => _event.dataType === EventType.GeoRelativePosition);
|
|
48
|
+
if (event) {
|
|
49
|
+
this.notify(event.clone());
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
error => this.notifyError(error),
|
|
53
|
+
this.name
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* @override
|
|
60
60
|
*/
|
|
61
61
|
stop() {
|
|
62
|
-
this.geoRelativeProvider
|
|
62
|
+
if (this.geoRelativeProvider) {
|
|
63
|
+
this.geoRelativeProvider.removeEventListener(this.providerId);
|
|
64
|
+
this.geoRelativeProvider = null;
|
|
65
|
+
}
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
|
|
@@ -2,7 +2,6 @@ import { GeoRelativePosition } from '@wemap/geo';
|
|
|
2
2
|
import { deg2rad } from '@wemap/maths';
|
|
3
3
|
|
|
4
4
|
import Provider from '../../Provider';
|
|
5
|
-
import Availability from '../../../events/Availability';
|
|
6
5
|
import EventType from '../../../events/EventType';
|
|
7
6
|
import {
|
|
8
7
|
StepDetection, AbsoluteAttitude
|
|
@@ -32,10 +31,10 @@ class PdrProvider extends Provider {
|
|
|
32
31
|
* @override
|
|
33
32
|
*/
|
|
34
33
|
get _availability() {
|
|
35
|
-
return
|
|
34
|
+
return Promise.all([
|
|
36
35
|
StepDetection.availability,
|
|
37
36
|
AbsoluteAttitude.availability
|
|
38
|
-
);
|
|
37
|
+
]);
|
|
39
38
|
}
|
|
40
39
|
|
|
41
40
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Constants as GeoConstants } from '@wemap/geo';
|
|
2
2
|
import { Quaternion } from '@wemap/maths';
|
|
3
3
|
|
|
4
|
-
import Availability from '../../events/Availability';
|
|
5
4
|
import EventType from '../../events/EventType';
|
|
6
5
|
import Provider from '../Provider';
|
|
7
6
|
import StepDetectionMinMaxPeaks2 from './StepDetectionMinMaxPeaks2';
|
|
@@ -20,11 +19,11 @@ class StepDetectionProvider extends Provider {
|
|
|
20
19
|
* @override
|
|
21
20
|
*/
|
|
22
21
|
get _availability() {
|
|
23
|
-
return
|
|
22
|
+
return Promise.all([
|
|
24
23
|
Accelerometer.availability,
|
|
25
24
|
Gyroscope.availability,
|
|
26
25
|
RelativeAttitudeFromInertial.availability
|
|
27
|
-
);
|
|
26
|
+
]);
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
/**
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
class Availability {
|
|
2
|
-
|
|
3
|
-
isSupported = false;
|
|
4
|
-
reason = null;
|
|
5
|
-
|
|
6
|
-
static no(reason) {
|
|
7
|
-
const availability = new Availability();
|
|
8
|
-
availability.reason = reason;
|
|
9
|
-
availability.isSupported = false;
|
|
10
|
-
return availability;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
static yes() {
|
|
14
|
-
const availability = new Availability();
|
|
15
|
-
availability.isSupported = true;
|
|
16
|
-
return availability;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
static merge(...availabilities) {
|
|
20
|
-
for (let i = 0; i < availabilities.length; i++) {
|
|
21
|
-
const availability = availabilities[i];
|
|
22
|
-
if (!availability.isSupported) {
|
|
23
|
-
return availability;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return Availability.yes();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static union(...availabilities) {
|
|
30
|
-
if (availabilities.length === 0) {
|
|
31
|
-
return Availability.yes();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
for (let i = 0; i < availabilities.length; i++) {
|
|
35
|
-
const availability = availabilities[i];
|
|
36
|
-
if (availability.isSupported) {
|
|
37
|
-
return availability;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return availabilities[0];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export default Availability;
|