Skip to content

Commit

Permalink
home button: adjust position after getting location from browser
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed May 27, 2024
1 parent b41e0e6 commit b88d94a
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4412,26 +4412,29 @@ function toggleFollow(override) {
}

function resetMap() {
if (SitePosition) {
CenterLon = SiteLon;
CenterLat = SiteLat;
} else {
CenterLon = DefaultCenterLon;
CenterLat = DefaultCenterLat;
}
// Reset loStore values and map settings
loStore['CenterLat'] = CenterLat
loStore['CenterLon'] = CenterLon
//loStore['zoomLvl'] = zoomLvl = DefaultZoomLvl;
geoFindMe().always(function() {
if (SitePosition) {
CenterLon = SiteLon;
CenterLat = SiteLat;
} else {
CenterLon = DefaultCenterLon;
CenterLat = DefaultCenterLat;
}
// Reset loStore values and map settings
loStore['CenterLat'] = CenterLat
loStore['CenterLon'] = CenterLon
//loStore['zoomLvl'] = zoomLvl = DefaultZoomLvl;

// Set and refresh
//OLMap.getView().setZoom(zoomLvl);
OLMap.getView().setCenter(ol.proj.fromLonLat([CenterLon, CenterLat]));
OLMap.getView().setRotation(mapOrientation);
// Set and refresh
//OLMap.getView().setZoom(zoomLvl);

//selectPlaneByHex(null,false);
jQuery("#update_error").css('display','none');
runAfterLoad(geoFindMe);
//console.log('resetMap setting center ' + [CenterLat, CenterLon]);
OLMap.getView().setCenter(ol.proj.fromLonLat([CenterLon, CenterLat]));
OLMap.getView().setRotation(mapOrientation);

//selectPlaneByHex(null,false);
jQuery("#update_error").css('display','none');
});
}

function updateMapSize() {
Expand Down Expand Up @@ -6576,11 +6579,8 @@ function watchPosition() {
let geoFindInterval = null;
function geoFindMe() {
//console.trace();
if (!geoFindEnabled()) {
initSitePos();
return;
}

g.geoFindDefer = jQuery.Deferred();
function success(position) {
SiteLat = DefaultCenterLat = position.coords.latitude;
SiteLon = DefaultCenterLon = position.coords.longitude;
Expand All @@ -6593,6 +6593,8 @@ function geoFindMe() {
initSitePos();
console.log('Location from browser: '+ SiteLat +', ' + SiteLon);

g.geoFindDefer.resolve();


{
// always update user location every 15 minutes
Expand All @@ -6614,10 +6616,17 @@ function geoFindMe() {
function error() {
console.log("Unable to query location.");
initSitePos();
g.geoFindDefer.reject();
}

if (!navigator.geolocation) {
if (!geoFindEnabled()) {
//console.log('Geolocation is not enabled');
initSitePos();
g.geoFindDefer.reject();
} else if (!navigator.geolocation) {
console.log('Geolocation is not supported by your browser');
initSitePos();
g.geoFindDefer.reject();
} else {
// change SitePos on location change
console.log('Locating…');
Expand All @@ -6628,6 +6637,8 @@ function geoFindMe() {
};
navigator.geolocation.getCurrentPosition(success, error, geoposOptions);
}

return g.geoFindDefer;
}

let initSitePosFirstRun = true;
Expand Down

0 comments on commit b88d94a

Please sign in to comment.