nakarte

Source code of https://map.sikmir.ru (fork)
git clone git://git.sikmir.ru/nakarte
Log | Files | Refs | LICENSE

commit 7c6e72478971d23b1b9c77f9f5d9b339bdfdfe47
parent 3bd2ae25c5c900450eb72d01b6e0c0120edfedeb
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Sat, 28 Apr 2018 01:59:06 +0300

geolocation: added user-friendly error messages #59

Diffstat:
Msrc/App.js | 17++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/App.js b/src/App.js @@ -27,7 +27,13 @@ import 'lib/leaflet.control.jnx/hash-state'; import 'lib/leaflet.control.azimuth'; import {hashState, bindHashStateReadOnly} from 'lib/leaflet.hashState/hashState'; import {LocateControl} from 'lib/leaflet.control.locate'; +import {notify} from 'lib/notifications'; +const locationErrorMessage = { + 0: 'Your browser does not support geolocation.', + 1: 'Geolocation is blocked for this site. Please, enable in browser setting.', + 2: 'Failed to acquire position for unknown reason.', +}; function setUp() { fixAll(); @@ -67,7 +73,16 @@ function setUp() { const azimuthControl = new L.Control.Azimuth({position: 'topleft'}).addTo(map); - new LocateControl({position: 'topleft'}).addTo(map); + new LocateControl({ + position: 'topleft', + showError: function({code, message}) { + let customMessage = locationErrorMessage[code]; + if (!customMessage) { + customMessage = `Geolocation error: ${message}`; + } + notify(customMessage); + } + }).addTo(map); /////////// controls top-right corner