@wemap/positioning 2.7.8 → 2.7.10

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.
@@ -48,57 +48,57 @@ class ArCoreAbsoluteComponent extends React.Component {
48
48
  }
49
49
  }
50
50
 
51
- onEvent = events => {
52
- const newState = {};
53
- events.forEach(event => {
54
- if (event.dataType === EventType.AbsolutePosition) {
55
- newState.position = event.data;
56
- } else if (event.dataType === EventType.AbsoluteAttitude) {
57
- newState.attitude = event.data;
58
- } else if (event.dataType === EventType.Barcode) {
59
- newState.barcode = event.data;
60
- }
61
- });
62
- if (!isEmpty(newState)) {
63
- this.setState(newState);
64
- }
65
-
66
- if (this.map) {
67
- this.map.parseEvents(events);
68
- }
69
- };
70
-
71
- onError = error => {
72
- this.errored = true;
73
- this.setState({
74
- position: error,
75
- attitude: error
76
- });
77
- };
78
-
79
- render() {
80
- const {barcode} = this.state;
81
-
82
- const attitudeRender = Utils.renderAttitude(this.state.attitude);
83
- const positionRender = Utils.renderPosition(this.state.position);
84
-
85
- return (
86
- <div>
87
- <h3>Position</h3>
88
- {positionRender}
89
- <h3>Attitude</h3>
90
- {attitudeRender}
91
- <h3>Barcode</h3>
92
- {barcode ? barcode : ''}
93
- <h3>Map</h3>
94
- <MapComponent
95
- ref={map => (this.map = map)}
96
- defaultZoom={21}
97
- network={NavigationConfig.ITINERARY}
98
- />
99
- </div>
100
- );
101
- }
51
+ onEvent = events => {
52
+ const newState = {};
53
+ events.forEach(event => {
54
+ if (event.dataType === EventType.AbsolutePosition) {
55
+ newState.position = event.data;
56
+ } else if (event.dataType === EventType.AbsoluteAttitude) {
57
+ newState.attitude = event.data;
58
+ } else if (event.dataType === EventType.Barcode) {
59
+ newState.barcode = event.data;
60
+ }
61
+ });
62
+ if (!isEmpty(newState)) {
63
+ this.setState(newState);
64
+ }
65
+
66
+ if (this.map) {
67
+ this.map.parseEvents(events);
68
+ }
69
+ };
70
+
71
+ onError = error => {
72
+ this.errored = true;
73
+ this.setState({
74
+ position: error,
75
+ attitude: error
76
+ });
77
+ };
78
+
79
+ render() {
80
+ const {barcode} = this.state;
81
+
82
+ const attitudeRender = Utils.renderAttitude(this.state.attitude);
83
+ const positionRender = Utils.renderPosition(this.state.position);
84
+
85
+ return (
86
+ <div>
87
+ <h3>Position</h3>
88
+ {positionRender}
89
+ <h3>Attitude</h3>
90
+ {attitudeRender}
91
+ <h3>Barcode</h3>
92
+ {barcode ? barcode : ''}
93
+ <h3>Map</h3>
94
+ <MapComponent
95
+ ref={map => (this.map = map)}
96
+ defaultZoom={21}
97
+ network={NavigationConfig.ITINERARY}
98
+ />
99
+ </div>
100
+ );
101
+ }
102
102
  }
103
103
 
104
104
  export default ArCoreAbsoluteComponent;
@@ -30,47 +30,47 @@ class GnssWifiPdrComponent extends React.Component {
30
30
  this.gnssWifiPdrProvider.stop();
31
31
  }
32
32
 
