@wemap/positioning 2.0.0 → 2.1.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.
- package/.eslintrc.json +4 -2
- package/debug/absolute-attitude.html +16 -0
- package/debug/gnss-wifi-pdr.html +16 -0
- package/debug/gnss-wifi.html +16 -0
- package/debug/imu.html +16 -0
- package/debug/inclination.html +16 -0
- package/debug/pdr.html +16 -0
- package/debug/pose.html +16 -0
- package/debug/positioning.html +16 -0
- package/debug/relative-attitude.html +16 -0
- package/package.json +6 -4
- package/src/PositioningHandler.js +96 -34
- package/src/components/AbsoluteAttitudeComponent.jsx +104 -0
- package/src/components/GnssWifiComponent.jsx +46 -0
- package/src/components/GnssWifiPdrComponent.jsx +85 -0
- package/src/components/ImuComponent.jsx +100 -0
- package/src/components/InclinationComponent.jsx +53 -0
- package/src/components/PdrComponent.jsx +88 -0
- package/src/components/PoseComponent.jsx +74 -0
- package/src/components/PositioningComponent.jsx +26 -0
- package/src/components/PositioningInclinationComponent.jsx +76 -0
- package/src/components/PositioningPoseComponent.jsx +111 -0
- package/src/components/RelativeAttitudeComponent.jsx +82 -0
- package/src/components/StartStopComponent.jsx +50 -0
- package/src/components/Utils.js +74 -0
- package/src/components/index.js +30 -0
- package/src/errors/AskImuOnDesktopError.js +9 -0
- package/src/errors/GeolocationApiMissingError.js +9 -0
- package/src/errors/GeolocationPermissionDeniedError.js +9 -0
- package/src/errors/GeolocationPositionUnavailableError.js +9 -0
- package/src/errors/IpResolveServerError.js +9 -0
- package/src/errors/MissingAccelerometerError.js +11 -0
- package/src/errors/MissingGyroscopeError.js +11 -0
- package/src/errors/MissingMagnetometerError.js +9 -0
- package/src/errors/MissingSensorError.js +14 -0
- package/src/events/EventType.js +20 -0
- package/src/events/ProviderError.js +52 -0
- package/src/events/ProviderEvent.js +35 -0
- package/src/index.js +2 -2
- package/src/providers/Constants.js +5 -0
- package/src/providers/FakeAbsolutePositionProvider.js +56 -0
- package/src/providers/Provider.js +218 -0
- package/src/providers/ProviderOptions.js +28 -0
- package/src/providers/ProvidersLogger.js +77 -0
- package/src/providers/attitude/AbsoluteAttitudeProvider.js +207 -0
- package/src/providers/attitude/EkfAttitude.js +238 -0
- package/src/providers/attitude/EkfAttitude.spec.js +116 -0
- package/src/providers/attitude/RelativeAttitudeProvider.js +129 -0
- package/src/providers/others/ImuProvider.js +186 -0
- package/src/providers/others/InclinationProvider.js +107 -0
- package/src/providers/others/MapMatchingProvider.js +147 -0
- package/src/providers/pose/GnssWifiPdrProvider.js +233 -0
- package/src/providers/pose/PoseProvider.js +90 -0
- package/src/providers/pose/pdr/PdrProvider.js +352 -0
- package/src/providers/pose/pdr/helpers/HeadingUnlocker.js +41 -0
- package/src/providers/pose/pdr/helpers/HeadingUnlocker.spec.js +26 -0
- package/src/providers/pose/pdr/helpers/Smoother.js +90 -0
- package/src/providers/pose/pdr/helpers/Smoother.spec.js +424 -0
- package/src/providers/pose/pdr/helpers/ThugDetector.js +37 -0
- package/src/providers/pose/pdr/steps/StepDetection.js +7 -0
- package/src/providers/pose/pdr/steps/StepDetectionLadetto.js +67 -0
- package/src/providers/pose/pdr/steps/StepDetectionMinMaxPeaks.js +80 -0
- package/src/providers/pose/pdr/steps/StepDetectionMinMaxPeaks2.js +108 -0
- package/src/providers/position/GnssWifiProvider.js +129 -0
- package/src/providers/position/IpProvider.js +75 -0
- package/src.old/providers/GnssPdrLocationSource.js +1 -1
- package/webpack/webpack.dev.js +1 -1
- package/debug/index.html +0 -15
- package/debug/index.old.html +0 -37
- package/scripts/release-github.js +0 -216
- package/src/providers/FakeLocationSource.js +0 -36
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React from 'react'; // eslint-disable-line no-unused-vars
|
|
2
|
+
import { rad2deg } from '@wemap/maths';
|
|
3
|
+
|
|
4
|
+
const NOT_AVAILABLE_STR = 'Not available';
|
|
5
|
+
|
|
6
|
+
class Utils {
|
|
7
|
+
|
|
8
|
+
static renderAttitude(attitude) {
|
|
9
|
+
|
|
10
|
+
if (!attitude) {
|
|
11
|
+
return <p>Waiting</p>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (attitude instanceof Error) {
|
|
15
|
+
return Utils.renderError(attitude);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const quaternion = attitude.quaternion;
|
|
19
|
+
|
|
20
|
+
const w = quaternion[0].toFixed(3);
|
|
21
|
+
const x = quaternion[1].toFixed(3);
|
|
22
|
+
const y = quaternion[2].toFixed(3);
|
|
23
|
+
const z = quaternion[3].toFixed(3);
|
|
24
|
+
|
|
25
|
+
const euler = attitude.eulerAnglesDegrees;
|
|
26
|
+
const yaw = euler[0].toFixed(2);
|
|
27
|
+
const pitch = euler[1].toFixed(2);
|
|
28
|
+
const roll = euler[2].toFixed(2);
|
|
29
|
+
const heading = attitude.headingDegrees.toFixed(2);
|
|
30
|
+
|
|
31
|
+
return <p>Quaternion: [{w}, {x}, {y}, {z}]<br />
|
|
32
|
+
Eulers: [{yaw}, {pitch}, {roll}]<br />
|
|
33
|
+
Heading: {heading}</p>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static renderPosition(position) {
|
|
37
|
+
|
|
38
|
+
if (!position) {
|
|
39
|
+
return <p>Waiting</p>;
|
|
40
|
+
}
|
|
41
|
+
if (position instanceof Error) {
|
|
42
|
+
return Utils.renderError(position);
|
|
43
|
+
}
|
|
44
|
+
return (
|
|
45
|
+
<p>
|
|
46
|
+
Latitude: {position.lat.toFixed(7)}<br />
|
|
47
|
+
Longitude: {position.lng.toFixed(7)}<br />
|
|
48
|
+
Altitude: {position.alt ? position.alt.toFixed(2) : NOT_AVAILABLE_STR}<br />
|
|
49
|
+
Bearing: {position.bearing ? position.bearing.toFixed(2) : NOT_AVAILABLE_STR}<br />
|
|
50
|
+
Accuracy: {position.accuracy ? position.accuracy.toFixed(2) : NOT_AVAILABLE_STR}<br />
|
|
51
|
+
Time: {position.time ? position.time.toFixed(2) : NOT_AVAILABLE_STR}<br />
|
|
52
|
+
Provider: {position.provider ? position.provider : NOT_AVAILABLE_STR}
|
|
53
|
+
</p>
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static renderInclination(inclination) {
|
|
59
|
+
if (inclination === null) {
|
|
60
|
+
return 'Waiting';
|
|
61
|
+
}
|
|
62
|
+
if (inclination instanceof Error) {
|
|
63
|
+
return Utils.renderError(inclination);
|
|
64
|
+
}
|
|
65
|
+
return rad2deg(inclination).toFixed(2);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static renderError(error) {
|
|
69
|
+
return (<span><strong>[{error.constructor.name}]</strong> {error.message}</span>);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default Utils;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
|
|
4
|
+
import AbsoluteAttitudeComponent from './AbsoluteAttitudeComponent';
|
|
5
|
+
import GnssWifiComponent from './GnssWifiComponent';
|
|
6
|
+
import GnssWifiPdrComponent from './GnssWifiPdrComponent';
|
|
7
|
+
import ImuComponent from './ImuComponent';
|
|
8
|
+
import InclinationComponent from './InclinationComponent';
|
|
9
|
+
import PdrComponent from './PdrComponent';
|
|
10
|
+
import PoseComponent from './PoseComponent';
|
|
11
|
+
import PositioningComponent from './PositioningComponent';
|
|
12
|
+
import RelativeAttitudeComponent from './RelativeAttitudeComponent';
|
|
13
|
+
|
|
14
|
+
const createReactElement = (component, container) => ReactDOM.render(
|
|
15
|
+
React.createElement(component, {}, null),
|
|
16
|
+
container
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
AbsoluteAttitudeComponent,
|
|
21
|
+
ImuComponent,
|
|
22
|
+
InclinationComponent,
|
|
23
|
+
GnssWifiComponent,
|
|
24
|
+
GnssWifiPdrComponent,
|
|
25
|
+
PdrComponent,
|
|
26
|
+
PoseComponent,
|
|
27
|
+
PositioningComponent,
|
|
28
|
+
RelativeAttitudeComponent,
|
|
29
|
+
createReactElement
|
|
30
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const DEFAULT_MESSAGE = 'Impossible to retrieve Acceleration data';
|
|
2
|
+
|
|
3
|
+
import MissingSensorError from './MissingSensorError';
|
|
4
|
+
|
|
5
|
+
class MissingAccelerometerError extends MissingSensorError {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message || DEFAULT_MESSAGE);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default MissingAccelerometerError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const DEFAULT_MESSAGE = 'Impossible to retrieve Angular Rate data';
|
|
2
|
+
|
|
3
|
+
import MissingSensorError from './MissingSensorError';
|
|
4
|
+
|
|
5
|
+
class MissingGyroscopeError extends MissingSensorError {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message || DEFAULT_MESSAGE);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default MissingGyroscopeError;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const DEFAULT_MESSAGE = 'Impossible to retrieve events, a sensor is missing';
|
|
2
|
+
|
|
3
|
+
class MissingSensorError extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message || DEFAULT_MESSAGE);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
from(fromMessage) {
|
|
9
|
+
this.message += ' from ' + fromMessage;
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default MissingSensorError;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event data types handled by {@link ProviderEvent}
|
|
3
|
+
*/
|
|
4
|
+
export default {
|
|
5
|
+
Unknown: 'UNKNOWN',
|
|
6
|
+
MagneticField: 'MAGNETIC_FIELD',
|
|
7
|
+
AngularRate: 'ANGULAR_RATE',
|
|
8
|
+
Acceleration: 'ACCELERATION',
|
|
9
|
+
Inclination: 'INCLINATION',
|
|
10
|
+
RelativeAttitude: 'RELATIVE_ATTITUDE',
|
|
11
|
+
AbsoluteAttitude: 'ABSOLUTE_ATTITUDE',
|
|
12
|
+
RelativePosition: 'RELATIVE_POSITION',
|
|
13
|
+
AbsolutePosition: 'ABSOLUTE_POSITION',
|
|
14
|
+
Pressure: 'PRESSURE',
|
|
15
|
+
BluetoothSignals: 'BLUETOOTH_SIGNALS',
|
|
16
|
+
WifiSignals: 'WIFI_SIGNALS',
|
|
17
|
+
ScanId: 'SCAN_ID',
|
|
18
|
+
Itinerary: 'ITINERARY',
|
|
19
|
+
Network: 'NETWORK'
|
|
20
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import EventType from './EventType';
|
|
2
|
+
import ProviderEvent from './ProviderEvent';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A provider error is an error event which is triggered by device sensors
|
|
6
|
+
* in case of problem
|
|
7
|
+
*/
|
|
8
|
+
class ProviderError extends ProviderEvent {
|
|
9
|
+
|
|
10
|
+
error = null;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create a Provider Error with the minimum information
|
|
14
|
+
* @param {String} providerName the provider name
|
|
15
|
+
* @param {EventType} dataType the type of event
|
|
16
|
+
* @param {Error} error the event error
|
|
17
|
+
*/
|
|
18
|
+
constructor(providerName, dataType, error) {
|
|
19
|
+
super(providerName, dataType, null);
|
|
20
|
+
this.error = error;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
clone() {
|
|
24
|
+
const evt = new ProviderError(this.providerName, this.dataType, this.error);
|
|
25
|
+
evt.timestamp = this.timestamp;
|
|
26
|
+
evt.isFromNative = this.isFromNative;
|
|
27
|
+
return evt;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Remove the same error in array
|
|
32
|
+
* @param {ProviderError[]} errorsArray
|
|
33
|
+
*/
|
|
34
|
+
static removeArrayDuplicates(errorsArray) {
|
|
35
|
+
return errorsArray.reduce((acc, current) => {
|
|
36
|
+
const found = acc.find(item => typeof item.error === typeof current.error && item.dataType === current.dataType);
|
|
37
|
+
return !found ? acc.concat([current]) : acc;
|
|
38
|
+
}, []);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static modifyArrayDataType(errorsArray, newDataType) {
|
|
42
|
+
const output = [];
|
|
43
|
+
errorsArray.forEach(error => {
|
|
44
|
+
const newError = error.clone();
|
|
45
|
+
newError.dataType = newDataType;
|
|
46
|
+
output.push(newError);
|
|
47
|
+
});
|
|
48
|
+
return ProviderError.removeArrayDuplicates(output);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default ProviderError;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import EventType from './EventType';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A provider event is an event which can be triggered by device sensors
|
|
5
|
+
* or can be computed from raw providers.
|
|
6
|
+
*/
|
|
7
|
+
class ProviderEvent {
|
|
8
|
+
|
|
9
|
+
timestamp = -1;
|
|
10
|
+
dataType = EventType.Unknown;
|
|
11
|
+
providerName = '';
|
|
12
|
+
isFromNative = false;
|
|
13
|
+
data = null;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Create a Provider Event with the minimum information
|
|
17
|
+
* @param {String} providerName the provider name
|
|
18
|
+
* @param {EventType} dataType the type of event
|
|
19
|
+
* @param {Object} data the event data
|
|
20
|
+
*/
|
|
21
|
+
constructor(providerName, dataType, data) {
|
|
22
|
+
this.providerName = providerName;
|
|
23
|
+
this.dataType = dataType;
|
|
24
|
+
this.data = data;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
clone() {
|
|
28
|
+
const evt = new ProviderEvent(this.providerName, this.dataType, this.data);
|
|
29
|
+
evt.timestamp = this.timestamp;
|
|
30
|
+
evt.isFromNative = this.isFromNative;
|
|
31
|
+
return evt;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default ProviderEvent;
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import InclinationProvider from './providers/computed/InclinationProvider';
|
|
1
2
|
import PositioningHandler from './PositioningHandler';
|
|
2
|
-
import AttitudeHandler from '../src.old/attitude/AttitudeHandler';
|
|
3
3
|
|
|
4
4
|
export {
|
|
5
|
-
|
|
5
|
+
InclinationProvider, PositioningHandler
|
|
6
6
|
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WGS84, Attitude
|
|
3
|
+
} from '@wemap/geo';
|
|
4
|
+
import Provider from './Provider';
|
|
5
|
+
import EventType from '../events/EventType';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
class FakeAbsolutePositionProvider extends Provider {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @override
|
|
15
|
+
*/
|
|
16
|
+
static get displayName() {
|
|
17
|
+
return 'FakeAbsolutePosition';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @override
|
|
22
|
+
*/
|
|
23
|
+
static get eventsType() {
|
|
24
|
+
return [EventType.AbsoluteAttitude, EventType.AbsolutePosition];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @override
|
|
29
|
+
*/
|
|
30
|
+
startInternal() {
|
|
31
|
+
|
|
32
|
+
this.interval = setInterval(() => {
|
|
33
|
+
this.notify(
|
|
34
|
+
this.createEvent(EventType.AbsoluteAttitude, new Attitude([1, 0, 0, 0])),
|
|
35
|
+
this.createEvent(EventType.AbsolutePosition, new WGS84(45, 5))
|
|
36
|
+
);
|
|
37
|
+
}, 1000);
|
|
38
|
+
|
|
39
|
+
return Promise.resolve();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @override
|
|
44
|
+
*/
|
|
45
|
+
stopInternal() {
|
|
46
|
+
|
|
47
|
+
if (this.interval) {
|
|
48
|
+
clearInterval(this.interval);
|
|
49
|
+
this.interval = null;
|
|
50
|
+
}
|
|
51
|
+
return Promise.resolve();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default FakeAbsolutePositionProvider;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import noop from 'lodash.noop';
|
|
2
|
+
|
|
3
|
+
import EventType from '../events/EventType';
|
|
4
|
+
import ProviderEvent from '../events/ProviderEvent';
|
|
5
|
+
import Logger from '@wemap/logger';
|
|
6
|
+
import ProviderError from '../events/ProviderError';
|
|
7
|
+
import ProvidersLogger from './ProvidersLogger';
|
|
8
|
+
|
|
9
|
+
let uniqueId = 1;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A provider is a meta class to define an entity which can be
|
|
13
|
+
* started / stopped and provides a data of {@link ProviderEvent#DataType}
|
|
14
|
+
*/
|
|
15
|
+
class Provider {
|
|
16
|
+
|
|
17
|
+
static DEFAULT_NAME = 'Unknown';
|
|
18
|
+
static DEFAULT_OPTIONS = {
|
|
19
|
+
stopOnError: true,
|
|
20
|
+
checkAvailabilityOnStart: true
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
static State = {
|
|
24
|
+
STARTING: 0,
|
|
25
|
+
STARTED: 1,
|
|
26
|
+
STOPPPED: 2
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
static Warnings = {
|
|
30
|
+
ALREADY_STARTED: 'Provider already started',
|
|
31
|
+
ALREADY_STOPPED: 'Provider already stopped'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
state = Provider.State.STOPPPED;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Provider constructor
|
|
38
|
+
* @param {Function} onEvent a callback which will receive events
|
|
39
|
+
* @param {Function} onError a callback when an error happen
|
|
40
|
+
* @param {Object} options provider options
|
|
41
|
+
*/
|
|
42
|
+
constructor(onEvent, onError, options) {
|
|
43
|
+
this.onEvent = onEvent || noop;
|
|
44
|
+
this.onError = onError || noop;
|
|
45
|
+
this.options = Object.assign(this.constructor.DEFAULT_OPTIONS, options);
|
|
46
|
+
this.id = uniqueId++;
|
|
47
|
+
ProvidersLogger.addEvent(this, 'constructor');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get the provider name
|
|
52
|
+
* @public
|
|
53
|
+
* @abstract
|
|
54
|
+
*/
|
|
55
|
+
static get displayName() {
|
|
56
|
+
return this.constructor.DEFAULT_NAME;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get the list of events type which can be returned by the provider
|
|
61
|
+
* @returns {EventType[]} the list of events type
|
|
62
|
+
* @public
|
|
63
|
+
* @abstract
|
|
64
|
+
*/
|
|
65
|
+
static get eventsType() {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @override
|
|
71
|
+
*/
|
|
72
|
+
static checkAvailabilityErrors() {
|
|
73
|
+
return this.requiredProviders.reduce(
|
|
74
|
+
(acc, val) => acc.concat(val.checkAvailabilityErrors()), []
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Return the list of required providers
|
|
80
|
+
*/
|
|
81
|
+
static get requiredProviders() {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Start the Provider
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
start() {
|
|
90
|
+
if (this.state === Provider.State.STARTING
|
|
91
|
+
|| this.state === Provider.State.STARTED) {
|
|
92
|
+
Logger.warn(Provider.Warnings.ALREADY_STARTED);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.state = Provider.State.STARTING;
|
|
96
|
+
|
|
97
|
+
if (this.options.checkAvailabilityOnStart) {
|
|
98
|
+
const availabilityErrors = this.constructor.checkAvailabilityErrors();
|
|
99
|
+
if (availabilityErrors.length !== 0) {
|
|
100
|
+
this.notifyError(...availabilityErrors);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
ProvidersLogger.addEvent(this, 'start');
|
|
106
|
+
this.startInternal();
|
|
107
|
+
this.state = Provider.State.STARTED;
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @abstract
|
|
113
|
+
*/
|
|
114
|
+
startInternal() {
|
|
115
|
+
throw new Error('Provider "' + this.constructor.name
|
|
116
|
+
+ '" does not @override startInternal()');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Stop the Provider
|
|
121
|
+
* @public
|
|
122
|
+
*/
|
|
123
|
+
stop() {
|
|
124
|
+
|
|
125
|
+
if (this.state === Provider.State.STOPPPED) {
|
|
126
|
+
Logger.warn(Provider.Warnings.ALREADY_STOPPED);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
ProvidersLogger.addEvent(this, 'stop');
|
|
131
|
+
this.stopInternal();
|
|
132
|
+
this.state = Provider.State.STOPPPED;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @abstract
|
|
137
|
+
*/
|
|
138
|
+
stopInternal() {
|
|
139
|
+
throw new Error('Provider "' + this.constructor.name
|
|
140
|
+
+ '" does not @override stopInternal()');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Notify the subscriber defined in {@link constructor}
|
|
146
|
+
* @param {ProviderEvent[]} events events to send to subscriber
|
|
147
|
+
*/
|
|
148
|
+
notify(...events) {
|
|
149
|
+
ProvidersLogger.incrementNotifications(this);
|
|
150
|
+
this.onEvent(events);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Notify the subscriber defined in {@link constructor}
|
|
155
|
+
* @param {ProviderError[]} errors The error raised
|
|
156
|
+
*/
|
|
157
|
+
notifyError(...errors) {
|
|
158
|
+
this.onError(errors);
|
|
159
|
+
if (this.options.stopOnError && this.state === Provider.State.STARTED) {
|
|
160
|
+
this.stop();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Create an event from current provider
|
|
166
|
+
* @param {ProviderEvent#DataType} dataType type of ProviderEvent
|
|
167
|
+
* @param {Object} data data exported to ProviderEvent
|
|
168
|
+
* @param {Number} timestamp event timestamp
|
|
169
|
+
* @protected
|
|
170
|
+
*/
|
|
171
|
+
static createEvent(dataType, data, timestamp) {
|
|
172
|
+
const event = new ProviderEvent(this.constructor.name, dataType, data);
|
|
173
|
+
if (timestamp) {
|
|
174
|
+
event.timestamp = timestamp;
|
|
175
|
+
}
|
|
176
|
+
return event;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Create an event from current provider
|
|
181
|
+
* @param {EventType} dataType type of ProviderEvent
|
|
182
|
+
* @param {Object} data data exported to ProviderEvent
|
|
183
|
+
* @param {Number} timestamp event timestamp
|
|
184
|
+
* @protected
|
|
185
|
+
*/
|
|
186
|
+
createEvent(dataType, data, timestamp) {
|
|
187
|
+
return this.constructor.createEvent(dataType, data, timestamp);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Create an event error from current provider
|
|
192
|
+
* @param {EventType} dataType type of ProviderError
|
|
193
|
+
* @param {ProviderError} error error raised by the problem exported to ProviderError
|
|
194
|
+
* @param {Number} timestamp event timestamp
|
|
195
|
+
* @protected
|
|
196
|
+
*/
|
|
197
|
+
static createError(dataType, error, timestamp) {
|
|
198
|
+
const event = new ProviderError(this.name, dataType, error);
|
|
199
|
+
if (timestamp) {
|
|
200
|
+
event.timestamp = timestamp;
|
|
201
|
+
}
|
|
202
|
+
return event;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Create an event error from current provider
|
|
207
|
+
* @param {EventType} dataType type of ProviderError
|
|
208
|
+
* @param {ProviderError} error error raised by the problem exported to ProviderError
|
|
209
|
+
* @param {Number} timestamp event timestamp
|
|
210
|
+
* @protected
|
|
211
|
+
*/
|
|
212
|
+
createError(dataType, error, timestamp) {
|
|
213
|
+
return this.constructor.createError(dataType, error, timestamp);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export default Provider;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const ProviderOptions = {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Does provider have to wait an input position to start
|
|
5
|
+
* @see PositioningHandler#setLocation()
|
|
6
|
+
*/
|
|
7
|
+
waitInputPosition: false,
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Does provider have to wait an input heading to start
|
|
11
|
+
* @see PositioningHandler#setHeading()
|
|
12
|
+
*/
|
|
13
|
+
waitInputHeading: false,
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Does provider will use map to
|
|
17
|
+
* @see PositioningHandler#setItinerary()
|
|
18
|
+
*/
|
|
19
|
+
useMapMatching: false,
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Providers listed here will not be used by PositioningHandler
|
|
23
|
+
* List of {@link Provider}
|
|
24
|
+
*/
|
|
25
|
+
ignoreProviders: []
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default ProviderOptions;
|