@wemap/positioning 2.4.5 → 2.4.7

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 CHANGED
@@ -8,10 +8,10 @@
8
8
  "Guillaume Pannetier <guillaume.pannetier@getwemap.com>"
9
9
  ],
10
10
  "dependencies": {
11
- "@wemap/geo": "^0.3.6",
11
+ "@wemap/geo": "^0.3.7",
12
12
  "@wemap/logger": "^0.1.6",
13
13
  "@wemap/maths": "^0.2.1",
14
- "@wemap/osm": "^0.2.8",
14
+ "@wemap/osm": "^0.2.9",
15
15
  "@wemap/utils": "^0.1.2",
16
16
  "geomagnetism": "^0.1.0",
17
17
  "lodash.isempty": "^4.4.0",
@@ -80,5 +80,5 @@
80
80
  "lint": "eslint --ext .js,.jsx --quiet src",
81
81
  "test": "mocha -r esm \"src/**/*.spec.js\""
82
82
  },
83
- "version": "2.4.5"
83
+ "version": "2.4.7"
84
84
  }
@@ -142,7 +142,7 @@ class PdrProvider extends MapMatchingProvider {
142
142
  if (position instanceof WGS84) {
143
143
  this.pdrPosition = WGS84UserPosition.fromWGS84(position);
144
144
  if (window && window.performance) {
145
- this.pdrPosition.time = window.performance / 1e3;
145
+ this.pdrPosition.time = window.performance.now() / 1e3;
146
146
  }
147
147
  } else {
148
148
  this.pdrPosition = position;
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable max-statements */
2
2
  import { WGS84UserPosition } from '@wemap/geo';
3
- import { rad2deg } from '@wemap/maths';
4
3
 
5
4
  // Generated positions by second
6
5
  const GEN_FREQUENCY = 60;
@@ -28,39 +27,42 @@ class Smoother {
28
27
  throw new Error('newPosition does not have time property');
29
28
  }
30
29
 
31
- if (this.previousPosition) {
30
+ if (!this.previousPosition) {
31
+ this.previousPosition = newPosition;
32
+ this.positionsQueue.push(this.previousPosition);
33
+ return;
34
+ }
32
35
 
33
- const distance = this.previousPosition.distanceTo(newPosition);
34
- const azimuth = this.previousPosition.bearingTo(newPosition);
36
+ const distance = this.previousPosition.distanceTo(newPosition);
37
+ const azimuth = this.previousPosition.bearingTo(newPosition);
35
38
 
36
- let refTimestamp = newPosition.time;
39
+ let refTimestamp = newPosition.time;
37
40
 
38
- const queueLength = this.positionsQueue.length;
39
- if (queueLength) {
40
- refTimestamp = Math.max(refTimestamp, this.positionsQueue[queueLength - 1].time);
41
- }
41
+ const queueLength = this.positionsQueue.length;
42
+ if (queueLength) {
43
+ refTimestamp = Math.max(refTimestamp, this.positionsQueue[queueLength - 1].time);
44
+ }
42
45
 
43
- let diffTime = newPosition.time - this.previousPosition.time;
46
+ let diffTime = newPosition.time - this.previousPosition.time;
44
47
 
45
- if (flyby) {
46
- diffTime = MAX_FLYBY_TIME;
47
- }
48
+ if (flyby) {
49
+ diffTime = MAX_FLYBY_TIME;
50
+ }
48
51
 
49
- const nSamples = GEN_FREQUENCY * Math.min(Math.max(MIN_FLYBY_TIME, diffTime), MAX_FLYBY_TIME);
52
+ const nSamples = GEN_FREQUENCY * Math.min(Math.max(MIN_FLYBY_TIME, diffTime), MAX_FLYBY_TIME);
50
53
 
51
- let i = 1;
52
- while (i < nSamples) {
53
- i = Math.min(i, nSamples);
54
- const smoothedPosition = this.previousPosition.destinationPoint(distance * i / nSamples, azimuth);
55
- smoothedPosition.time = refTimestamp + (i - 1) / GEN_FREQUENCY;
56
- smoothedPosition.bearing = rad2deg(azimuth);
57
- this.positionsQueue.push(smoothedPosition);
58
- i++;
59
- }
60
- newPosition.bearing = rad2deg(azimuth);
54
+ let i = 1;
55
+ while (i < nSamples + 1) {
56
+ i = Math.min(i, nSamples);
57
+ const smoothedPosition = this.previousPosition.destinationPoint(distance * i / nSamples, azimuth);
58
+ smoothedPosition.time = refTimestamp + (i - 1) / GEN_FREQUENCY;
59
+ smoothedPosition.bearing = newPosition.bearing;
60
+ this.positionsQueue.push(smoothedPosition);
61
+ i++;
61
62
  }
62
63
 
63
- this.positionsQueue.push(newPosition);
64
+ this.positionsQueue[this.positionsQueue.length - 1].level = newPosition.level;
65
+
64
66
  this.previousPosition = newPosition;
65
67
  }
66
68