Skip to content

Commit

Permalink
fix leaflet-compass on iPhoneOS
Browse files Browse the repository at this point in the history
fixes stefanocudini/leaflet-compass#15
cf. domoritz/leaflet-locatecontrol#267

note: the request for permission may only be asked as response to
a user gesture (either click or touchend event), and via https;
not localhost/file

via: https://developer.apple.com/forums/thread/128376

https://stackoverflow.com/a/60239824/2171120 indicates that
exiting (swiping away) then restarting Safari will clear the
“asked?” status and this seems to wfm
  • Loading branch information
mirabilos committed Nov 23, 2022
1 parent 65a8a8e commit 6502c25
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion LICENCE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MirKarte itself is covered by The MirOS Licence:

# Copyright © 2014, 2015, 2017, 2018, 2020
# Copyright © 2014, 2015, 2017, 2018, 2020, 2022
# mirabilos <m@mirbsd.org>
#
# Provided that these terms and disclaimer and all copyright notices
Expand Down
20 changes: 18 additions & 2 deletions leaflet-compass/leaflet-compass.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,31 @@ L.Control.Compass = L.Control.extend({
return this._currentAngle;
},

activate: function() {

_activate: function () {
this._isActive = true;

L.DomEvent.on(window, 'deviceorientation', this._rotateHandler, this);

L.DomUtil.addClass(this._button, 'active');
},

activate: function () {
if (typeof(DeviceOrientationEvent) !== 'undefined' &&
typeof(DeviceOrientationEvent.requestPermission) === 'function') {
/* iPhoneOS, must ask interactively */
var that = this;
DeviceOrientationEvent.requestPermission().then(function (permission) {
if (permission === 'granted')
that._activate();
else
alert('Cannot activate compass: permission ' + permission);
}, function (reason) {
alert('Error activating compass: ' + reason);
});
} else
this._activate();
},

deactivate: function() {

this.setAngle(0);
Expand Down

0 comments on commit 6502c25

Please sign in to comment.