mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-17 22:24:49 +02:00
Don't enter modeBrowse if geolocation was unsuccessful
Only set geolocation timeout when fetching the location Always fetch a new location when geolocating instead of only using the first one
This commit is contained in:
+32
-21
@@ -10,9 +10,14 @@ import { uiLoading } from './loading';
|
||||
import { uiTooltipHtml } from './tooltipHtml';
|
||||
|
||||
export function uiGeolocate(context) {
|
||||
var geoOptions = { enableHighAccuracy: false, timeout: 6000 /* 6sec */ };
|
||||
var locating = uiLoading(context).message(t('geolocate.locating')).blocking(true);
|
||||
var layer = context.layers().layer('geolocate');
|
||||
var _geolocationOptions = {
|
||||
// prioritize speed and power usage over precision
|
||||
enableHighAccuracy: false,
|
||||
// don't hang indefinitely getting the location
|
||||
timeout: 6000 // 6sec
|
||||
};
|
||||
var _locating = uiLoading(context).message(t('geolocate.locating')).blocking(true);
|
||||
var _layer = context.layers().layer('geolocate');
|
||||
var _position;
|
||||
var _extent;
|
||||
var _timeoutID;
|
||||
@@ -20,26 +25,26 @@ export function uiGeolocate(context) {
|
||||
|
||||
function click() {
|
||||
if (context.inIntro()) return;
|
||||
context.enter(modeBrowse(context));
|
||||
if (!layer.enabled()) {
|
||||
if (!_position) {
|
||||
context.container().call(locating);
|
||||
navigator.geolocation.getCurrentPosition(success, error, geoOptions);
|
||||
} else {
|
||||
zoomTo();
|
||||
}
|
||||
if (!_layer.enabled()) {
|
||||
|
||||
// This timeout ensures that we still call finish() even if
|
||||
// the user declines to share their location in Firefox
|
||||
_timeoutID = setTimeout(error, 10000 /* 10sec */ );
|
||||
|
||||
context.container().call(_locating);
|
||||
// get the latest position even if we already have one
|
||||
navigator.geolocation.getCurrentPosition(success, error, _geolocationOptions);
|
||||
} else {
|
||||
layer.enabled(null, false);
|
||||
_layer.enabled(null, false);
|
||||
updateButtonState();
|
||||
}
|
||||
// This timeout ensures that we still call finish() even if
|
||||
// the user declines to share their location in Firefox
|
||||
_timeoutID = setTimeout(error, 10000 /* 10sec */ );
|
||||
}
|
||||
|
||||
function zoomTo() {
|
||||
context.enter(modeBrowse(context));
|
||||
|
||||
var map = context.map();
|
||||
layer.enabled(_position, true);
|
||||
_layer.enabled(_position, true);
|
||||
updateButtonState();
|
||||
map.centerZoomEase(_extent.center(), Math.min(20, map.extentZoom(_extent)));
|
||||
}
|
||||
@@ -53,20 +58,26 @@ export function uiGeolocate(context) {
|
||||
}
|
||||
|
||||
function error() {
|
||||
uiFlash()
|
||||
.text(t('geolocate.location_unavailable'))
|
||||
.iconName('#iD-icon-geolocate')();
|
||||
if (_position) {
|
||||
// use the position from a previous call if we have one
|
||||
zoomTo();
|
||||
} else {
|
||||
uiFlash()
|
||||
.text(t('geolocate.location_unavailable'))
|
||||
.iconName('#iD-icon-geolocate')();
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
function finish() {
|
||||
locating.close(); // unblock ui
|
||||
_locating.close(); // unblock ui
|
||||
if (_timeoutID) { clearTimeout(_timeoutID); }
|
||||
_timeoutID = undefined;
|
||||
}
|
||||
|
||||
function updateButtonState() {
|
||||
_button.classed('active', layer.enabled());
|
||||
_button.classed('active', _layer.enabled());
|
||||
}
|
||||
|
||||
return function(selection) {
|
||||
|
||||
Reference in New Issue
Block a user