click and show detail as a pop-up

This commit is contained in:
matsuri 2023-08-24 23:18:05 +07:00
parent 4f3d74df6c
commit d2ed7fc3ea
2 changed files with 70 additions and 4 deletions

View file

@ -1,4 +1,13 @@
<template>
<div id="app">
<router-view />
<Popup
v-if="popupData"
:nearestStructureData="popupData"
:onClose="closePopup"
/>
</div>
<searchbar/>
@ -33,6 +42,7 @@
<script setup>
import searchbar from '@/components/searchbar.vue';
import Popup from "@/components/Popup.vue"; // Import the Popup componen
import { ref } from "vue";
import axios from "axios";
@ -41,23 +51,29 @@ const projection = ref("EPSG:4326");
const zoom = ref(19);
const rotation = ref(0);
const popupData = ref(null);
//Show API
const handleMapClick = async event => {
const clickedCoordinate = event.coordinate;
console.log("Clicked coordinate:", clickedCoordinate);
try {
const response = await axios.get(
`https://nominatim.openstreetmap.org/reverse?format=json&lat=${clickedCoordinate[1]}&lon=${clickedCoordinate[0]}`
);
console.log("API response:", response.data);
const nearestStructureData = response.data;
console.log("Nearest structure:", nearestStructureData);
popupData.value = nearestStructureData; // Show popup
} catch (error) {
console.error("Error fetching reverse geocoding data:", error);
}
};
const closePopup = () => {
popupData.value = null; // Hide popup
};
</script>
<style>