33
- onEvent = events => {
34
- const newState = {};
35
- events.forEach(event => {
36
- if (event.dataType === EventType.AbsolutePosition) {
37
- newState.position = event.data;
38
- } else if (event.dataType === EventType.AbsoluteAttitude) {
39
- newState.attitude = event.data;
40
- }
41
- });
42
- if (!isEmpty(newState)) {
43
- this.setState(newState);
44
- }
33
+ onEvent = events => {
34
+ const newState = {};
35
+ events.forEach(event => {
36
+ if (event.dataType === EventType.AbsolutePosition) {
37
+ newState.position = event.data;
38
+ } else if (event.dataType === EventType.AbsoluteAttitude) {
39
+ newState.attitude = event.data;
40
+ }
41
+ });
42
+ if (!isEmpty(newState)) {
43
+ this.setState(newState);
44
+ }
45
45
 
46
- if (this.map) {
47
- this.map.parseEvents(events);
48
- }
49
- };
46
+ if (this.map) {
47
+ this.map.parseEvents(events);
48
+ }
49
+ };
50
50
 
51
- onError = error => {
52
- this.setState({
53
- position: error,
54
- attitude: error
55
- });
56
- };
51
+ onError = error => {
52
+ this.setState({
53
+ position: error,
54
+ attitude: error
55
+ });
56
+ };
57
57
 
58
- render() {
59
- const attitudeRender = Utils.renderAttitude(this.state.attitude);
60
- const positionRender = Utils.renderPosition(this.state.position);
58
+ render() {
59
+ const attitudeRender = Utils.renderAttitude(this.state.attitude);
60
+ const positionRender = Utils.renderPosition(this.state.position);
61
61
 
62
- return (
63
- <div>
64
- <h3>Position</h3>
65
- {positionRender}
66
- <h3>Attitude</h3>
67
- {attitudeRender}
68
- <h3>Map</h3>
69
- <MapComponent ref={map => (this.map = map)}
70
- network={NavigationConfig.ITINERARY} />
71
- </div>
72
- );
73
- }
62
+ return (
63
+ <div>
64
+ <h3>Position</h3>
65
+ {positionRender}
66
+ <h3>Attitude</h3>
67
+ {attitudeRender}
68
+ <h3>Map</h3>
69
+ <MapComponent ref={map => (this.map = map)}
70
+ network={NavigationConfig.ITINERARY} />
71
+ </div>
72
+ );
73
+ }
74
74
  }
75
75
 
76
76
  export default GnssWifiPdrComponent;
@@ -11,7 +11,7 @@ import { Network } from '@wemap/graph';
11
11
  import EventType from '../../src/events/EventType';
12
12
 
13
13
  mapboxgl.accessToken
14
- = 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4M29iazA2Z2gycXA4N2pmbDZmangifQ.-g_vE53SD2WrJ6tFX7QHmA';
14
+ = 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4M29iazA2Z2gycXA4N2pmbDZmangifQ.-g_vE53SD2WrJ6tFX7QHmA';
15
15
 
