Added flyTo on geoloc click
This commit is contained in:
@@ -34,6 +34,7 @@ function toggleGeolocation() {
|
|||||||
if (hasLocation.value) {
|
if (hasLocation.value) {
|
||||||
pause()
|
pause()
|
||||||
isRequesting.value = false
|
isRequesting.value = false
|
||||||
|
emit('click-geoloc')
|
||||||
} else {
|
} else {
|
||||||
isRequesting.value = true
|
isRequesting.value = true
|
||||||
resume()
|
resume()
|
||||||
@@ -47,12 +48,14 @@ watch(coords, () => {
|
|||||||
userCoords.value = coords.value
|
userCoords.value = coords.value
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits(['click-geoloc'])
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="max-w-xs absolute top-5 left-5 z-10 grid gap-2">
|
<div class="max-w-xs absolute top-5 left-5 z-10 grid gap-2">
|
||||||
<button @click="toggleGeolocation"
|
<button @click="toggleGeolocation" :title="error?.message ?? (hasLocation ? 'Aller à ma position' : 'Me localiser')"
|
||||||
:title="error?.message ?? (hasLocation ? 'Désactiver la géolocalisation' : 'Me localiser')" :class="[
|
:class="[
|
||||||
'size-9 grid place-items-center border shadow rounded-full cursor-pointer transition-colors',
|
'size-9 grid place-items-center border shadow rounded-full cursor-pointer transition-colors',
|
||||||
hasLocation
|
hasLocation
|
||||||
? 'bg-primary text-primary-foreground border-primary'
|
? 'bg-primary text-primary-foreground border-primary'
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import 'leaflet/dist/leaflet.css'
|
import 'leaflet/dist/leaflet.css'
|
||||||
import 'vue-leaflet-markercluster/dist/style.css'
|
import 'vue-leaflet-markercluster/dist/style.css'
|
||||||
|
|
||||||
import L from 'leaflet'
|
import L, { Map } from 'leaflet'
|
||||||
globalThis.L = L
|
globalThis.L = L
|
||||||
|
|
||||||
import { useMap } from '@/stores/map'
|
import { useMap } from '@/stores/map'
|
||||||
@@ -12,11 +12,15 @@ import { API_BASE_URL, API_LIMIT, MAP_TILELAYER_URL, SpotAccess, SpotType } from
|
|||||||
import { useQuery } from '@pinia/colada'
|
import { useQuery } from '@pinia/colada'
|
||||||
import { LControlZoom, LIcon, LMap, LMarker, LTileLayer } from '@vue-leaflet/vue-leaflet'
|
import { LControlZoom, LIcon, LMap, LMarker, LTileLayer } from '@vue-leaflet/vue-leaflet'
|
||||||
import BikeFilters from './BikeFilters.vue'
|
import BikeFilters from './BikeFilters.vue'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref, useTemplateRef } from 'vue'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import BikeClusterLayer from './BikeClusterLayer.vue'
|
import BikeClusterLayer from './BikeClusterLayer.vue'
|
||||||
import { PhCircleNotch, PhMapPin } from '@phosphor-icons/vue'
|
import { PhCircleNotch, PhMapPin } from '@phosphor-icons/vue'
|
||||||
|
|
||||||
|
// Map setup
|
||||||
|
const mapRef = useTemplateRef<{ leafletObject: Map }>('map')
|
||||||
|
|
||||||
|
// Data fetching
|
||||||
const fetchedPages = ref(0)
|
const fetchedPages = ref(0)
|
||||||
const totalPages = ref(1)
|
const totalPages = ref(1)
|
||||||
const progress = computed(() => Math.round((fetchedPages.value / totalPages.value) * 100))
|
const progress = computed(() => Math.round((fetchedPages.value / totalPages.value) * 100))
|
||||||
@@ -81,13 +85,19 @@ const { filterUncovered, filterCovered, filterKorrigo } = storeToRefs(useMap())
|
|||||||
|
|
||||||
// Geolocation
|
// Geolocation
|
||||||
const { userCoords } = storeToRefs(useMap())
|
const { userCoords } = storeToRefs(useMap())
|
||||||
|
|
||||||
|
function handleClickGeoloc() {
|
||||||
|
if (userCoords.value) {
|
||||||
|
mapRef.value?.leafletObject.flyTo([userCoords.value.latitude, userCoords.value.longitude], 12)
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Transition enter-from-class="opacity-0 translate-y-2"
|
<Transition enter-from-class="opacity-0 translate-y-2"
|
||||||
enter-active-class="transition-all duration-300 ease-out delay-500" enter-to-class="opacity-100 translate-y-0">
|
enter-active-class="transition-all duration-300 ease-out delay-500" enter-to-class="opacity-100 translate-y-0">
|
||||||
<BikeFilters v-if="state.status === 'success'" :nb-uncovered="nonCoveredParkingsSpots"
|
<BikeFilters v-if="state.status === 'success'" :nb-uncovered="nonCoveredParkingsSpots"
|
||||||
:nb-covered="coveredParkingsSpots" :nb-korrigo="premiumParkingsSpots" />
|
:nb-covered="coveredParkingsSpots" :nb-korrigo="premiumParkingsSpots" @click-geoloc="handleClickGeoloc" />
|
||||||
</Transition>
|
</Transition>
|
||||||
|
|
||||||
<main class="relative z-0 h-screen w-screen grid place-items-center">
|
<main class="relative z-0 h-screen w-screen grid place-items-center">
|
||||||
|
|||||||
Reference in New Issue
Block a user