@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.
Files changed (99) hide show
  1. package/.eslintrc.json +4 -2
  2. package/debug/absolute-attitude.html +16 -0
  3. package/debug/arcore.html +16 -0
  4. package/debug/gnss-wifi-pdr.html +16 -0
  5. package/debug/gnss-wifi.html +16 -0
  6. package/debug/imu.html +16 -0
  7. package/debug/inclination.html +16 -0
  8. package/debug/pdr.html +16 -0
  9. package/debug/pose.html +16 -0
  10. package/debug/positioning.html +16 -0
  11. package/debug/relative-attitude.html +16 -0
  12. package/package.json +7 -4
  13. package/src/PositioningHandler.js +96 -34
  14. package/src/components/AbsoluteAttitudeComponent.jsx +104 -0
  15. package/src/components/ArCoreComponent.jsx +74 -0
  16. package/src/components/GnssWifiComponent.jsx +58 -0
  17. package/src/components/GnssWifiPdrComponent.jsx +94 -0
  18. package/src/components/ImuComponent.jsx +100 -0
  19. package/src/components/InclinationComponent.jsx +53 -0
  20. package/src/components/MapComponent.jsx +226 -0
  21. package/src/components/PdrComponent.jsx +97 -0
  22. package/src/components/PoseComponent.jsx +81 -0
  23. package/src/components/PositioningComponent.jsx +26 -0
  24. package/src/components/PositioningInclinationComponent.jsx +76 -0
  25. package/src/components/PositioningPoseComponent.jsx +120 -0
  26. package/src/components/RelativeAttitudeComponent.jsx +82 -0
  27. package/src/components/StartStopComponent.jsx +50 -0
  28. package/src/components/Utils.js +92 -0
  29. package/src/components/index.js +32 -0
  30. package/src/errors/AskImuOnDesktopError.js +9 -0
  31. package/src/errors/GeolocationApiMissingError.js +9 -0
  32. package/src/errors/GeolocationPermissionDeniedError.js +9 -0
  33. package/src/errors/GeolocationPositionUnavailableError.js +9 -0
  34. package/src/errors/IpResolveServerError.js +9 -0
  35. package/src/errors/MissingAccelerometerError.js +11 -0
  36. package/src/errors/MissingArCoreError.js +9 -0
  37. package/src/errors/MissingGyroscopeError.js +11 -0
  38. package/src/errors/MissingMagnetometerError.js +9 -0
  39. package/src/errors/MissingNativeInterfaceError.js +9 -0
  40. package/src/errors/MissingSensorError.js +14 -0
  41. package/src/events/EventType.js +20 -0
  42. package/src/events/ProviderError.js +52 -0
  43. package/src/events/ProviderEvent.js +35 -0
  44. package/src/index.js +2 -2
  45. package/src/providers/Constants.js +5 -0
  46. package/src/providers/FakeAbsolutePositionProvider.js +56 -0
  47. package/src/providers/Provider.js +230 -0
  48. package/src/providers/ProviderOptions.js +28 -0
  49. package/{src.old → src}/providers/ProvidersLogger.js +2 -2
  50. package/src/providers/attitude/AbsoluteAttitudeProvider.js +207 -0
  51. package/src/providers/attitude/RelativeAttitudeProvider.js +129 -0
  52. package/src/providers/others/ImuProvider.js +186 -0
  53. package/src/providers/others/InclinationProvider.js +107 -0
  54. package/{src.old/providers/LocationSource.js → src/providers/others/MapMatchingProvider.js} +5 -148
  55. package/src/providers/pose/ArCoreProvider.js +127 -0
  56. package/src/providers/pose/GnssWifiPdrProvider.js +233 -0
  57. package/src/providers/pose/PoseProvider.js +90 -0
  58. package/{src.old/providers/PdrLocationSource.js → src/providers/pose/pdr/PdrProvider.js} +145 -113
  59. package/{src.old/providers/pdr → src/providers/pose/pdr/helpers}/Smoother.js +1 -1
  60. package/src/providers/position/GnssWifiProvider.js +129 -0
  61. package/src/providers/position/IpProvider.js +75 -0
  62. package/webpack/webpack.common.js +1 -1
  63. package/webpack/webpack.dev.js +1 -1
  64. package/debug/index.html +0 -15
  65. package/debug/index.old.html +0 -37
  66. package/scripts/release-github.js +0 -216
  67. package/src/providers/FakeLocationSource.js +0 -36
  68. package/src.old/Constants.js +0 -11
  69. package/src.old/NavigationHandler.js +0 -244
  70. package/src.old/Pose.js +0 -8
  71. package/src.old/attitude/AttitudeHandler.js +0 -342
  72. package/src.old/components/AbsoluteAttitude.jsx +0 -136
  73. package/src.old/components/Imu.jsx +0 -89
  74. package/src.old/components/LocationSource.jsx +0 -434
  75. package/src.old/components/Logger.jsx +0 -113
  76. package/src.old/components/NavigationDebugApp.jsx +0 -106
  77. package/src.old/components/Others.jsx +0 -121
  78. package/src.old/components/RelativeAttitude.jsx +0 -104
  79. package/src.old/components/Utils.js +0 -35
  80. package/src.old/components/index.js +0 -13
  81. package/src.old/index.js +0 -7
  82. package/src.old/providers/FixedLocationImuLocationSource.js +0 -66
  83. package/src.old/providers/GnssLocationSource.js +0 -118
  84. package/src.old/providers/GnssPdrLocationSource.js +0 -182
  85. package/src.old/providers/IPLocationSource.js +0 -96
  86. package/src.old/sensors/SensorsCompatibility.js +0 -486
  87. package/src.old/sensors/SensorsCompatibility.spec.js +0 -270
  88. package/src.old/sensors/SensorsLogger.js +0 -94
  89. package/src.old/sensors/SensorsLoggerUtils.js +0 -35
  90. /package/{src.old → src/providers}/attitude/EkfAttitude.js +0 -0
  91. /package/{src.old → src/providers}/attitude/EkfAttitude.spec.js +0 -0
  92. /package/{src.old/providers/pdr → src/providers/pose/pdr/helpers}/HeadingUnlocker.js +0 -0
  93. /package/{src.old/providers/pdr → src/providers/pose/pdr/helpers}/HeadingUnlocker.spec.js +0 -0
  94. /package/{src.old/providers/pdr → src/providers/pose/pdr/helpers}/Smoother.spec.js +0 -0
  95. /package/{src.old/providers/pdr → src/providers/pose/pdr/helpers}/ThugDetector.js +0 -0
  96. /package/{src.old/providers → src/providers/pose/pdr}/steps/StepDetection.js +0 -0
  97. /package/{src.old/providers → src/providers/pose/pdr}/steps/StepDetectionLadetto.js +0 -0
  98. /package/{src.old/providers → src/providers/pose/pdr}/steps/StepDetectionMinMaxPeaks.js +0 -0
  99. /package/{src.old/providers → src/providers/pose/pdr}/steps/StepDetectionMinMaxPeaks2.js +0 -0
