Update MapTab component

This commit is contained in:
Alessio Davoli 2023-07-19 14:43:45 +02:00
parent 53002630c1
commit cc8bf87f3e

View file

@ -10,10 +10,13 @@
let latitude; let latitude;
let longitude; let longitude;
let accuracy; let accuracy;
const errorMessage = "Geolocation not available";
let errored = false;
const loadWorker = async () => { const watchPosition = async () => {
if (!("geolocation" in navigator)) { if (!("geolocation" in navigator)) {
return; errored = true;
throw new Error(errorMessage)
} }
const options = { const options = {
@ -45,7 +48,7 @@
}; };
onMount(async () => { onMount(async () => {
await loadWorker(); await watchPosition();
leaflet = await import('leaflet'); leaflet = await import('leaflet');
layerGroup = leaflet.layerGroup(); layerGroup = leaflet.layerGroup();
@ -75,8 +78,11 @@
} }
}); });
</script> </script>
{#if !errored}
<div id="map" in:fade bind:this={mapElement} /> <div id="map" in:fade bind:this={mapElement} />
{:else}
{errorMessage}
{/if}
<style> <style>
@import 'leaflet/dist/leaflet.css'; @import 'leaflet/dist/leaflet.css';