@wemap/providers 12.10.8 → 12.10.9

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 (146) hide show
  1. package/dist/helpers/CustomMapProvider.d.ts +10 -0
  2. package/{index.ts → dist/index.d.ts} +0 -14
  3. package/dist/index.js +1 -3446
  4. package/dist/index.js.map +1 -1
  5. package/{src/ProvidersOptions.ts → dist/src/ProvidersOptions.d.ts} +7 -16
  6. package/dist/src/errors/AskImuOnDesktopError.d.ts +5 -0
  7. package/dist/src/errors/ContainsIgnoredProviderError.d.ts +5 -0
  8. package/dist/src/errors/GeolocationApiMissingError.d.ts +5 -0
  9. package/dist/src/errors/GeolocationPermissionDeniedError.d.ts +5 -0
  10. package/dist/src/errors/GeolocationPositionUnavailableError.d.ts +5 -0
  11. package/dist/src/errors/IpResolveServerError.d.ts +5 -0
  12. package/dist/src/errors/MissingAccelerometerError.d.ts +6 -0
  13. package/dist/src/errors/MissingArCoreError.d.ts +5 -0
  14. package/dist/src/errors/MissingGyroscopeError.d.ts +6 -0
  15. package/dist/src/errors/MissingMagnetometerError.d.ts +5 -0
  16. package/dist/src/errors/MissingNativeInterfaceError.d.ts +5 -0
  17. package/dist/src/errors/MissingPoleStarError.d.ts +5 -0
  18. package/dist/src/errors/MissingSensorError.d.ts +6 -0
  19. package/dist/src/errors/NoProviderFoundError.d.ts +5 -0
  20. package/dist/src/events/AvailabilityHelper.d.ts +5 -0
  21. package/dist/src/events/ProvidersLoggerOld.d.ts +24 -0
  22. package/dist/src/events/Types.d.ts +34 -0
  23. package/dist/src/mapmatching/MapMatchingHandler.d.ts +93 -0
  24. package/dist/src/providers/Constants.d.ts +4 -0
  25. package/{src/providers/NativeProviders.ts → dist/src/providers/NativeProviders.d.ts} +2 -23
  26. package/dist/src/providers/Provider.d.ts +64 -0
  27. package/dist/src/providers/attitude/EkfAttitude.d.ts +41 -0
  28. package/dist/src/providers/attitude/TurnProvider.d.ts +17 -0
  29. package/dist/src/providers/attitude/absolute/AbsoluteAttitudeFromBrowserProvider.d.ts +60 -0
  30. package/dist/src/providers/attitude/absolute/AbsoluteAttitudeProvider.d.ts +44 -0
  31. package/dist/src/providers/attitude/relative/RelativeAttitudeFromBrowserProvider.d.ts +31 -0
  32. package/dist/src/providers/attitude/relative/RelativeAttitudeFromEkfProvider.d.ts +26 -0
  33. package/dist/src/providers/attitude/relative/RelativeAttitudeFromInertialProvider.d.ts +18 -0
  34. package/dist/src/providers/attitude/relative/RelativeAttitudeProvider.d.ts +25 -0
  35. package/dist/src/providers/imu/AccelerometerProvider.d.ts +11 -0
  36. package/dist/src/providers/imu/GyroscopeProvider.d.ts +11 -0
  37. package/dist/src/providers/imu/HighRotationsProvider.d.ts +15 -0
  38. package/dist/src/providers/imu/ImuProvider.d.ts +34 -0
  39. package/dist/src/providers/imu/MagnetometerCalibrationProvider.d.ts +11 -0
  40. package/dist/src/providers/inclination/InclinationFromAccProvider.d.ts +18 -0
  41. package/dist/src/providers/inclination/InclinationFromRelativeAttitudeProvider.d.ts +19 -0
  42. package/dist/src/providers/inclination/InclinationProvider.d.ts +18 -0
  43. package/dist/src/providers/legacy/helpers/HeadingUnlocker.d.ts +12 -0
  44. package/dist/src/providers/legacy/helpers/ThugDetector.d.ts +8 -0
  45. package/dist/src/providers/others/CameraNativeProvider.d.ts +11 -0
  46. package/dist/src/providers/others/CameraProjectionMatrixProvider.d.ts +11 -0
  47. package/dist/src/providers/position/absolute/AbsolutePositionProvider.d.ts +35 -0
  48. package/dist/src/providers/position/absolute/GnssWifiProvider.d.ts +28 -0
  49. package/dist/src/providers/position/absolute/IpProvider.d.ts +16 -0
  50. package/dist/src/providers/position/absolute/PoleStarProvider.d.ts +14 -0
  51. package/dist/src/providers/position/relative/GeoRelativePositionFromArCoreProvider.d.ts +17 -0
  52. package/dist/src/providers/position/relative/GeoRelativePositionProvider.d.ts +12 -0
  53. package/dist/src/providers/position/relative/PdrProvider.d.ts +15 -0
  54. package/dist/src/providers/steps/StepDetectionLadetto.d.ts +15 -0
  55. package/dist/src/providers/steps/StepDetectionMinMaxPeaks.d.ts +19 -0
  56. package/dist/src/providers/steps/StepDetectionMinMaxPeaks2.d.ts +27 -0
  57. package/dist/src/providers/steps/StepDetectionMinMaxPeaks3.d.ts +24 -0
  58. package/dist/src/providers/steps/StepProvider.d.ts +36 -0
  59. package/dist/src/providers/steps/StraightLineProvider.d.ts +21 -0
  60. package/dist/src/providers/vision/ArCoreProvider.d.ts +50 -0
  61. package/dist/src/providers/vision/BarcodeProvider.d.ts +11 -0
  62. package/dist/src/providers/vision/vps/ImageRelocalization.d.ts +11 -0
  63. package/dist/src/providers/vision/vps/RelativeRotationCalc.d.ts +10 -0
  64. package/dist/src/providers/vision/vps/VpsMetadata.d.ts +33 -0
  65. package/dist/src/providers/vision/vps/VpsProvider.d.ts +45 -0
  66. package/dist/src/providers/vision/vps/VpsRequest.d.ts +18 -0
  67. package/dist/src/providers/vision/vps/VpsResponse.d.ts +15 -0
  68. package/dist/src/smoothers/AttitudeSmoother.d.ts +23 -0
  69. package/dist/src/smoothers/PositionSmoother.d.ts +21 -0
  70. package/package.json +16 -12
  71. package/src/errors/AskImuOnDesktopError.ts +0 -10
  72. package/src/errors/ContainsIgnoredProviderError.ts +0 -10
  73. package/src/errors/GeolocationApiMissingError.ts +0 -10
  74. package/src/errors/GeolocationPermissionDeniedError.ts +0 -10
  75. package/src/errors/GeolocationPositionUnavailableError.ts +0 -10
  76. package/src/errors/IpResolveServerError.ts +0 -10
  77. package/src/errors/MissingAccelerometerError.ts +0 -11
  78. package/src/errors/MissingArCoreError.ts +0 -10
  79. package/src/errors/MissingGyroscopeError.ts +0 -11
  80. package/src/errors/MissingMagnetometerError.ts +0 -9
  81. package/src/errors/MissingNativeInterfaceError.ts +0 -11
  82. package/src/errors/MissingPoleStarError.ts +0 -10
  83. package/src/errors/MissingSensorError.ts +0 -15
  84. package/src/errors/NoProviderFoundError.ts +0 -10
  85. package/src/events/AvailabilityHelper.spec.ts +0 -30
  86. package/src/events/AvailabilityHelper.ts +0 -28
  87. package/src/events/ProvidersLoggerOld.ts +0 -87
  88. package/src/events/Types.ts +0 -18
  89. package/src/mapmatching/MapMatchingHandler.spec.ts +0 -142
  90. package/src/mapmatching/MapMatchingHandler.ts +0 -540
  91. package/src/providers/Constants.ts +0 -5
  92. package/src/providers/FakeProvider.spec.ts +0 -49
  93. package/src/providers/Provider.spec.ts +0 -113
  94. package/src/providers/Provider.ts +0 -244
  95. package/src/providers/attitude/EkfAttitude.spec.ts +0 -115
  96. package/src/providers/attitude/EkfAttitude.ts +0 -233
  97. package/src/providers/attitude/TurnProvider.ts +0 -58
  98. package/src/providers/attitude/absolute/AbsoluteAttitudeFromBrowserProvider.ts +0 -267
  99. package/src/providers/attitude/absolute/AbsoluteAttitudeProvider.ts +0 -268
  100. package/src/providers/attitude/relative/RelativeAttitudeFromBrowserProvider.ts +0 -84
  101. package/src/providers/attitude/relative/RelativeAttitudeFromEkfProvider.ts +0 -89
  102. package/src/providers/attitude/relative/RelativeAttitudeFromInertialProvider.ts +0 -66
  103. package/src/providers/attitude/relative/RelativeAttitudeProvider.ts +0 -70
  104. package/src/providers/imu/AccelerometerProvider.ts +0 -28
  105. package/src/providers/imu/GyroscopeProvider.ts +0 -27
  106. package/src/providers/imu/HighRotationsProvider.ts +0 -49
  107. package/src/providers/imu/ImuProvider.ts +0 -110
  108. package/src/providers/imu/MagnetometerCalibrationProvider.ts +0 -21
  109. package/src/providers/inclination/InclinationFromAccProvider.ts +0 -57
  110. package/src/providers/inclination/InclinationFromRelativeAttitudeProvider.ts +0 -51
  111. package/src/providers/inclination/InclinationProvider.ts +0 -59
  112. package/src/providers/legacy/helpers/HeadingUnlocker.spec.ts +0 -53
  113. package/src/providers/legacy/helpers/HeadingUnlocker.ts +0 -44
  114. package/src/providers/legacy/helpers/ThugDetector.ts +0 -30
  115. package/src/providers/others/CameraNativeProvider.ts +0 -29
  116. package/src/providers/others/CameraProjectionMatrixProvider.ts +0 -25
  117. package/src/providers/position/absolute/AbsolutePositionProvider.spec.ts +0 -31
  118. package/src/providers/position/absolute/AbsolutePositionProvider.ts +0 -277
  119. package/src/providers/position/absolute/GnssWifiProvider.ts +0 -126
  120. package/src/providers/position/absolute/GnssWifiProviders.spec.ts +0 -90
  121. package/src/providers/position/absolute/IpProvider.ts +0 -47
  122. package/src/providers/position/absolute/PoleStarProvider.ts +0 -88
  123. package/src/providers/position/relative/GeoRelativePositionFromArCoreProvider.ts +0 -82
  124. package/src/providers/position/relative/GeoRelativePositionProvider.ts +0 -35
  125. package/src/providers/position/relative/PdrProvider.ts +0 -107
  126. package/src/providers/steps/StepDetectionLadetto.ts +0 -67
  127. package/src/providers/steps/StepDetectionMinMaxPeaks.ts +0 -70
  128. package/src/providers/steps/StepDetectionMinMaxPeaks2.ts +0 -99
  129. package/src/providers/steps/StepDetectionMinMaxPeaks3.ts +0 -192
  130. package/src/providers/steps/StepProvider.ts +0 -151
  131. package/src/providers/steps/StraightLineProvider.ts +0 -69
  132. package/src/providers/vision/ArCoreProvider.ts +0 -184
  133. package/src/providers/vision/BarcodeProvider.ts +0 -28
  134. package/src/providers/vision/vps/ImageRelocalization.ts +0 -98
  135. package/src/providers/vision/vps/RelativeRotationCalc.ts +0 -58
  136. package/src/providers/vision/vps/VpsMetadata.ts +0 -63
  137. package/src/providers/vision/vps/VpsProvider.ts +0 -251
  138. package/src/providers/vision/vps/VpsRequest.ts +0 -29
  139. package/src/providers/vision/vps/VpsResponse.ts +0 -43
  140. package/src/providers/vision/vps/VpsSchema.json +0 -90
  141. package/src/smoothers/AttitudeSmoother.ts +0 -110
  142. package/src/smoothers/PositionSmoother.spec.ts +0 -53
  143. package/src/smoothers/PositionSmoother.ts +0 -96
  144. package/tsconfig.json +0 -3
  145. package/vite.config.ts +0 -4
  146. /package/{src/providers/ProviderState.ts → dist/src/providers/ProviderState.d.ts} +0 -0