@@ -1,5 +1,5 @@
1
1
  /* eslint max-statements: ["error", 27]*/
2
- import {WGS84UserPosition} from '@wemap/geo';
2
+ import { WGS84UserPosition } from '@wemap/geo';
3
3
 
4
4
  // Generated locations by second
5
5
  const GEN_FREQUENCY = 60;
@@ -0,0 +1,129 @@
1
+ import { deg2rad } from '@wemap/maths';
2
+ import { WGS84UserPosition } from '@wemap/geo';
3
+ import { DateUtils } from '@wemap/utils';
4
+
5
+ import EventType from '../../events/EventType';
6
+ import GeolocationApiMissingError from '../../errors/GeolocationApiMissingError';
7
+ import Provider from '../Provider';
8
+ import GeolocationPermissionDeniedError from '../../errors/GeolocationPermissionDeniedError';
9
+ import GeolocationPositionUnavailableError from '../../errors/GeolocationPositionUnavailableError';
10
+
11
+ const POSITION_OPTIONS = {
12
+ enableHighAccuracy: true,
13
+ timeout: Infinity,
14
+ maximumAge: 0
15
+ };
16
+
17
+ /**
18
+ * GnssWifiProvider is a provider based on navigator.geolocation.
19
+ * This API does not allow us to know if the position returned is provided
20
+ * by Wifi Fingerprinting algorithms or by GNSS. That is why the name is
21
+ * "GnssWifi".
22
+ */
23
+ class GnssWifiProvider extends Provider {
24
+
25
+ /**
26
+ * @override
27
+ */
28
+ static get displayName() {
29
+ return 'GNSS / Wifi from Browser';
30
+ }
31
+
32
+ /**
33
+ * @override
34
+ */
35
+ static get eventsType() {
36
+ return [EventType.AbsolutePosition];
37
+ }
38
+
39
+ /**
40
+ * @override
41
+ */
42
+ static checkAvailabilityErrors() {
43
+
44
+ if (navigator && navigator.geolocation) {
45
+ return [];
46
+ }
47
+
48
+ return [
49
+ GnssWifiProvider.createError(
50
+ EventType.AbsolutePosition,
51
+ new GeolocationApiMissingError()
52
+ )
53
+ ];
54
+ }
55
+
56
+ /**
57
+ * @override
58
+ */
59
+ startInternal() {
60
+
61
+ this.geoLocationId = navigator.geolocation.watchPosition(
62
+ this.onNewPosition,
63
+ this.onPositionError,
64
+ POSITION_OPTIONS
65
+ );
66
+
67
+ }
68
+
69
+ /**
70
+ * @override
71
+ */
72
+ stopInternal() {
73
+
74
+ navigator.geolocation.clearWatch(this.geoLocationId);
75
+
76
+ }
77
+
78
+ /**
79
+ * @private
80
+ */
81
+ onNewPosition = position => {
82
+ const { coords } = position;
83
+ if (!coords) {
84
+ return;
85
+ }
86
+
87
+ let bearing;
88
+ if (coords.heading) {
89
+ bearing = deg2rad(coords.heading);
90
+ }
91
+
92
+ const timestamp = DateUtils.unixTimestampToPerformanceNow(position.timestamp) / 1e3;
93
+
94
+ const location = new WGS84UserPosition(
95
+ coords.latitude,
96
+ coords.longitude,
97
+ coords.altitude,
98
+ timestamp,
99
+ coords.accuracy,
100
+ bearing,
101
+ GnssWifiProvider.name);
102
+
103
+ this.notify(this.createEvent(
104
+ EventType.AbsolutePosition, location, timestamp
105
+ ));
106
+
107
+ };
108
+
109
+ onPositionError = error => {
110
+
111
+ let customError;
112
+ switch (error.code) {
113
+ case 1:
114
+ customError = new GeolocationPermissionDeniedError(error.message);
115
+ break;
116
+ case 2:
117
+ customError = new GeolocationPositionUnavailableError(error.message);
118
+ }
119
+
120
+ if (customError) {
121
+ this.notifyError(this.createError(
122
+ EventType.AbsolutePosition,
123
+ customError
124
+ ));
125
+ }
126
+ };
127
+ }
128
+
129
+ export default GnssWifiProvider;
@@ -0,0 +1,75 @@
1
+ import { WGS84UserPosition } from '@wemap/geo';
2
+
3
+ import EventType from '../../events/EventType';
4
+ import Provider from '../Provider';
5
+ import IpResolveServerError from '../../errors/IpResolveServerError';
6
+
7
+ /**
8
+ * GnssWifiProvider is a provider based on navigator.geolocation.
9
+ * This API does not allow us to know if the position returned is provided
10
+ * by Wifi Fingerprinting algorithms or by GNSS. That is why the name is
11
+ * "GnssWifi".
12
+ */
13
+ class GnssWifiProvider extends Provider {
14
+
15
+ /**
16
+ * @override
17
+ */
18
+ static get displayName() {
19
+ return 'IP from ipinfo.io';
20
+ }
21
+
22
+ /**
23
+ * @override
24
+ */
25
+ static get eventsType() {
26
+ return [EventType.AbsolutePosition];
27
+ }
28
+
29
+ /**
30
+ * @override
31
+ */
32
+ static checkAvailabilityErrors() {
33
+ return [];
34
+ }
35
+
36
+ /**
37
+ * @override
38
+ */
39
+ startInternal() {
40
+
41
+ fetch('https://ipinfo.io/geo?token=24a7ca2f3b489d')
42
+ .then((response) => {
43
+ if (!response) {
44
+ this.notifyError(this.createError(
45
+ EventType.AbsolutePosition,
46
+ new IpResolveServerError()
47
+ ));
48
+ return;
49
+ }
50
+
51
+ const timestamp = performance.now() / 1e3;
52
+
53
+ const position = new WGS84UserPosition(
54
+ parseFloat(response.loc.split(',')[0]),
55
+ parseFloat(response.loc.split(',')[1]),
56
+ null,
57
+ timestamp
58
+ );
59
+
60
+ this.notify(this.createEvent(
61
+ EventType.AbsolutePosition, position, timestamp
62
+ ));
63
+ });
64
+ }
65
+
66
+ /**
67
+ * @override
68
+ */
69
+ stopInternal() {
70
+
71
+ }
72
+
73
+ }
74
+
75
+ export default GnssWifiProvider;
@@ -12,7 +12,7 @@ module.exports = {
12
12
  },
