Dalsi iterace planovace, snad jiz kompletni vrstvy mapy
This commit is contained in:
@@ -1,18 +1,10 @@
|
||||
import {ref} from "vue";
|
||||
import axios from "axios";
|
||||
|
||||
export const useGeocode = (emits) => {
|
||||
export const useGeocode = () => {
|
||||
|
||||
const center = ref({
|
||||
lat: 50.1314,
|
||||
lng: 14.5256
|
||||
});
|
||||
const zoom = ref(10);
|
||||
const center = ref({lat: 50.1314, lng: 14.5256});
|
||||
|
||||
const emitModels = (lat, lng) => {
|
||||
emits("update:gpsLatitude", lat);
|
||||
emits("update:gpsLongitude", lng);
|
||||
}
|
||||
|
||||
const searchGeocode = (address) => {
|
||||
return axios.get(`https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURI(address)}&key=${process.env.GOOGLE_MAPS_API_KEY}`).then(response => {
|
||||
@@ -24,18 +16,29 @@ export const useGeocode = (emits) => {
|
||||
});
|
||||
}
|
||||
|
||||
const setCoordinatesFromGeocode = (address) => {
|
||||
// TODO: odstranit a nahradit za searchGeocode! Vlastne cela tato composable by sla nahradit
|
||||
axios.get(`https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURI(address)}&key=${process.env.GOOGLE_MAPS_API_KEY}`).then(response => {
|
||||
if (response.data.status !== 'OK') {
|
||||
emits("notFound", address);
|
||||
const searchPlaceName = (lat, lng) => {
|
||||
return axios.get(`https://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${lng}&key=${process.env.GOOGLE_MAPS_API_KEY}`).then(response => {
|
||||
if (response.data.status !== 'OK' || !response.data.results?.length) {
|
||||
return null;
|
||||
}
|
||||
center.value = response.data.results[0].geometry.location;
|
||||
emitModels(center.value.lat, center.value.lng);
|
||||
zoom.value = 13;
|
||||
|
||||
const results = response.data.results;
|
||||
const components = {};
|
||||
for (const addressComponent of results[0].address_components) {
|
||||
for (const namePartType of ["locality", "postal_town", 'administrative_area_level_2']) {
|
||||
if (addressComponent.types.includes(namePartType)) {
|
||||
components[namePartType] = addressComponent.long_name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!Object.keys(components).length) {
|
||||
return "Bod na mapě";
|
||||
}
|
||||
|
||||
return Object.values(components).join(", ");
|
||||
});
|
||||
}
|
||||
|
||||
return {emitModels, setCoordinatesFromGeocode, zoom, center, searchGeocode}
|
||||
return {center, searchGeocode, searchPlaceName}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user