Stop location when switching tabs

This commit is contained in:
Austen Adler 2023-03-25 23:27:18 -04:00
parent 4bb5216687
commit a723001dbb
2 changed files with 18 additions and 4 deletions

View File

@ -9,15 +9,25 @@
let locationChecked; let locationChecked;
let locationControl; let locationControl;
export let isVisible = true;
export let onMapClick = () => {}; export let onMapClick = () => {};
export let map; export let map;
$: if (isVisible) {
locationCheckedChanged(false);
}
const locationCheckedChanged = (setValue) => { const locationCheckedChanged = (setValue) => {
if (!map) {
return;
}
if (setValue === true || setValue === false) { if (setValue === true || setValue === false) {
// Shortcut to set it in this function, if they passed a boolean // Shortcut to set it in this function, if they passed a boolean
locationChecked = !!setValue; locationChecked = !!setValue;
} }
console.log('Setting chceked to ', setValue);
if (locationChecked) { if (locationChecked) {
map.locate({ setView: true, watch: true, enableHighAccuracy: true }); map.locate({ setView: true, watch: true, enableHighAccuracy: true });
} else { } else {
@ -103,7 +113,7 @@
}); });
</script> </script>
<div id="container" class="h-3/4"> <div id="container" class="h-3/4" class:invisible={!isVisible}>
<!-- TODO: I want to set the border background to some tailwind class, but I don't know how. <!-- TODO: I want to set the border background to some tailwind class, but I don't know how.
This is to copy .leaflet-touch .leaflet-control-layers, .leaflet-touch .leaflet-bar border style This is to copy .leaflet-touch .leaflet-control-layers, .leaflet-touch .leaflet-bar border style
--> -->

View File

@ -156,6 +156,12 @@
outputValue = `${e}`; outputValue = `${e}`;
} }
}; };
let mapIsVisible = false;
$: {
mapIsVisible = initSuccess && tabInfo.selected == 0;
}
</script> </script>
<h1 class="font-bold text-2xl pb-4">App</h1> <h1 class="font-bold text-2xl pb-4">App</h1>
@ -193,6 +199,4 @@
<Error {message}>Could not start core module</Error> <Error {message}>Could not start core module</Error>
{/await} {/await}
<span class:invisible={!initSuccess || tabInfo.selected !== 0}> <Map bind:map {onMapClick} on:locationfound={locationfound} bind:isVisible={mapIsVisible} />
<Map bind:map {onMapClick} on:locationfound={locationfound} />
</span>