16
16
  const COMPASS_STYLE = {
17
17
  width: '15px',
@@ -38,191 +38,191 @@ const POSITION_STYLE = {
38
38
  };
39
39
 
40
40
  class MapComponent extends React.Component {
41
- static propTypes = {
42
- network: PropTypes.instanceOf(Network),
43
- defaultZoom: PropTypes.number
44
- };
45
-
46
- static defaultProps = { defaultZoom: 19 };
47
-
48
- componentDidMount() {
49
- this.map = new mapboxgl.Map({
50
- container: this.mapContainer,
51
- style: 'mapbox://styles/mapbox/streets-v9'
52
- });
53
- this.renderNetwork();
54
- }
55
-
56
- componentWillUnmount() {
57
- this.map.remove();
58
- }
59
-
60
- createMarker(options) {
61
- var elem, marker;
62
-
63
- elem = document.createElement('div');
64
- elem.style.marginLeft = '-' + options.iconAnchor[0] + 'px';
65
- elem.style.marginTop = '-' + options.iconAnchor[1] + 'px';
66
- elem.style.width = 0;
67
- elem.style.height = 0;
68
- elem.appendChild(options.dom);
69
-
70
- marker = new mapboxgl.Marker(elem);
71
- marker.setLngLat([options.longitude, options.latitude]);
72
- return marker;
73
- }
74
-
75
- createPositionMarker(position) {
76
- const coreIcon = document.createElement('div');
77
- this.applyStyleToDomElement(coreIcon, POSITION_STYLE);
78
-
79
- this.positionIcon = document.createElement('div');
80
- this.positionIcon.appendChild(coreIcon);
81
-
82
- return this.createMarker({
83
- dom: this.positionIcon,
84
- iconAnchor: [0, 0],
85
- latitude: position[1],
86
- longitude: position[0]
87
- });
88
- }
89
-
90
- createCompassElement() {
91
- if (!this.positionIcon) {
92
- throw new Error('createPositionMarker() should be called before');
93
- }
94
- this.compassIcon = document.createElement('div');
95
- this.applyStyleToDomElement(this.compassIcon, COMPASS_STYLE);
96
- this.positionIcon.appendChild(this.compassIcon);
97
- }
98
-
99
- applyStyleToDomElement(domElement, style) {
100
- for (const key in style) {
101
- if (style.hasOwnProperty(key)) {
102
- domElement.style[key] = style[key];
103
- }
104
- }
105
- }
106
-
107
- parseEvents(events) {
108
- if (!this.map) {
109
- return;
110
- }
111
- events.forEach(event => {
112
- if (event.dataType === EventType.AbsolutePosition) {
113
- this.updatePosition(event.data);
114
- } else if (event.dataType === EventType.AbsoluteAttitude) {
115
- this.updateAttitude(event.data);
116
- }
117
- });
118
- }
119
-
120
- updatePosition(position) {
121
- if (!this.map) {
122
- return;
123
- }
124
-
125
- if (!(position instanceof WGS84)) {
126
- if (this.mapMarker) {
127
- this.mapMarker.remove();
128
- this.mapMarker = null;
129
- this.positionIcon = null;
130
- }
131
- return;
132
- }
133
-
134
- const lngLat = [position.lng, position.lat];
135
-
136
- if (!this.mapMarker) {
137
- this.mapMarker = this.createPositionMarker(lngLat).addTo(this.map);
138
- this.map.jumpTo({
139
- center: lngLat,
140
- zoom: this.props.defaultZoom
141
- });
142
- } else {
143
- this.mapMarker.setLngLat(lngLat);
144
- }
145
- }
146
-
147
- updateAttitude(attitude) {
148
- if (!this.positionIcon) {
149
- return;
150
- }
151
-
152
- if (!(attitude instanceof Attitude)) {
153
- if (this.compassIcon) {
154
- this.positionIcon.removeChild(this.compassIcon);
155
- }
156
- return;
157
- }
158
-
159
- if (!this.compassIcon) {
160
- this.createCompassElement();
161
- }
162
-
163
- this.positionIcon.style.transform
164
- = 'rotate(' + attitude.headingDegrees + 'deg)';
165
- }
166
-
167
- renderNetwork() {
168
- if (!this.map) {
169
- return;
170
- }
171
-
172
- const network = this.props.network;
173
-
174
- if (network === this.previousNetwork) {
175
- return;
176
- }
177
- this.previousNetwork = network;
178
-
179
- if (!network) {
180
- if (this.networkLayer) {
181
- this.map.removeLayer(this.networkLayer);
182
- this.networkLayer = null;
183
- }
184
- return;
185
- }
186
-
187
- const layer = {
188
- id: 'network',
189
- type: 'line',
190
- source: {
191
- type: 'geojson',
192
- data: {
193
- type: 'Feature',
194
- properties: {},
195
- geometry: {
196
- type: 'MultiLineString',
197
- coordinates: []
198
- }
199
- }
200
- },
201
- paint: {
202
- 'line-color': '#0000FF',
203
- 'line-width': 3
204
- }
205
- };
206
-
207
- for (let i = 0; i < network.edges.length; i++) {
208
- layer.source.data.geometry.coordinates.push([
209
- [network.edges[i].node1.coords.lng, network.edges[i].node1.coords.lat],
210
- [network.edges[i].node2.coords.lng, network.edges[i].node2.coords.lat]
211
- ]);
212
- }
213
-
214
- this.map.on('load', () => {
215
- this.networkLayer = this.map.addLayer(layer);
216
- });
217
- }
218
-
219
- render() {
220
- this.renderNetwork();
221
- return (
222
- <div ref={map => (this.mapContainer = map)}
223
- style={{ height: '300px' }} />
224
- );
225
- }
41
+ static propTypes = {
42
+ network: PropTypes.instanceOf(Network),
43
+ defaultZoom: PropTypes.number
44
+ };
45
+
46
+ static defaultProps = { defaultZoom: 19 };
47
+
48
+ componentDidMount() {
49
+ this.map = new mapboxgl.Map({
50
+ container: this.mapContainer,
51
+ style: 'mapbox://styles/mapbox/streets-v9'
52
+ });
53
+ this.renderNetwork();
54
+ }
55
+
56
+ componentWillUnmount() {
57
+ this.map.remove();
58
+ }
59
+
60
+ createMarker(options) {
61
+ var elem, marker;
62
+
63
+ elem = document.createElement('div');
64
+ elem.style.marginLeft = '-' + options.iconAnchor[0] + 'px';
65
+ elem.style.marginTop = '-' + options.iconAnchor[1] + 'px';
66
+ elem.style.width = 0;
67
+ elem.style.height = 0;
68
+ elem.appendChild(options.dom);
69
+
70
+ marker = new mapboxgl.Marker(elem);
71
+ marker.setLngLat([options.longitude, options.latitude]);
72
+ return marker;
73
+ }
74
+
75
+ createPositionMarker(position) {
76
+ const coreIcon = document.createElement('div');
77
+ this.applyStyleToDomElement(coreIcon, POSITION_STYLE);
78
+
79
+ this.positionIcon = document.createElement('div');
80
+ this.positionIcon.appendChild(coreIcon);
81
+
82
+ return this.createMarker({
83
+ dom: this.positionIcon,
84
+ iconAnchor: [0, 0],
85
+ latitude: position[1],
86
+ longitude: position[0]
87
+ });
88
+ }
89
+
90
+ createCompassElement() {
91
+ if (!this.positionIcon) {
92
+ throw new Error('createPositionMarker() should be called before');
93
+ }
94
+ this.compassIcon = document.createElement('div');
95
+ this.applyStyleToDomElement(this.compassIcon, COMPASS_STYLE);
96
+ this.positionIcon.appendChild(this.compassIcon);
97
+ }
98
+
99
+ applyStyleToDomElement(domElement, style) {
100
+ for (const key in style) {
101
+ if (style.hasOwnProperty(key)) {
102
+ domElement.style[key] = style[key];
103
+ }
104
+ }
105
+ }
106
+
107
+ parseEvents(events) {
108
+ if (!this.map) {
109
+ return;
110
+ }
111
+ events.forEach(event => {
112
+ if (event.dataType === EventType.AbsolutePosition) {
113
+ this.updatePosition(event.data);
114
+ } else if (event.dataType === EventType.AbsoluteAttitude) {
115
+ this.updateAttitude(event.data);
116
+ }
117
+ });
118
+ }
119
+
120
+ updatePosition(position) {
121
+ if (!this.map) {
122
+ return;
123
+ }
124
+
125
+ if (!(position instanceof WGS84)) {
126
+ if (this.mapMarker) {
127
+ this.mapMarker.remove();
128
+ this.mapMarker = null;
129
+ this.positionIcon = null;
130
+ }
131
+ return;
132
+ }
133
+
134
+ const lngLat = [position.lng, position.lat];
135
+
136
+ if (!this.mapMarker) {
137
+ this.mapMarker = this.createPositionMarker(lngLat).addTo(this.map);
138
+ this.map.jumpTo({
139
+ center: lngLat,
140
+ zoom: this.props.defaultZoom
141
+ });
142
+ } else {
143
+ this.mapMarker.setLngLat(lngLat);
144
+ }
145
+ }
146
+
147
+ updateAttitude(attitude) {
148
+ if (!this.positionIcon) {
149
+ return;
150
+ }
151
+
152
+ if (!(attitude instanceof Attitude)) {
153
+ if (this.compassIcon) {
154
+ this.positionIcon.removeChild(this.compassIcon);
155
+ }
156
+ return;
157
+ }
158
+
159
+ if (!this.compassIcon) {
160
+ this.createCompassElement();
161
+ }
162
+
163
+ this.positionIcon.style.transform
164
+ = 'rotate(' + attitude.headingDegrees + 'deg)';
165
+ }
166
+
167
+ renderNetwork() {
168
+ if (!this.map) {
169
+ return;
170
+ }
171
+
172
+ const network = this.props.network;
173
+
174
+ if (network === this.previousNetwork) {
175
+ return;
176
+ }
177
+ this.previousNetwork = network;
178
+
179
+ if (!network) {
180
+ if (this.networkLayer) {
181
+ this.map.removeLayer(this.networkLayer);
182
+ this.networkLayer = null;
183
+ }
184
+ return;
185
+ }
186
+
187
+ const layer = {
188
+ id: 'network',
189
+ type: 'line',
190
+ source: {
191
+ type: 'geojson',
192
+ data: {
193
+ type: 'Feature',
194
+ properties: {},
195
+ geometry: {
196
+ type: 'MultiLineString',
197
+ coordinates: []
198
+ }
199
+ }
200
+ },
201
+ paint: {
202
+ 'line-color': '#0000FF',
203
+ 'line-width': 3
204
+ }
205
+ };
206
+
207
+ for (let i = 0; i < network.edges.length; i++) {
208
+ layer.source.data.geometry.coordinates.push([
209
+ [network.edges[i].node1.coords.lng, network.edges[i].node1.coords.lat],
210
+ [network.edges[i].node2.coords.lng, network.edges[i].node2.coords.lat]
211
+ ]);
212
+ }
213
+
214
+ this.map.on('load', () => {
215
+ this.networkLayer = this.map.addLayer(layer);
216
+ });
217
+ }
218
+
219
+ render() {
220
+ this.renderNetwork();
221
+ return (
222
+ <div ref={map => (this.mapContainer = map)}
223
+ style={{ height: '300px' }} />
224
+ );
225
+ }
226
226
  }
227
227
 
228
228
  export default MapComponent;
@@ -29,47 +29,47 @@ class PdrComponent extends React.Component {
29
29
  this.pdrProvider.stop();
30
30
  }
31
31
 
32
- onEvent = events => {
33
- const newState = {};
34
- events.forEach(event => {
35
- if (event.dataType === EventType.AbsolutePosition) {
36
- newState.position = event.data;
37
- } else if (event.dataType === EventType.AbsoluteAttitude) {
38
- newState.attitude = event.data;
39
- }
40
- });
41
- if (!isEmpty(newState)) {
42
- this.setState(newState);
43
- }
32
+ onEvent = events => {
33
+ const newState = {};
34
+ events.forEach(event => {
35
+ if (event.dataType === EventType.AbsolutePosition) {
36
+ newState.position = event.data;
37
+ } else if (event.dataType === EventType.AbsoluteAttitude) {
38
+ newState.attitude = event.data;
39
+ }
40
+ });
41
+ if (!isEmpty(newState)) {
42
+ this.setState(newState);
43
+ }
44
44
 
45
- if (this.map) {
46
- this.map.parseEvents(events);
47
- }
48
- };
45
+ if (this.map) {
46
+ this.map.parseEvents(events);
47
+ }
48
+ };
49
49
 
50
- onError = error => {
51
- this.setState({
52
- position: error,
53
- attitude: error
54
- });
55
- };
50
+ onError = error => {
51
+ this.setState({
52
+ position: error,
53
+ attitude: error
54
+ });
55
+ };
56
56
 
57
- render() {
58
- const attitudeRender = Utils.renderAttitude(this.state.attitude);
59
- const positionRender = Utils.renderPosition(this.state.position);
57
+ render() {
58
+ const attitudeRender = Utils.renderAttitude(this.state.attitude);
59
+ const positionRender = Utils.renderPosition(this.state.position);
60
60
 
61
- return (
62
- <div>
63
- <h3>Position</h3>
64
- {positionRender}
65
- <h3>Attitude</h3>
66
- {attitudeRender}
67
- <h3>Map</h3>
68
- <MapComponent ref={map => (this.map = map)}
69
- network={NavigationConfig.ITINERARY} />
70
- </div>
71
- );
72
- }
61
+ return (
62
+ <div>
63
+ <h3>Position</h3>
64
+ {positionRender}
65
+ <h3>Attitude</h3>
66
+ {attitudeRender}
67
+ <h3>Map</h3>
68
+ <MapComponent ref={map => (this.map = map)}
69
+ network={NavigationConfig.ITINERARY} />
70
+ </div>
71
+ );
72
+ }
73
73
  }