13
13
  {
14
14
  test: /\.css$/,
15
- use: { loader: 'css-loader' }
15
+ use: ['style-loader', 'css-loader']
16
16
  }
17
17
  ]
18
18
  },
@@ -7,7 +7,7 @@ const debugFolder = path.join(__dirname, '../debug');
7
7
 
8
8
  module.exports = merge(common, {
9
9
  mode: 'development',
10
- entry: { 'navigation-components': './src/components/index.js' },
10
+ entry: { 'positioning-components': './src/components/index.js' },
11
11
  output: {
12
12
  publicPath: '/js/',
13
13
  filename: '[name].js',
package/debug/index.html DELETED
@@ -1,15 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
-
4
- <head>
5
- <meta charset="utf-8">
6
- <title>Debug navigation</title>
7
- <script src="/js/navigation-components.js"></script>
8
- </head>
9
-
10
- <body>
11
- <div id="app"></div>
12
- <script>createReactElement(NavigationDebugApp, document.getElementById('app'));</script>
13
- </body>
14
-
15
- </html>
@@ -1,37 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
-
4
- <head>
5
- <meta charset="utf-8">
6
-
7
- <title>Positioning</title>
8
-
9
- <script src="/js/navigation.js"></script>
10
-
11
- </head>
12
-
13
- <body>
14
- Hello world !
15
-
16
- <script>
17
- const navHandler = new NavigationHandler(pose => console.log(pose));
18
-
19
- navHandler.startIfNecessary()
20
- .then(() => {
21
- console.log('Navigation started');
22
- });
23
-
24
- setTimeout(() => {
25
- navHandler.startIfNecessary();
26
- }, 3000);
27
-
28
- setTimeout(() => {
29
- navHandler.stop()
30
- .then(() => {
31
- console.log('Navigation stopped');
32
- });
33
- }, 5000);
34
- </script>
35
- </body>
36
-
37
- </html>
@@ -1,216 +0,0 @@
1
- const dotenv = require('dotenv');
2
- const fs = require('fs');
3
- const git = require('simple-git/promise')('.').silent(true);
4
- const path = require('path');
5
- const npm = require('npm');
6
- const requestp = require('request-promise');
7
-
8
- const config = require('../config.json');
9
-
10
- /**
11
- * Check GITHUB_TOKEN in .env file
12
- */
13
- const result = dotenv.config();
14
- if (result.error) {
15
- console.error('.env does not exist. '
16
- + 'You have to create a .env file at the root directory');
17
- return;
18
- }
19
- const ENV = result.parsed;
20
- if (!ENV.GITHUB_TOKEN) {
21
- console.error('GITHUB_TOKEN does not exist in .env file. '
22
- + 'More info here: https://github.com/settings/tokens');
23
- return;
24
- }
25
-
26
- /**
27
- * Github Url and Headers
28
- */
29
-
30
- const GITHUB_API_URL = 'https://api.github.com';
31
- const GITHUB_UPLOAD_URL = 'https://uploads.github.com';
32
-
33
- const HEADERS = {
34
- 'Authorization': 'token ' + ENV.GITHUB_TOKEN,
35
- 'User-Agent': 'NodeJS/Release-' + config.githubRepoName
36
- };
37
-
38
- function checkGithubToken() {
39
-
40
- const uri = GITHUB_API_URL;
41
- const headers = HEADERS;
42
-
43
- return requestp({
44
- method: 'GET',
45
- uri,
46
- headers,
47
- json: true
48
- }).catch(e => {
49
- return Promise.reject(e.message);
50
- });
51
- }
52
-
53
- function createRelease(version) {
54
-
55
- const uri = GITHUB_API_URL + '/repos/' + config.githubRepoOwner + '/'
56
- + config.githubRepoName + '/releases';
57
- const headers = Object.assign({ 'Content-Type': 'application/json' }, HEADERS);
58
- const inputData = {
59
- 'tag_name': version,
60
- 'target_commitish': 'master',
61
- 'name': version
62
- };
63
-
64
- return requestp({
65
- method: 'POST',
66
- uri,
67
- headers,
68
- body: inputData,
69
- json: true
70
- }).catch(e => {
71
- return Promise.reject(e.message);
72
- });
73
- }
74
-
75
-
76
- function uploadFile(releaseId, fileName, filePath) {
77
-
78
- const stats = fs.statSync(filePath);
79
- const fileSizeInBytes = stats.size;
80
-
81
- const uri = GITHUB_UPLOAD_URL + '/repos/' + config.githubRepoOwner + '/'
82
- + config.githubRepoName + '/releases/' + releaseId
83
- + '/assets?name=' + fileName;
84
-
85
- const headers = Object.assign({
86
- 'Content-Type': 'application/javascript',
87
- 'Content-length': fileSizeInBytes
88
- }, HEADERS);
89
-
90
- return requestp({
91
- method: 'POST',
92
- uri,
93
- headers,
94
- body: fs.createReadStream(filePath)
95
- }).catch(e => {
96
- return e.message;
97
- });
98
- }
99
-
100
- function revertNpmVersion() {
101
- return git.reset(['--hard', 'HEAD^1'])
102
- .then(() => git.tag(['-d', 'v1.1.0']))
103
- .catch(err => console.error(err));
104
- }
105
-
106
- const npmLoaderPromise = new Promise((resolve, reject) => {
107
- npm.load(err => {
108
- if (err) {
109
- reject(err);
110
- } else {
111
- resolve();
112
- }
113
- });
114
- });
115
-
116
-
117
- function main() {
118
-
119
- const versionsList = ['minor', 'major', 'patch'];
120
-
121
- let isVersionCreated = false;
122
- const isPushed = false;
123
-
124
- Promise.resolve()
125
- // Check github token as soon as possible to avoid to revert a push
126
- .then(checkGithubToken)
127
-
128
- // Check if current branch name corresponds to "releaseBranch"
129
- .then(async () => {
130
- const res = await git.raw(['rev-parse', '--abbrev-ref', 'HEAD']);
131
- if (res.trim() !== config.releaseBranch) {
132
- return Promise.reject('You are not on the ' + config.releaseBranch + ' branch');
133
- }
134
- return Promise.resolve();
135
- })
136
-
137
- // Check if git repo is clean before running npm version
138
- .then(async () => {
139
- const res = await git.raw(['status', '--porcelain']);
140
- if (res) {
141
- return Promise.reject('Your git working directory not clean');
142
- }
143
- return Promise.resolve();
144
- })
145
-
146
- // Update npm version with npm version argv[2]
147
- .then(async () => {
148
- const args = process.argv;
149
- if (args.length < 3) {
150
- throw new Error('version argument is missing');
151
- }
152
- if (!versionsList.includes(args[2])) {
153
- throw new Error('version argument is unknown, it should be: ' + versionsList.join(','));
154
- }
155
-
156
- await npmLoaderPromise;
157
- return new Promise((resolve, reject) => {
158
- npm.commands.version([args[2]], err => {
159
- if (err) {
160
- reject(err);
161
- } else {
162
- isVersionCreated = true;
163
- resolve();
164
- }
165
- });
166
- });
167
- })
168
-
169
- // Build the project in production mode
170
- .then(async () => {
171
- await npmLoaderPromise;
172
- return new Promise((resolve, reject) => {
173
- npm.commands.run(['build'], err => {
174
- if (err) {
175
- reject(err);
176
- } else {
177
- resolve();
178
- }
179
- });
180
- });
181
- })
182
-
183
- // Push release to origin
184
- .then(() => git.push('origin', config.releaseBranch, ['--tags']))
185
-
186
- // Get tag name
187
- .then(async () => {
188
- const res = await git.raw(['describe']);
189
- // TODO this condition can be improved
190
- if (!res || res[0] !== 'v') {
191
- return Promise.reject('Could not find tag name');
192
- }
193
- return Promise.resolve(res.trim());
194
- })
195
-
196
- // Create the release
197
- .then((tagName) => createRelease(tagName))
198
-
199
- // Upload file
200
- .then(response => {
201
- const filePath = path.join(config.distFolder, config.distFileName);
202
- uploadFile(response.id, config.distFileName, filePath);
203
- })
204
-
205
- .then(() => {
206
- console.log('Release finished with success');
207
- })
208
- .catch(e => {
209
- if (isVersionCreated && !isPushed) {
210
- revertNpmVersion();
211
- }
212
- console.error('error', e);
213
- });
214
- }
215
-
216
- main();
@@ -1,36 +0,0 @@
1
- import noop from 'lodash.noop';
2
- import {
3
- WGS84, Attitude
4
- } from '@wemap/geo';
5
-
6
- /**
7
- * @private
8
- */
9
- class FakeLocationSource {
10
-
11
- constructor(callback) {
12
- this.callback = callback || noop;
13
- }
14
-
15
- start() {
16
- this.interval = setInterval(() => {
17
- this.callback({
18
- location: new WGS84(45, 5),
19
- attitude: new Attitude([1, 0, 0, 0])
20
- });
21
- }, 1000);
22
-
23
- return Promise.resolve();
24
- }
25
-
26
- stop() {
27
- if (this.interval) {
28
- clearInterval(this.interval);
29
- this.interval = null;
30
- }
31
- return Promise.resolve();
32
- }
33
-
34
- }
35
-
36
- export default FakeLocationSource;
@@ -1,11 +0,0 @@
1
- const Constants = {
2
- LOCATION_SOURCE_PROVIDERS: {
3
- IP: 'IP',
4
- GNSS: 'GNSS/WIFI',
5
- PDR: 'PDR',
6
- GNSS_PDR: 'GNSS/WIFI-PDR',
7
- FIXED_LOCATION: 'FIXED_LOCATION'
8
- }
9
- };
10
-
11
- export default Constants;