Problem/Motivation
When the locatecontrol plugin is used, when the user decides to block location control on the browser.
They're prompted with the Geolocation error: User denied geolocation prompt alert every time the page is loaded.
Steps to reproduce
1. Add a leaflet map with location control enabled.
2. Under the "Locate and Show User Position" section, tick "Enable Locate Leaflet Plugin functionality." and "Automatically locate & show user current position."
3. On your browser, deny access to location and click "Remember this decision".
4. Every time the widget is loaded, and it automatically tries to locate the user, the user will be prompted with the alert.
Proposed resolution
As per the documentation, the callback can be safely suppressed.
If the onLocationError callback is not specified by the site, I believe we should override the default onLocationError callback option as the alert isn't useful to end users. We can instead log the error to the console, and sites which require specialised location error handling may do so using the locationerror leaflet event as designed.
Remaining tasks
Provide MR.
User interface changes
N/A
API changes
N/A
Data model changes
N/A
| Comment | File | Size | Author |
|---|
Issue fork leaflet-3593902
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #6
itamair commentedthanks @codebymikey for pointing this out.
Please clarify me your use case.
It looks that the default onLocationError callback Alert is ONLY shown every time the user click the Locate control again and NOT every time the Leaflet Map Widget, or Formatter or View is loaded in the page.
In this use case (the one that I experience) the default onLocationError callback Alert is not so disturbing, but gives a useful feedback to the user trying to locate himself, that otherwise wouldn't have.
Let me know what you experience otherwise, differently from me, and how it happens.
Moreover I don't think this is a Leaflet bug but the default Leaflet Locate onLocationError Alert ...
Thus we should/would eventually require to alter that default behaviour and rather impose our new default one
(when it would be possibile to everyone (with proper coding skills) to customise and overwrite that default onLocationError callback in his own way
PS: I made a further commit to your MR !74 to eventually only log the error.message and not the whole error object.
Comment #7
codebymikey commented@itamair, ah right, sorry, I missed the most important bit in the summary.
The issue is apparent when it's configured to automatically locate and show the user's current position, in that scenario, the deny becomes more of a nuisance with no way to suppress it since it happens on every page load.
I've updated the issue summary accordingly.
If the alert is important for certain use cases and backwards compatibility, then it's probably better to introduce a new configuration instead to suppress the default
onLocationErrorbehaviour, and/or emit our own document level event on location error.I wasn't able to delve deep into the API, but I wasn't aware of any hooks that easily allows third party modules to alter the config data in such a way that they could easily provide their own JS callbacks easily since it does a
JSON.parse()directly rather than working off an existing object, so having a patch here made sense at the time.