@wemap/positioning 2.0.0 → 2.2.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/arcore.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 +7 -4
- package/src/PositioningHandler.js +96 -34
- package/src/components/AbsoluteAttitudeComponent.jsx +104 -0
- package/src/components/ArCoreComponent.jsx +74 -0
- package/src/components/GnssWifiComponent.jsx +58 -0
- package/src/components/GnssWifiPdrComponent.jsx +94 -0
- package/src/components/ImuComponent.jsx +100 -0
- package/src/components/InclinationComponent.jsx +53 -0
- package/src/components/MapComponent.jsx +226 -0
- package/src/components/PdrComponent.jsx +97 -0
- package/src/components/PoseComponent.jsx +81 -0
- package/src/components/PositioningComponent.jsx +26 -0
- package/src/components/PositioningInclinationComponent.jsx +76 -0
- package/src/components/PositioningPoseComponent.jsx +120 -0
- package/src/components/RelativeAttitudeComponent.jsx +82 -0
- package/src/components/StartStopComponent.jsx +50 -0
- package/src/components/Utils.js +92 -0
- package/src/components/index.js +32 -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/MissingArCoreError.js +9 -0
- package/src/errors/MissingGyroscopeError.js +11 -0
- package/src/errors/MissingMagnetometerError.js +9 -0
- package/src/errors/MissingNativeInterfaceError.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 +230 -0
- package/src/providers/ProviderOptions.js +28 -0
- package/{src.old → src}/providers/ProvidersLogger.js +2 -2
- package/src/providers/attitude/AbsoluteAttitudeProvider.js +207 -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.old/providers/LocationSource.js → src/providers/others/MapMatchingProvider.js} +5 -148
- package/src/providers/pose/ArCoreProvider.js +127 -0
- package/src/providers/pose/GnssWifiPdrProvider.js +233 -0
- package/src/providers/pose/PoseProvider.js +90 -0
- package/{src.old/providers/PdrLocationSource.js → src/providers/pose/pdr/PdrProvider.js} +145 -113
- package/{src.old/providers/pdr → src/providers/pose/pdr/helpers}/Smoother.js +1 -1
- package/src/providers/position/GnssWifiProvider.js +129 -0
- package/src/providers/position/IpProvider.js +75 -0
- package/webpack/webpack.common.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
- package/src.old/Constants.js +0 -11
- package/src.old/NavigationHandler.js +0 -244
- package/src.old/Pose.js +0 -8
- package/src.old/attitude/AttitudeHandler.js +0 -342
- package/src.old/components/AbsoluteAttitude.jsx +0 -136
- package/src.old/components/Imu.jsx +0 -89
- package/src.old/components/LocationSource.jsx +0 -434
- package/src.old/components/Logger.jsx +0 -113
- package/src.old/components/NavigationDebugApp.jsx +0 -106
- package/src.old/components/Others.jsx +0 -121
- package/src.old/components/RelativeAttitude.jsx +0 -104
- package/src.old/components/Utils.js +0 -35
- package/src.old/components/index.js +0 -13
- package/src.old/index.js +0 -7
- package/src.old/providers/FixedLocationImuLocationSource.js +0 -66
- package/src.old/providers/GnssLocationSource.js +0 -118
- package/src.old/providers/GnssPdrLocationSource.js +0 -182
- package/src.old/providers/IPLocationSource.js +0 -96
- package/src.old/sensors/SensorsCompatibility.js +0 -486
- package/src.old/sensors/SensorsCompatibility.spec.js +0 -270
- package/src.old/sensors/SensorsLogger.js +0 -94
- package/src.old/sensors/SensorsLoggerUtils.js +0 -35
- /package/{src.old → src/providers}/attitude/EkfAttitude.js +0 -0
- /package/{src.old → src/providers}/attitude/EkfAttitude.spec.js +0 -0
- /package/{src.old/providers/pdr → src/providers/pose/pdr/helpers}/HeadingUnlocker.js +0 -0
- /package/{src.old/providers/pdr → src/providers/pose/pdr/helpers}/HeadingUnlocker.spec.js +0 -0
- /package/{src.old/providers/pdr → src/providers/pose/pdr/helpers}/Smoother.spec.js +0 -0
- /package/{src.old/providers/pdr → src/providers/pose/pdr/helpers}/ThugDetector.js +0 -0
- /package/{src.old/providers → src/providers/pose/pdr}/steps/StepDetection.js +0 -0
- /package/{src.old/providers → src/providers/pose/pdr}/steps/StepDetectionLadetto.js +0 -0
- /package/{src.old/providers → src/providers/pose/pdr}/steps/StepDetectionMinMaxPeaks.js +0 -0
- /package/{src.old/providers → src/providers/pose/pdr}/steps/StepDetectionMinMaxPeaks2.js +0 -0
|
@@ -0,0 +1,94 @@
|
|
|
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 EventType from '../events/EventType';
|
|
10
|
+
import GnssWifiPdrProvider from '../providers/pose/GnssWifiPdrProvider';
|
|
11
|
+
import MapComponent from './MapComponent';
|
|
12
|
+
|
|
13
|
+
const INITIAL_LOCATION = new WGS84UserPosition(43.6091955, 3.8841255);
|
|
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 GnssWifiPdrComponent extends React.Component {
|
|
23
|
+
|
|
24
|
+
constructor(props, context) {
|
|
25
|
+
super(props, context);
|
|
26
|
+
this.state = { position: null };
|
|
27
|
+
|
|
28
|
+
this.gnssWifiPdrProvider = new GnssWifiPdrProvider(this.onEvent, this.onError);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
componentDidMount() {
|
|
33
|
+
this.gnssWifiPdrProvider.enableMapMatching(ITINERARY);
|
|
34
|
+
this.gnssWifiPdrProvider.start();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
componentWillUnmount() {
|
|
38
|
+
this.gnssWifiPdrProvider.stop();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
onEvent = events => {
|
|
42
|
+
const newState = {};
|
|
43
|
+
events.forEach(event => {
|
|
44
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
45
|
+
newState.position = event.data;
|
|
46
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
47
|
+
newState.attitude = event.data;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
if (!isEmpty(newState)) {
|
|
51
|
+
this.setState(newState);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (this.map) {
|
|
55
|
+
this.map.parseEvents(events);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
onError = events => {
|
|
60
|
+
const newState = {};
|
|
61
|
+
events.forEach(event => {
|
|
62
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
63
|
+
newState.position = event.error;
|
|
64
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
65
|
+
newState.attitude = event.error;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
if (!isEmpty(newState)) {
|
|
69
|
+
this.setState(newState);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
render() {
|
|
74
|
+
|
|
75
|
+
const attitudeRender = Utils.renderAttitude(this.state.attitude);
|
|
76
|
+
const positionRender = Utils.renderPosition(this.state.position);
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div>
|
|
80
|
+
<h3>Position</h3>
|
|
81
|
+
{positionRender}
|
|
82
|
+
<h3>Attitude</h3>
|
|
83
|
+
{attitudeRender}
|
|
84
|
+
<h3>Map</h3>
|
|
85
|
+
<MapComponent
|
|
86
|
+
ref={map => (this.map = map)}
|
|
87
|
+
network={ITINERARY} />
|
|
88
|
+
</div>
|
|
89
|
+
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export default GnssWifiPdrComponent;
|
|
@@ -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,226 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import mapboxgl from 'mapbox-gl';
|
|
3
|
+
import 'mapbox-gl/dist/mapbox-gl.css';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
WGS84, Attitude, Network
|
|
8
|
+
} from '@wemap/geo';
|
|
9
|
+
import EventType from '../events/EventType';
|
|
10
|
+
|
|
11
|
+
mapboxgl.accessToken = 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4M29iazA2Z2gycXA4N2pmbDZmangifQ.-g_vE53SD2WrJ6tFX7QHmA';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const COMPASS_STYLE = {
|
|
15
|
+
'width': '15px',
|
|
16
|
+
'height': '15px',
|
|
17
|
+
'border-radius': '50%',
|
|
18
|
+
'z-index': '10000001',
|
|
19
|
+
'position': 'absolute',
|
|
20
|
+
'top': '-14px',
|
|
21
|
+
'left': '-14px',
|
|
22
|
+
'border': '7px solid',
|
|
23
|
+
'border-color': 'transparent',
|
|
24
|
+
'border-top-color': '#008DF1',
|
|
25
|
+
'opacity': 0.5
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const LOCATION_STYLE = {
|
|
29
|
+
'width': '15px',
|
|
30
|
+
'height': '15px',
|
|
31
|
+
'top': '-7px',
|
|
32
|
+
'left': '-7px',
|
|
33
|
+
'position': 'absolute',
|
|
34
|
+
'border-radius': '50%',
|
|
35
|
+
'background': '#008DF1'
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class MapComponent extends React.Component {
|
|
40
|
+
|
|
41
|
+
static propTypes = { network: PropTypes.instanceOf(Network) };
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
componentDidMount() {
|
|
45
|
+
this.map = new mapboxgl.Map({
|
|
46
|
+
container: this.mapContainer,
|
|
47
|
+
style: 'mapbox://styles/mapbox/streets-v9'
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
componentWillUnmount() {
|
|
52
|
+
this.map.remove();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
createMarker(options) {
|
|
56
|
+
var elem, marker;
|
|
57
|
+
|
|
58
|
+
elem = document.createElement('div');
|
|
59
|
+
elem.style.marginLeft = '-' + options.iconAnchor[0] + 'px';
|
|
60
|
+
elem.style.marginTop = '-' + options.iconAnchor[1] + 'px';
|
|
61
|
+
elem.style.width = 0;
|
|
62
|
+
elem.style.height = 0;
|
|
63
|
+
elem.appendChild(options.dom);
|
|
64
|
+
|
|
65
|
+
marker = new mapboxgl.Marker(elem);
|
|
66
|
+
marker.setLngLat([options.longitude, options.latitude]);
|
|
67
|
+
return marker;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
createLocationMarker(location) {
|
|
71
|
+
const coreIcon = document.createElement('div');
|
|
72
|
+
this.applyStyleToDomElement(coreIcon, LOCATION_STYLE);
|
|
73
|
+
|
|
74
|
+
this.locationIcon = document.createElement('div');
|
|
75
|
+
this.locationIcon.appendChild(coreIcon);
|
|
76
|
+
|
|
77
|
+
return this.createMarker({
|
|
78
|
+
dom: this.locationIcon,
|
|
79
|
+
iconAnchor: [0, 0],
|
|
80
|
+
latitude: location[1],
|
|
81
|
+
longitude: location[0]
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
createCompassElement() {
|
|
86
|
+
if (!this.locationIcon) {
|
|
87
|
+
throw new Error('createLocationMarker() should be called before');
|
|
88
|
+
}
|
|
89
|
+
this.compassIcon = document.createElement('div');
|
|
90
|
+
this.applyStyleToDomElement(this.compassIcon, COMPASS_STYLE);
|
|
91
|
+
this.locationIcon.appendChild(this.compassIcon);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
applyStyleToDomElement(domElement, style) {
|
|
95
|
+
for (const key in style) {
|
|
96
|
+
if (style.hasOwnProperty(key)) {
|
|
97
|
+
domElement.style[key] = style[key];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
parseEvents(events) {
|
|
103
|
+
if (!this.map) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
events.forEach(event => {
|
|
107
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
108
|
+
this.updatePosition(event.data);
|
|
109
|
+
|
|
110
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
111
|
+
this.updateAttitude(event.data);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
updatePosition(position) {
|
|
117
|
+
|
|
118
|
+
if (!this.map) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (!(position instanceof WGS84)) {
|
|
123
|
+
if (this.mapMarker) {
|
|
124
|
+
this.mapMarker.remove();
|
|
125
|
+
this.mapMarker = null;
|
|
126
|
+
this.locationIcon = null;
|
|
127
|
+
}
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const lngLat = [position.lng, position.lat];
|
|
132
|
+
|
|
133
|
+
if (!this.mapMarker) {
|
|
134
|
+
this.mapMarker = this.createLocationMarker(lngLat)
|
|
135
|
+
.addTo(this.map);
|
|
136
|
+
this.map.jumpTo({
|
|
137
|
+
center: lngLat,
|
|
138
|
+
zoom: 19
|
|
139
|
+
});
|
|
140
|
+
} else {
|
|
141
|
+
this.mapMarker.setLngLat(lngLat);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
updateAttitude(attitude) {
|
|
147
|
+
|
|
148
|
+
if (!this.locationIcon) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (!(attitude instanceof Attitude)) {
|
|
153
|
+
if (this.compassIcon) {
|
|
154
|
+
this.locationIcon.removeChild(this.compassIcon);
|
|
155
|
+
}
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (!this.compassIcon) {
|
|
160
|
+
this.createCompassElement();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this.locationIcon.style.transform = 'rotate(' + attitude.headingDegrees + 'deg)';
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
renderNetwork() {
|
|
167
|
+
|
|
168
|
+
if (!this.map) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const network = this.props.network;
|
|
173
|
+
|
|
174
|
+
if (!network) {
|
|
175
|
+
if (this.networkLayer) {
|
|
176
|
+
this.map.removeLayer(this.networkLayer);
|
|
177
|
+
this.networkLayer = null;
|
|
178
|
+
}
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const layer = {
|
|
183
|
+
id: 'network',
|
|
184
|
+
type: 'line',
|
|
185
|
+
source: {
|
|
186
|
+
type: 'geojson',
|
|
187
|
+
data: {
|
|
188
|
+
type: 'Feature',
|
|
189
|
+
properties: {},
|
|
190
|
+
geometry: {
|
|
191
|
+
type: 'MultiLineString',
|
|
192
|
+
coordinates: []
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
paint: {
|
|
197
|
+
'line-color': '#0000FF',
|
|
198
|
+
'line-width': 3
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
for (let i = 0; i < network.length; i++) {
|
|
203
|
+
layer.source.data.geometry.coordinates.push(
|
|
204
|
+
[
|
|
205
|
+
[network.edges[i].node1.lng, network.edges[i].node1.lat],
|
|
206
|
+
[network.edges[i].node2.lng, network.edges[i].node2.lat]
|
|
207
|
+
]
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
this.map.on('load', () => {
|
|
211
|
+
this.networkLayer = this.map.addLayer(layer);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
render() {
|
|
216
|
+
this.renderNetwork();
|
|
217
|
+
return (
|
|
218
|
+
<div
|
|
219
|
+
ref={map => (this.mapContainer = map)}
|
|
220
|
+
style={{ height: '300px' }} />
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
export default MapComponent;
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
import MapComponent from './MapComponent';
|
|
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 PdrComponent extends React.Component {
|
|
24
|
+
|
|
25
|
+
constructor(props, context) {
|
|
26
|
+
super(props, context);
|
|
27
|
+
this.state = { position: null };
|
|
28
|
+
|
|
29
|
+
this.pdrProvider = new PdrProvider(this.onEvent, this.onError);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
componentDidMount() {
|
|
34
|
+
this.pdrProvider.setLocation(INITIAL_LOCATION);
|
|
35
|
+
this.pdrProvider.setHeading(INITIAL_HEADING);
|
|
36
|
+
this.pdrProvider.enableMapMatching(ITINERARY);
|
|
37
|
+
this.pdrProvider.start();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
componentWillUnmount() {
|
|
41
|
+
this.pdrProvider.stop();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
onEvent = events => {
|
|
45
|
+
const newState = {};
|
|
46
|
+
events.forEach(event => {
|
|
47
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
48
|
+
newState.position = event.data;
|
|
49
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
50
|
+
newState.attitude = event.data;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
if (!isEmpty(newState)) {
|
|
54
|
+
this.setState(newState);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (this.map) {
|
|
58
|
+
this.map.parseEvents(events);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
onError = events => {
|
|
63
|
+
const newState = {};
|
|
64
|
+
events.forEach(event => {
|
|
65
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
66
|
+
newState.position = event.error;
|
|
67
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
68
|
+
newState.attitude = event.error;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
if (!isEmpty(newState)) {
|
|
72
|
+
this.setState(newState);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
render() {
|
|
77
|
+
|
|
78
|
+
const attitudeRender = Utils.renderAttitude(this.state.attitude);
|
|
79
|
+
const positionRender = Utils.renderPosition(this.state.position);
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<div>
|
|
83
|
+
<h3>Position</h3>
|
|
84
|
+
{positionRender}
|
|
85
|
+
<h3>Attitude</h3>
|
|
86
|
+
{attitudeRender}
|
|
87
|
+
<h3>Map</h3>
|
|
88
|
+
<MapComponent
|
|
89
|
+
ref={map => (this.map = map)}
|
|
90
|
+
network={ITINERARY} />
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export default PdrComponent;
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
import MapComponent from './MapComponent';
|
|
8
|
+
|
|
9
|
+
class PoseComponent extends React.Component {
|
|
10
|
+
|
|
11
|
+
constructor(props, context) {
|
|
12
|
+
super(props, context);
|
|
13
|
+
this.state = {
|
|
14
|
+
position: null,
|
|
15
|
+
attitude: null
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
this.poseProvider = new PoseProvider(this.onEvent, this.onError);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
componentDidMount() {
|
|
23
|
+
this.poseProvider.start();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
componentWillUnmount() {
|
|
27
|
+
this.poseProvider.stop();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
onEvent = events => {
|
|
31
|
+
const newState = {};
|
|
32
|
+
events.forEach(event => {
|
|
33
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
34
|
+
newState.position = event.data;
|
|
35
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
36
|
+
newState.attitude = event.data;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
if (!isEmpty(newState)) {
|
|
40
|
+
this.setState(newState);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (this.map) {
|
|
44
|
+
this.map.parseEvents(events);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
onError = events => {
|
|
49
|
+
const newState = {};
|
|
50
|
+
events.forEach(event => {
|
|
51
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
52
|
+
newState.position = event.error;
|
|
53
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
54
|
+
newState.attitude = event.error;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
if (!isEmpty(newState)) {
|
|
58
|
+
this.setState(newState);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
render() {
|
|
63
|
+
|
|
64
|
+
const attitudeRender = Utils.renderAttitude(this.state.attitude);
|
|
65
|
+
const positionRender = Utils.renderPosition(this.state.position);
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div>
|
|
69
|
+
<h3>Position</h3>
|
|
70
|
+
{positionRender}
|
|
71
|
+
<h3>Attitude</h3>
|
|
72
|
+
{attitudeRender}
|
|
73
|
+
<h3>Map</h3>
|
|
74
|
+
<MapComponent ref={map => (this.map = map)} />
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
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;
|