74
74
 
75
75
  export default PdrComponent;
@@ -13,105 +13,105 @@ import ProvidersLogger from '../../src/providers/ProvidersLogger';
13
13
  ProvidersLogger.enabled = true;
14
14
 
15
15
  class PositioningPoseComponent extends React.Component {
16
- static propTypes = {positioningHandler: PropTypes.instanceOf(PositioningHandler).isRequired};
17
-
18
- constructor(props, context) {
19
- super(props, context);
20
- this.state = {
21
- position: null,
22
- attitude: null,
23
- errored: false
24
- };
25
- }
26
-
27
- start() {
28
- const output = this.props.positioningHandler.start(
29
- [EventType.AbsolutePosition, EventType.AbsoluteAttitude],
30
- this.onEvents,
31
- this.onError,
32
- {
33
- waitInputPosition: true,
34
- useMapMatching: true
35
- }
36
- );
37
-
38
- if (!output) {
39
- return;
40
- }
41
-
42
- this.id = output.id;
43
-
44
- this.props.positioningHandler.setItinerary(this.id, NavigationConfig.ITINERARY);
45
- this.props.positioningHandler.setNetwork(this.id, NavigationConfig.ITINERARY);
46
- this.props.positioningHandler.setPosition(this.id, NavigationConfig.INITIAL_POSITION);
47
- this.props.positioningHandler.setHeading(this.id, NavigationConfig.INITIAL_HEADING);
48
- }
49
-
50
- stop() {
51
- this.props.positioningHandler.stop(this.id);
52
- this.setState({
53
- position: null,
54
- attitude: null,
55
- errored: false
56
- });
57
- }
58
-
59
- onEvents = events => {
60
- const newState = {};
61
- events.forEach(event => {
62
- if (event.dataType === EventType.AbsolutePosition) {
63
- newState.position = event.data;
64
- } else if (event.dataType === EventType.AbsoluteAttitude) {
65
- newState.attitude = event.data;
66
- }
67
- });
68
- if (!isEmpty(newState)) {
69
- this.setState(newState);
70
- }
71
-
72
- if (this.map) {
73
- this.map.parseEvents(events);
74
- }
75
- };
76
-
77
- onError = error => {
78
- this.setState({
79
- position: error,
80
- attitude: error,
81
- errored: true
82
- });
83
- };
84
-
85
- render() {
86
- const attitudeRender = Utils.renderAttitude(this.state.attitude);
87
- const positionRender = Utils.renderPosition(this.state.position);
88
-
89
- const itineraryRender = Utils.renderItineraryInfo(
90
- this.state.position && !(this.state.position instanceof Error)
91
- ? NavigationConfig.ITINERARY.getInfo(this.state.position)
92
- : null
93
- );
94
-
95
- return (
96
- <div>
97
- <StartStopComponent
98
- onStart={() => this.start()}
99
- onStop={() => this.stop()}
100
- errored={this.state.errored}
101
- />
102
-
103
- <h3>Position</h3>
104
- {positionRender}
105
- <h3>Attitude</h3>
106
- {attitudeRender}
107
- <h3>Map</h3>
108
- <MapComponent ref={map => (this.map = map)}
109
- network={NavigationConfig.ITINERARY} />
110
- <h3>ItineraryInfo</h3>
111
- {itineraryRender}
112
- </div>
113
- );
114
- }
16
+ static propTypes = {positioningHandler: PropTypes.instanceOf(PositioningHandler).isRequired};
17
+
18
+ constructor(props, context) {
19
+ super(props, context);
20
+ this.state = {
21
+ position: null,
22
+ attitude: null,
23
+ errored: false
24
+ };
25
+ }
26
+
27
+ start() {
28
+ const output = this.props.positioningHandler.start(
29
+ [EventType.AbsolutePosition, EventType.AbsoluteAttitude],
30
+ this.onEvents,
31
+ this.onError,
32
+ {
33
+ waitInputPosition: true,
34
+ useMapMatching: true
35
+ }
36
+ );
37
+
38
+ if (!output) {
39
+ return;
40
+ }
41
+
42
+ this.id = output.id;
43
+
44
+ this.props.positioningHandler.setItinerary(this.id, NavigationConfig.ITINERARY);
45
+ this.props.positioningHandler.setNetwork(this.id, NavigationConfig.ITINERARY);
46
+ this.props.positioningHandler.setPosition(this.id, NavigationConfig.INITIAL_POSITION);
47
+ this.props.positioningHandler.setHeading(this.id, NavigationConfig.INITIAL_HEADING);
48
+ }
49
+
50
+ stop() {
51
+ this.props.positioningHandler.stop(this.id);
52
+ this.setState({
53
+ position: null,
54
+ attitude: null,
55
+ errored: false
56
+ });
57
+ }
58
+
59
+ onEvents = events => {
60
+ const newState = {};
61
+ events.forEach(event => {
62
+ if (event.dataType === EventType.AbsolutePosition) {
63
+ newState.position = event.data;
64
+ } else if (event.dataType === EventType.AbsoluteAttitude) {
65
+ newState.attitude = event.data;
66
+ }
67
+ });
68
+ if (!isEmpty(newState)) {
69
+ this.setState(newState);
70
+ }
71
+
72
+ if (this.map) {
73
+ this.map.parseEvents(events);
74
+ }
75
+ };
76
+
77
+ onError = error => {
78
+ this.setState({
79
+ position: error,
80
+ attitude: error,
81
+ errored: true
82
+ });
83
+ };
84
+
85
+ render() {
86
+ const attitudeRender = Utils.renderAttitude(this.state.attitude);
87
+ const positionRender = Utils.renderPosition(this.state.position);
88
+
89
+ const itineraryRender = Utils.renderItineraryInfo(
90
+ this.state.position && !(this.state.position instanceof Error)
91
+ ? NavigationConfig.ITINERARY.getInfo(this.state.position)
92
+ : null
93
+ );
94
+
95
+ return (
96
+ <div>
97
+ <StartStopComponent
98
+ onStart={() => this.start()}
99
+ onStop={() => this.stop()}
100
+ errored={this.state.errored}
101
+ />
102
+
103
+ <h3>Position</h3>
104
+ {positionRender}
105
+ <h3>Attitude</h3>
106
+ {attitudeRender}
107
+ <h3>Map</h3>
108
+ <MapComponent ref={map => (this.map = map)}
109
+ network={NavigationConfig.ITINERARY} />
110
+ <h3>ItineraryInfo</h3>
111
+ {itineraryRender}
112
+ </div>
113
+ );
114
+ }
115
115
  }
