@wemap/providers 3.2.4 → 3.2.5

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/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import EventType from './src/events/EventType.js';
2
2
  import PositionSmoother from './src/smoothers/PositionSmoother.js';
3
3
  import ProvidersInterface from './src/ProvidersInterface.js';
4
+ import ProvidersLogger from './src/logger/ProvidersLogger.js';
4
5
  import ProvidersOptions from './src/ProvidersOptions.js';
6
+ import Utils from './src/utils/index.js';
5
7
 
6
8
  export {
7
- EventType, PositionSmoother, ProvidersInterface, ProvidersOptions
9
+ EventType, PositionSmoother, ProvidersInterface, ProvidersLogger, ProvidersOptions, Utils
8
10
  };
package/package.json CHANGED
@@ -9,10 +9,10 @@
9
9
  ],
10
10
  "dependencies": {
11
11
  "@wemap/geo": "^3.2.3",
12
- "@wemap/graph": "^3.2.3",
12
+ "@wemap/graph": "^3.2.5",
13
13
  "@wemap/logger": "^3.2.3",
14
14
  "@wemap/maths": "^3.2.3",
15
- "@wemap/navigation-logger": "^3.2.4",
15
+ "@wemap/navigation-logger": "^3.2.5",
16
16
  "@wemap/utils": "^3.2.3",
17
17
  "geomagnetism": "^0.1.0",
18
18
  "lodash.isempty": "^4.4.0",
@@ -20,8 +20,8 @@
20
20
  },
21
21
  "description": "A package using different geoloc systems",
22
22
  "devDependencies": {
23
- "@wemap/map": "^3.2.3",
24
- "@wemap/osm": "^3.2.3",
23
+ "@wemap/map": "^3.2.5",
24
+ "@wemap/osm": "^3.2.5",
25
25
  "mapbox-gl": "^1.11.1",
26
26
  "mapbox-gl-indoor": "0.0.4"
27
27
  },
@@ -44,6 +44,6 @@
44
44
  "url": "git+https://github.com/wemap/wemap-modules-js.git"
45
45
  },
46
46
  "type": "module",
47
- "version": "3.2.4",
48
- "gitHead": "2b6080727464a2b671cd173a317ffd7bb196f789"
47
+ "version": "3.2.5",
48
+ "gitHead": "e90b23e4265edc0073101a70c6300fa54cd3d379"
49
49
  }
@@ -3,7 +3,6 @@ import {
3
3
  Attitude, AbsoluteHeading, UserPosition
4
4
  } from '@wemap/geo';
5
5
  import { Network } from '@wemap/graph';
6
- import { NavigationLogger } from '@wemap/navigation-logger';
7
6
 
8
7
  import EventType from './events/EventType.js';
9
8
  import MetaProvider from './providers/MetaProvider.js';
@@ -11,6 +10,7 @@ import {
11
10
  AbsoluteAttitude, AbsolutePosition, Barcode, CameraNative, CameraProjectionMatrix, Inclination
12
11
  } from './Providers.js';
13
12
  import ProvidersLoggerOld from './events/ProvidersLoggerOld.js';
13
+ import ProvidersLogger from './logger/ProvidersLogger.js';
14
14
 
