@@ -12,7 +12,7 @@ let deviceHeadingOffset = 0; // offset between the gps heading when above 5kph a
1212let watchPositionIDs = [ ] ;
1313let last5PositionsAngles = [ ] ;
1414let inStraightLine = false ;
15- let isRotationEnabled = false ;
15+ let isRotationEnabled ;
1616
1717async function initMap ( ) {
1818 // Set cycleways style
@@ -463,6 +463,8 @@ function getLocation(zoom = true, followLocationOverride) {
463463
464464function startLocationDotRotation ( ) {
465465 if ( isRotationEnabled ) return ;
466+ isRotationEnabled = true ;
467+ console . log ( "Enabling rotation" ) ;
466468 let isIOS = / i P a d | i P h o n e | i P o d / . 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}
0 commit comments