Raruto / leaflet-rotate

Leaflet plugin that allows to add rotation functionality to map tiles
GNU General Public License v3.0
81 stars 23 forks source link

Allow iPhone Compass requestPermission() #44

Closed ttooo closed 8 months ago

ttooo commented 11 months ago

This isn't an issue, I found a fix, so if you want to add it for iPhone support it's good. By default on iPhone devices the compass access is not authorized, you can show this code to ensure the iPhone support will work after permission asked :

allow-iphone

// Compass mode
      else if (!map.compassBearing.enabled()) {
        map.touchRotate.disable();
        // map.compassBearing.enable(); // -- before

        // new code added ---> start
        if (DeviceOrientationEvent && typeof DeviceOrientationEvent.requestPermission === "function") {
          DeviceOrientationEvent.requestPermission().then(function (permissionState) {
            if (permissionState === "granted") {
              map.compassBearing.enable();
            }
          });
        } else {
          map.compassBearing.enable();
        }
        // new code added <--- end
      }
Raruto commented 11 months ago

Thanks @ttooo, I can't test but please send a PR anyway.

👋 Raruto