Skip to content

Commit de4a7ff

Browse files
committed
fix: update rotation correctly
1 parent d9862f5 commit de4a7ff

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

scripts/map.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let deviceHeadingOffset = 0; // offset between the gps heading when above 5kph a
1212
let watchPositionIDs = [];
1313
let last5PositionsAngles = [];
1414
let inStraightLine = false;
15-
let isRotationEnabled = false;
15+
let isRotationEnabled;
1616

1717
async function initMap() {
1818
// Set cycleways style
@@ -463,6 +463,8 @@ function getLocation(zoom = true, followLocationOverride) {
463463

464464
function startLocationDotRotation() {
465465
if (isRotationEnabled) return;
466+
isRotationEnabled = true;
467+
console.log("Enabling rotation");
466468
let isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
467469

468470
let handler = e => {
@@ -531,18 +533,25 @@ function startLocationDotRotation() {
531533
"Nos dispositivos Apple, é necessária permissão do utilizador para aceder à bússola do dispositivo.",
532534
() => {
533535
// User clicked OK
534-
DeviceOrientationEvent.requestPermission()
536+
DeviceOrientationEvent.requestPermission?.()
535537
.then(response => {
536538
if (response === "granted") {
537539
window.addEventListener("deviceorientation", e => requestAnimationFrame(() => handler(e)), true);
538540
} else {
541+
isRotationEnabled = false;
539542
alert("A orientação não irá funcionar corretamente!");
540543
}
541544
})
542-
.catch(() => alert("Bússola não suportada"));
545+
.catch(() => {
546+
isRotationEnabled = false;
547+
alert("Bússola não suportada");
548+
});
543549
},
544550
// User clicked Ignore
545-
() => alert("A orientação não irá funcionar corretamente!"),
551+
() => {
552+
isRotationEnabled = false;
553+
alert("A orientação não irá funcionar corretamente!");
554+
},
546555
"Ok",
547556
"Ignorar"
548557
);
@@ -564,5 +573,4 @@ function startLocationDotRotation() {
564573
} else {
565574
window.addEventListener("deviceorientationabsolute", e => requestAnimationFrame(() => handler(e)), true);
566575
}
567-
isRotationEnabled = true;
568576
}

scripts/navigation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ async function orientationChangeHandler(event) {
436436

437437
async function goIntoLandscapeNavigationUI() {
438438
startLocationDotRotation();
439+
getLocation();
439440
// Make the device awake
440441
try {
441442
wakeLock = await navigator.wakeLock.request("screen");

0 commit comments

Comments
 (0)