@@ -1,142 +0,0 @@
1
- import chai from 'chai';
2
- import { Coordinates } from '@wemap/geo';
3
- import { deg2rad } from '@wemap/maths';
4
- import { Graph, Itinerary, Vertex } from '@wemap/routers';
5
-
6
- import MMH from './MapMatchingHandler.js';
7
-
8
- const { expect } = chai;
9
-
10
- describe('MapMatchingHandler', () => {
11
-
12
- const p0 = new Coordinates(0, 0, null, 0);
13
- const p1 = p0.destinationPoint(5, 0);
14
- const p2 = p1.destinationPoint(5, Math.PI / 2);
15
- const p3 = p1.destinationPoint(10, 0);
16
- const p4 = p0.destinationPoint(2, deg2rad(10));
17
-
18
- const pos1 = p0.clone();
19
- const pos2 = pos1.destinationPoint(3, 0);
20
- const pos3 = pos2.destinationPoint(10, 0);
21
-
22
-
23
- it('_hasTurnInCircle - itinerary', () => {
24
-
25
- expect(MMH._hasTurnInCircle(pos1, Number.MAX_VALUE)).is.false;
26
-
27
- // p4 -> p1 -> p2 is a turn
28
- MMH.itinerary = Itinerary.fromOrderedCoordinates([p0, p4, p1, p2], p0, p2);
29
- let graph = MMH.graph as Graph;
30
-
31
- expect(MMH._nodeHasTurn(graph.getVertexByCoords(p0)!)).is.false;
32
- expect(MMH._nodeHasTurn(graph.getVertexByCoords(p1)!)).is.true;
33
- expect(MMH._nodeHasTurn(graph.getVertexByCoords(p2)!)).is.false;
34
- expect(MMH._nodeHasTurn(graph.getVertexByCoords(p4)!)).is.false;
35
-
36
- expect(MMH._hasTurnInCircle(pos1, 1)).is.false;
37
- expect(MMH._hasTurnInCircle(pos1, 3)).is.false;
38
- expect(MMH._hasTurnInCircle(pos1, 10)).is.true;
39
- expect(MMH._hasTurnInCircle(pos2, 1)).is.false;
40
- expect(MMH._hasTurnInCircle(pos2, 3)).is.true;
41
- expect(MMH._hasTurnInCircle(pos2, 10)).is.true;
42
- expect(MMH._hasTurnInCircle(pos3, 1)).is.false;
43
- expect(MMH._hasTurnInCircle(pos3, 3)).is.false;
44
- expect(MMH._hasTurnInCircle(pos3, 10)).is.true;
45
-
46
- // Straight line
47
- MMH.itinerary = Itinerary.fromOrderedCoordinates([p0, p4, p1, p3], p0, p3);
48
- graph = MMH.graph as Graph;
49
-
50
- expect(MMH._nodeHasTurn(graph.getVertexByCoords(p1) as Vertex)).is.false;
51
- expect(MMH._nodeHasTurn(graph.getVertexByCoords(p4) as Vertex)).is.false;
52
-
53
- expect(MMH._hasTurnInCircle(pos1, 10)).is.false;
54
- expect(MMH._hasTurnInCircle(pos2, 10)).is.false;
55
- expect(MMH._hasTurnInCircle(pos3, 10)).is.false;
56
-
57
- });
58
-
59
-
60
- it('_hasTurnInCircle - network', () => {
61
-
62
- // p1 has turns
63
- const graph = Graph.fromCoordinatesSegments([[p0, p4, p1], [p1, p2], [p3, p1]]);
64
- MMH.graph = graph;
65
-
66
- expect(MMH._nodeHasTurn(graph.getVertexByCoords(p1) as Vertex)).is.true;
67
- expect(MMH._nodeHasTurn(graph.getVertexByCoords(p4) as Vertex)).is.false;
68
-
69
- expect(MMH._hasTurnInCircle(pos1, 1)).is.false;
70
- expect(MMH._hasTurnInCircle(pos1, 3)).is.false;
71
- expect(MMH._hasTurnInCircle(pos1, 10)).is.true;
72
- expect(MMH._hasTurnInCircle(pos2, 1)).is.false;
73
- expect(MMH._hasTurnInCircle(pos2, 3)).is.true;
74
- expect(MMH._hasTurnInCircle(pos2, 10)).is.true;
75
- expect(MMH._hasTurnInCircle(pos3, 1)).is.false;
76
- expect(MMH._hasTurnInCircle(pos3, 3)).is.false;
77
- expect(MMH._hasTurnInCircle(pos3, 10)).is.true;
78
-
79
- });
80
-
81
- const p10 = new Coordinates(0, 0, null, 1);
82
- const p11 = p10.destinationPoint(5, 0);
83
- const p12 = p11.destinationPoint(5, Math.PI / 2);
84
- const p13 = p11.destinationPoint(10, 0);
85
-
86
- const pos12 = p10.clone().destinationPoint(3, 0);
87
- const pos012 = new Coordinates(0, 0, null, [0, 1]).destinationPoint(3, 0);
88
-
89
- it('_hasTurnInCircle - multi-levels', () => {
90
-
91
- // level 1 is a straight line
92
- let graph = Graph.fromCoordinatesSegments([
93
- [p0, p4, p1], [p1, p2], [p3, p1],
94
- [p10, p11, p13]
95
- ]);
96
- MMH.graph = graph;
97
-
98
- expect(MMH._nodeHasTurn(graph.getVertexByCoords(p1) as Vertex)).is.true;
99
- expect(MMH._nodeHasTurn(graph.getVertexByCoords(p11) as Vertex)).is.false;
100
-
101
- expect(MMH._hasTurnInCircle(pos2, 1)).is.false;
102
- expect(MMH._hasTurnInCircle(pos2, 3)).is.true;
103
- expect(MMH._hasTurnInCircle(pos2, 10)).is.true;
104
- expect(MMH._hasTurnInCircle(pos12, 1)).is.false;
105
- expect(MMH._hasTurnInCircle(pos12, 3)).is.false;
106
- expect(MMH._hasTurnInCircle(pos12, 10)).is.false;
107
- expect(MMH._hasTurnInCircle(pos012, 1)).is.false;
108
- expect(MMH._hasTurnInCircle(pos012, 3)).is.true;
109
- expect(MMH._hasTurnInCircle(pos012, 10)).is.true;
110
-
111
- // Changing level
112
- // straight line
113
- graph = Graph.fromCoordinatesSegments([
114
- [p0, p4, p11], [p11, p13]
115
- ]);
116
- MMH.graph = graph;
117
- expect(MMH._nodeHasTurn(graph.getVertexByCoords(p4) as Vertex)).is.false;
118
- expect(MMH._hasTurnInCircle(pos2, Number.MAX_VALUE)).is.false;
119
- expect(MMH._hasTurnInCircle(pos12, Number.MAX_VALUE)).is.false;
120
- expect(MMH._hasTurnInCircle(pos012, Number.MAX_VALUE)).is.false;
121
-
122
- // Changing level
123
- // turn in p11
124
- graph = Graph.fromCoordinatesSegments([
125
- [p0, p4, p11], [p11, p12], [p11, p13]
126
- ]);
127
- MMH.graph = graph;
128
-
129
- expect(MMH._nodeHasTurn(graph.getVertexByCoords(p11) as Vertex)).is.true;
130
- expect(MMH._hasTurnInCircle(pos2, 1)).is.false;
131
- expect(MMH._hasTurnInCircle(pos2, 3)).is.false;
132
- expect(MMH._hasTurnInCircle(pos2, 10)).is.false;
133
- expect(MMH._hasTurnInCircle(pos12, 1)).is.false;
134
- expect(MMH._hasTurnInCircle(pos12, 3)).is.true;
135
- expect(MMH._hasTurnInCircle(pos12, 10)).is.true;
136
- expect(MMH._hasTurnInCircle(pos012, 1)).is.false;
137
- expect(MMH._hasTurnInCircle(pos012, 3)).is.true;
138
- expect(MMH._hasTurnInCircle(pos012, 10)).is.true;
139
-
140
- });
141
-
142
- });
@@ -1,540 +0,0 @@
1
- import { AbsoluteHeading, Level, UserPosition, Coordinates } from '@wemap/geo';
2
- import { deg2rad, diffAngle, diffAngleLines } from '@wemap/maths';
3
- import { Edge, Graph, GraphProjection, Itinerary, ItineraryInfoManager, Vertex } from '@wemap/routers';
4
- import { TimeUtils } from '@wemap/utils';
5
-
6
- import AbsoluteAttitudeProvider from '../providers/attitude/absolute/AbsoluteAttitudeProvider.js';
7
- import AbsoluteAttitudeFromBrowser from '../providers/attitude/absolute/AbsoluteAttitudeFromBrowserProvider.js';
8
- import TurnProvider from '../providers/attitude/TurnProvider.js';
9
- import Constants from '../providers/Constants.js';
10
- import AbsolutePositionProvider from '../providers/position/absolute/AbsolutePositionProvider.js';
11
- import Provider from '../providers/Provider.js';
12
- import StepProvider from '../providers/steps/StepProvider.js';
13
- import StraightLineProvider from '../providers/steps/StraightLineProvider.js';
14
- import ProvidersOptions from '../ProvidersOptions.js';
15
- import { AbsolutePosition } from '../events/Types.js';
16
-
17
-
18
- type MapMatchingEvent = { graph?: Graph, itinerary?: Itinerary | null };
19
- class MapMatchingHandler extends Provider<MapMatchingEvent> {
20
-
21
- static DEFAULT_MM_MAX_ANGLE = deg2rad(30); // radians
22
- static DEFAULT_MM_MAX_DIST = 30; // meters
23
- static DEFAULT_MM_MIN_DIST = 0; // meters
24
- static DEFAULT_USE_ITINERARY_START_AS_POSITION = false;
25
- static DEFAULT_USE_ORIENTATION_MATCHING = true;
26
- static DEFAULT_MM_HUGE_JUMP_DISTANCE = 3; // meters
27
- static DEFAULT_DISABLE_MM_CLOSE_TO_A_TURN_DISTANCE = 2; // meters
28
- static DEFAULT_MIN_STEPS_BETWEEN_ORIENTATION_MATCHING = 3;
29
- static DEFAULT_MIN_STEPS_FOR_ORIENTATION_MATCHING = 5;
30
- static DEFAULT_LAST_PROJECTIONS_WINDOW_SIZE = 3;
31
- static DEFAULT_LAST_PROJECTIONS_EDGE_ANGLE_THRESHOLD = deg2rad(3); // radians
32
-
33
- _mapMatchingMaxDistance = MapMatchingHandler.DEFAULT_MM_MAX_DIST;
34
- _mapMatchingMinDistance = MapMatchingHandler.DEFAULT_MM_MIN_DIST;
35
- _mapMatchingMaxAngleBearing = MapMatchingHandler.DEFAULT_MM_MAX_ANGLE;
36
- _useItineraryStartAsPosition = MapMatchingHandler.DEFAULT_USE_ITINERARY_START_AS_POSITION;
37
- _useOrientationMatching = MapMatchingHandler.DEFAULT_USE_ORIENTATION_MATCHING;
38
- _hugeJumpDistance = MapMatchingHandler.DEFAULT_MM_HUGE_JUMP_DISTANCE;
39
- _disableMMCloseToATurnDistance = MapMatchingHandler.DEFAULT_DISABLE_MM_CLOSE_TO_A_TURN_DISTANCE;
40
- _minStepsBetweenOrientationMatching = MapMatchingHandler.DEFAULT_MIN_STEPS_BETWEEN_ORIENTATION_MATCHING;
41
- _minStepsForOrientationMatching = MapMatchingHandler.DEFAULT_MIN_STEPS_FOR_ORIENTATION_MATCHING;
42
- _lastProjectionsWindowSize = MapMatchingHandler.DEFAULT_LAST_PROJECTIONS_WINDOW_SIZE;
43
- _lastProjectionsEdgeAngleThreshold = MapMatchingHandler.DEFAULT_LAST_PROJECTIONS_EDGE_ANGLE_THRESHOLD;
44
-
45
- _graph: Graph | null = null;
46
- _internalProvidersStarted = false;
47
- _straightLineProviderId?: number;
48
- _turnProviderId?: number;
49
- _stepProviderId?: number;
50
- _projectionsWithAbsAndWithoutRelAttitudeInARow: GraphProjection[] = [];
51
- _countStepsFromLastMatching = 0;
52
- _lastProjections: GraphProjection[] = [];
53
-
54
- _itineraryInfoManager: ItineraryInfoManager | null = null;
55
-
56
-
57
- getName = () => 'MapMatchingHandler';
58
-
59
- availability = () => Promise.resolve();
60
-
61
- start() {
62
- if (this.graph) {
63
- this._startInternalProviders();
64
- }
65
- }
66
-
67
- stop() {
68
- this._stopInternalProviders();
69
- }
70
-
71
- _manageStartStop = () => {
72
- if (this.graph && !this._internalProvidersStarted) {
73
- this._startInternalProviders();
74
- } else if (!this.graph && this._internalProvidersStarted) {
75
- this._stopInternalProviders();
76
- }
77
- }
78
-
79
- _startInternalProviders() {
80
-
81
- if (this.enabled && this._internalProvidersStarted) {
82
- return;
83
- }
84
-
85
- this._straightLineProviderId = StraightLineProvider.addEventListener();
86
- this._turnProviderId = TurnProvider.addEventListener();
87
- this._stepProviderId = StepProvider.addEventListener(() => (this._countStepsFromLastMatching++));
88
-
89
- this._internalProvidersStarted = true;
90
- }
91
-
92
- _stopInternalProviders() {
93
-
94
- if (this.enabled && !this._internalProvidersStarted) {
95
- return;
96
- }
97
-
98
- StraightLineProvider.removeEventListener(this._straightLineProviderId);
99
- TurnProvider.removeEventListener(this._turnProviderId);
100
- StepProvider.removeEventListener(this._stepProviderId);
101
-
102
- this._internalProvidersStarted = false;
103
- }
104
-
105
- get enabled() {
106
- return ProvidersOptions.useMapMatching;
107
- }
108
-
109
- get graph() {
110
- return this._graph;
111
- }
112
-
113
- set graph(graph) {
114
-
115
- this._graph = graph;
116
- this._itineraryInfoManager = null;
117
- this.notify({ ...(graph && { graph }) });
118
-
119
- this._manageStartStop();
120
-
121
- if (this.canUseMapMatching()) {
122
- // TODO if necessary
123
- // this._notifyPositionFromNetworkInput(network);
124
- }
125
- }
126
-
127
- set itinerary(itinerary: Itinerary | null) {
128
-
129
- this._graph = itinerary ? itinerary.toGraph() : null;
130
- this._itineraryInfoManager = new ItineraryInfoManager(itinerary);
131
- this.notify({ ...(itinerary && { itinerary }) });
132
-
133
- this._manageStartStop();
134
-
135
- if (this.canUseMapMatching() && itinerary) {
136
- this._notifyPositionFromItineraryInput(itinerary);
137
- }
138
- }
139
-
140
- canUseMapMatching() {
141
- return this.enabled && this.graph;
142
- }
143
-
144
-
145
- private _notifyPositionFromItineraryInput(itinerary: Itinerary) {
146
-
147
- if (!this._useItineraryStartAsPosition || !itinerary.origin) {
148
- return;
149
- }
150
-
151
- const lastPosition = AbsolutePositionProvider.lastEvent || null;
152
-
153
- // In case of an itinerary, use itinerary start as new position,
154
- // but add the distance between lastPosition and itinerary start for the accuracy
155
- const newPosition = UserPosition.fromCoordinates(itinerary.origin);
156
-
157
- if (lastPosition) {
158
- newPosition.alt = lastPosition.alt;
159
- newPosition.time = lastPosition.time;
160
- newPosition.accuracy = lastPosition.accuracy! + newPosition.distanceTo(lastPosition);
161
- newPosition.bearing = lastPosition.bearing;
162
- } else if (itinerary.coords.length >= 2) {
163
- newPosition.alt = Constants.DEFAULT_ALTITUDE;
164
- newPosition.time = TimeUtils.preciseTime();
165
- newPosition.accuracy = 0;
166
- newPosition.bearing = itinerary.coords[0].bearingTo(itinerary.coords[1]);
167
- } else {
168
- return;
169
- }
170
-
171
- // if the distance between itinerary.start and itinerary.nodes[0] is less than MM_MAX_DIST,
172
- // projection.coords is itinerary.nodes[0]
173
- const projection = this.getProjection(newPosition, true);
174
- if (projection) {
175
- AbsolutePositionProvider.notify(projection.coords);
176
- // Do not notify for attitude projection because bearing has not been used.
177
- } else {
178
- AbsolutePositionProvider.notify(newPosition);
179
- }
180
- return;
181
- }
182
-
183
- notifyPositionFromFeed(newPositionEvent: AbsolutePosition) {
184
-
185
- const projection = this.getProjection(newPositionEvent, true, false);
186
- if (!projection) {
187
- AbsolutePositionProvider.notify(newPositionEvent);
188
- return;
189
- }
190
-
191
- AbsolutePositionProvider.notify(projection.coords);
192
- }
193
-
194
-
195
- /**
196
- * @returns if input position is used by the system (true = used, false = discarded)
197
- */
198
- notifyPositionFromAbsolute(newPosition: AbsolutePosition) {
199
-
200
- let projectionWithBearing = null;
201
- if (newPosition.bearing !== null) {
202
- projectionWithBearing = this.getProjection(newPosition, true, true);
203
- }
204
-
205
- if (!projectionWithBearing) {
206
- // Verify if the newPosition is far enough from the network to be used by the system.
207
- // const projectionWithoutBearing = this.getProjection(newPosition, true, false);
208
- // if (!projectionWithoutBearing) {
209
- // In this case, the newPosition is far enough and can be used safely.
210
- AbsolutePositionProvider.notify(newPosition);
211
- return true;
212
- // }
213
- // return true;
214
- }
215
-
216
- // newPosition must not be used after this line
217
-
218
- const thisWillBeAHugeJump = projectionWithBearing.distanceFromNearestElement > this._hugeJumpDistance;
219
-
220
- // In case of a huge jump, be sure the user is in a straight line
221
- if (thisWillBeAHugeJump && !StraightLineProvider.isStraight()) {
222
- return false;
223
- }
224
-
225
- // Detector to avoid big jumps in the wrong direction
226
- if (thisWillBeAHugeJump && this._detectWrongBigJump(projectionWithBearing)) {
227
- return false;
228
- }
229
-
230
- AbsolutePositionProvider.notify(projectionWithBearing.coords);
231
-
232
- this.tryOrientationMatching(projectionWithBearing);
233
- return true;
234
- }
235
-
236
-
237
- /**
238
- * @returns if input position is used by the system (true = used, false = discarded)
239
- */
240
- notifyPositionFromRelative(newPosition: AbsolutePosition) {
241
-
242
- if (TurnProvider.isTurning()) {
243
- this._projectionsWithAbsAndWithoutRelAttitudeInARow = [];
244
- this._lastProjections = [];
245
- AbsolutePositionProvider.notify(newPosition);
246
- return true;
247
- }
248
-
249
- const projection = this.getProjection(newPosition, true, true);
250
-
251
- if (projection) {
252
- this._projectionsWithAbsAndWithoutRelAttitudeInARow = [];
253
- this._lastProjections.push(projection);
254
- if (this._lastProjections.length > this._lastProjectionsWindowSize) {
255
- this._lastProjections.shift();
256
- }
257
-
258
- const thisWillBeAHugeJump = projection.distanceFromNearestElement > this._hugeJumpDistance;
259
-
260
- // In case of a huge jump, be sure the user is in a straight line
261
- if (thisWillBeAHugeJump && !StraightLineProvider.isStraight()) {
262
- AbsolutePositionProvider.notify(newPosition);
263
- return true;
264
- }
265
-
266
- // Detector to avoid big jumps in the wrong direction
267
- if (thisWillBeAHugeJump && this._detectWrongBigJump(projection)) {
268
- AbsolutePositionProvider.notify(newPosition);
269
- return true;
270
- }
271
-
272
- // Do not use projection if the neareast element is not the same direction than previous
273
- if (!this._areLastProjectionsInTheSameDirection()) {
274
- AbsolutePositionProvider.notify(newPosition);
275
- return true;
276
- }
277
-
278
- // Detector to avoid map-matching close to network turns
279
- if (this._disableMMCloseToATurnDistance > 0
280
- && this._hasTurnInCircle(projection.coords, this._disableMMCloseToATurnDistance)) {
281
- AbsolutePositionProvider.notify(newPosition);
282
- return true;
283
- }
284
-
285
- AbsolutePositionProvider.notify(projection.coords);
286
- this.tryOrientationMatching(projection);
287
-
288
- return true;
289
-
290
- }
291
- // else {
292
-
293
- // Sometimes, the newPosition.bearing diverges due to the Absolute Attitude offset
294
- // and the Orientation Matching. So, we created this detector to check if projection
295
- // with bearing from "AbsoluteAttitudeFromBrowser" is better than the current bearing.
296
- // /!\ This works only if the user is waking in the same direction than the smartphone orientation /!\
297
- if (StraightLineProvider.isStraight()) {
298
-
299
- const testedPosition = newPosition.clone();
300
- testedPosition.bearing = AbsoluteAttitudeFromBrowser.lastEvent?.heading || null;
301
- const projectionWithAbs = this.getProjection(testedPosition, true, true);
302
-
303
- if (projectionWithAbs) {
304
-
305
- this._projectionsWithAbsAndWithoutRelAttitudeInARow.push(projectionWithAbs);
306
- if (this._projectionsWithAbsAndWithoutRelAttitudeInARow.length < 3) {
307
- AbsolutePositionProvider.notify(newPosition);
308
- return true;
309
- }
310
-
311
- this._lastProjections.push(projectionWithAbs);
312
- if (this._lastProjections.length > this._lastProjectionsWindowSize) {
313
- this._lastProjections.shift();
314
- }
315
-
316
-
317
- if (!this._areLastProjectionsInTheSameDirection()) {
318
- AbsolutePositionProvider.notify(newPosition);
319
- return true;
320
- }
321
-
322
- AbsolutePositionProvider.notify(projectionWithAbs.coords);
323
-
324
- this.tryOrientationMatching(projectionWithAbs);
325
- return true;
326
- }
327
- }
328
-
329
- this._projectionsWithAbsAndWithoutRelAttitudeInARow = [];
330
- this._lastProjections = [];
331
-
332
- // If no projection found with both projection methods, simply use the newPosition.
333
- AbsolutePositionProvider.notify(newPosition);
334
- return true;
335
-
336
- // }
337
-
338
- }
339
-
340
- _detectWrongBigJump(projection: GraphProjection<UserPosition>) {
341
-
342
- if (this._itineraryInfoManager && AbsolutePositionProvider.lastEvent) {
343
- const infoPrevious = this._itineraryInfoManager.getInfo(AbsolutePositionProvider.lastEvent);
344
- const infoProjection = this._itineraryInfoManager.getInfo(projection.coords);
345
- if (infoPrevious
346
- && infoProjection
347
- && infoPrevious.traveledDistance > infoProjection.traveledDistance
348
- && (infoPrevious.traveledDistance - infoProjection.traveledDistance) > projection.origin.accuracy!
349
- && projection.distanceFromNearestElement > projection.origin.accuracy!
350
- && projection.origin.distanceTo(AbsolutePositionProvider.lastEvent) < projection.origin.accuracy! + AbsolutePositionProvider.lastEvent.accuracy!) {
351
-
352
- return true;
353
- }
354
- }
355
-
356
- return false;
357
- }
358
-
359
- _areLastProjectionsInTheSameDirection() {
360
-
361
- if (this._lastProjections.length === 0) {
362
- return false;
363
- }
364
-
365
- const firstProjection = this._lastProjections[0];
366
- return !this._lastProjections.some(projection =>
367
- !(projection.nearestElement instanceof Edge)
368
- || !(firstProjection.nearestElement instanceof Edge)
369
- || (diffAngleLines(projection.nearestElement.bearing, firstProjection.nearestElement.bearing)
370
- > this._lastProjectionsEdgeAngleThreshold)
371
- );
372
- }
373
-
374
-
375
- _nodeHasTurn(vertex: Vertex) {
376
- // works but slow
377
- if (!this._graph) return;
378
- const edges = this._graph.edges.filter(e => e.vertex1 === vertex || e.vertex2 === vertex);
379
-
380
- for (let i = 0; i < edges.length; i++) {
381
- for (let j = i + 1; j < edges.length; j++) {
382
- const angle = diffAngleLines(edges[i].bearing, edges[j].bearing);
383
- if (angle > MapMatchingHandler.DEFAULT_MM_MAX_ANGLE) {
384
- return true;
385
- }
386
- }
387
- }
388
- return false;
389
- }
390
-
391
-
392
- _hasTurnInCircle(center: Coordinates, radius: number) {
393
- const graph = this._graph;
394
- if (!graph) {
395
- return false;
396
- }
397
-
398
- return graph.vertices.filter(vertex =>
399
- vertex.coords.distanceTo(center) <= radius
400
- && Level.intersect(vertex.coords.level, center.level)
401
- ).some(it => this._nodeHasTurn(it));
402
- }
403
-
404
- tryOrientationMatching(projection: GraphProjection<UserPosition>) {
405
-
406
- if (!this._useOrientationMatching) {
407
- return;
408
- }
409
-
410
- if (this.state !== 'started'
411
- || this._countStepsFromLastMatching < this._minStepsBetweenOrientationMatching
412
- || StraightLineProvider.numStepsDetectedFromLastTurn < this._minStepsForOrientationMatching) {
413
- return;
414
- }
415
-
416
- const { nearestElement, origin } = projection;
417
- if (!(nearestElement instanceof Edge)) {
418
- return;
419
- }
420
-
421
- let matchingDirection;
422
- const matchingDirectionAngle1 = diffAngle(nearestElement.bearing, origin.bearing!);
423
- const matchingDirectionAngle2 = diffAngle(nearestElement.bearing + Math.PI, origin.bearing!);
424
-
425
- if (Math.abs(matchingDirectionAngle1) < Math.abs(matchingDirectionAngle2)) {
426
- matchingDirection = nearestElement.bearing;
427
- } else {
428
- matchingDirection = (nearestElement.bearing + Math.PI) % (2 * Math.PI);
429
- }
430
-
431
- const matchedHeading = new AbsoluteHeading(
432
- matchingDirection,
433
- origin.time,
434
- 0
435
- // Math.min(Math.abs(matchingDirectionAngle1), Math.abs(matchingDirectionAngle2))
436
- );
437
-
438
- AbsoluteAttitudeProvider._forceHeadingForRelative(matchedHeading);
439
-
440
- this._countStepsFromLastMatching = 0;
441
- }
442
-
443
- getProjection(position: UserPosition, useDistance?: boolean, useBearing?: boolean) {
444
- const projectionsOptions = {
445
- ...(useDistance && { maxDistance: this._mapMatchingMaxDistance }),
446
- ...(useBearing && { maxBearingAngle: this._mapMatchingMaxAngleBearing }),
447
- }
448
- return this._graph?.getProjection(position, projectionsOptions);
449
- }
450
-
451
- get maxDistance() {
452
- return this._mapMatchingMaxDistance;
453
- }
454
-
455
- set maxDistance(maxDistance) {
456
- this._mapMatchingMaxDistance = maxDistance;
457
- }
458
-
459
- get minDistance() {
460
- return this._mapMatchingMinDistance;
461
- }
462
-
463
- set minDistance(minDistance) {
464
- this._mapMatchingMinDistance = minDistance;
465
- }
466
-
467
- get maxAngleBearing() {
468
- return this._mapMatchingMaxAngleBearing;
469
- }
470
-
471
- set maxAngleBearing(maxAngleBearing) {
472
- this._mapMatchingMaxAngleBearing = maxAngleBearing;
473
- }
474
-
475
- get useItineraryStartAsPosition() {
476
- return this._useItineraryStartAsPosition;
477
- }
478
-
479
- set useItineraryStartAsPosition(useItineraryStartAsPosition) {
480
- this._useItineraryStartAsPosition = useItineraryStartAsPosition;
481
- }
482
-
483
- get useOrientationMatching() {
484
- return this._useOrientationMatching;
485
- }
486
-
487
- set useOrientationMatching(useOrientationMatching) {
488
- this._useOrientationMatching = useOrientationMatching;
489
- }
490
-
491
- get hugeJumpDistance() {
492
- return this._hugeJumpDistance;
493
- }
494
-
495
- set hugeJumpDistance(hugeJumpDistance) {
496
- this._hugeJumpDistance = hugeJumpDistance;
497
- }
498
-
499
- get disableMMCloseToATurnDistance() {
500
- return this._disableMMCloseToATurnDistance;
501
- }
502
-
503
- set disableMMCloseToATurnDistance(disableMMCloseToATurnDistance) {
504
- this._disableMMCloseToATurnDistance = disableMMCloseToATurnDistance;
505
- }
506
-
507
- get minStepsBetweenOrientationMatching() {
508
- return this._minStepsBetweenOrientationMatching;
509
- }
510
-
511
- set minStepsBetweenOrientationMatching(minStepsBetweenOrientationMatching) {
512
- this._minStepsBetweenOrientationMatching = minStepsBetweenOrientationMatching;
513
- }
514
-
515
- get minStepsForOrientationMatching() {
516
- return this._minStepsForOrientationMatching;
517
- }
518
-
519
- set minStepsForOrientationMatching(minStepsForOrientationMatching) {
520
- this._minStepsForOrientationMatching = minStepsForOrientationMatching;
521
- }
522
-
523
- get lastProjectionsWindowSize() {
524
- return this._lastProjectionsWindowSize;
525
- }
526
-
527
- set lastProjectionsWindowSize(lastProjectionsWindowSize) {
528
- this._lastProjectionsWindowSize = lastProjectionsWindowSize;
529
- }
530
-
531
- get lastProjectionsEdgeAngleThreshold() {
532
- return this._lastProjectionsEdgeAngleThreshold;
533
- }
534
-
535
- set lastProjectionsEdgeAngleThreshold(lastProjectionsEdgeAngleThreshold) {
536
- this._lastProjectionsEdgeAngleThreshold = lastProjectionsEdgeAngleThreshold;
537
- }
538
- }
539
-
540
- export default new MapMatchingHandler();
@@ -1,5 +0,0 @@
1
- const Constants = {
2
- DEFAULT_ALTITUDE: 1.6
3
- };
4
-
5
- export default Constants;