@wemap/providers 3.1.3 → 3.1.5
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/debug/Common.css +172 -0
- package/debug/MainComponent.jsx +51 -0
- package/debug/components/AbsolutePositionComponent.jsx +1 -1
- package/debug/components/GnssWifiComponent.jsx +1 -1
- package/debug/components/StartStopComponent.jsx +5 -3
- package/debug/components/Utils.js +4 -2
- package/debug/details/DetailsAttitudeComponent.jsx +128 -0
- package/debug/details/DetailsComponent.jsx +32 -0
- package/debug/details/DetailsPositionComponent.jsx +135 -0
- package/debug/details/ItineraryComponent.jsx +323 -0
- package/debug/index.js +28 -0
- package/debug/map/MapComponent.jsx +77 -0
- package/debug/map/MapHandler.js +53 -0
- package/debug/map/MapboxHelper.js +50 -0
- package/debug/map/helpers/ItineraryMapHandler.js +284 -0
- package/debug/map/helpers/MapClickHandler.js +119 -0
- package/debug/map/helpers/UserOnMapHandler.js +470 -0
- package/debug/stores/ItineraryStore.js +223 -0
- package/dist/assets/indoor-maps/bureaux-wemap-montpellier.geojson +7444 -0
- package/dist/{pose.html → index.html} +4 -1
- package/dist/js/providers-components.js +353 -209
- package/package.json +9 -7
- package/src/ProvidersInterface.js +5 -4
- package/src/providers/FakeProvider.spec.js +2 -7
- package/src/providers/MetaProvider.js +3 -1
- package/src/providers/Provider.js +19 -14
- package/src/providers/Provider.spec.js +21 -20
- package/src/providers/attitude/absolute/AbsoluteAttitudeFromBrowserProvider.js +2 -3
- package/src/providers/attitude/absolute/AbsoluteAttitudeProvider.js +3 -3
- package/src/providers/attitude/relative/RelativeAttitudeFromBrowserProvider.js +2 -3
- package/src/providers/attitude/relative/RelativeAttitudeFromEkfProvider.js +3 -4
- package/src/providers/attitude/relative/RelativeAttitudeFromInertialProvider.js +18 -12
- package/src/providers/imu/ImuProvider.js +2 -3
- package/src/providers/inclination/InclinationProvider.js +4 -3
- package/src/providers/position/absolute/AbsolutePositionFromRelProvider.js +1 -1
- package/src/providers/position/absolute/AbsolutePositionProvider.js +41 -26
- package/src/providers/position/absolute/GnssWifiProvider.js +2 -3
- package/src/providers/position/relative/ArCoreProvider.js +3 -4
- package/src/providers/position/relative/GeoRelativePositionFromArCoreProvider.js +2 -1
- package/src/providers/position/relative/GeoRelativePositionProvider.js +23 -20
- package/src/providers/position/relative/PdrProvider.js +4 -4
- package/src/providers/steps/StepDetectionProvider.js +2 -3
- package/src/smoothers/PositionSmoother.js +10 -2
- package/webpack/webpack.common.js +5 -5
- package/webpack/webpack.dev.js +7 -1
- package/debug/components/Common.css +0 -27
- package/debug/components/MapComponent.jsx +0 -366
- package/debug/components/PoseComponent.jsx +0 -169
- package/debug/components/index.js +0 -28
- package/src/events/Availability.js +0 -44
- package/src/providers/legacy/AbsolutePdrProvider.js +0 -258
- package/src/providers/legacy/ArCoreAbsoluteProvider.js +0 -230
- package/src/providers/legacy/GnssWifiPdrProvider.js +0 -217
- package/src/providers/legacy/MapMatchingProvider.js +0 -65
- package/src/providers/legacy/PdrProvider.old.js +0 -300
- package/src/providers/legacy/PoseProvider.js +0 -68
- package/src/providers/legacy/helpers/Smoother.js +0 -92
- package/src/providers/legacy/helpers/Smoother.spec.js +0 -426
|
@@ -9,7 +9,6 @@ import Provider from '../../Provider';
|
|
|
9
9
|
import EventType from '../../../events/EventType';
|
|
10
10
|
import MissingArCoreError from '../../../errors/MissingArCoreError';
|
|
11
11
|
import MissingNativeInterfaceError from '../../../errors/MissingNativeInterfaceError';
|
|
12
|
-
import Availability from '../../../events/Availability';
|
|
13
12
|
import ProviderState from '../../ProviderState';
|
|
14
13
|
|
|
15
14
|
|
|
@@ -164,14 +163,14 @@ class ArCoreProvider extends Provider {
|
|
|
164
163
|
const nativeProvider = this.nativeProvider;
|
|
165
164
|
|
|
166
165
|
if (!nativeProvider.checkAvailability()) {
|
|
167
|
-
return
|
|
166
|
+
return Promise.reject(new MissingArCoreError());
|
|
168
167
|
}
|
|
169
168
|
|
|
170
169
|
} catch (e) {
|
|
171
|
-
return
|
|
170
|
+
return Promise.reject(e);
|
|
172
171
|
}
|
|
173
172
|
|
|
174
|
-
return
|
|
173
|
+
return Promise.resolve();
|
|
175
174
|
}
|
|
176
175
|
|
|
177
176
|
enableBarcodeScanner() {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { PromiseUtils } from '@wemap/utils';
|
|
2
|
+
|
|
1
3
|
import MetaProvider from '../../MetaProvider';
|
|
2
|
-
import Availability from '../../../events/Availability';
|
|
3
4
|
import EventType from '../../../events/EventType';
|
|
4
5
|
import {
|
|
5
6
|
Pdr, GeoRelativePositionFromArCore
|
|
@@ -25,10 +26,10 @@ class GeoRelativePositionProvider extends MetaProvider {
|
|
|
25
26
|
* @override
|
|
26
27
|
*/
|
|
27
28
|
get _availability() {
|
|
28
|
-
return
|
|
29
|
+
return PromiseUtils.any([
|
|
29
30
|
Pdr.availability,
|
|
30
31
|
GeoRelativePositionFromArCore.availability
|
|
31
|
-
);
|
|
32
|
+
]);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
|
|
@@ -37,29 +38,31 @@ class GeoRelativePositionProvider extends MetaProvider {
|
|
|
37
38
|
*/
|
|
38
39
|
start() {
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
this.geoRelativeProvider = GeoRelativePositionFromArCore
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
);
|
|
41
|
+
GeoRelativePositionFromArCore.availability
|
|
42
|
+
.then(() => (this.geoRelativeProvider = GeoRelativePositionFromArCore))
|
|
43
|
+
.catch(() => (this.geoRelativeProvider = Pdr))
|
|
44
|
+
.finally(() => {
|
|
45
|
+
this.providerId = this.geoRelativeProvider.addEventListener(
|
|
46
|
+
events => {
|
|
47
|
+
const event = events.find(_event => _event.dataType === EventType.GeoRelativePosition);
|
|
48
|
+
if (event) {
|
|
49
|
+
this.notify(event.clone());
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
error => this.notifyError(error),
|
|
53
|
+
this.name
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* @override
|
|
60
60
|
*/
|
|
61
61
|
stop() {
|
|
62
|
-
this.geoRelativeProvider
|
|
62
|
+
if (this.geoRelativeProvider) {
|
|
63
|
+
this.geoRelativeProvider.removeEventListener(this.providerId);
|
|
64
|
+
this.geoRelativeProvider = null;
|
|
65
|
+
}
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
|
|
@@ -2,7 +2,6 @@ import { GeoRelativePosition } from '@wemap/geo';
|
|
|
2
2
|
import { deg2rad } from '@wemap/maths';
|
|
3
3
|
|
|
4
4
|
import Provider from '../../Provider';
|
|
5
|
-
import Availability from '../../../events/Availability';
|
|
6
5
|
import EventType from '../../../events/EventType';
|
|
7
6
|
import {
|
|
8
7
|
StepDetection, AbsoluteAttitude
|
|
@@ -32,10 +31,10 @@ class PdrProvider extends Provider {
|
|
|
32
31
|
* @override
|
|
33
32
|
*/
|
|
34
33
|
get _availability() {
|
|
35
|
-
return
|
|
34
|
+
return Promise.all([
|
|
36
35
|
StepDetection.availability,
|
|
37
36
|
AbsoluteAttitude.availability
|
|
38
|
-
);
|
|
37
|
+
]);
|
|
39
38
|
}
|
|
40
39
|
|
|
41
40
|
|
|
@@ -116,7 +115,8 @@ class PdrProvider extends Provider {
|
|
|
116
115
|
stepSize * Math.cos(deviceDirection),
|
|
117
116
|
0,
|
|
118
117
|
timestamp,
|
|
119
|
-
accuracy
|
|
118
|
+
accuracy,
|
|
119
|
+
deviceDirection
|
|
120
120
|
);
|
|
121
121
|
|
|
122
122
|
this.notify(this.createEvent(
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Constants as GeoConstants } from '@wemap/geo';
|
|
2
2
|
import { Quaternion } from '@wemap/maths';
|
|
3
3
|
|
|
4
|
-
import Availability from '../../events/Availability';
|
|
5
4
|
import EventType from '../../events/EventType';
|
|
6
5
|
import Provider from '../Provider';
|
|
7
6
|
import StepDetectionMinMaxPeaks2 from './StepDetectionMinMaxPeaks2';
|
|
@@ -20,11 +19,11 @@ class StepDetectionProvider extends Provider {
|
|
|
20
19
|
* @override
|
|
21
20
|
*/
|
|
22
21
|
get _availability() {
|
|
23
|
-
return
|
|
22
|
+
return Promise.all([
|
|
24
23
|
Accelerometer.availability,
|
|
25
24
|
Gyroscope.availability,
|
|
26
25
|
RelativeAttitudeFromInertial.availability
|
|
27
|
-
);
|
|
26
|
+
]);
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
/**
|
|
@@ -18,7 +18,6 @@ class PositionSmoother {
|
|
|
18
18
|
constructor(callback, frequency = this.constructor.DEFAULT_FREQUENCY) {
|
|
19
19
|
this.callback = callback;
|
|
20
20
|
this.positionsQueue = [];
|
|
21
|
-
this.timeoutPositions = null;
|
|
22
21
|
this.frequency = frequency;
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -63,7 +62,10 @@ class PositionSmoother {
|
|
|
63
62
|
smoothedPosition.time = refTimestamp + (i - 1) / this.frequency;
|
|
64
63
|
smoothedPosition.level = newPositionLevel;
|
|
65
64
|
smoothedPosition.bearing = newPosition.bearing;
|
|
66
|
-
smoothedPosition.accuracy
|
|
65
|
+
smoothedPosition.accuracy = Math.max(
|
|
66
|
+
smoothedPosition.accuracy + (newPosition.accuracy - smoothedPosition.accuracy) * i / nSamples,
|
|
67
|
+
0
|
|
68
|
+
);
|
|
67
69
|
this.positionsQueue.push(smoothedPosition);
|
|
68
70
|
i++;
|
|
69
71
|
}
|
|
@@ -87,6 +89,12 @@ class PositionSmoother {
|
|
|
87
89
|
delete this.timeoutNotify;
|
|
88
90
|
}
|
|
89
91
|
}
|
|
92
|
+
|
|
93
|
+
clear() {
|
|
94
|
+
clearTimeout(this.timeoutNotify);
|
|
95
|
+
delete this.timeoutNotify;
|
|
96
|
+
this.positionsQueue = [];
|
|
97
|
+
}
|
|
90
98
|
}
|
|
91
99
|
|
|
92
100
|
export default PositionSmoother;
|
|
@@ -3,16 +3,16 @@ module.exports = {
|
|
|
3
3
|
rules: [
|
|
4
4
|
{
|
|
5
5
|
test: /\.jsx?$/,
|
|
6
|
-
|
|
7
|
-
/src/,
|
|
8
|
-
/wemap-(.*)/
|
|
9
|
-
],
|
|
10
|
-
exclude: /(\/mapbox-gl\/|.test.js|.spec.js|.mock.js)/,
|
|
6
|
+
exclude: /(node_modules|.test.js|.spec.js|.mock.js)/,
|
|
11
7
|
use: { loader: 'babel-loader' }
|
|
12
8
|
},
|
|
13
9
|
{
|
|
14
10
|
test: /\.css$/,
|
|
15
11
|
use: ['style-loader', 'css-loader']
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
test: /\.(png|jpe?g|gif|svg)$/i,
|
|
15
|
+
use: ['file-loader']
|
|
16
16
|
}
|
|
17
17
|
]
|
|
18
18
|
},
|
package/webpack/webpack.dev.js
CHANGED
|
@@ -8,7 +8,7 @@ const distFolder = path.join(__dirname, '../', config.distFolder);
|
|
|
8
8
|
|
|
9
9
|
module.exports = merge(common, {
|
|
10
10
|
mode: 'development',
|
|
11
|
-
entry: { 'providers-components': './debug/
|
|
11
|
+
entry: { 'providers-components': './debug/index.js' },
|
|
12
12
|
output: {
|
|
13
13
|
publicPath: '/js/',
|
|
14
14
|
filename: '[name].js',
|
|
@@ -21,5 +21,11 @@ module.exports = merge(common, {
|
|
|
21
21
|
hot: true,
|
|
22
22
|
host: '0.0.0.0',
|
|
23
23
|
port: 9000
|
|
24
|
+
},
|
|
25
|
+
resolve: {
|
|
26
|
+
alias: {
|
|
27
|
+
'mapbox-gl': '@thibaudm/mapbox-gl-js-indoor/dist/mapbox-gl.js',
|
|
28
|
+
'mapbox-gl-css': '@thibaudm/mapbox-gl-js-indoor/dist/mapbox-gl.css'
|
|
29
|
+
}
|
|
24
30
|
}
|
|
25
31
|
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
html,
|
|
2
|
-
body {
|
|
3
|
-
margin: 0;
|
|
4
|
-
font-size: 12px;
|
|
5
|
-
height: 100%;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
@media screen and (min-width: 400px) {
|
|
9
|
-
body {
|
|
10
|
-
font-size: 14px;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
#app {
|
|
15
|
-
height: 100%
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
p {
|
|
19
|
-
margin-top: 0;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
.title {
|
|
23
|
-
font-size: 18px;
|
|
24
|
-
font-weight: bold;
|
|
25
|
-
margin-top: 10px;
|
|
26
|
-
margin-bottom: 5px;
|
|
27
|
-
}
|
|
@@ -1,366 +0,0 @@
|
|
|
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
|
-
Attitude, UserPosition, Constants
|
|
8
|
-
} from '@wemap/geo';
|
|
9
|
-
import { Network } from '@wemap/graph';
|
|
10
|
-
|
|
11
|
-
mapboxgl.accessToken
|
|
12
|
-
= 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4M29iazA2Z2gycXA4N2pmbDZmangifQ.-g_vE53SD2WrJ6tFX7QHmA';
|
|
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 POSITION_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
|
-
class MapComponent extends React.Component {
|
|
39
|
-
static propTypes = {
|
|
40
|
-
network: PropTypes.instanceOf(Network),
|
|
41
|
-
positionRenderFrequency: PropTypes.number,
|
|
42
|
-
centerCameraFrequency: PropTypes.number,
|
|
43
|
-
maxZoom: PropTypes.number
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
static defaultProps = {
|
|
47
|
-
maxZoom: 22,
|
|
48
|
-
positionRenderFrequency: 60,
|
|
49
|
-
centerCameraFrequency: 1
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
userAccuracySource = {
|
|
53
|
-
'type': 'geojson',
|
|
54
|
-
'data': {
|
|
55
|
-
'type': 'FeatureCollection',
|
|
56
|
-
'features': []
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
followUser = true;
|
|
61
|
-
positionDirty = false;
|
|
62
|
-
positionForCameraDirty = false;
|
|
63
|
-
|
|
64
|
-
componentDidMount() {
|
|
65
|
-
this.map = new mapboxgl.Map({
|
|
66
|
-
container: this.mapContainer,
|
|
67
|
-
style: 'mapbox://styles/mapbox/streets-v9',
|
|
68
|
-
maxZoom: this.props.maxZoom
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
this.createFollowingUser();
|
|
72
|
-
this.map.on('load', () => {
|
|
73
|
-
this.createUserAccuracyLayer();
|
|
74
|
-
});
|
|
75
|
-
this.renderNetwork();
|
|
76
|
-
|
|
77
|
-
this.positionRenderLoopId = setInterval(this.positionRenderLoop, 1e3 / this.props.positionRenderFrequency);
|
|
78
|
-
this.centerCameraRenderLoopId = setInterval(this.centerCameraRenderLoop, 1e3 / this.props.centerCameraFrequency);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
componentWillUnmount() {
|
|
82
|
-
clearInterval(this.positionRenderLoopId);
|
|
83
|
-
clearInterval(this.centerCameraRenderLoopId);
|
|
84
|
-
this.map.remove();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
createMarker(options) {
|
|
88
|
-
var elem, marker;
|
|
89
|
-
|
|
90
|
-
elem = document.createElement('div');
|
|
91
|
-
elem.style.marginLeft = '-' + options.iconAnchor[0] + 'px';
|
|
92
|
-
elem.style.marginTop = '-' + options.iconAnchor[1] + 'px';
|
|
93
|
-
elem.style.width = 0;
|
|
94
|
-
elem.style.height = 0;
|
|
95
|
-
elem.appendChild(options.dom);
|
|
96
|
-
|
|
97
|
-
marker = new mapboxgl.Marker(elem);
|
|
98
|
-
marker.setLngLat([options.longitude, options.latitude]);
|
|
99
|
-
return marker;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
createPositionMarker(position) {
|
|
103
|
-
const coreIcon = document.createElement('div');
|
|
104
|
-
this.applyStyleToDomElement(coreIcon, POSITION_STYLE);
|
|
105
|
-
|
|
106
|
-
this.positionIcon = document.createElement('div');
|
|
107
|
-
this.positionIcon.appendChild(coreIcon);
|
|
108
|
-
|
|
109
|
-
return this.createMarker({
|
|
110
|
-
dom: this.positionIcon,
|
|
111
|
-
iconAnchor: [0, 0],
|
|
112
|
-
latitude: position[1],
|
|
113
|
-
longitude: position[0]
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
createCompassElement() {
|
|
118
|
-
if (!this.positionIcon) {
|
|
119
|
-
throw new Error('createPositionMarker() should be called before');
|
|
120
|
-
}
|
|
121
|
-
this.compassIcon = document.createElement('div');
|
|
122
|
-
this.applyStyleToDomElement(this.compassIcon, COMPASS_STYLE);
|
|
123
|
-
this.positionIcon.appendChild(this.compassIcon);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
applyStyleToDomElement(domElement, style) {
|
|
127
|
-
for (const key in style) {
|
|
128
|
-
if (style.hasOwnProperty(key)) {
|
|
129
|
-
domElement.style[key] = style[key];
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* @param {UserPosition} position
|
|
136
|
-
*/
|
|
137
|
-
updatePosition(position) {
|
|
138
|
-
if (this.position !== position) {
|
|
139
|
-
this.positionDirty = true;
|
|
140
|
-
this.positionForCameraDirty = true;
|
|
141
|
-
}
|
|
142
|
-
this.position = position;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
positionRenderLoop = () => {
|
|
146
|
-
|
|
147
|
-
if (!this.positionDirty) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (this.position === null) {
|
|
152
|
-
if (this.mapMarker) {
|
|
153
|
-
this.mapMarker.remove();
|
|
154
|
-
this.mapMarker = null;
|
|
155
|
-
}
|
|
156
|
-
this.map.setLayoutProperty('user-accuracy', 'visibility', 'none');
|
|
157
|
-
this.positionIcon = null;
|
|
158
|
-
this.compassIcon = null;
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const lngLat = [this.position.lng, this.position.lat];
|
|
163
|
-
|
|
164
|
-
if (!this.mapMarker) {
|
|
165
|
-
this.mapMarker = this.createPositionMarker(lngLat).addTo(this.map);
|
|
166
|
-
} else {
|
|
167
|
-
this.mapMarker.setLngLat(lngLat);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (this.position.accuracy) {
|
|
171
|
-
this.userAccuracySource.data.features = [{
|
|
172
|
-
'type': 'Feature',
|
|
173
|
-
'geometry': {
|
|
174
|
-
'type': 'Polygon',
|
|
175
|
-
'coordinates': [this.constructor.createGeoJSONCircle(lngLat, this.position.accuracy / 1e3)]
|
|
176
|
-
}
|
|
177
|
-
}];
|
|
178
|
-
this.map.setLayoutProperty('user-accuracy', 'visibility', 'visible');
|
|
179
|
-
} else {
|
|
180
|
-
this.userAccuracySource.data.features = [];
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const userAccuracySource = this.map.getSource('user-accuracy');
|
|
184
|
-
if (userAccuracySource) {
|
|
185
|
-
userAccuracySource.setData(this.userAccuracySource.data);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
centerCameraRenderLoop = () => {
|
|
190
|
-
|
|
191
|
-
if (!this.positionForCameraDirty || !this.followUser || !this.position) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
this.positionForCameraDirty = false;
|
|
196
|
-
|
|
197
|
-
const center = [this.position.lng, this.position.lat];
|
|
198
|
-
let zoom = this.props.maxZoom;
|
|
199
|
-
if (this.position.accuracy) {
|
|
200
|
-
zoom = Math.min(Math.round(Math.log2(
|
|
201
|
-
Constants.R_MAJOR * Math.cos(this.position.lat / 180 * Math.PI)
|
|
202
|
-
/ this.position.accuracy
|
|
203
|
-
/ 256
|
|
204
|
-
* Math.min(this.mapContainer.offsetWidth, this.mapContainer.offsetHeight)
|
|
205
|
-
)), this.props.maxZoom);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
this.map.easeTo({
|
|
209
|
-
center,
|
|
210
|
-
zoom
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
updateAttitude(attitude) {
|
|
215
|
-
if (!this.positionIcon) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (!(attitude instanceof Attitude)) {
|
|
220
|
-
if (this.compassIcon) {
|
|
221
|
-
this.positionIcon.removeChild(this.compassIcon);
|
|
222
|
-
}
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (!this.compassIcon) {
|
|
227
|
-
this.createCompassElement();
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
this.positionIcon.style.transform
|
|
231
|
-
= 'rotate(' + attitude.headingDegrees + 'deg)';
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
renderNetwork() {
|
|
235
|
-
if (!this.map) {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const network = this.props.network;
|
|
240
|
-
|
|
241
|
-
if (network === this.previousNetwork) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
this.previousNetwork = network;
|
|
245
|
-
|
|
246
|
-
if (!network) {
|
|
247
|
-
if (this.networkLayer) {
|
|
248
|
-
this.map.removeLayer(this.networkLayer);
|
|
249
|
-
this.networkLayer = null;
|
|
250
|
-
}
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const layer = {
|
|
255
|
-
id: 'network',
|
|
256
|
-
type: 'line',
|
|
257
|
-
source: {
|
|
258
|
-
type: 'geojson',
|
|
259
|
-
data: {
|
|
260
|
-
type: 'Feature',
|
|
261
|
-
properties: {},
|
|
262
|
-
geometry: {
|
|
263
|
-
type: 'MultiLineString',
|
|
264
|
-
coordinates: []
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
paint: {
|
|
269
|
-
'line-color': '#0000FF',
|
|
270
|
-
'line-width': 3
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
for (let i = 0; i < network.edges.length; i++) {
|
|
275
|
-
layer.source.data.geometry.coordinates.push([
|
|
276
|
-
[network.edges[i].node1.coords.lng, network.edges[i].node1.coords.lat],
|
|
277
|
-
[network.edges[i].node2.coords.lng, network.edges[i].node2.coords.lat]
|
|
278
|
-
]);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
this.networkLayer = this.map.addLayer(layer);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
createUserAccuracyLayer() {
|
|
285
|
-
this.map.addSource('user-accuracy', this.userAccuracySource);
|
|
286
|
-
this.map.addLayer({
|
|
287
|
-
'id': 'user-accuracy',
|
|
288
|
-
'type': 'fill',
|
|
289
|
-
'source': 'user-accuracy',
|
|
290
|
-
'layout': {},
|
|
291
|
-
'paint': {
|
|
292
|
-
'fill-color': 'blue',
|
|
293
|
-
'fill-opacity': 0.1
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// https://stackoverflow.com/a/39006388/2239938
|
|
299
|
-
static createGeoJSONCircle(center, radiusInKm, points) {
|
|
300
|
-
if (!points) {
|
|
301
|
-
points = 64;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
var coords = {
|
|
305
|
-
latitude: center[1],
|
|
306
|
-
longitude: center[0]
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
var km = radiusInKm;
|
|
310
|
-
|
|
311
|
-
var ret = [];
|
|
312
|
-
var distanceX = km / (111.320 * Math.cos(coords.latitude * Math.PI / 180));
|
|
313
|
-
var distanceY = km / 110.574;
|
|
314
|
-
|
|
315
|
-
var theta, x, y;
|
|
316
|
-
for (let i = 0; i < points; i++) {
|
|
317
|
-
theta = (i / points) * (2 * Math.PI);
|
|
318
|
-
x = distanceX * Math.cos(theta);
|
|
319
|
-
y = distanceY * Math.sin(theta);
|
|
320
|
-
|
|
321
|
-
ret.push([coords.longitude + x, coords.latitude + y]);
|
|
322
|
-
}
|
|
323
|
-
ret.push(ret[0]);
|
|
324
|
-
return ret;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
createFollowingUser() {
|
|
328
|
-
|
|
329
|
-
const topRightContainer = document.getElementsByClassName('mapboxgl-ctrl-top-right')[0];
|
|
330
|
-
|
|
331
|
-
const container = document.createElement('div');
|
|
332
|
-
container.className = 'mapboxgl-ctrl mapboxgl-ctrl-group';
|
|
333
|
-
topRightContainer.appendChild(container);
|
|
334
|
-
|
|
335
|
-
const button = document.createElement('button');
|
|
336
|
-
button.type = 'button';
|
|
337
|
-
button.title = 'Find my location';
|
|
338
|
-
button.className = 'mapboxgl-ctrl-geolocate';
|
|
339
|
-
container.appendChild(button);
|
|
340
|
-
|
|
341
|
-
const span = document.createElement('span');
|
|
342
|
-
span.className = 'mapboxgl-ctrl-icon';
|
|
343
|
-
button.appendChild(span);
|
|
344
|
-
|
|
345
|
-
button.onclick = () => {
|
|
346
|
-
this.followUser = true;
|
|
347
|
-
this.positionForCameraDirty = true;
|
|
348
|
-
this.centerCameraRenderLoop();
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
this.map.on('dragstart', () => (this.followUser = false));
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
render() {
|
|
355
|
-
this.renderNetwork();
|
|
356
|
-
return (
|
|
357
|
-
<div ref={map => (this.mapContainer = map)}
|
|
358
|
-
style={{
|
|
359
|
-
width: '100%',
|
|
360
|
-
height: '100%'
|
|
361
|
-
}} />
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
export default MapComponent;
|