116
116
 
117
117
  export default PositioningPoseComponent;
package/package.json CHANGED
@@ -8,11 +8,11 @@
8
8
  "Guillaume Pannetier <guillaume.pannetier@getwemap.com>"
9
9
  ],
10
10
  "dependencies": {
11
- "@wemap/geo": "^2.7.8",
12
- "@wemap/graph": "^2.7.8",
11
+ "@wemap/geo": "^2.7.9",
12
+ "@wemap/graph": "^2.7.9",
13
13
  "@wemap/logger": "^2.7.7",
14
14
  "@wemap/maths": "^2.7.7",
15
- "@wemap/osm": "^2.7.8",
15
+ "@wemap/osm": "^2.7.9",
16
16
  "@wemap/utils": "^2.7.7",
17
17
  "geomagnetism": "^0.1.0",
18
18
  "lodash.isempty": "^4.4.0",
@@ -60,6 +60,6 @@
60
60
  "lint": "eslint --ext .js,.jsx --quiet src",
61
61
  "test": "mocha -r esm \"src/**/*.spec.js\""
62
62
  },
63
- "version": "2.7.8",
64
- "gitHead": "859b08bd29d1dbcc828be931509e10437fc8cf75"
63
+ "version": "2.7.10",
64
+ "gitHead": "2073a2c4ee7d4cd82b964508be163f0fcb87867e"
65
65
  }
