@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,100 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import EventType from '../events/EventType';
|
|
4
|
+
import ImuProvider from '../providers/others/ImuProvider';
|
|
5
|
+
import Utils from './Utils';
|
|
6
|
+
|
|
7
|
+
class ImuComponent extends React.Component {
|
|
8
|
+
|
|
9
|
+
constructor(props, context) {
|
|
10
|
+
super(props, context);
|
|
11
|
+
|
|
12
|
+
this.state = {
|
|
13
|
+
acc: null,
|
|
14
|
+
gyr: null
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
this.imuProvider = new ImuProvider(this.onEvent, this.onError, {require: [
|
|
18
|
+
EventType.Acceleration, EventType.AngularRate
|
|
19
|
+
]});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
componentDidMount() {
|
|
23
|
+
this.imuProvider.start();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
componentWillUnmount() {
|
|
27
|
+
this.imuProvider.stop();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
onEvent = events => {
|
|
31
|
+
const newState = {};
|
|
32
|
+
|
|
33
|
+
events.forEach(event => {
|
|
34
|
+
if (event.dataType === EventType.Acceleration) {
|
|
35
|
+
newState.acc = event.data;
|
|
36
|
+
}
|
|
37
|
+
if (event.dataType === EventType.AngularRate) {
|
|
38
|
+
newState.gyr = event.data;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
this.setState(newState);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
onError = events => {
|
|
46
|
+
const newState = {};
|
|
47
|
+
|
|
48
|
+
events.forEach(event => {
|
|
49
|
+
if (event.dataType === EventType.Acceleration) {
|
|
50
|
+
newState.acc = event.error;
|
|
51
|
+
}
|
|
52
|
+
if (event.dataType === EventType.AngularRate) {
|
|
53
|
+
newState.gyr = event.error;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
this.setState(newState);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
render() {
|
|
61
|
+
|
|
62
|
+
let accelerometerString;
|
|
63
|
+
const acc = this.state.acc;
|
|
64
|
+
if (!acc) {
|
|
65
|
+
accelerometerString = 'Waiting';
|
|
66
|
+
} else if (acc instanceof Error) {
|
|
67
|
+
accelerometerString = Utils.renderError(acc);
|
|
68
|
+
} else {
|
|
69
|
+
accelerometerString = '[' + acc[0].toFixed(2)
|
|
70
|
+
+ ', ' + acc[1].toFixed(2)
|
|
71
|
+
+ ', ' + acc[2].toFixed(2)
|
|
72
|
+
+ ']';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let gyroscopeString;
|
|
76
|
+
const gyr = this.state.gyr;
|
|
77
|
+
if (!gyr) {
|
|
78
|
+
gyroscopeString = 'Waiting';
|
|
79
|
+
} else if (gyr instanceof Error) {
|
|
80
|
+
gyroscopeString = Utils.renderError(gyr);
|
|
81
|
+
} else {
|
|
82
|
+
gyroscopeString = '[' + gyr[0].toFixed(2)
|
|
83
|
+
+ ', ' + gyr[1].toFixed(2)
|
|
84
|
+
+ ', ' + gyr[2].toFixed(2)
|
|
85
|
+
+ ']';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<div>
|
|
90
|
+
<h3>Acceleration</h3>
|
|
91
|
+
<p>{accelerometerString}</p>
|
|
92
|
+
<h3>Angular Velocity</h3>
|
|
93
|
+
<p>{gyroscopeString}</p>
|
|
94
|
+
</div>
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default ImuComponent;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import InclinationProvider from '../providers/others/InclinationProvider';
|
|
4
|
+
import EventType from '../events/EventType';
|
|
5
|
+
import Utils from './Utils';
|
|
6
|
+
|
|
7
|
+
class InclinationComponent extends React.Component {
|
|
8
|
+
|
|
9
|
+
constructor(props, context) {
|
|
10
|
+
super(props, context);
|
|
11
|
+
|
|
12
|
+
this.state = { inclination: null };
|
|
13
|
+
|
|
14
|
+
this.inclinationProvider = new InclinationProvider(this.onEvent, this.onError);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
componentDidMount() {
|
|
18
|
+
this.inclinationProvider.start();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
componentWillUnmount() {
|
|
22
|
+
this.inclinationProvider.stop();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
onEvent = events => {
|
|
26
|
+
events.forEach(event => {
|
|
27
|
+
if (event.dataType === EventType.Inclination) {
|
|
28
|
+
this.setState({ inclination: event.data });
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
onError = events => {
|
|
34
|
+
events.forEach(event => {
|
|
35
|
+
if (event.dataType === EventType.Inclination) {
|
|
36
|
+
this.setState({ inclination: event.error });
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
render() {
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div>
|
|
45
|
+
<h3>Inclination</h3>
|
|
46
|
+
<p>{Utils.renderInclination(this.state.inclination)}</p>
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export default InclinationComponent;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import isEmpty from 'lodash.isempty';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Itinerary, WGS84UserPosition
|
|
6
|
+
} from '@wemap/geo';
|
|
7
|
+
|
|
8
|
+
import Utils from './Utils';
|
|
9
|
+
import PdrProvider from '../providers/pose/pdr/PdrProvider';
|
|
10
|
+
import EventType from '../events/EventType';
|
|
11
|
+
|
|
12
|
+
const INITIAL_LOCATION = new WGS84UserPosition(43.6091955, 3.8841255);
|
|
13
|
+
const INITIAL_HEADING = 191.9;
|
|
14
|
+
const ITINERARY = Itinerary.fromPoints([
|
|
15
|
+
[INITIAL_LOCATION.lat, INITIAL_LOCATION.lng],
|
|
16
|
+
[43.6091883, 3.8841242],
|
|
17
|
+
[43.6091709, 3.8842382],
|
|
18
|
+
[43.6091288, 3.884226],
|
|
19
|
+
[43.6091461, 3.884112]
|
|
20
|
+
], false);
|
|
21
|
+
|
|
22
|
+
class PdrComponent extends React.Component {
|
|
23
|
+
|
|
24
|
+
constructor(props, context) {
|
|
25
|
+
super(props, context);
|
|
26
|
+
this.state = { position: null };
|
|
27
|
+
|
|
28
|
+
this.pdrProvider = new PdrProvider(this.onEvent, this.onError);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
componentDidMount() {
|
|
33
|
+
this.pdrProvider.setLocation(INITIAL_LOCATION);
|
|
34
|
+
this.pdrProvider.setHeading(INITIAL_HEADING);
|
|
35
|
+
this.pdrProvider.enableMapMatching(ITINERARY);
|
|
36
|
+
this.pdrProvider.start();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
componentWillUnmount() {
|
|
40
|
+
this.pdrProvider.stop();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
onEvent = events => {
|
|
44
|
+
const newState = {};
|
|
45
|
+
events.forEach(event => {
|
|
46
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
47
|
+
newState.position = event.data;
|
|
48
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
49
|
+
newState.attitude = event.data;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
if (!isEmpty(newState)) {
|
|
53
|
+
this.setState(newState);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
onError = events => {
|
|
58
|
+
const newState = {};
|
|
59
|
+
events.forEach(event => {
|
|
60
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
61
|
+
newState.position = event.error;
|
|
62
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
63
|
+
newState.attitude = event.error;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
if (!isEmpty(newState)) {
|
|
67
|
+
this.setState(newState);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
render() {
|
|
72
|
+
|
|
73
|
+
const attitudeRender = Utils.renderAttitude(this.state.attitude);
|
|
74
|
+
const positionRender = Utils.renderPosition(this.state.position);
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div>
|
|
78
|
+
<h3>Position</h3>
|
|
79
|
+
{positionRender}
|
|
80
|
+
<h3>Attitude</h3>
|
|
81
|
+
{attitudeRender}
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export default PdrComponent;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import isEmpty from 'lodash.isempty';
|
|
3
|
+
|
|
4
|
+
import EventType from '../events/EventType';
|
|
5
|
+
import Utils from './Utils';
|
|
6
|
+
import PoseProvider from '../providers/pose/PoseProvider';
|
|
7
|
+
|
|
8
|
+
class PoseComponent extends React.Component {
|
|
9
|
+
|
|
10
|
+
constructor(props, context) {
|
|
11
|
+
super(props, context);
|
|
12
|
+
this.state = {
|
|
13
|
+
position: null,
|
|
14
|
+
attitude: null
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
this.poseProvider = new PoseProvider(this.onEvent, this.onError);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
componentDidMount() {
|
|
22
|
+
this.poseProvider.start();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
componentWillUnmount() {
|
|
26
|
+
this.poseProvider.stop();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
onEvent = events => {
|
|
30
|
+
const newState = {};
|
|
31
|
+
events.forEach(event => {
|
|
32
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
33
|
+
newState.position = event.data;
|
|
34
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
35
|
+
newState.attitude = event.data;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
if (!isEmpty(newState)) {
|
|
39
|
+
this.setState(newState);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
onError = events => {
|
|
44
|
+
const newState = {};
|
|
45
|
+
events.forEach(event => {
|
|
46
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
47
|
+
newState.position = event.error;
|
|
48
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
49
|
+
newState.attitude = event.error;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
if (!isEmpty(newState)) {
|
|
53
|
+
this.setState(newState);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
render() {
|
|
58
|
+
|
|
59
|
+
const attitudeRender = Utils.renderAttitude(this.state.attitude);
|
|
60
|
+
const positionRender = Utils.renderPosition(this.state.position);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<div>
|
|
64
|
+
<h3>Position</h3>
|
|
65
|
+
{positionRender}
|
|
66
|
+
<h3>Attitude</h3>
|
|
67
|
+
{attitudeRender}
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default PoseComponent;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PositioningPoseComponent from './PositioningPoseComponent';
|
|
3
|
+
import PositioningHandler from '../PositioningHandler';
|
|
4
|
+
import PositioningInclinationComponent from './PositioningInclinationComponent';
|
|
5
|
+
|
|
6
|
+
class PositioningComponent extends React.Component {
|
|
7
|
+
|
|
8
|
+
constructor(props, context) {
|
|
9
|
+
super(props, context);
|
|
10
|
+
this.positioningHandler = new PositioningHandler();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
render() {
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div>
|
|
17
|
+
<h2>Pose</h2>
|
|
18
|
+
<div><PositioningPoseComponent positioningHandler={this.positioningHandler} /></div>
|
|
19
|
+
<h2>Inclination</h2>
|
|
20
|
+
<div><PositioningInclinationComponent positioningHandler={this.positioningHandler} /></div>
|
|
21
|
+
</div>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default PositioningComponent;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import isEmpty from 'lodash.isempty';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
import EventType from '../events/EventType';
|
|
6
|
+
import Utils from './Utils';
|
|
7
|
+
import PositioningHandler from '../PositioningHandler';
|
|
8
|
+
import StartStopComponent from './StartStopComponent';
|
|
9
|
+
|
|
10
|
+
class PositioningInclinationComponent extends React.Component {
|
|
11
|
+
|
|
12
|
+
static propTypes = { positioningHandler: PropTypes.instanceOf(PositioningHandler).isRequired };
|
|
13
|
+
|
|
14
|
+
constructor(props, context) {
|
|
15
|
+
super(props, context);
|
|
16
|
+
this.state = {
|
|
17
|
+
inclination: null,
|
|
18
|
+
errored: false
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
start() {
|
|
24
|
+
this.id = this.props.positioningHandler.start(
|
|
25
|
+
[EventType.Inclination],
|
|
26
|
+
this.onEvents,
|
|
27
|
+
this.onErrors
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
stop() {
|
|
33
|
+
this.props.positioningHandler.stop(this.id);
|
|
34
|
+
this.setState({
|
|
35
|
+
inclination: null,
|
|
36
|
+
errored: false
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
onEvents = (events) => {
|
|
41
|
+
const newState = {};
|
|
42
|
+
events.forEach(event => {
|
|
43
|
+
if (event.dataType === EventType.Inclination) {
|
|
44
|
+
newState.inclination = event.data;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
if (!isEmpty(newState)) {
|
|
48
|
+
this.setState(newState);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
onErrors = events => {
|
|
53
|
+
const newState = { errored: true };
|
|
54
|
+
events.forEach(event => {
|
|
55
|
+
if (event.dataType === EventType.Inclination) {
|
|
56
|
+
newState.inclination = event.error;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
this.setState(newState);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
render() {
|
|
63
|
+
return (
|
|
64
|
+
<div>
|
|
65
|
+
<StartStopComponent
|
|
66
|
+
onStart={() => this.start()}
|
|
67
|
+
onStop={() => this.stop()}
|
|
68
|
+
errored={this.state.errored} />
|
|
69
|
+
|
|
70
|
+
<p>{Utils.renderInclination(this.state.inclination)}</p>
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default PositioningInclinationComponent;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import isEmpty from 'lodash.isempty';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
import EventType from '../events/EventType';
|
|
6
|
+
import Utils from './Utils';
|
|
7
|
+
import PositioningHandler from '../PositioningHandler';
|
|
8
|
+
import StartStopComponent from './StartStopComponent';
|
|
9
|
+
import {
|
|
10
|
+
WGS84UserPosition, Itinerary
|
|
11
|
+
} from '@wemap/geo';
|
|
12
|
+
|
|
13
|
+
const INITIAL_LOCATION = new WGS84UserPosition(43.6091955, 3.8841255);
|
|
14
|
+
const INITIAL_HEADING = 191.9;
|
|
15
|
+
const ITINERARY = Itinerary.fromPoints([
|
|
16
|
+
[INITIAL_LOCATION.lat, INITIAL_LOCATION.lng],
|
|
17
|
+
[43.6091883, 3.8841242],
|
|
18
|
+
[43.6091709, 3.8842382],
|
|
19
|
+
[43.6091288, 3.884226],
|
|
20
|
+
[43.6091461, 3.884112]
|
|
21
|
+
], false);
|
|
22
|
+
|
|
23
|
+
class PositioningPoseComponent extends React.Component {
|
|
24
|
+
|
|
25
|
+
static propTypes = { positioningHandler: PropTypes.instanceOf(PositioningHandler).isRequired };
|
|
26
|
+
|
|
27
|
+
constructor(props, context) {
|
|
28
|
+
super(props, context);
|
|
29
|
+
this.state = {
|
|
30
|
+
position: null,
|
|
31
|
+
attitude: null,
|
|
32
|
+
errored: false
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
start() {
|
|
38
|
+
this.id = this.props.positioningHandler.start(
|
|
39
|
+
[EventType.AbsolutePosition, EventType.AbsoluteAttitude],
|
|
40
|
+
this.onEvents,
|
|
41
|
+
this.onErrors,
|
|
42
|
+
{
|
|
43
|
+
waitInputPosition: true,
|
|
44
|
+
useMapMatching: true
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
this.props.positioningHandler.setPosition(this.id, INITIAL_LOCATION);
|
|
50
|
+
this.props.positioningHandler.setHeading(this.id, INITIAL_HEADING);
|
|
51
|
+
this.props.positioningHandler.setItinerary(this.id, ITINERARY);
|
|
52
|
+
}, 3000);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
stop() {
|
|
57
|
+
this.props.positioningHandler.stop(this.id);
|
|
58
|
+
this.setState({
|
|
59
|
+
position: null,
|
|
60
|
+
attitude: null,
|
|
61
|
+
errored: false
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
onEvents = (events) => {
|
|
66
|
+
const newState = {};
|
|
67
|
+
events.forEach(event => {
|
|
68
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
69
|
+
newState.position = event.data;
|
|
70
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
71
|
+
newState.attitude = event.data;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
if (!isEmpty(newState)) {
|
|
75
|
+
this.setState(newState);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
onErrors = events => {
|
|
80
|
+
const newState = { errored: true };
|
|
81
|
+
events.forEach(event => {
|
|
82
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
83
|
+
newState.position = event.error;
|
|
84
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
85
|
+
newState.attitude = event.error;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
this.setState(newState);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
render() {
|
|
92
|
+
const attitudeRender = Utils.renderAttitude(this.state.attitude);
|
|
93
|
+
const positionRender = Utils.renderPosition(this.state.position);
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<div>
|
|
97
|
+
<StartStopComponent
|
|
98
|
+
onStart={() => this.start()}
|
|
99
|
+
onStop={() => this.stop()}
|
|
100
|
+
errored={this.state.errored} />
|
|
101
|
+
|
|
102
|
+
<h3>Position</h3>
|
|
103
|
+
{positionRender}
|
|
104
|
+
<h3>Attitude</h3>
|
|
105
|
+
{attitudeRender}
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export default PositioningPoseComponent;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import RelativeAttitudeProvider from '../providers/attitude/RelativeAttitudeProvider';
|
|
4
|
+
import Utils from './Utils';
|
|
5
|
+
import EventType from '../events/EventType';
|
|
6
|
+
|
|
7
|
+
class RelativeAttitudeComponent extends React.Component {
|
|
8
|
+
|
|
9
|
+
constructor(props, context) {
|
|
10
|
+
super(props, context);
|
|
11
|
+
|
|
12
|
+
this.state = {
|
|
13
|
+
attitude: null,
|
|
14
|
+
deviceorientation: null
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
this.relativeAttitudeProvider = new RelativeAttitudeProvider(this.onEvent, this.onError);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
componentDidMount() {
|
|
21
|
+
this.relativeAttitudeProvider.start();
|
|
22
|
+
window.addEventListener('deviceorientation', this.onDeviceOrientationEventListener, true);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
componentWillUnmount() {
|
|
26
|
+
this.relativeAttitudeProvider.stop();
|
|
27
|
+
window.removeEventListener('deviceorientation', this.onDeviceOrientationEventListener, true);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
onEvent = events => {
|
|
31
|
+
events.forEach(event => {
|
|
32
|
+
if (event.dataType === EventType.RelativeAttitude) {
|
|
33
|
+
this.setState({ attitude: event.data });
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
onError = events => {
|
|
39
|
+
events.forEach(event => {
|
|
40
|
+
if (event.dataType === EventType.RelativeAttitude) {
|
|
41
|
+
this.setState({ attitude: event.error });
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
onDeviceOrientationEventListener = (e) => this.setState({ deviceorientation: e });
|
|
47
|
+
|
|
48
|
+
setOffset(offset) {
|
|
49
|
+
this.relativeAttitudeProvider.setOffset(offset);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
render() {
|
|
53
|
+
|
|
54
|
+
let rawRender = <span>Not available</span>;
|
|
55
|
+
|
|
56
|
+
if (this.state.deviceorientation) {
|
|
57
|
+
const alpha = this.state.deviceorientation.alpha;
|
|
58
|
+
const beta = this.state.deviceorientation.beta;
|
|
59
|
+
const gamma = this.state.deviceorientation.gamma;
|
|
60
|
+
|
|
61
|
+
if (alpha && beta && gamma) {
|
|
62
|
+
rawRender = <p>alpha: {alpha.toFixed(2)}, <br />
|
|
63
|
+
beta: {beta.toFixed(2)}, <br />
|
|
64
|
+
gamma: {gamma.toFixed(2)}</p>;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const browserRender = Utils.renderAttitude(this.state.attitude);
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<div>
|
|
72
|
+
<h3>Raw:</h3>
|
|
73
|
+
{rawRender}
|
|
74
|
+
<h3>From browser:</h3>
|
|
75
|
+
{browserRender}
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default RelativeAttitudeComponent;
|
|
82
|
+
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
class StartStopComponent extends React.Component {
|
|
5
|
+
|
|
6
|
+
static propTypes = {
|
|
7
|
+
onStart: PropTypes.func.isRequired,
|
|
8
|
+
onStop: PropTypes.func.isRequired,
|
|
9
|
+
errored: PropTypes.bool.isRequired
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
constructor(props, context) {
|
|
13
|
+
super(props, context);
|
|
14
|
+
this.state = { started: false };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
start() {
|
|
18
|
+
this.setState({started: true});
|
|
19
|
+
this.props.onStart();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
componentWillUnmount() {
|
|
23
|
+
stop();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
stop() {
|
|
27
|
+
this.setState({started: false});
|
|
28
|
+
this.props.onStop();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
render() {
|
|
33
|
+
return (
|
|
34
|
+
<div>
|
|
35
|
+
<button onClick={() => this.start()}
|
|
36
|
+
disabled={(this.state.started && !this.props.errored)}>
|
|
37
|
+
Start
|
|
38
|
+
</button>
|
|
39
|
+
<button onClick={() => this.stop()}
|
|
40
|
+
disabled={!(this.state.started && !this.props.errored)}>
|
|
41
|
+
Stop
|
|
42
|
+
</button>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default StartStopComponent;
|