@wemap/providers 11.0.0-alpha.8 → 11.0.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.
package/dist/index.js CHANGED
@@ -307,6 +307,7 @@ const Constants = {
307
307
  const _GnssWifiProvider = class extends Provider {
308
308
  constructor() {
309
309
  super(...arguments);
310
+ __publicField(this, "discardPositionsAbove", _GnssWifiProvider.DEFAULT_DISCARD_POSITIONS_ABOVE);
310
311
  __publicField(this, "geoLocationId");
311
312
  __publicField(this, "getName", () => "GnssWifi");
312
313
  __publicField(this, "onNewPosition", (geolocation) => {
@@ -328,6 +329,9 @@ const _GnssWifiProvider = class extends Provider {
328
329
  coords.accuracy,
329
330
  bearing
330
331
  );
332
+ if (typeof this.discardPositionsAbove === "number" && coords.accuracy > this.discardPositionsAbove) {
333
+ return;
334
+ }
331
335
  this.notify(position);
332
336
  });
333
337
  __publicField(this, "onPositionError", (error) => {
@@ -370,6 +374,7 @@ __publicField(GnssWifiProvider, "POSITION_OPTIONS", {
370
374
  timeout: Infinity,
371
375
  maximumAge: 0
372
376
  });
377
+ __publicField(GnssWifiProvider, "DEFAULT_DISCARD_POSITIONS_ABOVE", 50);
373
378
  const GnssWifiProvider$1 = new GnssWifiProvider();
374
379
  const _MissingArCoreError = class extends Error {
375
380
  constructor(message) {
@@ -744,7 +749,7 @@ class ImuProvider extends Provider {
744
749
  } = e.accelerationIncludingGravity;
745
750
  if (typeof x === "number" && typeof y === "number" && typeof z === "number") {
746
751
  acc = [x, y, z];
747
- if (utils.BrowserUtils.name === utils.Browser.SAFARI || utils.BrowserUtils.name === utils.Browser.IOS_WEBVIEW) {
752
+ if (utils.BrowserUtils.getName() === utils.Browser.SAFARI || utils.BrowserUtils.getName() === utils.Browser.IOS_WEBVIEW) {
748
753
  acc[0] *= -1;
749
754
  acc[1] *= -1;
750
755
  acc[2] *= -1;
@@ -1308,6 +1313,25 @@ const _StepProvider = class extends Provider {
1308
1313
  __publicField(this, "_algorithm", _StepProvider.DEFAULT_ALGORITHM);
1309
1314
  __publicField(this, "_accValues", []);
1310
1315
  __publicField(this, "getName", () => "StepDetector");
1316
+ __publicField(this, "onAccelerometerEvent", (accelerationEvent) => {
1317
+ if (!this.attitudeEvent || !this.angularRateEvent) {
1318
+ return;
1319
+ }
1320
+ const {
1321
+ values: acceleration,
1322
+ timestamp
1323
+ } = accelerationEvent;
1324
+ const linearAcc = _StepProvider.computeLinearAcceleration(
1325
+ this.attitudeEvent.quaternion,
1326
+ acceleration
1327
+ );
1328
+ const stepDetected = this.stepDetector.compute(timestamp, linearAcc, this.angularRateEvent.values);
1329
+ if (stepDetected) {
1330
+ const size = this.stepDetector.lastStepSize * this._stepSizeMultiplier;
1331
+ this.numOfSteps++;
1332
+ this.notify({ size, number: this.numOfSteps });
1333
+ }
1334
+ });
1311
1335
  this.algorithm = this._algorithm;
1312
1336
  }
1313
1337
  availability() {
@@ -1337,25 +1361,6 @@ const _StepProvider = class extends Provider {
1337
1361
  GyroscopeProvider$1.removeEventListener(this.gyroscopeProviderId);
1338
1362
  RelativeAttitudeFromInertialProvider.removeEventListener(this.attitudeProviderId);
1339
1363
  }
1340
- onAccelerometerEvent(accelerationEvent) {
1341
- if (!this.attitudeEvent || !this.angularRateEvent) {
1342
- return;
1343
- }
1344
- const {
1345
- values: acceleration,
1346
- timestamp
1347
- } = accelerationEvent;
1348
- const linearAcc = _StepProvider.computeLinearAcceleration(
1349
- this.attitudeEvent.quaternion,
1350
- acceleration
1351
- );
1352
- const stepDetected = this.stepDetector.compute(timestamp, linearAcc, this.angularRateEvent.values);
1353
- if (stepDetected) {
1354
- const size = this.stepDetector.lastStepSize * this._stepSizeMultiplier;
1355
- this.numOfSteps++;
1356
- this.notify({ size, number: this.numOfSteps });
1357
- }
1358
- }
1359
1364
  static computeLinearAcceleration(quaternion, acc) {
1360
1365
  const linearAcc = maths.Quaternion.rotateMatlab(maths.Quaternion.inverse(quaternion), acc);
1361
1366
  linearAcc[2] -= geo.Constants.EARTH_GRAVITY;
@@ -2005,7 +2010,9 @@ const _AbsolutePositionProvider = class extends Provider {
2005
2010
  start() {
2006
2011
  GeoRelativePositionProvider$1.getAvailability().then((error) => {
2007
2012
  if (!error) {
2008
- this._relativePositionProviderId = GeoRelativePositionProvider$1.addEventListener(this._onRelativePosition);
2013
+ this._relativePositionProviderId = GeoRelativePositionProvider$1.addEventListener(
2014
+ (e) => this._onRelativePosition(e)
2015
+ );
2009
2016
  }
2010
2017
  });
2011
2018
  this._gnssWifiProviderId = GnssWifiProvider$1.addEventListener(
@@ -2228,7 +2235,7 @@ class AbsoluteAttitudeFromBrowser extends Provider {
2228
2235
  }
2229
2236
  start() {
2230
2237
  const subscribe = () => {
2231
- switch (utils.BrowserUtils.name) {
2238
+ switch (utils.BrowserUtils.getName()) {
2232
2239
  case utils.Browser.CHROME:
2233
2240
  window.addEventListener(
2234
2241
  "deviceorientationabsolute",
@@ -2269,7 +2276,7 @@ class AbsoluteAttitudeFromBrowser extends Provider {
2269
2276
  }
2270
2277
  }
2271
2278
  stop() {
2272
- switch (utils.BrowserUtils.name) {
2279
+ switch (utils.BrowserUtils.getName()) {
2273
2280
  case utils.Browser.CHROME:
2274
2281
  window.removeEventListener(
2275
2282
  "deviceorientationabsolute",
@@ -2640,7 +2647,7 @@ const _MapMatchingHandler = class extends Provider {
2640
2647
  __publicField(this, "_minStepsForOrientationMatching", _MapMatchingHandler.DEFAULT_MIN_STEPS_FOR_ORIENTATION_MATCHING);
2641
2648
  __publicField(this, "_lastProjectionsWindowSize", _MapMatchingHandler.DEFAULT_LAST_PROJECTIONS_WINDOW_SIZE);
2642
2649
  __publicField(this, "_lastProjectionsEdgeAngleThreshold", _MapMatchingHandler.DEFAULT_LAST_PROJECTIONS_EDGE_ANGLE_THRESHOLD);
2643
- __publicField(this, "_mapMatching");
2650
+ __publicField(this, "_geoGraphProjectionHandler");
2644
2651
  __publicField(this, "_internalProvidersStarted", false);
2645
2652
  __publicField(this, "_straightLineProviderId");
2646
2653
  __publicField(this, "_turnProviderId");
@@ -2652,18 +2659,18 @@ const _MapMatchingHandler = class extends Provider {
2652
2659
  __publicField(this, "getName", () => "MapMatchingHandler");
2653
2660
  __publicField(this, "availability", () => Promise.resolve());
2654
2661
  __publicField(this, "_manageStartStop", () => {
2655
- if (this.network && !this._internalProvidersStarted) {
2662
+ if (this.graph && !this._internalProvidersStarted) {
2656
2663
  this._startInternalProviders();
2657
- } else if (!this.network && this._internalProvidersStarted) {
2664
+ } else if (!this.graph && this._internalProvidersStarted) {
2658
2665
  this._stopInternalProviders();
2659
2666
  }
2660
2667
  });
2661
- this._mapMatching = new geo.MapMatching();
2662
- this._mapMatching.maxDistance = _MapMatchingHandler.DEFAULT_MM_MAX_DIST;
2663
- this._mapMatching.maxAngleBearing = _MapMatchingHandler.DEFAULT_MM_MAX_ANGLE;
2668
+ this._geoGraphProjectionHandler = new geo.GeoGraphProjectionHandler();
2669
+ this._geoGraphProjectionHandler.maxDistance = _MapMatchingHandler.DEFAULT_MM_MAX_DIST;
2670
+ this._geoGraphProjectionHandler.maxAngleBearing = _MapMatchingHandler.DEFAULT_MM_MAX_ANGLE;
2664
2671
  }
2665
2672
  start() {
2666
- if (this.network) {
2673
+ if (this.graph) {
2667
2674
  this._startInternalProviders();
2668
2675
  }
2669
2676
  }
@@ -2691,19 +2698,19 @@ const _MapMatchingHandler = class extends Provider {
2691
2698
  get enabled() {
2692
2699
  return ProvidersOptions.useMapMatching;
2693
2700
  }
2694
- get network() {
2695
- return this._mapMatching.network;
2701
+ get graph() {
2702
+ return this._geoGraphProjectionHandler.graph;
2696
2703
  }
2697
- set network(network) {
2698
- this._mapMatching.network = network;
2704
+ set graph(graph) {
2705
+ this._geoGraphProjectionHandler.graph = graph;
2699
2706
  this._itineraryInfoManager = null;
2700
- this.notify({ ...network && { network } });
2707
+ this.notify({ ...graph && { graph } });
2701
2708
  this._manageStartStop();
2702
2709
  if (this.canUseMapMatching())
2703
2710
  ;
2704
2711
  }
2705
2712
  set itinerary(itinerary) {
2706
- this._mapMatching.network = itinerary ? itinerary.toNetwork() : null;
2713
+ this._geoGraphProjectionHandler.graph = itinerary ? itinerary.toGraph() : null;
2707
2714
  this._itineraryInfoManager = new routers.ItineraryInfoManager(itinerary);
2708
2715
  this.notify({ ...itinerary && { itinerary } });
2709
2716
  this._manageStartStop();
@@ -2712,7 +2719,7 @@ const _MapMatchingHandler = class extends Provider {
2712
2719
  }
2713
2720
  }
2714
2721
  canUseMapMatching() {
2715
- return this.enabled && this.network;
2722
+ return this.enabled && this.graph;
2716
2723
  }
2717
2724
  _notifyPositionFromItineraryInput(itinerary) {
2718
2725
  if (!this._useItineraryStartAsPosition || itinerary.from) {
@@ -2849,7 +2856,7 @@ const _MapMatchingHandler = class extends Provider {
2849
2856
  }
2850
2857
  const firstProjection = this._lastProjections[0];
2851
2858
  return !this._lastProjections.some(
2852
- (projection) => !(projection.nearestElement instanceof geo.GraphEdge) || !(firstProjection.nearestElement instanceof geo.GraphEdge) || maths.diffAngleLines(projection.nearestElement.bearing, firstProjection.nearestElement.bearing) > this._lastProjectionsEdgeAngleThreshold
2859
+ (projection) => !(projection.nearestElement instanceof geo.GeoGraphEdge) || !(firstProjection.nearestElement instanceof geo.GeoGraphEdge) || maths.diffAngleLines(projection.nearestElement.bearing, firstProjection.nearestElement.bearing) > this._lastProjectionsEdgeAngleThreshold
2853
2860
  );
2854
2861
  }
2855
2862
  _nodeHasTurn(node) {
@@ -2865,12 +2872,12 @@ const _MapMatchingHandler = class extends Provider {
2865
2872
  return false;
2866
2873
  }
2867
2874
  _hasTurnInCircle(center, radius) {
2868
- const network = this._mapMatching.network;
2875
+ const network = this._geoGraphProjectionHandler.graph;
2869
2876
  if (!network) {
2870
2877
  return false;
2871
2878
  }
2872
- return network.nodes.filter(
2873
- (node) => node.coords.distanceTo(center) <= radius && geo.Level.intersect(node.coords.level, center.level)
2879
+ return network.vertices.filter(
2880
+ (vertex) => vertex.coords.distanceTo(center) <= radius && geo.Level.intersect(vertex.coords.level, center.level)
2874
2881
  ).some(this._nodeHasTurn);
2875
2882
  }
2876
2883
  tryOrientationMatching(projection) {
@@ -2881,7 +2888,7 @@ const _MapMatchingHandler = class extends Provider {
2881
2888
  return;
2882
2889
  }
2883
2890
  const { nearestElement, origin } = projection;
2884
- if (!(nearestElement instanceof geo.GraphEdge)) {
2891
+ if (!(nearestElement instanceof geo.GeoGraphEdge)) {
2885
2892
  return;
2886
2893
  }
2887
2894
  let matchingDirection;
@@ -2901,13 +2908,13 @@ const _MapMatchingHandler = class extends Provider {
2901
2908
  this._countStepsFromLastMatching = 0;
2902
2909
  }
2903
2910
  getProjection(position, useDistance, useBearing) {
2904
- return this._mapMatching.getProjection(position, useDistance, useBearing);
2911
+ return this._geoGraphProjectionHandler.getProjection(position, useDistance, useBearing);
2905
2912
  }
2906
2913
  get maxDistance() {
2907
- return this._mapMatching.maxDistance;
2914
+ return this._geoGraphProjectionHandler.maxDistance;
2908
2915
  }
2909
2916
  set maxDistance(maxDistance) {
2910
- this._mapMatching.maxDistance = maxDistance;
2917
+ this._geoGraphProjectionHandler.maxDistance = maxDistance;
2911
2918
  }
2912
2919
  get minDistance() {
2913
2920
  return this._mapMatchingMinDistance;
@@ -2916,10 +2923,10 @@ const _MapMatchingHandler = class extends Provider {
2916
2923
  this._mapMatchingMinDistance = minDistance;
2917
2924
  }
2918
2925
  get maxAngleBearing() {
2919
- return this._mapMatching.maxAngleBearing;
2926
+ return this._geoGraphProjectionHandler.maxAngleBearing;
2920
2927
  }
2921
2928
  set maxAngleBearing(maxAngleBearing) {
2922
- this._mapMatching.maxAngleBearing = maxAngleBearing;
2929
+ this._geoGraphProjectionHandler.maxAngleBearing = maxAngleBearing;
2923
2930
  }
2924
2931
  get useItineraryStartAsPosition() {
2925
2932
  return this._useItineraryStartAsPosition;
@@ -3261,6 +3268,7 @@ exports.RelativeAttitudeFromBrowserProvider = RelativeAttitudeFromBrowser$1;
3261
3268
  exports.RelativeAttitudeFromEkfProvider = RelativeAttitudeFromEkfProvider;
3262
3269
  exports.RelativeAttitudeFromInertialProvider = RelativeAttitudeFromInertialProvider;
3263
3270
  exports.RelativeAttitudeProvider = RelativeAttitudeProvider$1;
3271
+ exports.RelativeRotationCalc = RelativeRotationCalc;
3264
3272
  exports.StepDetectionMinMaxPeaks2 = StepDetectionMinMaxPeaks2;
3265
3273
  exports.StepDetectionMinMaxPeaks3 = StepDetectionMinMaxPeaks3;
3266
3274
  exports.StepProvider = StepProvider$1;