@wemap/positioning 2.3.11 → 2.4.1
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/package.json +5 -6
- package/src/components/AbsoluteAttitudeComponent.jsx +1 -4
- package/src/components/ArCoreAbsoluteComponent.jsx +52 -63
- package/src/components/GnssWifiPdrComponent.jsx +46 -61
- package/src/components/MapComponent.jsx +5 -4
- package/src/components/PdrComponent.jsx +44 -63
- package/src/components/PositioningInclinationComponent.jsx +9 -3
- package/src/components/PositioningPoseComponent.jsx +97 -106
- package/src/components/Utils.js +53 -0
- package/src/providers/others/MapMatchingProvider.js +7 -66
- package/src/providers/pose/GnssWifiPdrProvider.js +3 -3
- package/src/providers/pose/pdr/PdrProvider.js +6 -5
package/package.json
CHANGED
|
@@ -8,13 +8,12 @@
|
|
|
8
8
|
"Guillaume Pannetier <guillaume.pannetier@getwemap.com>"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@wemap/geo": "^0.1
|
|
12
|
-
"@wemap/logger": "^0.1.
|
|
13
|
-
"@wemap/maths": "^0.1
|
|
11
|
+
"@wemap/geo": "^0.3.1",
|
|
12
|
+
"@wemap/logger": "^0.1.5",
|
|
13
|
+
"@wemap/maths": "^0.2.1",
|
|
14
|
+
"@wemap/osm": "^0.2.1",
|
|
14
15
|
"@wemap/utils": "^0.1.2",
|
|
15
|
-
"file-saver": "^2.0.2",
|
|
16
16
|
"geomagnetism": "^0.1.0",
|
|
17
|
-
"jszip": "^3.2.2",
|
|
18
17
|
"lodash.isempty": "^4.4.0",
|
|
19
18
|
"lodash.isnumber": "^3.0.3",
|
|
20
19
|
"lodash.noop": "^3.0.1"
|
|
@@ -81,5 +80,5 @@
|
|
|
81
80
|
"lint": "eslint --ext .js,.jsx --quiet src",
|
|
82
81
|
"test": "mocha -r esm \"src/**/*.spec.js\""
|
|
83
82
|
},
|
|
84
|
-
"version": "2.
|
|
83
|
+
"version": "2.4.1"
|
|
85
84
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { WGS84 } from '@wemap/geo';
|
|
4
|
-
|
|
5
3
|
import AbsoluteAttitudeProvider from '../providers/attitude/AbsoluteAttitudeProvider';
|
|
6
4
|
import Utils from './Utils';
|
|
7
5
|
import EventType from '../events/EventType';
|
|
8
6
|
|
|
9
|
-
const userPosition = new WGS84(43.609275, 3.884236);
|
|
10
7
|
|
|
11
8
|
class AbsoluteAttitudeComponent extends React.Component {
|
|
12
9
|
|
|
@@ -20,7 +17,7 @@ class AbsoluteAttitudeComponent extends React.Component {
|
|
|
20
17
|
};
|
|
21
18
|
|
|
22
19
|
this.absoluteAttitudeProvider = new AbsoluteAttitudeProvider(this.onEvent, this.onError);
|
|
23
|
-
this.absoluteAttitudeProvider.setPosition(
|
|
20
|
+
this.absoluteAttitudeProvider.setPosition(Utils.INITIAL_POSITION);
|
|
24
21
|
}
|
|
25
22
|
|
|
26
23
|
componentDidMount() {
|
|
@@ -1,27 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import isEmpty from 'lodash.isempty';
|
|
3
3
|
|
|
4
|
+
import { deg2rad } from '@wemap/maths';
|
|
5
|
+
|
|
4
6
|
import EventType from '../events/EventType';
|
|
5
7
|
import Utils from './Utils';
|
|
6
8
|
import ArCoreAbsoluteProvider from '../providers/pose/ArCoreAbsoluteProvider';
|
|
7
|
-
import { deg2rad } from '@wemap/maths';
|
|
8
|
-
import {
|
|
9
|
-
WGS84UserPosition, Itinerary
|
|
10
|
-
} from '@wemap/geo';
|
|
11
9
|
import MapComponent from './MapComponent';
|
|
12
10
|
|
|
13
|
-
const INITIAL_POSITION = new WGS84UserPosition(43.6091955, 3.8841255);
|
|
14
|
-
const INITIAL_HEADING = 191.9;
|
|
15
|
-
const ITINERARY = Itinerary.fromPoints([
|
|
16
|
-
[INITIAL_POSITION.lat, INITIAL_POSITION.lng],
|
|
17
|
-
[43.6091883, 3.8841242],
|
|
18
|
-
[43.6091709, 3.8842382],
|
|
19
|
-
[43.6091288, 3.884226],
|
|
20
|
-
[43.6091461, 3.884112]
|
|
21
|
-
], false);
|
|
22
11
|
|
|
23
12
|
class ArCoreAbsoluteComponent extends React.Component {
|
|
24
|
-
|
|
25
13
|
constructor(props, context) {
|
|
26
14
|
super(props, context);
|
|
27
15
|
this.state = {
|
|
@@ -29,10 +17,12 @@ class ArCoreAbsoluteComponent extends React.Component {
|
|
|
29
17
|
attitude: null
|
|
30
18
|
};
|
|
31
19
|
|
|
32
|
-
this.arCoreAbsoluteProvider = new ArCoreAbsoluteProvider(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
this.arCoreAbsoluteProvider = new ArCoreAbsoluteProvider(
|
|
21
|
+
this.onEvent,
|
|
22
|
+
this.onError
|
|
23
|
+
);
|
|
24
|
+
this.arCoreAbsoluteProvider.setPosition(Utils.INITIAL_POSITION);
|
|
25
|
+
this.arCoreAbsoluteProvider.setHeading(deg2rad(Utils.INITIAL_HEADING));
|
|
36
26
|
}
|
|
37
27
|
|
|
38
28
|
componentDidMount() {
|
|
@@ -43,51 +33,50 @@ class ArCoreAbsoluteComponent extends React.Component {
|
|
|
43
33
|
this.arCoreAbsoluteProvider.stop();
|
|
44
34
|
}
|
|
45
35
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
36
|
+
onEvent = events => {
|
|
37
|
+
const newState = {};
|
|
38
|
+
events.forEach(event => {
|
|
39
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
40
|
+
newState.position = event.data;
|
|
41
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
42
|
+
newState.attitude = event.data;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
if (!isEmpty(newState)) {
|
|
46
|
+
this.setState(newState);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (this.map) {
|
|
50
|
+
this.map.parseEvents(events);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
onError = error => {
|
|
55
|
+
this.setState({
|
|
56
|
+
position: error,
|
|
57
|
+
attitude: error
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
render() {
|
|
62
|
+
const attitudeRender = Utils.renderAttitude(this.state.attitude);
|
|
63
|
+
const positionRender = Utils.renderPosition(this.state.position);
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div>
|
|
67
|
+
<h3>Position</h3>
|
|
68
|
+
{positionRender}
|
|
69
|
+
<h3>Attitude</h3>
|
|
70
|
+
{attitudeRender}
|
|
71
|
+
<h3>Map</h3>
|
|
72
|
+
<MapComponent
|
|
73
|
+
ref={map => (this.map = map)}
|
|
74
|
+
defaultZoom={21}
|
|
75
|
+
network={Utils.ITINERARY}
|
|
76
|
+
/>
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
91
80
|
}
|
|
92
81
|
|
|
93
82
|
export default ArCoreAbsoluteComponent;
|
|
@@ -1,36 +1,24 @@
|
|
|
1
1
|
import isEmpty from 'lodash.isempty';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
Itinerary, WGS84UserPosition
|
|
6
|
-
} from '@wemap/geo';
|
|
7
|
-
|
|
8
4
|
import Utils from './Utils';
|
|
9
5
|
import EventType from '../events/EventType';
|
|
10
6
|
import GnssWifiPdrProvider from '../providers/pose/GnssWifiPdrProvider';
|
|
11
7
|
import MapComponent from './MapComponent';
|
|
12
8
|
|
|
13
|
-
const INITIAL_POSITION = new WGS84UserPosition(43.6091955, 3.8841255);
|
|
14
|
-
const ITINERARY = Itinerary.fromPoints([
|
|
15
|
-
[INITIAL_POSITION.lat, INITIAL_POSITION.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
9
|
class GnssWifiPdrComponent extends React.Component {
|
|
23
|
-
|
|
24
10
|
constructor(props, context) {
|
|
25
11
|
super(props, context);
|
|
26
12
|
this.state = { position: null };
|
|
27
13
|
|
|
28
|
-
this.gnssWifiPdrProvider = new GnssWifiPdrProvider(
|
|
14
|
+
this.gnssWifiPdrProvider = new GnssWifiPdrProvider(
|
|
15
|
+
this.onEvent,
|
|
16
|
+
this.onError
|
|
17
|
+
);
|
|
29
18
|
}
|
|
30
19
|
|
|
31
|
-
|
|
32
20
|
componentDidMount() {
|
|
33
|
-
this.gnssWifiPdrProvider.enableMapMatching(ITINERARY);
|
|
21
|
+
this.gnssWifiPdrProvider.enableMapMatching(Utils.ITINERARY);
|
|
34
22
|
this.gnssWifiPdrProvider.start();
|
|
35
23
|
}
|
|
36
24
|
|
|
@@ -38,50 +26,47 @@ class GnssWifiPdrComponent extends React.Component {
|
|
|
38
26
|
this.gnssWifiPdrProvider.stop();
|
|
39
27
|
}
|
|
40
28
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
);
|
|
84
|
-
}
|
|
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
|
+
if (this.map) {
|
|
43
|
+
this.map.parseEvents(events);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
onError = error => {
|
|
48
|
+
this.setState({
|
|
49
|
+
position: error,
|
|
50
|
+
attitude: error
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
render() {
|
|
55
|
+
const attitudeRender = Utils.renderAttitude(this.state.attitude);
|
|
56
|
+
const positionRender = Utils.renderPosition(this.state.position);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div>
|
|
60
|
+
<h3>Position</h3>
|
|
61
|
+
{positionRender}
|
|
62
|
+
<h3>Attitude</h3>
|
|
63
|
+
{attitudeRender}
|
|
64
|
+
<h3>Map</h3>
|
|
65
|
+
<MapComponent ref={map => (this.map = map)}
|
|
66
|
+
network={Utils.ITINERARY} />
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
85
70
|
}
|
|
86
71
|
|
|
87
72
|
export default GnssWifiPdrComponent;
|
|
@@ -4,8 +4,9 @@ import 'mapbox-gl/dist/mapbox-gl.css';
|
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
|
|
7
|
+
Attitude, Network, WGS84
|
|
8
8
|
} from '@wemap/geo';
|
|
9
|
+
|
|
9
10
|
import EventType from '../events/EventType';
|
|
10
11
|
|
|
11
12
|
mapboxgl.accessToken = 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4M29iazA2Z2gycXA4N2pmbDZmangifQ.-g_vE53SD2WrJ6tFX7QHmA';
|
|
@@ -209,11 +210,11 @@ class MapComponent extends React.Component {
|
|
|
209
210
|
}
|
|
210
211
|
};
|
|
211
212
|
|
|
212
|
-
for (let i = 0; i < network.length; i++) {
|
|
213
|
+
for (let i = 0; i < network.edges.length; i++) {
|
|
213
214
|
layer.source.data.geometry.coordinates.push(
|
|
214
215
|
[
|
|
215
|
-
[network.edges[i].node1.lng, network.edges[i].node1.lat],
|
|
216
|
-
[network.edges[i].node2.lng, network.edges[i].node2.lat]
|
|
216
|
+
[network.edges[i].node1.coords.lng, network.edges[i].node1.coords.lat],
|
|
217
|
+
[network.edges[i].node2.coords.lng, network.edges[i].node2.coords.lat]
|
|
217
218
|
]
|
|
218
219
|
);
|
|
219
220
|
}
|
|
@@ -1,39 +1,23 @@
|
|
|
1
1
|
import isEmpty from 'lodash.isempty';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
Itinerary, WGS84UserPosition
|
|
6
|
-
} from '@wemap/geo';
|
|
7
|
-
|
|
8
4
|
import Utils from './Utils';
|
|
9
5
|
import PdrProvider from '../providers/pose/pdr/PdrProvider';
|
|
10
6
|
import EventType from '../events/EventType';
|
|
11
7
|
import MapComponent from './MapComponent';
|
|
12
8
|
|
|
13
|
-
const INITIAL_POSITION = new WGS84UserPosition(43.6091955, 3.8841255);
|
|
14
|
-
const INITIAL_HEADING = 191.9;
|
|
15
|
-
const ITINERARY = Itinerary.fromPoints([
|
|
16
|
-
[INITIAL_POSITION.lat, INITIAL_POSITION.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
9
|
class PdrComponent extends React.Component {
|
|
24
|
-
|
|
25
10
|
constructor(props, context) {
|
|
26
11
|
super(props, context);
|
|
27
12
|
this.state = { position: null };
|
|
28
13
|
|
|
29
14
|
this.pdrProvider = new PdrProvider(this.onEvent, this.onError);
|
|
30
|
-
this.pdrProvider.enableMapMatching(ITINERARY);
|
|
15
|
+
this.pdrProvider.enableMapMatching(Utils.ITINERARY);
|
|
31
16
|
}
|
|
32
17
|
|
|
33
|
-
|
|
34
18
|
componentDidMount() {
|
|
35
|
-
this.pdrProvider.setPosition(INITIAL_POSITION);
|
|
36
|
-
this.pdrProvider.setHeading(INITIAL_HEADING);
|
|
19
|
+
this.pdrProvider.setPosition(Utils.INITIAL_POSITION);
|
|
20
|
+
this.pdrProvider.setHeading(Utils.INITIAL_HEADING);
|
|
37
21
|
this.pdrProvider.start();
|
|
38
22
|
}
|
|
39
23
|
|
|
@@ -41,50 +25,47 @@ class PdrComponent extends React.Component {
|
|
|
41
25
|
this.pdrProvider.stop();
|
|
42
26
|
}
|
|
43
27
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
);
|
|
87
|
-
}
|
|
28
|
+
onEvent = events => {
|
|
29
|
+
const newState = {};
|
|
30
|
+
events.forEach(event => {
|
|
31
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
32
|
+
newState.position = event.data;
|
|
33
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
34
|
+
newState.attitude = event.data;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (!isEmpty(newState)) {
|
|
38
|
+
this.setState(newState);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (this.map) {
|
|
42
|
+
this.map.parseEvents(events);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
onError = error => {
|
|
47
|
+
this.setState({
|
|
48
|
+
position: error,
|
|
49
|
+
attitude: error
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
render() {
|
|
54
|
+
const attitudeRender = Utils.renderAttitude(this.state.attitude);
|
|
55
|
+
const positionRender = Utils.renderPosition(this.state.position);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div>
|
|
59
|
+
<h3>Position</h3>
|
|
60
|
+
{positionRender}
|
|
61
|
+
<h3>Attitude</h3>
|
|
62
|
+
{attitudeRender}
|
|
63
|
+
<h3>Map</h3>
|
|
64
|
+
<MapComponent ref={map => (this.map = map)}
|
|
65
|
+
network={Utils.ITINERARY} />
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
88
69
|
}
|
|
89
70
|
|
|
90
71
|
export default PdrComponent;
|
|
@@ -21,11 +21,17 @@ class PositioningInclinationComponent extends React.Component {
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
start() {
|
|
24
|
-
|
|
24
|
+
const output = this.props.positioningHandler.start(
|
|
25
25
|
[EventType.Inclination],
|
|
26
26
|
this.onEvents,
|
|
27
27
|
this.onError
|
|
28
|
-
)
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
if (!output) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
this.id = output.id;
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
|
|
@@ -51,7 +57,7 @@ class PositioningInclinationComponent extends React.Component {
|
|
|
51
57
|
|
|
52
58
|
onError = error => {
|
|
53
59
|
this.setState({
|
|
54
|
-
|
|
60
|
+
errored: true,
|
|
55
61
|
inclination: error
|
|
56
62
|
});
|
|
57
63
|
}
|
|
@@ -6,116 +6,107 @@ import EventType from '../events/EventType';
|
|
|
6
6
|
import Utils from './Utils';
|
|
7
7
|
import PositioningHandler from '../PositioningHandler';
|
|
8
8
|
import StartStopComponent from './StartStopComponent';
|
|
9
|
-
import {
|
|
10
|
-
WGS84UserPosition, Itinerary
|
|
11
|
-
} from '@wemap/geo';
|
|
12
9
|
import MapComponent from './MapComponent';
|
|
13
10
|
|
|
14
|
-
const INITIAL_POSITION = new WGS84UserPosition(43.6091955, 3.8841255);
|
|
15
|
-
const INITIAL_HEADING = 191.9;
|
|
16
|
-
const ITINERARY = Itinerary.fromPoints([
|
|
17
|
-
[INITIAL_POSITION.lat, INITIAL_POSITION.lng],
|
|
18
|
-
[43.6091883, 3.8841242],
|
|
19
|
-
[43.6091709, 3.8842382],
|
|
20
|
-
[43.6091288, 3.884226],
|
|
21
|
-
[43.6091461, 3.884112]
|
|
22
|
-
], false);
|
|
23
11
|
|
|
24
12
|
class PositioningPoseComponent extends React.Component {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
13
|
+
static propTypes = {positioningHandler: PropTypes.instanceOf(PositioningHandler).isRequired};
|
|
14
|
+
|
|
15
|
+
constructor(props, context) {
|
|
16
|
+
super(props, context);
|
|
17
|
+
this.state = {
|
|
18
|
+
position: null,
|
|
19
|
+
attitude: null,
|
|
20
|
+
errored: false
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
start() {
|
|
25
|
+
const output = this.props.positioningHandler.start(
|
|
26
|
+
[EventType.AbsolutePosition, EventType.AbsoluteAttitude],
|
|
27
|
+
this.onEvents,
|
|
28
|
+
this.onError,
|
|
29
|
+
{
|
|
30
|
+
waitInputPosition: true,
|
|
31
|
+
useMapMatching: true
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if (!output) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this.id = output.id;
|
|
40
|
+
|
|
41
|
+
this.props.positioningHandler.setItinerary(this.id, Utils.ITINERARY);
|
|
42
|
+
this.props.positioningHandler.setNetwork(this.id, Utils.ITINERARY);
|
|
43
|
+
this.props.positioningHandler.setPosition(this.id, Utils.INITIAL_POSITION);
|
|
44
|
+
this.props.positioningHandler.setHeading(this.id, Utils.INITIAL_HEADING);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
stop() {
|
|
48
|
+
this.props.positioningHandler.stop(this.id);
|
|
49
|
+
this.setState({
|
|
50
|
+
position: null,
|
|
51
|
+
attitude: null,
|
|
52
|
+
errored: false
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
onEvents = events => {
|
|
57
|
+
const newState = {};
|
|
58
|
+
events.forEach(event => {
|
|
59
|
+
if (event.dataType === EventType.AbsolutePosition) {
|
|
60
|
+
newState.position = event.data;
|
|
61
|
+
} else if (event.dataType === EventType.AbsoluteAttitude) {
|
|
62
|
+
newState.attitude = event.data;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
if (!isEmpty(newState)) {
|
|
66
|
+
this.setState(newState);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (this.map) {
|
|
70
|
+
this.map.parseEvents(events);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
onError = error => {
|
|
75
|
+
this.setState({
|
|
76
|
+
position: error,
|
|
77
|
+
attitude: error,
|
|
78
|
+
errored: true
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
render() {
|
|
83
|
+
const attitudeRender = Utils.renderAttitude(this.state.attitude);
|
|
84
|
+
const positionRender = Utils.renderPosition(this.state.position);
|
|
85
|
+
|
|
86
|
+
const itineraryRender = Utils.renderItineraryInfo(
|
|
87
|
+
this.state.position ? Utils.ITINERARY.getInfo(this.state.position) : null
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<div>
|
|
92
|
+
<StartStopComponent
|
|
93
|
+
onStart={() => this.start()}
|
|
94
|
+
onStop={() => this.stop()}
|
|
95
|
+
errored={this.state.errored}
|
|
96
|
+
/>
|
|
97
|
+
|
|
98
|
+
<h3>Position</h3>
|
|
99
|
+
{positionRender}
|
|
100
|
+
<h3>Attitude</h3>
|
|
101
|
+
{attitudeRender}
|
|
102
|
+
<h3>Map</h3>
|
|
103
|
+
<MapComponent ref={map => (this.map = map)}
|
|
104
|
+
network={Utils.ITINERARY} />
|
|
105
|
+
<h3>ItineraryInfo</h3>
|
|
106
|
+
{itineraryRender}
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
119
110
|
}
|
|
120
111
|
|
|
121
112
|
export default PositioningPoseComponent;
|
package/src/components/Utils.js
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
import React from 'react'; // eslint-disable-line no-unused-vars
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Itinerary, WGS84UserPosition
|
|
5
|
+
} from '@wemap/geo';
|
|
2
6
|
import { rad2deg } from '@wemap/maths';
|
|
7
|
+
import { OsrmUtils } from '@wemap/osm';
|
|
3
8
|
|
|
4
9
|
const NOT_AVAILABLE_STR = 'Not available';
|
|
5
10
|
|
|
6
11
|
class Utils {
|
|
7
12
|
|
|
13
|
+
static INITIAL_POSITION = new WGS84UserPosition(43.6091955, 3.8841255);
|
|
14
|
+
static INITIAL_HEADING = 191.9;
|
|
15
|
+
static ITINERARY = Itinerary.fromOrderedPointsArray(
|
|
16
|
+
[
|
|
17
|
+
[Utils.INITIAL_POSITION.lat, Utils.INITIAL_POSITION.lng],
|
|
18
|
+
[43.6091883, 3.8841242],
|
|
19
|
+
[43.6091709, 3.8842382],
|
|
20
|
+
[43.6091288, 3.884226],
|
|
21
|
+
[43.6091461, 3.884112]
|
|
22
|
+
],
|
|
23
|
+
[Utils.INITIAL_POSITION.lat, Utils.INITIAL_POSITION.lng],
|
|
24
|
+
[43.6091461, 3.884112],
|
|
25
|
+
false
|
|
26
|
+
);
|
|
27
|
+
|
|
8
28
|
static renderAttitude(attitude) {
|
|
9
29
|
|
|
10
30
|
if (!attitude) {
|
|
@@ -73,6 +93,38 @@ class Utils {
|
|
|
73
93
|
|
|
74
94
|
}
|
|
75
95
|
|
|
96
|
+
static renderItineraryInfo(info) {
|
|
97
|
+
|
|
98
|
+
if (!info) {
|
|
99
|
+
return <p>Waiting</p>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const step = info.nextStep;
|
|
103
|
+
let nextStepStr = '[' + step.number + '] ';
|
|
104
|
+
if (step.firstStep) {
|
|
105
|
+
nextStepStr += 'Depart';
|
|
106
|
+
} else if (step.lastStep) {
|
|
107
|
+
nextStepStr += 'Arrive';
|
|
108
|
+
} else {
|
|
109
|
+
nextStepStr += 'Turn '
|
|
110
|
+
+ OsrmUtils.getModifierFromAngle(step.angle);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<p>
|
|
116
|
+
projection: {info.projection.nearestElement.constructor.name}<br />
|
|
117
|
+
distanceOfProjection: {info.projection.distanceFromNearestElement.toFixed(1)}m<br />
|
|
118
|
+
traveledDistance: {info.traveledDistance.toFixed(1)}m
|
|
119
|
+
({(info.traveledPercentage * 100).toFixed(1)}%)<br />
|
|
120
|
+
remainingDistance: {info.remainingDistance.toFixed(1)}m
|
|
121
|
+
({(info.remainingPercentage * 100).toFixed(1)}%)<br />
|
|
122
|
+
nextStep: {nextStepStr}
|
|
123
|
+
</p>
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
76
128
|
static renderInclination(inclination) {
|
|
77
129
|
if (inclination === null) {
|
|
78
130
|
return 'Waiting';
|
|
@@ -87,6 +139,7 @@ class Utils {
|
|
|
87
139
|
return (<span><strong>[{error.constructor.name}]</strong> {error.message}</span>);
|
|
88
140
|
}
|
|
89
141
|
|
|
142
|
+
|
|
90
143
|
}
|
|
91
144
|
|
|
92
145
|
export default Utils;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Provider from '../Provider';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
Itinerary, MapMatching, Network, WGS84
|
|
4
4
|
} from '@wemap/geo';
|
|
5
5
|
|
|
6
6
|
class MapMatchingProvider extends Provider {
|
|
@@ -46,29 +46,6 @@ class MapMatchingProvider extends Provider {
|
|
|
46
46
|
return this.mapMatching !== null;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
/**
|
|
50
|
-
* Returns projection of a position on network
|
|
51
|
-
* @param {WGS84} position if position is null, projection of this.position is used
|
|
52
|
-
* @returns The projected position {WGS84} or null.
|
|
53
|
-
* @public
|
|
54
|
-
*/
|
|
55
|
-
getProjectionOnNetwork(position = null) {
|
|
56
|
-
|
|
57
|
-
if (!this.mapMatching) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
let positionToProject = position;
|
|
62
|
-
if (!position) {
|
|
63
|
-
positionToProject = this.position;
|
|
64
|
-
}
|
|
65
|
-
if (!positionToProject) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return this.mapMatching.getProjection(positionToProject, false, false);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
49
|
|
|
73
50
|
/**
|
|
74
51
|
* Itinerary
|
|
@@ -87,60 +64,24 @@ class MapMatchingProvider extends Provider {
|
|
|
87
64
|
this.itinerary = itinerary;
|
|
88
65
|
}
|
|
89
66
|
|
|
90
|
-
|
|
91
67
|
/**
|
|
92
68
|
* Returns projection and itinerary info of a position on network
|
|
93
|
-
* @param {WGS84} position if position is null, projection of this.position is used
|
|
69
|
+
* @param {WGS84} position if position is null/undefined, projection of this.position is used
|
|
94
70
|
* @returns An object of the projected position and itinerary info or null.
|
|
95
71
|
* @public
|
|
96
72
|
*/
|
|
97
|
-
getItineraryInfo(position
|
|
73
|
+
getItineraryInfo(position) {
|
|
98
74
|
|
|
99
75
|
if (!this.itinerary) {
|
|
100
76
|
throw new Error('No itinerary found');
|
|
101
77
|
}
|
|
102
|
-
const projection = this.getProjectionOnNetwork(position);
|
|
103
|
-
if (!projection) {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const totalDistance = this.itinerary.distance;
|
|
108
|
-
let traveledDistance = 0;
|
|
109
|
-
const edges = this.itinerary.edges;
|
|
110
78
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const edge = edges[i];
|
|
115
|
-
if (edge.node1.equalsTo(projection.nearestElement)) {
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
traveledDistance += edge.getLength();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
} else if (projection.nearestElement instanceof Edge) {
|
|
123
|
-
|
|
124
|
-
for (let i = 0; i < edges.length; i++) {
|
|
125
|
-
const edge = edges[i];
|
|
126
|
-
if (edge.equalsTo(projection.nearestElement)) {
|
|
127
|
-
traveledDistance += edge.node1.distanceTo(projection.projection);
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
traveledDistance += edge.getLength();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
} else {
|
|
134
|
-
throw new Error('No projection found');
|
|
79
|
+
const _position = position || this.position;
|
|
80
|
+
if (!_position) {
|
|
81
|
+
return null;
|
|
135
82
|
}
|
|
136
83
|
|
|
137
|
-
return
|
|
138
|
-
projection: projection,
|
|
139
|
-
traveledDistance,
|
|
140
|
-
traveledPercentage: traveledDistance / totalDistance,
|
|
141
|
-
remainingDistance: totalDistance - traveledDistance,
|
|
142
|
-
remainingPercentage: 1 - traveledDistance / totalDistance
|
|
143
|
-
};
|
|
84
|
+
return this.itinerary.getInfo(position || this.position);
|
|
144
85
|
}
|
|
145
86
|
}
|
|
146
87
|
|
|
@@ -117,7 +117,7 @@ class GnssWifiPdrProvider extends MapMatchingProvider {
|
|
|
117
117
|
} else {
|
|
118
118
|
|
|
119
119
|
this.gnssPosition.bearing = this.attitude.headingDegrees;
|
|
120
|
-
const projection = this.mapMatching.getProjection(this.gnssPosition);
|
|
120
|
+
const projection = this.mapMatching.getProjection(this.gnssPosition, true, true);
|
|
121
121
|
|
|
122
122
|
if (projection && projection.projection) {
|
|
123
123
|
|
|
@@ -193,7 +193,7 @@ class GnssWifiPdrProvider extends MapMatchingProvider {
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
let startEdge;
|
|
196
|
-
if (itinerary.firstEdge.
|
|
196
|
+
if (itinerary.firstEdge.length <= MM_GNSS_DIST) {
|
|
197
197
|
startEdge = itinerary.firstEdge;
|
|
198
198
|
} else {
|
|
199
199
|
startEdge = itinerary.secondEdge;
|
|
@@ -201,7 +201,7 @@ class GnssWifiPdrProvider extends MapMatchingProvider {
|
|
|
201
201
|
const startPoint = WGS84UserPosition.fromWGS84(startEdge.node1);
|
|
202
202
|
startPoint.alt = Constants.DEFAULT_ALTITUDE;
|
|
203
203
|
this.pdrProvider.setPosition(startPoint);
|
|
204
|
-
this.pdrProvider.setStepDetectionLockerOrientation(startEdge.
|
|
204
|
+
this.pdrProvider.setStepDetectionLockerOrientation(startEdge.bearing);
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import noop from 'lodash.noop';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
Constants as GeoConstants, Itinerary,
|
|
4
|
+
Constants as GeoConstants, Itinerary, WGS84, WGS84UserPosition
|
|
5
5
|
} from '@wemap/geo';
|
|
6
6
|
import {
|
|
7
7
|
rad2deg, Quaternion
|
|
@@ -255,7 +255,7 @@ class PdrProvider extends MapMatchingProvider {
|
|
|
255
255
|
return newPositionWithoutMM;
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
const projection = this.mapMatching.getProjection(newPositionWithoutMM);
|
|
258
|
+
const projection = this.mapMatching.getProjection(newPositionWithoutMM, true, true);
|
|
259
259
|
|
|
260
260
|
if (!projection || !projection.projection) {
|
|
261
261
|
return newPositionWithoutMM;
|
|
@@ -314,14 +314,15 @@ class PdrProvider extends MapMatchingProvider {
|
|
|
314
314
|
throw new Error('Empty itinerary');
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
-
|
|
318
|
-
|
|
317
|
+
const edgeAt = itinerary.getEdgeAt(LO_SEGMENT_SIZE);
|
|
318
|
+
if (edgeAt) {
|
|
319
|
+
return edgeAt.bearing;
|
|
319
320
|
}
|
|
320
321
|
|
|
321
322
|
if (itinerary.length < 2) {
|
|
322
323
|
throw new Error('Itinerary is too short');
|
|
323
324
|
}
|
|
324
|
-
return itinerary.secondEdge.
|
|
325
|
+
return itinerary.secondEdge.bearing;
|
|
325
326
|
}
|
|
326
327
|
|
|
327
328
|
setStepDetectionLockerOrientation(orientation) {
|