-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught error when i search a location #237
Comments
this is my code <script setup> import MaplibreGeocoder from "@maplibre/maplibre-gl-geocoder"; import "@maplibre/maplibre-gl-geocoder/dist/maplibre-gl-geocoder.css"; import { useForm } from "@inertiajs/vue3"; import Layout from "../Layouts/Layout.vue"; import SetupProfileLayout from "../Layouts/SetupProfileLayout.vue"; import { route } from "../../../../vendor/tightenco/ziggy/src/js"; import InputFlashMessage from "../Components/InputFlashMessage.vue"; import dayjs from "dayjs"; import { defineComponent, ref, Transition, watch, onMounted } from "vue"; import { MglMap, MglMarker } from "@indoorequal/vue-maplibre-gl"; import { useMap } from "@indoorequal/vue-maplibre-gl"; import { useControl } from "@indoorequal/vue-maplibre-gl"; defineOptions({ layout: [Layout, SetupProfileLayout], }); let form = useForm({ full_name: null, phone_number: null, birth_year: null, gender: null, employer_type: null, business_name: null, business_logo: null, industry: null, company_description: null, company_location: null, }); let showCompanyForm = ref(false); watch( () => form.employer_type, () => { if (form.employer_type === "business") { showCompanyForm.value = true; } if (form.employer_type === "individual") { showCompanyForm.value = false; } }, ); const style = "https://tiles.openfreemap.org/styles/liberty"; const center = [12.550343, 55.665957]; const zoom = 14; const submit = () => { form.post(route("create.profile.employer.post")); }; function setPointerCursor(event) { event.event.target.getCanvas().style.cursor = "default"; } let markedCoordinates = ref([0, 0]); function setMarker(event) { let { lat, lng } = event.event.lngLat; markedCoordinates.value = [lng, lat]; } let map = useMap(); let geocoderApi = ref({ forwardGeocode: async (query) => { const features = []; try { const request = `https://nominatim.openstreetmap.org/search?q=${query}&format=geojson&polygon_geojson=1&addressdetails=1`; const response = await fetch(request); console.log("Response status:", response.status); if (!response.ok) { throw new Error( `API request failed with status: ${response.status}`, ); } const results = await response.json(); console.log("Response status:", results.features); if (results.features.length === 0) { throw new Error("No results found."); } for (const result of results.features) { let centerY = (result.bbox[3] + result.bbox[1]) / 2; let centerX = (result.bbox[2] + result.bbox[0]) / 2; const point = { type: "Feature", geometry: { type: "Point", coordinates: [centerX, centerY], }, place_name: result.properties.display_name, properties: result.properties, text: result.properties.display_name, place_type: ["place"], center: [centerX, centerY], }; features.push(point); } } catch (e) { console.error("Geocoding failed:", error); // Error details const errMsg = error?.message || "No message available"; console.error(`Error Message: ${errMsg}`); // Rethrow the error to ensure it's logged throw error; console.error("Geocoding failed:", e); } return { features, }; }, }); let coordinateResult = ref([]); // Ensure geocoding control is added only after the map is loaded let geocoding = defineComponent({ setup() { return useControl( () => { return new MaplibreGeocoder(geocoderApi.value, { maplibregl: map, }); }, { position: "top-right", }, ); }, render() { return null; }, }); </script>Tell us about youLorem, ipsum dolor sit amet consectetur adipisicing elit. Reiciendis corporis itaque eum eius unde aperiam aliquid vel ratione doloremque! Ullam illo pariatur officiis tempore iste totam soluta dignissimos libero. Hic?
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The nominatim api is working good but when i return an object with feature property it shows uncaught error.
this is the error
@maplibre_maplibre-gl-geocoder.js?t=1737868887708&v=c72c84f4:708 Uncaught (in promise) Error: Unhandled error. (No message available)
at EventEmitter.emit (@maplibre_maplibre-gl-geocoder.js?t=1737868887708&v=c72c84f4:708:17)
at MaplibreGeocoder._handleGeocodeErrorResponse (@maplibre_maplibre-gl-geocoder.js?t=1737868887708&v=c72c84f4:1507:24)
at MaplibreGeocoder. (@maplibre_maplibre-gl-geocoder.js?t=1737868887708&v=c72c84f4:1414:14)
at Generator.throw ()
at rejected (@maplibre_maplibre-gl-geocoder.js?t=1737868887708&v=c72c84f4:15:32)
The text was updated successfully, but these errors were encountered: