@wemap/providers 3.2.17 → 3.2.18

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
@@ -42,6 +42,6 @@
42
42
  "url": "git+https://github.com/wemap/wemap-modules-js.git"
43
43
  },
44
44
  "type": "module",
45
- "version": "3.2.17",
46
- "gitHead": "8b5e0144472bfaa8e07ac24cb227294c83a7541a"
45
+ "version": "3.2.18",
46
+ "gitHead": "5b5342754059b05298d7961f78c13b8198685a85"
47
47
  }
@@ -127,7 +127,7 @@ class Provider {
127
127
  }
128
128
 
129
129
  get nativeInterface() {
130
- return typeof window !== 'undefined' ? (window.WemapProvidersAndroid || null) : null;
130
+ return typeof window !== 'undefined' ? (window.__nativeProviders || null) : null;
131
131
  }
132
132
 
133
133
  get useCameraNatively() {
@@ -152,6 +152,9 @@ class AbsoluteAttitudeFromBrowserProvider extends Provider {
152
152
  };
153
153
 
154
154
 
155
+ iosPreviousQuat = null;
156
+ iosIsSkyMode;
157
+
155
158
  onDeviceOrientationSafariEvent = e => {
156
159
 
157
160
  this.magQuaternionTimestamp = e.timeStamp / 1e3;
@@ -166,17 +169,47 @@ class AbsoluteAttitudeFromBrowserProvider extends Provider {
166
169
  return;
167
170
  }
168
171
 
169
- // The following code works only in beta < 135.
170
- // TODO: enhance
172
+ /**
173
+ * Trying the best to retrieve a good quaternion from devicemotion event.
174
+ */
171
175
 
172
176
  let alpha;
173
- // Next condition is not optimal
174
- // if (Math.abs(e.beta) > 135) {
175
- // alpha = 180 - e.webkitCompassHeading;
176
- // } else {
177
- alpha = AbsoluteAttitudeFromBrowserProvider.webkitCompassToHeading(
178
- e.webkitCompassHeading, e.beta, e.gamma);
179
- // }
177
+ const [qw, qx, qy, qz] = Rotations.eulerToQuaternionZXYDegrees([e.webkitCompassHeading, e.beta, e.gamma]);
178
+ const groundAngle = rad2deg(Math.acos(qw ** 2 - qx ** 2 - qy ** 2 + qz ** 2));
179
+
180
+ let isSkyMode;
181
+ if (groundAngle > 136) {
182
+ isSkyMode = true;
183
+ } else if (groundAngle < 134) {
184
+ isSkyMode = false;
185
+ } else if (this.iosPreviousQuat && this.iosIsSkyMode !== null) {
186
+ /**
187
+ * This condition is true only if :
188
+ * - we are in the [134°; 136°] ground angle range
189
+ * - we know the previous quaternion
190
+ * - one of the both previous condition has been reached during this session
191
+ *
192
+ * In this case, we define a threshold to detect if there is a "jump" in the quaternion calculation,
193
+ * then, the mode is switched.
194
+ */
195
+ isSkyMode = Quaternion.distance([qw, qx, qy, qz], this.iosPreviousQuat) < 0.5
196
+ ? this.iosIsSkyMode
197
+ : !this.iosIsSkyMode;
198
+ }
199
+ this.iosPreviousQuat = [qw, qx, qy, qz];
200
+ this.iosIsSkyMode = isSkyMode;
201
+
202
+ if (typeof (isSkyMode) === 'undefined') {
203
+ // Algorithm uncertainity
204
+ return;
205
+ }
206
+
207
+ if (isSkyMode) {
208
+ alpha = 180 - e.webkitCompassHeading;
209
+ } else {
210
+ alpha = AbsoluteAttitudeFromBrowserProvider.webkitCompassToHeading(
211
+ e.webkitCompassHeading, e.beta, e.gamma);
212
+ }
180
213
 
181
214
  this.magQuaternion = Rotations.eulerToQuaternionZXYDegrees([alpha, e.beta, e.gamma]);
182
215