diff --git a/data/core.yaml b/data/core.yaml index 91e381e93..ed9d4d069 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -233,6 +233,7 @@ en: no_results_worldwide: No results found geolocate: title: Show My Location + locating: "Locating, please wait..." inspector: no_documentation_combination: There is no documentation available for this tag combination no_documentation_key: There is no documentation available for this key diff --git a/dist/locales/en.json b/dist/locales/en.json index 1da5e01ad..bfe9f419d 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -285,7 +285,8 @@ "no_results_worldwide": "No results found" }, "geolocate": { - "title": "Show My Location" + "title": "Show My Location", + "locating": "Locating, please wait..." }, "inspector": { "no_documentation_combination": "There is no documentation available for this tag combination", diff --git a/js/id/ui.js b/js/id/ui.js index 3c7a51b90..f06f3a845 100644 --- a/js/id/ui.js +++ b/js/id/ui.js @@ -73,7 +73,7 @@ iD.ui = function(context) { controls.append('div') .attr('class', 'map-control geolocate-control') - .call(iD.ui.Geolocate(map)); + .call(iD.ui.Geolocate(context)); controls.append('div') .attr('class', 'map-control background-control') diff --git a/js/id/ui/geolocate.js b/js/id/ui/geolocate.js index 3942af10a..de191941c 100644 --- a/js/id/ui/geolocate.js +++ b/js/id/ui/geolocate.js @@ -1,17 +1,36 @@ -iD.ui.Geolocate = function(map) { +iD.ui.Geolocate = function(context) { + var geoOptions = { enableHighAccuracy: false, timeout: 6000 /* 6sec */ }, + locating = iD.ui.Loading(context).message(t('geolocate.locating')).blocking(true), + timeoutId; + function click() { - navigator.geolocation.getCurrentPosition( - success, error); + context.enter(iD.modes.Browse(context)); + context.container().call(locating); + navigator.geolocation.getCurrentPosition(success, error, geoOptions); + + // This timeout ensures that we still call finish() even if + // the user declines to share their location in Firefox + timeoutId = setTimeout(finish, 10000 /* 10sec */ ); } function success(position) { - var extent = iD.geo.Extent([position.coords.longitude, position.coords.latitude]) - .padByMeters(position.coords.accuracy); + var map = context.map(), + extent = iD.geo.Extent([position.coords.longitude, position.coords.latitude]) + .padByMeters(position.coords.accuracy); map.centerZoom(extent.center(), Math.min(20, map.extentZoom(extent))); + finish(); } - function error() { } + function error() { + finish(); + } + + function finish() { + locating.close(); // unblock ui + if (timeoutId) { clearTimeout(timeoutId); } + timeoutId = undefined; + } return function(selection) { if (!navigator.geolocation) return;