The component MapboxGeocoder work but i have this error in my console when i use it :
TypeError: Cannot set properties of undefined (setting '_eventEmitter')
at MapboxGeocoder
import { MapboxMap, MapboxImage, MapboxCluster, MapboxPopup } from '@studiometa/vue-mapbox-gl'
import 'mapbox-gl/dist/mapbox-gl.css'
import axios from 'redaxios'
import Runner from '../assets/img/runner.png'
import 'flexboxgrid'
import '@mapbox/mapbox-gl-geocoder/lib/mapbox-gl-geocoder.css'
import mapboxgl from 'mapbox-gl'
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder'
const tokenMapBox = import.meta.env.VITE_MAPBOX_API_KEY
const tokenNocodb = import.meta.env.VITE_XC_API_TOKEN
const mapCenter = ref([3, 47])
const isOpen = ref(false)
const position = ref([0, 0])
const content = ref()
const map = ref(null)
const geocoder = ref(null)
const geojsonData = ref({
type: 'FeatureCollection',
features: []
})
onMounted(() => {
getConcess()
// Initialize MapboxGeocoder
geocoder.value = new MapboxGeocoder({
accessToken: tokenMapBox,
mapboxgl: mapboxgl
})
// Append the geocoder to the map container
map.value.addControl(geocoder.value)
})
const getConcess = async () => {
const response = await axios.get('', {
headers: {
}
})
let data = response.data.list
data.forEach((item) => {
geojsonData.value.features.push({
type: 'Feature',
properties: {
id: item.Id,
title: item.titre,
date: item.date_start,
ville: item.ville,
lat: item.latitude,
lon: item.longitude
},
geometry: { type: 'Point', coordinates: [item.longitude, item.latitude] }
})
})
}
const flyto = (features) => {
const { lat, lon, title, date, ville } = features
map.value.flyTo({ center: [lon, lat], zoom: 14 })
isOpen.value = false
openPopup({
geometry: { coordinates: [lon, lat] },
properties: { title: title, date: date, ville: ville }
})
}
const openPopup = async ({ geometry, properties }) => {
await nextTick()
console.log(geometry, properties)
position.value = [...geometry.coordinates]
isOpen.value = true
content.value = Object.fromEntries(
Object.entries(properties).map(([key, value]) => {
try {
return [key, JSON.parse(value)]
} catch (err) {
// Silence is golden.
}
return [key, value]
})
)
}
</script>
<template>
<div class="row">
<div class="col-xs-3 list">
<ul>
<li
v-for="feature in geojsonData.features"
:key="feature.properties.id"
@click="flyto(feature.properties)"
>
<h2>{{ feature.properties.title }}</h2>
<p>{{ feature.properties.date }}</p>
<p>{{ feature.properties.ville }}</p>
</li>
</ul>
</div>
<div class="col-xs-9">
<MapboxMap
style="height: 400px"
:access-token="tokenMapBox"
map-style="mapbox://styles/mapbox/streets-v11"
:center="mapCenter"
:zoom="4"
@mb-created="(mapInstance) => (map = mapInstance)"
>
<MapboxPopup
v-if="isOpen"
:key="position.join('-')"
:lng-lat="position"
anchor="bottom"
@mb-close="() => (isOpen = false)"
>
<h2>{{ content.title }}</h2>
<p>{{ content.date }}</p>
<p>{{ content.ville }}</p>
</MapboxPopup>
<MapboxImage id="runner" :src="Runner">
<MapboxCluster
:data="geojsonData"
unclustered-point-layer-type="symbol"
:unclustered-point-layout="{
'icon-image': 'runner',
'icon-size': 0.2
}"
:unclustered-point-paint="null"
@mb-feature-click="openPopup"
:clustersPaint="{
'circle-color': '#002c5f',
'circle-radius': 30
}"
/>
</MapboxImage>
<MapboxGeocoder />
</MapboxMap>
</div>
</div>
</template>```
if anyone can help me that would be great !