From 61d7f88b15d9f91a410c7cb7328e62c75bae94d3 Mon Sep 17 00:00:00 2001 From: Ota Prokopec Date: Thu, 6 Apr 2023 17:13:41 +0200 Subject: [PATCH] fast, relyable maps/bettercode/trigger --- src/__routes.svelte | 9 ++++--- src/lib/components/Map/Erantmap.svelte | 6 ++++- src/routes/map/map.svelte | 34 +++++++------------------- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/src/__routes.svelte b/src/__routes.svelte index 7f7adf2..7a52957 100644 --- a/src/__routes.svelte +++ b/src/__routes.svelte @@ -54,6 +54,10 @@ path: '/profile/:erantId', component: () => import('$routes/profile/profile.svelte'), }, + { + path: '/map', + component: () => import('$routes/map/map.svelte'), + }, ].map((routes) => { return { ...routes, layout: NavigationBarLayout } }), @@ -86,10 +90,7 @@ path: '/test', component: () => import('$routes/test.svelte'), },*/ - { - path: '/map', - component: () => import('$root/src/routes/map/map.svelte'), - }, + { path: '/profile/', component: () => import('$src/__error.svelte'), diff --git a/src/lib/components/Map/Erantmap.svelte b/src/lib/components/Map/Erantmap.svelte index f3b4749..08cb445 100644 --- a/src/lib/components/Map/Erantmap.svelte +++ b/src/lib/components/Map/Erantmap.svelte @@ -43,8 +43,10 @@ const userCenter = () => { // @ts-ignore - document.getElementsByClassName('mapboxgl-ctrl-geolocate')[0].click() + if (trigger) trigger() } + + let trigger @@ -54,6 +56,7 @@ setTimeout(() => userCenter(), 100)} {center} bind:mapComponent class={className} on:move> {}} on:geolocate={(e) => { // @ts-ignore diff --git a/src/routes/map/map.svelte b/src/routes/map/map.svelte index 91a4db5..1284f5f 100644 --- a/src/routes/map/map.svelte +++ b/src/routes/map/map.svelte @@ -8,36 +8,20 @@ import { onMount } from 'svelte' let userLocation: { lat: number; lng: number } = { lat: 0, lng: 0 } - let granted = false - const lastGame = localStorage.getItem('lastGame') - - const handleLocationGranted = (position: GeolocationPosition) => { + /*const handleLocationGranted = (position: GeolocationPosition) => { userLocation = { lat: position.coords.latitude, lng: position.coords.longitude } granted = true - } + }*/ - navigator.geolocation.getCurrentPosition(handleLocationGranted) + //navigator.geolocation.getCurrentPosition(handleLocationGranted) $: [experiences] = getExperiencesAsStore() - - {#if granted} - - - {#each $experiences as experience} - navigate(`/${experience.ExpURL}`)} - lat={experience.ExpLocation[0]} - lng={experience.ExpLocation[1]} - {userLocation} - /> - {/each} - - {:else} - - (granted = true)} /> - {/if} - + + + {#each $experiences as experience} + navigate(`/${experience.ExpURL}`)} lat={experience.ExpLocation[0]} lng={experience.ExpLocation[1]} {userLocation} /> + {/each} +