@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
|
@@ -127,7 +127,7 @@ class Provider {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
get nativeInterface() {
|
|
130
|
-
return typeof window !== 'undefined' ? (window.
|
|
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
|
-
|
|
170
|
-
|
|
172
|
+
/**
|
|
173
|
+
* Trying the best to retrieve a good quaternion from devicemotion event.
|
|
174
|
+
*/
|
|
171
175
|
|
|
172
176
|
let alpha;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
|