diff --git a/src/components/flightPlans/FlightPlanPlaceInput.vue b/src/components/flightPlans/FlightPlanPlaceInput.vue
index 9f48805..2667ba2 100644
--- a/src/components/flightPlans/FlightPlanPlaceInput.vue
+++ b/src/components/flightPlans/FlightPlanPlaceInput.vue
@@ -29,13 +29,18 @@ const placesFilter = (val, update, abort) => {
searchGeocode(val).then(results => {
if (!results) return;
- placesOptions.value = results.map(result => ({
- name: result.formatted_address,
- type: "geocode",
- id: null,
- gpsLatitude: result.geometry.location.lat,
- gpsLongitude: result.geometry.location.lng,
- }))
+ console.log(results)
+
+ placesOptions.value = results.map(result => {
+ console.log(result, result.geometry.location)
+ return {
+ name: result.formatted_address,
+ type: "geocode",
+ id: null,
+ gpsLatitude: result.geometry.location.lat(),
+ gpsLongitude: result.geometry.location.lng(),
+ }
+ })
});
}
} else {
diff --git a/src/components/flightPlans/FlightPlanRoute.vue b/src/components/flightPlans/FlightPlanRoute.vue
index 8e7ba25..c6b055d 100644
--- a/src/components/flightPlans/FlightPlanRoute.vue
+++ b/src/components/flightPlans/FlightPlanRoute.vue
@@ -31,6 +31,9 @@ const swapMarkers = (idx1, idx2) => {
};
const handlePlaceSelect = (modelVal) => {
model.value.push(modelVal);
+
+ // TODO: upravit bounds u mapy
+
}
watch(() => model.value, () => {
diff --git a/src/components/inputs/MapGPSInput.vue b/src/components/inputs/MapGPSInput.vue
index 9d871b1..9c35471 100644
--- a/src/components/inputs/MapGPSInput.vue
+++ b/src/components/inputs/MapGPSInput.vue
@@ -1,6 +1,6 @@
diff --git a/src/components/map/MapWrapper.vue b/src/components/map/MapWrapper.vue
index 6df774d..25a70e4 100644
--- a/src/components/map/MapWrapper.vue
+++ b/src/components/map/MapWrapper.vue
@@ -241,6 +241,11 @@ const isControlsOpened = ref(false);
+
+
+
+
+
{
+
+
+
-
+
{
:slug-source="formData.name"
:rules="rules.urlSlug"
/>
-
-
+
+
diff --git a/src/composables/geocoding.js b/src/composables/geocoding.js
index 9ccc948..195ed5b 100644
--- a/src/composables/geocoding.js
+++ b/src/composables/geocoding.js
@@ -1,43 +1,73 @@
import {ref} from "vue";
-import axios from "axios";
export const useGeocode = () => {
-
const center = ref({lat: 50.1314, lng: 14.5256});
+ const getGeocoder = (limitMs = 5000) => {
+ let interval = null
+ const poolingWindowMs = 100
- 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 => {
- if (response.data.status !== 'OK') {
- return null;
- }
+ const tries = limitMs / poolingWindowMs
+ let currentTry = 0
- return response.data.results;
- });
- }
+ return new Promise((resolve, reject) => {
+ let instance = null
+ interval = setInterval(() => {
+ try {
+ instance = new google.maps.Geocoder()
- 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;
- }
+ clearInterval(interval)
+ return resolve(instance)
- 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
+ } catch (e) {
+ if (++currentTry >= tries) {
+ clearInterval(interval)
+ return reject(instance)
}
}
- }
+ }, poolingWindowMs)
+ })
+ }
- if (!Object.keys(components).length) {
- return "Bod na mapě";
- }
+ const searchGeocode = (address) => new Promise((resolve, reject) => {
+ getGeocoder().then(geocoder => geocoder
+ .geocode({address})
+ .then(({results}) => resolve(results))
+ .catch((e) => reject(e))).catch(() => {
+ console.log("Cannot get geocoder")
+ })
+ })
- return Object.values(components).join(", ");
- });
+
+ const searchPlaceName = (lat, lng) => {
+ const latlng = {
+ lat: parseFloat(lat), lng: parseFloat(lng),
+ };
+
+ return new Promise((resolve, reject) => {
+ getGeocoder().then((geocoder) => geocoder
+ .geocode({location: latlng})
+ .then((response) => {
+ const results = response.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 resolve("Bod na mapě");
+ }
+
+ return resolve(Object.values(components).join(", "));
+ })
+ .catch((e) => reject(e))
+ )
+
+ })
}
return {center, searchGeocode, searchPlaceName}
diff --git a/src/graphql/fragments/flight.js b/src/graphql/fragments/flight.js
index bac7b5b..766f43b 100644
--- a/src/graphql/fragments/flight.js
+++ b/src/graphql/fragments/flight.js
@@ -7,7 +7,7 @@ import {FRAGMENT_COPILOT_PUBLIC_INFO} from "src/graphql/fragments/copilot";
export const FRAGMENT_WEATHER_FULL_INFO = gql`
fragment weatherFullInfo on WeatherInfo {
- datetime
+ dateTime
qnh
temperatureSurface
dewpointSurface