2026-03-18 13:21:19 +01:00
|
|
|
<map-view>
|
|
|
|
|
<div class="map-box">
|
|
|
|
|
<h3>Carte des formations</h3>
|
2026-03-18 13:44:30 +01:00
|
|
|
<div class="map" ref="map"></div>
|
2026-03-18 13:21:19 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
onMounted() {
|
2026-03-18 13:44:30 +01:00
|
|
|
const mapElement = this.$('div[ref="map"]')
|
|
|
|
|
|
|
|
|
|
this.map = L.map(mapElement).setView([46.8, 2.5], 6)
|
2026-03-18 13:21:19 +01:00
|
|
|
|
|
|
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
|
|
|
attribution: '© OpenStreetMap contributors'
|
|
|
|
|
}).addTo(this.map)
|
|
|
|
|
|
|
|
|
|
this.markersLayer = L.layerGroup().addTo(this.map)
|
|
|
|
|
this.refreshMarkers()
|
2026-03-18 13:44:30 +01:00
|
|
|
|
|
|
|
|
// important : Leaflet calcule parfois mal la taille au montage
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.map.invalidateSize()
|
|
|
|
|
}, 100)
|
2026-03-18 13:21:19 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onUpdated() {
|
|
|
|
|
this.refreshMarkers()
|
2026-03-18 13:44:30 +01:00
|
|
|
|
|
|
|
|
if (this.map) {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.map.invalidateSize()
|
|
|
|
|
}, 50)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onBeforeUnmount() {
|
|
|
|
|
if (this.map) {
|
|
|
|
|
this.map.remove()
|
|
|
|
|
this.map = null
|
|
|
|
|
}
|
2026-03-18 13:21:19 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
refreshMarkers() {
|
|
|
|
|
if (!this.map || !this.markersLayer) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.markersLayer.clearLayers()
|
|
|
|
|
|
|
|
|
|
const points = []
|
2026-03-18 13:44:30 +01:00
|
|
|
const results = this.props.results || []
|
2026-03-18 13:21:19 +01:00
|
|
|
|
2026-03-18 13:44:30 +01:00
|
|
|
for (let i = 0; i < results.length; i++) {
|
|
|
|
|
const f = results[i]
|
2026-03-18 13:21:19 +01:00
|
|
|
|
2026-03-18 13:44:30 +01:00
|
|
|
if (f.latitude != null && f.longitude != null) {
|
2026-03-18 13:21:19 +01:00
|
|
|
const marker = L.marker([f.latitude, f.longitude])
|
|
|
|
|
marker.bindPopup(`<b>${f.nom}</b><br>${f.ville}`)
|
|
|
|
|
marker.addTo(this.markersLayer)
|
|
|
|
|
|
|
|
|
|
points.push([f.latitude, f.longitude])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (points.length > 0) {
|
|
|
|
|
this.map.fitBounds(points, { padding: [20, 20] })
|
|
|
|
|
} else {
|
|
|
|
|
this.map.setView([46.8, 2.5], 6)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
</map-view>
|