@@ -16,6 +16,7 @@ export default {
16
16
  WifiSignals: 'WIFI_SIGNALS',
17
17
  ScanId: 'SCAN_ID',
18
18
  Barcode: 'BARCODE',
19
+ ProjectionMatrix: 'PROJECTION_MATRIX',
19
20
  Itinerary: 'ITINERARY',
20
21
  Network: 'NETWORK'
21
22
  };
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-bitwise */
1
2
  import { Attitude } from '@wemap/geo';
2
3
 
3
4
  import Provider from '../Provider';
@@ -6,6 +7,26 @@ import MissingArCoreError from '../../errors/MissingArCoreError';
6
7
  import MissingNativeInterfaceError from '../../errors/MissingNativeInterfaceError';
7
8
  import Availability from '../../events/Availability';
8
9
 
10
+
11
+ const Payload = {
12
+ Pose: {
13
+ ref: 2 ** 0,
14
+ size: 7
15
+ },
16
+ Barcode: {
17
+ ref: 2 ** 1,
18
+ size: 1
19
+ },
20
+ ProjMat: {
21
+ ref: 2 ** 2,
22
+ size: 16
23
+ },
24
+ ImageRef: {
25
+ ref: 2 ** 3,
26
+ size: 1
27
+ }
28
+ };
29
+
9
30
  /**
10
31
  * Pose provider is the provider used by the PositioningHandler. It uses the best fusion
11
32
  * of what he can and provides an AbsoluteAttitude and an AbsolutePosition as an output.
@@ -67,7 +88,7 @@ class ArCoreProvider extends Provider {
67
88
  }
68
89
 
69
90
  const payload = JSON.parse(ArCoreProvider.nativeProvider.getInfo());
70
- if (payload.length !== 0) {
91
+ if (payload.length > 1) {
71
92
  this.parsePayload(payload);
72
93
  }
73
94
  requestAnimationFrame(this.pullDataLoop);
@@ -75,17 +96,28 @@ class ArCoreProvider extends Provider {
75
96
 
76
97
  parsePayload(payload) {
77
98
 
99
+ const ref = payload[0];
100
+ let bufferIndex = 1;
101
+
78
102
  const events = [];
79
103
 
80
- if (payload[0] !== null) {
81
- const attitude = new Attitude(payload.slice(0, 4));
82
- const position = payload.slice(4, 7);
104
+ if (ref & Payload.Pose.ref) {
105
+ const attitude = new Attitude(payload.slice(bufferIndex, bufferIndex + 4));
106
+ const position = payload.slice(bufferIndex + 4, bufferIndex + 7);
83
107
  events.push(this.createEvent(EventType.RelativeAttitude, attitude));
84
108
  events.push(this.createEvent(EventType.RelativePosition, position));
109
+ bufferIndex += Payload.Pose.size;
85
110
  }
86
- const barcode = payload[7];
87
- if (barcode !== null) {
88
- events.push(this.createEvent(EventType.Barcode, barcode));
111
+
112
+ if (ref & Payload.Barcode.ref) {
113
+ events.push(this.createEvent(EventType.Barcode, payload[bufferIndex]));
114
+ bufferIndex += Payload.Barcode.size;
115
+ }
116
+
117
+ if (ref & Payload.ProjMat.ref) {
118
+ const projMatrix = payload.slice(bufferIndex, bufferIndex + Payload.ProjMat.size);
119
+ events.push(this.createEvent(EventType.ProjectionMatrix, projMatrix));
120
+ bufferIndex += Payload.ProjMat.size;
89
121
  }
90
122
 
91
123
  if (events.length !== 0) {