Return to browse mode and block ui while geolocating

(fixes #3016)
This commit is contained in:
Bryan Housel
2016-03-10 11:07:52 -05:00
parent c5143b3125
commit 58e6ac075b
4 changed files with 29 additions and 8 deletions
+1
View File
@@ -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
+2 -1
View File
@@ -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",
+1 -1
View File
@@ -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')
+25 -6
View File
@@ -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;