карта ПВЗ
All checks were successful
Deploy / build (push) Successful in 52s

This commit is contained in:
alsaze 2025-10-15 15:30:26 +03:00
parent b06786ad96
commit 9c59939015

View File

@ -1,28 +1,28 @@
<template> <template>
<div ref="mapContainer" class="w-full" style="height: calc(100dvh - 54px)" /> <div ref="mapContainer" class="w-full" style="height: calc(100dvh - 54px)" />
{{ coords }} <div v-if="!coordsReady" class="p-4 text-center">
{{ locatedAt }} Определяем ваше местоположение...
</div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { useGeolocation } from '@vueuse/core' import { useGeolocation } from '@vueuse/core'
import { onMounted, ref } from 'vue' import { ref, watch } from 'vue'
const props = defineProps<{ const props = defineProps<{
pickupPoints: { pickupPoints: {
id: string id: string
address: string address: string
location: { lat: number, lon: number } position: { latitude: number, longitude: number }
}[] }[]
}>() }>()
const { coords, locatedAt } = useGeolocation()
const token = '13f4c06b-cb7e-4eeb-81f1-af52f12587b2' const token = '13f4c06b-cb7e-4eeb-81f1-af52f12587b2'
const mapContainer = ref<HTMLDivElement | null>(null) const mapContainer = ref<HTMLDivElement | null>(null)
const { coords } = useGeolocation()
const coordsReady = ref(false)
const loadYandexMap = async () => { const initMap = async (lat: number, lon: number) => {
if (!window.ymaps) { if (!window.ymaps) {
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
const script = document.createElement('script') const script = document.createElement('script')
@ -34,17 +34,17 @@ const loadYandexMap = async () => {
window.ymaps.ready(() => { window.ymaps.ready(() => {
const map = new window.ymaps.Map(mapContainer.value!, { const map = new window.ymaps.Map(mapContainer.value!, {
center: [coords.value.latitude, coords.value.longitude], center: [lat, lon],
zoom: 10, zoom: 10,
controls: ['zoomControl'], controls: ['zoomControl'],
}) })
props?.pickupPoints?.forEach((point) => { props.pickupPoints.forEach((point) => {
const placemark = new window.ymaps.Placemark( const placemark = new window.ymaps.Placemark(
[point?.position?.latitude, point?.position?.longitude], [point?.position?.latitude, point?.position?.longitude],
{ {
balloonContent: `<strong>${point?.position?.longitude}</strong>\n<strong>${point?.position?.latitude}</strong>`, balloonContent: `<strong>${Object.values(point?.position)}</strong>`,
hintContent: point?.position?.longitude, hintContent: Object.values(point?.position),
}, },
{ preset: 'islands#redIcon' }, { preset: 'islands#redIcon' },
) )
@ -53,7 +53,14 @@ const loadYandexMap = async () => {
}) })
} }
onMounted(async () => { watch(
await loadYandexMap() () => coords.value,
}) async (val) => {
if (val.latitude && val.longitude && !coordsReady.value) {
coordsReady.value = true
await initMap(val.latitude, val.longitude)
}
},
{ deep: true },
)
</script> </script>