@wemap/positioning 2.2.0 → 2.3.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.
@@ -1,7 +1,7 @@
1
1
  /* eslint max-statements: ["error", 27]*/
2
2
  import { WGS84UserPosition } from '@wemap/geo';
3
3
 
4
- // Generated locations by second
4
+ // Generated positions by second
5
5
  const GEN_FREQUENCY = 60;
6
6
 
7
7
  // Min and max time for flyby (in second)
@@ -11,40 +11,40 @@ const MAX_FLYBY_TIME = 1;
11
11
  class Smoother {
12
12
 
13
13
  constructor() {
14
- this.locationsQueue = [];
14
+ this.positionsQueue = [];
15
15
  }
16
16
 
17
17
  /**
18
- * Calculate smoothed positions for the next milliseconds given a new location
18
+ * Calculate smoothed positions for the next milliseconds given a new position
19
19
  */
20
- generateNextLocations(_newLocation, flyby = false) {
20
+ generateNextPositions(_newPosition, flyby = false) {
21
21
 
22
- if (!(_newLocation instanceof WGS84UserPosition)) {
23
- throw new TypeError('newLocation is not instance of WGS84UserPosition');
22
+ if (!(_newPosition instanceof WGS84UserPosition)) {
23
+ throw new TypeError('newPosition is not instance of WGS84UserPosition');
24
24
  }
25
25
 
26
- const newLocation = _newLocation.clone();
27
- if (!newLocation.hasOwnProperty('time')) {
28
- throw new Error('newLocation does not have time property');
26
+ const newPosition = _newPosition.clone();
27
+ if (!newPosition.hasOwnProperty('time')) {
28
+ throw new Error('newPosition does not have time property');
29
29
  }
30
30
 
31
- if (!this.previousLocation) {
32
- this.previousLocation = newLocation;
33
- this.locationsQueue.push(this.previousLocation);
31
+ if (!this.previousPosition) {
32
+ this.previousPosition = newPosition;
33
+ this.positionsQueue.push(this.previousPosition);
34
34
  return;
35
35
  }
36
36
 
37
- const distance = this.previousLocation.distanceTo(newLocation);
38
- const azimuth = this.previousLocation.bearingTo(newLocation);
37
+ const distance = this.previousPosition.distanceTo(newPosition);
38
+ const azimuth = this.previousPosition.bearingTo(newPosition);
39
39
 
40
- let refTimestamp = newLocation.time;
40
+ let refTimestamp = newPosition.time;
41
41
 
42
- const queueLength = this.locationsQueue.length;
42
+ const queueLength = this.positionsQueue.length;
43
43
  if (queueLength) {
44
- refTimestamp = Math.max(refTimestamp, this.locationsQueue[queueLength - 1].time);
44
+ refTimestamp = Math.max(refTimestamp, this.positionsQueue[queueLength - 1].time);
45
45
  }
46
46
 
47
- let diffTime = newLocation.time - this.previousLocation.time;
47
+ let diffTime = newPosition.time - this.previousPosition.time;
48
48
 
49
49
  if (flyby) {
50
50
  diffTime = MAX_FLYBY_TIME;
@@ -55,34 +55,34 @@ class Smoother {
55
55
  let i = 1;
56
56
  while (i < nSamples + 1) {
57
57
  i = Math.min(i, nSamples);
58
- const smoothedLocation = this.previousLocation.destinationPoint(distance * i / nSamples, azimuth);
59
- smoothedLocation.time = refTimestamp + (i - 1) / GEN_FREQUENCY;
60
- this.locationsQueue.push(smoothedLocation);
58
+ const smoothedPosition = this.previousPosition.destinationPoint(distance * i / nSamples, azimuth);
59
+ smoothedPosition.time = refTimestamp + (i - 1) / GEN_FREQUENCY;
60
+ this.positionsQueue.push(smoothedPosition);
61
61
  i++;
62
62
  }
63
63
 
64
- this.previousLocation = newLocation;
64
+ this.previousPosition = newPosition;
65
65
  }
66
66
 
67
67
  /**
68
- * Pull locations until timestamp and return the last one.
69
- * @param {*} timestamp location returned is the last before this timestamp
70
- * @returns last known location before timestamp, undefined otherwise
68
+ * Pull positions until timestamp and return the last one.
69
+ * @param {*} timestamp position returned is the last before this timestamp
70
+ * @returns last known position before timestamp, undefined otherwise
71
71
  */
72
- pullLocation(timestamp) {
72
+ pullPosition(timestamp) {
73
73
 
74
74
  if ((typeof timestamp === 'undefined' || !timestamp)
75
- && this.locationsQueue.length > 0) {
76
- const output = this.locationsQueue[this.locationsQueue.length - 1];
77
- this.locationsQueue = [];
75
+ && this.positionsQueue.length > 0) {
76
+ const output = this.positionsQueue[this.positionsQueue.length - 1];
77
+ this.positionsQueue = [];
78
78
  return output;
79
79
  }
80
80
 
81
- let location;
82
- while (this.locationsQueue.length && this.locationsQueue[0].time <= timestamp) {
83
- location = this.locationsQueue.shift();
81
+ let position;
82
+ while (this.positionsQueue.length && this.positionsQueue[0].time <= timestamp) {
83
+ position = this.positionsQueue.shift();
84
84
  }
85
- return location;
85
+ return position;
86
86
  }
87
87
 
88
88
  }
@@ -388,10 +388,10 @@ describe('validSmoother', () => {
388
388
  for (let i = 0; i < positions.length; i++) {
389
389
  const pos = new WGS84UserPosition(positions[i][1], positions[i][2]);
390
390
  pos.time = positions[i][0];
391
- smoother.generateNextLocations(pos, positions[i][3]);
391
+ smoother.generateNextPositions(pos, positions[i][3]);
392
392
  }
393
393
 
394
- const predicted = smoother.locationsQueue;
394
+ const predicted = smoother.positionsQueue;
395
395
  expect(predicted.length).to.equal(expectations.length);
396
396
 
397
397
  for (let i = 0; i < predicted.length; i++) {
@@ -401,8 +401,8 @@ describe('validSmoother', () => {
401
401
  expect(timeDiff).to.almost.equal(0);
402
402
  }
403
403
 
404
- const locationAt10 = smoother.pullLocation(10);
405
- expect(locationAt10.distanceTo(new WGS84(3.7669421260460435E-5, 2.5766995044818355E-5))).to.almost.equal(0);
404
+ const positionAt10 = smoother.pullPosition(10);
405
+ expect(positionAt10.distanceTo(new WGS84(3.7669421260460435E-5, 2.5766995044818355E-5))).to.almost.equal(0);
406
406
  });
407
407
  });
408
408
 
@@ -413,12 +413,12 @@ describe('smoother return same value if unique', () => {
413
413
  const smoother = new Smoother();
414
414
 
415
415
  const pos = new WGS84UserPosition(positions[0][1], positions[0][2]);
416
- smoother.generateNextLocations(pos);
417
- const posExpected = smoother.pullLocation();
416
+ smoother.generateNextPositions(pos);
417
+ const posExpected = smoother.pullPosition();
418
418
 
419
419
  expect(posExpected).to.be.an.instanceof(WGS84UserPosition);
420
420
  expect(posExpected.distanceTo(pos)).to.almost.equal(0);
421
- expect(smoother.locationsQueue).to.be.an('array').that.is.empty;
421
+ expect(smoother.positionsQueue).to.be.an('array').that.is.empty;
422
422
  });
423
423
  });
424
424
 
@@ -78,8 +78,8 @@ class GnssWifiProvider extends Provider {
78
78
  /**
79
79
  * @private
80
80
  */
81
- onNewPosition = position => {
82
- const { coords } = position;
81
+ onNewPosition = geolocation => {
82
+ const { coords } = geolocation;
83
83
  if (!coords) {
84
84
  return;
85
85
  }
@@ -89,9 +89,9 @@ class GnssWifiProvider extends Provider {
89
89
  bearing = deg2rad(coords.heading);
90
90
  }
91
91
 
92
- const timestamp = DateUtils.unixTimestampToPerformanceNow(position.timestamp) / 1e3;
92
+ const timestamp = DateUtils.unixTimestampToPerformanceNow(geolocation.timestamp) / 1e3;
93
93
 
94
- const location = new WGS84UserPosition(
94
+ const position = new WGS84UserPosition(
95
95
  coords.latitude,
96
96
  coords.longitude,
97
97
  coords.altitude,
@@ -101,7 +101,7 @@ class GnssWifiProvider extends Provider {
101
101
  GnssWifiProvider.name);
102
102
 
103
103
  this.notify(this.createEvent(
104
- EventType.AbsolutePosition, location, timestamp
104
+ EventType.AbsolutePosition, position, timestamp
105
105
  ));
106
106
 
107
107
  };
@@ -10,7 +10,7 @@ import IpResolveServerError from '../../errors/IpResolveServerError';
10
10
  * by Wifi Fingerprinting algorithms or by GNSS. That is why the name is
11
11
  * "GnssWifi".
12
12
  */
13
- class GnssWifiProvider extends Provider {
13
+ class IpProvider extends Provider {
14
14
 
15
15
  /**
16
16
  * @override
@@ -72,4 +72,4 @@ class GnssWifiProvider extends Provider {
72
72
 
73
73
  }
74
74
 
75
- export default GnssWifiProvider;
75
+ export default IpProvider;