Skip to content

Commit

Permalink
🚸 Use the Page Visibility API to save preferences instead of beforeun…
Browse files Browse the repository at this point in the history
  • Loading branch information
ENT8R committed Mar 10, 2024
1 parent 8d3eec3 commit 863dcb5
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions app/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,23 @@ function listener() {

window.addEventListener('beforeunload', () => {
// Remove the iframe in order to prevent a restoring of the content when reloading the page
// which effectively leads to JOSM loading the content again
document.getElementById('remote').remove();
});

// Save the current state of the map and query which will be restored when visiting the page again
const center = map.center();
Preferences.set({
view: ui.view,
map: {
center: [center.lat, center.lng],
zoom: map.zoom()
},
query: query.data
});
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'hidden') {
// Save the current state of the map and query which will be restored when visiting the page again
const center = map.center();
Preferences.set({
view: ui.view,
map: {
center: [center.lat, center.lng],
zoom: map.zoom()
},
query: query.data
});
}
});

// Dynamic listeners
Expand Down

0 comments on commit 863dcb5

Please sign in to comment.