15
15
  class ProvidersInterface {
16
16
 
@@ -48,7 +48,7 @@ class ProvidersInterface {
48
48
  * @param {Object} data
49
49
  */
50
50
  static feed(eventType, data) {
51
- NavigationLogger.feedExternalData(eventType, data, true);
51
+ ProvidersLogger.feedExternalData(eventType, data, true);
52
52
  this._checkEventTypeDataConsistency(eventType, data);
53
53
  this._getMetaProviderFromEventType(eventType).feed(data, eventType);
54
54
  }
@@ -136,7 +136,7 @@ class ProvidersInterface {
136
136
 
137
137
  static set mapMatchingMaxDistance(maxDistance) {
138
138
  AbsolutePosition.mapMatchingMaxDistance = maxDistance;
139
- NavigationLogger.feedProvidersMM({ mapMatchingMaxDistance: maxDistance });
139
+ ProvidersLogger.feedProvidersMM({ mapMatchingMaxDistance: maxDistance });
140
140
  }
141
141
 
142
142
  static get mapMatchingMinDistance() {
@@ -145,7 +145,7 @@ class ProvidersInterface {
145
145
 
146
146
  static set mapMatchingMinDistance(minDistance) {
147
147
  AbsolutePosition.mapMatchingMinDistance = minDistance;
148
- NavigationLogger.feedProvidersMM({ mapMatchingMinDistance: minDistance });
148
+ ProvidersLogger.feedProvidersMM({ mapMatchingMinDistance: minDistance });
149
149
  }
150
150
 
151
151
  static get mapMatchingMaxAngleBearing() {
@@ -154,7 +154,7 @@ class ProvidersInterface {
154
154
 
155
155
  static set mapMatchingMaxAngleBearing(maxAngleBearing) {
156
156
  AbsolutePosition.mapMatchingMaxAngleBearing = maxAngleBearing;
157
- NavigationLogger.feedProvidersMM({ mapMatchingMaxAngleBearing: maxAngleBearing });
157
+ ProvidersLogger.feedProvidersMM({ mapMatchingMaxAngleBearing: maxAngleBearing });
158
158
  }
159
159
  }
160
160
 
@@ -0,0 +1,78 @@
1
+ import ProvidersOptions from '../ProvidersOptions';
2
+ import ProvidersLoggerConverter from './ProvidersLoggerConverter.js';
3
+
4
+ import { NavigationLogger } from '@wemap/navigation-logger';
5
+ import { TimeUtils } from '@wemap/utils';
6
+
7
+ class ProvidersLogger {
8
+
9
+ static logs = [];
10
+ static currentLogIndex = 0;
11
+
12
+ static Converter = ProvidersLoggerConverter;
13
+
14
+ static feedImuData(event) {
15
+ if (!NavigationLogger.isRecording) {
16
+ return;
17
+ }
18
+ this._feed(ProvidersLoggerConverter.imuDataToLog(TimeUtils.preciseTime, event));
19
+ }
20
+
21
+ static feedGeolocation(geolocationEvent) {
22
+ if (!NavigationLogger.isRecording) {
23
+ return;
24
+ }
25
+ this._feed(ProvidersLoggerConverter.geolocationToLog(TimeUtils.preciseTime, geolocationEvent));
26
+ }
27
+
28
+ static feedExternalData(eventType, data) {
29
+ if (!NavigationLogger.isRecording) {
30
+ return;
31
+ }
32
+ this._feed(ProvidersLoggerConverter.externalDataToLog(TimeUtils.preciseTime, eventType, data));
33
+ }
34
+
35
+ static feedProvidersMM(obj) {
36
+ if (!NavigationLogger.isRecording) {
37
+ return;
38
+ }
39
+ this._feed(ProvidersLoggerConverter.providersMMToLog(TimeUtils.preciseTime, obj));
40
+ }
41
+
42
+ static _feed(line) {
43
+ this.logs[this.currentLogIndex++] = line;
44
+ }
45
+
46
+ static _onStart() {
47
+ fetch(NavigationLogger.apiUrl + '/providers-config', {
48
+ method: 'POST',
49
+ headers: {
50
+ 'Accept': 'application/json',
51
+ 'Content-Type': 'application/json'
52
+ },
53
+ body: JSON.stringify({ ProvidersOptions })
54
+ });
55
+ }
56
+
57
+ static _onFlush() {
58
+
59
+ if (this.logs.length === 0) {
60
+ return;
61
+ }
62
+
63
+ fetch(NavigationLogger.apiUrl + '/providers', {
64
+ method: 'POST',
65
+ headers: { 'Content-Type': 'text/plain' },
66
+ body: this.logs.join('\n')
67
+ });
68
+
69
+ this.logs = [];
70
+ this.currentLogIndex = 0;
71
+ }
72
+
73
+ }
74
+
75
+ NavigationLogger.on('started', () => ProvidersLogger._onStart());
76
+ NavigationLogger.on('flush', () => ProvidersLogger._onFlush());
77
+
78
+ export default ProvidersLogger;
@@ -0,0 +1,275 @@
1
+ /* eslint-disable complexity */
2
+ import {
3
+ UserPosition, AbsoluteHeading, Attitude
4
+ } from '@wemap/geo';
5
+ import {
6
+ Network, Itinerary
7
+ } from '@wemap/graph';
8
+
9
+ import { EventType } from '@wemap/providers';
10
+
11
+ const SEPARATOR = ',';
12
+
13
+ const PRECISION = 1e-6;
14
+ const PRECISION_INV = 1 / PRECISION;
15
+ const round = num => typeof num === 'number' ? Math.round(num * PRECISION_INV) / PRECISION_INV : num;
16
+
17
+ class ProvidersLoggerConverter {
18
+
19
+ static geolocationToLog(time, event) {
20
+ return [
21
+ 2,
22
+ round(time),
23
+ round(event.timestamp),
24
+ event.coords.latitude,
25
+ event.coords.longitude,
26
+ typeof event.coords.altitude === 'number' ? round(event.coords.altitude) : null,
27
+ round(event.coords.accuracy),
28
+ typeof event.coords.altitudeAccuracy === 'number' ? round(event.coords.altitudeAccuracy) : null,
29
+ typeof event.coords.heading === 'number' ? round(event.coords.heading) : null,
30
+ typeof event.coords.speed === 'number' ? round(event.coords.speed) : null
31
+ ].join(SEPARATOR);
32
+ }
33
+
34
+ static imuDataToLog(time, event) {
35
+ switch (event.type) {
36
+
37
+ case 'devicemotion':
38
+ const acc = event.accelerationIncludingGravity;
39
+ const gyr = event.rotationRate;
40
+ const linearAcc = event.acceleration;
41
+ return [
42
+ 3,
43
+ event.type,
44
+ round(time),
45
+ round(event.timeStamp),
46
+ acc && typeof acc.x === 'number' ? round(acc.x) : null,
47
+ acc && typeof acc.y === 'number' ? round(acc.y) : null,
48
+ acc && typeof acc.z === 'number' ? round(acc.z) : null,
49
+ gyr && typeof gyr.alpha === 'number' ? round(gyr.alpha) : null,
50
+ gyr && typeof gyr.beta === 'number' ? round(gyr.beta) : null,
51
+ gyr && typeof gyr.gamma === 'number' ? round(gyr.gamma) : null,
52
+ linearAcc && typeof linearAcc.x === 'number' ? round(linearAcc.x) : null,
53
+ linearAcc && typeof linearAcc.y === 'number' ? round(linearAcc.y) : null,
54
+ linearAcc && typeof linearAcc.z === 'number' ? round(linearAcc.z) : null,
55
+ round(event.interval)
56
+ ].join(SEPARATOR);
57
+
58
+ case 'deviceorientation':
59
+ return [
60
+ 3,
61
+ event.type,
62
+ round(time),
63
+ round(event.timeStamp),
64
+ round(event.alpha),
65
+ round(event.beta),
66
+ round(event.gamma),
67
+ round(event.webkitCompassHeading),
68
+ event.absolute ? 1 : 0
69
+ ].join(SEPARATOR);
70
+
71
+ case 'deviceorientationabsolute':
72
+ return [
73
+ 3,
74
+ event.type,
75
+ round(time),
76
+ round(event.timeStamp),
77
+ round(event.alpha),
78
+ round(event.beta),
79
+ round(event.gamma),
80
+ event.absolute ? 1 : 0
81
+ ].join(SEPARATOR);
82
+ }
83
+
84
+ throw new Error(`Cannot parse event: ${event.type}`, event);
85
+ }
86
+
87
+ static externalDataToLog(time, eventType, data) {
88
+ switch (eventType) {
89
+ case EventType.Network:
90
+ if (data instanceof Itinerary) {
91
+ return [4, 'itinerary', round(time), data === null ? null : JSON.stringify(data.toCompressedJson())].join(SEPARATOR);
92
+ }
93
+ return [4, 'network', round(time), data === null ? null : JSON.stringify(data.toCompressedJson())].join(SEPARATOR);
94
+ case EventType.AbsolutePosition:
95
+ return [4, 'absolute-position', round(time), JSON.stringify(data.toJson())].join(SEPARATOR);
96
+ case EventType.AbsoluteHeading:
97
+ return [4, 'absolute-heading', round(time), JSON.stringify(data.toJson())].join(SEPARATOR);
98
+ case EventType.AbsoluteAttitude:
99
+ return [4, 'absolute-attitude', round(time), JSON.stringify(data.toJson())].join(SEPARATOR);
100
+ }
101
+ return [4, 'unknown', eventType].join(SEPARATOR);
102
+ }
103
+
104
+ static providersMMToLog(time, obj) {
105
+ return [5, time, JSON.stringify(obj)].join(SEPARATOR);
106
+ }
107
+
108
+
109
+ static logToObj(str) {
110
+ const logType = parseInt(str[0], 10);
111
+ switch (logType) {
112
+ case 2:
113
+ return this.logToGeolocation(str);
114
+ case 3:
115
+ return this.logToImu(str);
116
+ case 4:
117
+ return this.logToExternalData(str);
118
+ case 5:
119
+ return this.logToProvidersMM(str);
120
+ }
121
+
122
+ throw new Error(`Cannot parse log: ${str}`);
123
+ }
124
+
125
+ static logToGeolocation(str) {
126
+ const array = str.split(SEPARATOR).map(parseFloat);
127
+ return {
128
+ type: 'geolocation',
129
+ time: array[1],
130
+ data: {
131
+ timestamp: array[2],
132
+ coords: {
133
+ latitude: array[3],
134
+ longitude: array[4],
135
+ altitude: array[5],
136
+ accuracy: array[6],
137
+ altitudeAccuracy: array[7],
138
+ heading: array[8],
139
+ speed: array[9]
140
+ }
141
+ }
142
+ };
143
+ }
144
+
145
+ static logToImu(str) {
146
+
147
+ const indexOfSecondComma = str.indexOf(SEPARATOR, 2);
148
+ const eventName = str.substring(2, indexOfSecondComma);
149
+ const data = str.substring(indexOfSecondComma + 1).split(SEPARATOR).map(parseFloat);
150
+
151
+ const event = new CustomEvent(eventName);
152
+ Object.defineProperties(event, { timeStamp: { writable: true } });
153
+
154
+ switch (eventName) {
155
+ case 'devicemotion':
156
+ Object.assign(event, {
157
+ timeStamp: data[1],
158
+ accelerationIncludingGravity: {
159
+ x: data[2],
160
+ y: data[3],
161
+ z: data[4]
162
+ },
163
+ rotationRate: {
164
+ alpha: data[5],
165
+ beta: data[6],
166
+ gamma: data[7]
167
+ },
168
+ acceleration: {
169
+ x: data[8],
170
+ y: data[9],
171
+ z: data[10]
172
+ }
173
+ });
174
+ break;
175
+
176
+ case 'deviceorientation':
177
+ Object.assign(event, {
178
+ timeStamp: data[1],
179
+ alpha: data[2],
180
+ beta: data[3],
181
+ gamma: data[4],
182
+ webkitCompassHeading: data[5],
183
+ absolute: data[6] === 1
184
+ });
185
+ break;
186
+
187
+
188
+ case 'deviceorientationabsolute':
189
+ Object.assign(event, {
190
+ timeStamp: data[1],
191
+ alpha: data[2],
192
+ beta: data[3],
193
+ gamma: data[4],
194
+ absolute: data[5] === 1
195
+ });
196
+ break;
197
+ }
198
+
199
+ return {
200
+ type: 'imu',
201
+ time: data[0],
202
+ data: event
203
+ };
204
+ }
205
+
206
+ static logToExternalData(str) {
207
+
208
+ const indexOfSecondComma = str.indexOf(SEPARATOR, 2);
209
+ const eventTypeStr = str.substring(2, indexOfSecondComma);
210
+
211
+ const indexOfThirdComma = str.indexOf(SEPARATOR, indexOfSecondComma + 1);
212
+ const time = parseFloat(str.substring(indexOfSecondComma + 1, indexOfThirdComma));
213
+
214
+ const dataStr = str.substring(indexOfThirdComma + 1);
215
+
216
+ let data;
217
+ switch (eventTypeStr) {
218
+
219
+ case 'network':
220
+ data = {
221
+ eventType: EventType.Network,
222
+ data: dataStr === null ? null : Network.fromCompressedJson(JSON.parse(dataStr))
223
+ };
224
+ break;
225
+
226
+ case 'itinerary':
227
+ data = {
228
+ eventType: EventType.Network,
229
+ data: dataStr === null ? null : Itinerary.fromCompressedJson(JSON.parse(dataStr))
230
+ };
231
+ break;
232
+
233
+ case 'absolute-position':
234
+ data = {
235
+ eventType: EventType.AbsolutePosition,
236
+ data: dataStr === null ? null : UserPosition.fromJson(JSON.parse(dataStr))
237
+ };
238
+ break;
239
+
240
+ case 'absolute-attitude':
241
+ data = {
242
+ eventType: EventType.AbsoluteAttitude,
243
+ data: dataStr === null ? null : Attitude.fromJson(JSON.parse(dataStr))
244
+ };
245
+ break;
246
+
247
+ case 'absolute-heading':
248
+ data = {
249
+ eventType: EventType.AbsoluteHeading,
250
+ data: dataStr === null ? null : AbsoluteHeading.fromJson(JSON.parse(dataStr))
251
+ };
252
+ break;
253
+
254
+ default:
255
+ throw new Error(`Cannot parse eventType: ${eventTypeStr}`);
256
+ }
257
+
258
+ return {
259
+ type: 'external',
260
+ time,
261
+ data
262
+ };
263
+ }
264
+
265
+ static logToProvidersMM(str) {
266
+ const array = str.split(SEPARATOR);
267
+ return {
268
+ type: 'providersMM',
269
+ time: parseFloat(array[1]),
270
+ data: JSON.parse(array[2])
271
+ };
272
+ }
273
+ }
274
+
275
+ export default ProvidersLoggerConverter;
@@ -6,7 +6,6 @@ import {
6
6
  import {
7
7
  deg2rad, rad2deg, Quaternion, Rotations
8
8
  } from '@wemap/maths';
9
- import { NavigationLogger } from '@wemap/navigation-logger';
10
9
  import {
11
10
  Browser, BrowserUtils
12
11
  } from '@wemap/utils';
@@ -17,6 +16,7 @@ import AskImuOnDesktopError from '../../../errors/AskImuOnDesktopError.js';
17
16
  import MissingMagnetometerError from '../../../errors/MissingMagnetometerError.js';
18
17
  import MissingSensorError from '../../../errors/MissingSensorError.js';
19
18
  import { AbsolutePosition } from '../../../Providers.js';
19
+ import ProvidersLogger from '../../../logger/ProvidersLogger.js';
20
20
 
21
21
 
22
22
  /**
@@ -136,7 +136,7 @@ class AbsoluteAttitudeFromBrowserProvider extends Provider {
136
136
 
137
137
 
138
138
  onDeviceOrientationChromeEvent = e => {
139
- NavigationLogger.feedImuData(e);
139
+ ProvidersLogger.feedImuData(e);
140
140
 
141
141
  this.magQuaternionTimestamp = e.timeStamp / 1e3;
142
142
 
@@ -153,7 +153,7 @@ class AbsoluteAttitudeFromBrowserProvider extends Provider {
153
153
 
154
154
 
155
155
  onDeviceOrientationSafariEvent = e => {
156
- NavigationLogger.feedImuData(e);
156
+ ProvidersLogger.feedImuData(e);
157
157
 
158
158
  this.magQuaternionTimestamp = e.timeStamp / 1e3;
159
159
 
@@ -1,6 +1,5 @@
1
1
  import { Attitude } from '@wemap/geo';
2
2
  import { Rotations } from '@wemap/maths';
3
- import { NavigationLogger } from '@wemap/navigation-logger';
4
3
  import { BrowserUtils } from '@wemap/utils';
5
4
 
6
5
  import Provider from '../../Provider.js';
@@ -8,6 +7,7 @@ import EventType from '../../../events/EventType.js';
8
7
  import AskImuOnDesktopError from '../../../errors/AskImuOnDesktopError.js';
9
8
  import MissingSensorError from '../../../errors/MissingSensorError.js';
10
9
  import RelativeAttitudeFromInertialProvider from './RelativeAttitudeFromInertialProvider.js';
10
+ import ProvidersLogger from '../../../logger/ProvidersLogger.js';
11
11
 
12
12
 
13
13
  /**
@@ -80,7 +80,7 @@ class RelativeAttitudeFromBrowserProvider extends Provider {
80
80
 
81
81
 
82
82
  onDeviceOrientationEvent = e => {
83
- NavigationLogger.feedImuData(e);
83
+ ProvidersLogger.feedImuData(e);
84
84
 
85
85
  const timestamp = e.timeStamp / 1e3;
86
86
 
@@ -1,5 +1,4 @@
1
1
  import { deg2rad } from '@wemap/maths';
2
- import { NavigationLogger } from '@wemap/navigation-logger';
3
2
  import {
4
3
  Browser, BrowserUtils
5
4
  } from '@wemap/utils';
@@ -7,6 +6,7 @@ import {
7
6
  import Provider from '../Provider.js';
8
7
  import EventType from '../../events/EventType';
9
8
  import AskImuOnDesktopError from '../../errors/AskImuOnDesktopError.js';
9
+ import ProvidersLogger from '../../logger/ProvidersLogger.js';
10
10
 
11
11
  /**
12
12
  * Imu (Inertial Measurement Unit) provider retrieve acceleration data
@@ -83,7 +83,7 @@ class ImuProvider extends Provider {
83
83
  * @private
84
84
  */
85
85
  parseDeviceMotionEvent = e => {
86
- NavigationLogger.feedImuData(e);
86
+ ProvidersLogger.feedImuData(e);
87
87
 
88
88
  const events = [];
89
89
 
@@ -1,6 +1,5 @@
1
1
  import { deg2rad } from '@wemap/maths';
2
2
  import { UserPosition } from '@wemap/geo';
3
- import { NavigationLogger } from '@wemap/navigation-logger';
4
3
  import { TimeUtils } from '@wemap/utils';
5
4
 
6
5
  import EventType from '../../../events/EventType.js';
@@ -9,6 +8,7 @@ import Provider from '../../Provider.js';
9
8
  import GeolocationPermissionDeniedError from '../../../errors/GeolocationPermissionDeniedError.js';
10
9
  import GeolocationPositionUnavailableError from '../../../errors/GeolocationPositionUnavailableError.js';
11
10
  import Constants from '../../Constants.js';
11
+ import ProvidersLogger from '../../../logger/ProvidersLogger.js';
12
12
 
13
13
  const POSITION_OPTIONS = {
14
14
  enableHighAccuracy: true,
@@ -73,7 +73,7 @@ class GnssWifiProvider extends Provider {
73
73
  * @private
74
74
  */
75
75
  onNewPosition = geolocation => {
76
- NavigationLogger.feedGeolocation(geolocation);
76
+ ProvidersLogger.feedGeolocation(geolocation);
77
77
 
78
78
  const { coords } = geolocation;
79
79
  if (!coords) {
@@ -0,0 +1,104 @@
1
+ import { Map } from 'mapbox-gl';
2
+
3
+ import { GeolocationLayer } from '@wemap/map';
4
+ import {
5
+ PositionSmoother, ProvidersInterface, EventType
6
+ } from '@wemap/providers';
7
+ import { TimeUtils } from '@wemap/utils';
8
+
9
+
10
+ /**
11
+ * Create map.geolocation object
12
+ * @param {Map} map
13
+ */
14
+ function addGeolocationOnMap(map) {
15
+
16
+ let smoother;
17
+
18
+ let attitudeProviderId;
19
+ let positionProviderId;
20
+
21
+ let isStarted = false;
22
+
23
+ Object.assign(map, { geolocation: new GeolocationLayer(map) });
24
+
25
+ Object.assign(map.geolocation, {
26
+
27
+ start: () => {
28
+
29
+ if (isStarted) {
30
+ return;
31
+ }
32
+ isStarted = true;
33
+
34
+ /**
35
+ * Attitude
36
+ */
37
+ attitudeProviderId = ProvidersInterface.addEventListener(
38
+ EventType.AbsoluteAttitude,
39
+ attitude => map.geolocation.updateHeading(attitude.headingDegrees)
40
+ );
41
+
42
+ // There is no sense to show the last known attitude on the map
43
+ // map.geolocation.updateHeading(ProvidersInterface.getLastKnown(EventType.AbsoluteAttitude));
44
+
45
+
46
+ /**
47
+ * Position
48
+ */
49
+
50
+ const positionTransform = input => {
51
+ if (input === null) {
52
+ return null;
53
+ }
54
+ return Object.assign(input.clone(),
55
+ { timestamp: TimeUtils.preciseTimeToUnixTimestamp(input.time * 1e3) }
56
+ );
57
+ };
58
+
59
+ smoother = new PositionSmoother(position => {
60
+ map.geolocation.updatePosition(positionTransform(position));
61
+ });
62
+
63
+ positionProviderId = ProvidersInterface.addEventListener(
64
+ EventType.AbsolutePosition,
65
+ position => smoother.feed(position)
66
+ );
67
+
68
+ const lastKnownPosition = ProvidersInterface.getLastKnown(EventType.AbsolutePosition);
69
+ if (lastKnownPosition) {
70
+ map.geolocation.updatePosition(positionTransform(lastKnownPosition));
71
+ }
72
+ },
73
+
74
+ stop: () => {
75
+
76
+ if (!isStarted) {
77
+ return;
78
+ }
79
+
80
+ /**
81
+ * Attitude
82
+ */
83
+
84
+ ProvidersInterface.removeEventListener(attitudeProviderId);
85
+
86
+
87
+ /**
88
+ * Position
89
+ */
90
+
91
+ ProvidersInterface.removeEventListener(positionProviderId);
92
+ smoother.clear();
93
+ smoother = null;
94
+
95
+ isStarted = false;
96
+ }
97
+ });
98
+
99
+ map.geolocation.on('start.clicked', map.geolocation.start);
100
+ map.geolocation.on('stop.clicked', map.geolocation.stop);
101
+ }
102
+
103
+
104
+ export default addGeolocationOnMap;
@@ -0,0 +1,3 @@
1
+ import addGeolocationOnMap from './addGeolocationOnMap.js';
2
+
3
+ export default { addGeolocationOnMap };