@wemap/providers 6.1.1 → 6.1.3

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/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "@wemap/geo": "^6.0.0",
13
13
  "@wemap/geomagnetism": "^0.1.1",
14
14
  "@wemap/logger": "^6.0.0",
15
- "@wemap/map": "^6.0.2",
15
+ "@wemap/map": "^6.1.2",
16
16
  "@wemap/maths": "^6.0.0",
17
17
  "@wemap/osm": "^6.0.0",
18
18
  "@wemap/utils": "^6.0.0"
@@ -40,6 +40,6 @@
40
40
  "url": "git+https://github.com/wemap/wemap-modules-js.git"
41
41
  },
42
42
  "type": "module",
43
- "version": "6.1.1",
44
- "gitHead": "b3cb15c80ce9428bcffa00c946d63fd71688a384"
43
+ "version": "6.1.3",
44
+ "gitHead": "98aaf7ce4508834258b528bbf9dca90b0045f882"
45
45
  }
@@ -80,6 +80,7 @@ class ProvidersInterface {
80
80
  return AbsoluteAttitude;
81
81
 
82
82
  case EventType.AbsolutePosition:
83
+ case EventType.ForceVps:
83
84
  return AbsolutePosition;
84
85
 
85
86
  case EventType.RelativeAttitude:
@@ -34,5 +34,7 @@ export default {
34
34
  CameraNative: 'CAMERA_NATIVE',
35
35
 
36
36
  Itinerary: 'ITINERARY',
37
- Network: 'NETWORK'
37
+ Network: 'NETWORK',
38
+
39
+ ForceVps: 'FORCE_VPS'
38
40
  };
@@ -28,6 +28,9 @@ class AbsolutePosition extends Provider {
28
28
  /** @type {number?} */
29
29
  _mapMatchingHandlerId
30
30
 
31
+ /** @type {boolean?} */
32
+ _waitUntilNextVpsPosition = false;
33
+
31
34
  /**
32
35
  * @override
33
36
  */
@@ -70,14 +73,9 @@ class AbsolutePosition extends Provider {
70
73
  if (ProvidersOptions.hasVps) {
71
74
 
72
75
  this._vpsProviderId = Vps.addEventListener(events => {
73
- for (const providerEvent of events) {
74
- if (providerEvent.dataType === EventType.AbsolutePosition) {
75
- this._onAbsolutePosition(providerEvent);
76
- Vps.removeEventListener(this._vpsProviderId);
77
- this._vpsProviderId = null;
78
- return;
79
- }
80
- }
76
+ this._onAbsolutePosition(events.find(event => event.dataType === EventType.AbsolutePosition));
77
+ Vps.removeEventListener(this._vpsProviderId);
78
+ this._vpsProviderId = null;
81
79
  });
82
80
 
83
81
  } else {
@@ -170,7 +168,7 @@ class AbsolutePosition extends Provider {
170
168
  */
171
169
  _onRelativePosition(relativeEvent) {
172
170
 
173
- if (!this.lastEvent) {
171
+ if (!this.lastEvent || this._waitUntilNextVpsPosition) {
174
172
  return;
175
173
  }
176
174
 
@@ -207,12 +205,27 @@ class AbsolutePosition extends Provider {
207
205
  /**
208
206
  * @override
209
207
  * @param {UserPosition|ProviderEvent} data
208
+ * @param {EventType} eventType
210
209
  */
211
- feed(data) {
210
+ feed(data, eventType) {
212
211
 
213
212
  /** @type {ProviderEvent<UserPosition>} */
214
213
  let newPositionEvent;
215
214
 
215
+ if (eventType === EventType.ForceVps && !this._vpsProviderId) {
216
+
217
+ this._waitUntilNextVpsPosition = true;
218
+ this._vpsProviderId = Vps.addEventListener(events => {
219
+ this._waitUntilNextVpsPosition = false;
220
+ this._onAbsolutePosition(events.find(event => event.dataType === EventType.AbsolutePosition));
221
+ Vps.removeEventListener(this._vpsProviderId);
222
+ this._vpsProviderId = null;
223
+ });
224
+
225
+ return;
226
+
227
+ }
228
+
216
229
  if (data instanceof UserPosition) {
217
230
 
218
231
  if (data.time === null) {
@@ -104,7 +104,7 @@ class Vps extends Provider {
104
104
  camera.on('started', this._internalStart);
105
105
  camera.on('stopped', this._internalStop);
106
106
 
107
- if (camera.isStarted) {
107
+ if (camera.state === Camera.State.STARTED) {
108
108
  this._internalStart();
109
109
  }
110
110
  }
@@ -114,13 +114,13 @@ class Vps extends Provider {
114
114
 
115
115
  this._serverError = false;
116
116
 
117
- let lastTimestamp = -1;
118
-
119
117
  while (this.state !== ProviderState.STOPPPED) {
120
118
 
121
- const diffTime = TimeUtils.preciseTime() - lastTimestamp;
122
- const timeToWait = Math.max(0, Vps.MIN_TIME_BETWEEN_TWO_REQUESTS - diffTime);
123
- await new Promise(resolve => setTimeout(resolve, timeToWait));
119
+ if (this.lastEvent) {
120
+ const diffTime = TimeUtils.preciseTime() - this.lastEvent.data.time * 1e3;
121
+ const timeToWait = Math.max(0, Vps.MIN_TIME_BETWEEN_TWO_REQUESTS - diffTime);
122
+ await new Promise(resolve => setTimeout(resolve, timeToWait));
123
+ }
124
124
 
125
125
  if (this.state === ProviderState.STOPPPED) {
126
126
  break;
@@ -159,8 +159,6 @@ class Vps extends Provider {
159
159
  if (events.length) {
160
160
  this.notify(...events);
161
161
  }
162
-
163
- lastTimestamp = TimeUtils.preciseTime();
164
162
  }
165
163
 
166
164
  if (this.state !== ProviderState.STOPPPED) {
@@ -182,7 +180,7 @@ class Vps extends Provider {
182
180
 
183
181
  // Retrieve the image
184
182
  const image = await camera.currentImage;
185
- const time = TimeUtils.preciseTime();
183
+ const time = TimeUtils.preciseTime() / 1e3;
186
184
  // TODO: move the grayscale conversion in the currentImage getter
187
185
  CameraUtils.convertToGrayscale(image);
188
186
  const reducedImage = CameraUtils.reduceImageSize(image, 1280);