@wemap/positioning 2.2.0 → 2.3.1

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.
@@ -32,10 +32,10 @@ const DEFAULT_OPTIONS = {
32
32
 
33
33
  class PdrProvider extends MapMatchingProvider {
34
34
 
35
- // pdrLocation can be different from this.location
36
- // pdrLocation is raw location calculated by PdrProvider where
37
- // this.location is smoothed location.
38
- pdrLocation = null;
35
+ // pdrPosition can be different from this.position
36
+ // pdrPosition is raw position calculated by PdrProvider where
37
+ // this.position is smoothed position.
38
+ pdrPosition = null;
39
39
 
40
40
  /**
41
41
  * @override
@@ -127,18 +127,18 @@ class PdrProvider extends MapMatchingProvider {
127
127
  this.relativeAttitudeProvider.setOffset(heading);
128
128
  }
129
129
 
130
- setLocation(location) {
131
- this.pdrLocation = location;
130
+ setPosition(position) {
131
+ this.pdrPosition = position;
132
132
 
133
133
  if (this.options.smoother) {
134
- this.smoother.generateNextLocations(location, true);
135
- // this.smoother.pullLocation(location.time) should never return null
136
- this.location = this.smoother.pullLocation(location.time);
134
+ this.smoother.generateNextPositions(position, true);
135
+ // this.smoother.pullPosition(position.time) should never return null
136
+ this.position = this.smoother.pullPosition(position.time);
137
137
  } else {
138
- this.location = location.clone();
138
+ this.position = position.clone();
139
139
  }
140
140
 
141
- this.notify(this.createEvent(EventType.AbsolutePosition, this.location));
141
+ this.notify(this.createEvent(EventType.AbsolutePosition, this.position));
142
142
  }
143
143
 
144
144
  /**
@@ -163,8 +163,8 @@ class PdrProvider extends MapMatchingProvider {
163
163
  return;
164
164
  }
165
165
 
166
- if (!this.pdrLocation) {
167
- // We should wait at least an input location for PDR
166
+ if (!this.pdrPosition) {
167
+ // We should wait at least an input position for PDR
168
168
  return;
169
169
  }
170
170
 
@@ -201,36 +201,36 @@ class PdrProvider extends MapMatchingProvider {
201
201
 
202
202
  if (stepDetected) {
203
203
 
204
- this.pdrLocation = this.calculateNewLocation(this.pdrLocation, timestamp,
204
+ this.pdrPosition = this.calculateNewPosition(this.pdrPosition, timestamp,
205
205
  heading, this.stepDetection.lastStepSize);
206
206
 
207
207
  /**
208
208
  * Update current_position
209
209
  */
210
210
  if (this.options.smoother) {
211
- this.smoother.generateNextLocations(this.pdrLocation);
212
- const newLocation = this.smoother.pullLocation(timestamp);
213
- // At this time, newLocation can be null if a new step has been detected
211
+ this.smoother.generateNextPositions(this.pdrPosition);
212
+ const newPosition = this.smoother.pullPosition(timestamp);
213
+ // At this time, newPosition can be null if a new step has been detected
214
214
  // and smoother has not been completely consumed.
215
- if (newLocation) {
216
- this.location = newLocation;
215
+ if (newPosition) {
216
+ this.position = newPosition;
217
217
  }
218
218
  } else {
219
- this.location = this.pdrLocation;
219
+ this.position = this.pdrPosition;
220
220
  }
221
221
 
222
222
  } else if (this.options.smoother) {
223
- // If no step is detected, we pull last known location from smoother until now (timestamp).
224
- const smoothedLocation = this.smoother.pullLocation(timestamp);
225
- if (!smoothedLocation) {
223
+ // If no step is detected, we pull last known position from smoother until now (timestamp).
224
+ const smoothedPosition = this.smoother.pullPosition(timestamp);
225
+ if (!smoothedPosition) {
226
226
  return;
227
227
  }
228
- this.location = smoothedLocation;
228
+ this.position = smoothedPosition;
229
229
  } else {
230
230
  return;
231
231
  }
232
232
 
233
- this.notify(this.createEvent(EventType.AbsolutePosition, this.location));
233
+ this.notify(this.createEvent(EventType.AbsolutePosition, this.position));
234
234
  }
235
235
 
236
236
  onProviderError(errors) {
@@ -254,39 +254,39 @@ class PdrProvider extends MapMatchingProvider {
254
254
  );
255
255
  }
256
256
 
257
- calculateNewLocation(previousLocation, timestamp, heading, stepSize) {
257
+ calculateNewPosition(previousPosition, timestamp, heading, stepSize) {
258
258
 
259
259
  /**
260
260
  * Compute new_position
261
261
  */
262
- const newLocationWithoutMM = previousLocation.clone();
263
- newLocationWithoutMM.move(stepSize, heading);
264
- newLocationWithoutMM.bearing = rad2deg(heading);
265
- newLocationWithoutMM.time = timestamp;
262
+ const newPositionWithoutMM = previousPosition.clone();
263
+ newPositionWithoutMM.move(stepSize, heading);
264
+ newPositionWithoutMM.bearing = rad2deg(heading);
265
+ newPositionWithoutMM.time = timestamp;
266
266
 
267
267
  if (!this.mapMatching) {
268
- return newLocationWithoutMM;
268
+ return newPositionWithoutMM;
269
269
  }
270
270
 
271
- const projection = this.mapMatching.getProjection(newLocationWithoutMM);
271
+ const projection = this.mapMatching.getProjection(newPositionWithoutMM);
272
272
 
273
273
  if (!projection || !projection.projection) {
274
- return newLocationWithoutMM;
274
+ return newPositionWithoutMM;
275
275
  }
276
276
 
277
277
  if (projection.distanceFromNearestElement < stepSize) {
278
- return WGS84UserPosition.fromWGS84(projection.projection, newLocationWithoutMM);
278
+ return WGS84UserPosition.fromWGS84(projection.projection, newPositionWithoutMM);
279
279
  }
280
280
 
281
281
  /**
282
282
  * Update new_position
283
283
  */
284
284
  const smoothedDistance = projection.distanceFromNearestElement * MM_CONV_SPEED;
285
- const smoothedBearing = previousLocation.bearingTo(projection.projection);
286
- const smoothedLocation = previousLocation.clone();
287
- smoothedLocation.move(smoothedDistance, smoothedBearing);
285
+ const smoothedBearing = previousPosition.bearingTo(projection.projection);
286
+ const smoothedPosition = previousPosition.clone();
287
+ smoothedPosition.move(smoothedDistance, smoothedBearing);
288
288
 
289
- return WGS84UserPosition.fromWGS84(smoothedLocation, newLocationWithoutMM);
289
+ return WGS84UserPosition.fromWGS84(smoothedPosition, newPositionWithoutMM);
290
290
  }
291
291
 
292
292
 
@@ -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;