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-20 01:51:08 +01:00
|
|
|
var mapElement = this.$('div[ref="map"]')
|
2026-03-18 13:44:30 +01:00
|
|
|
|
|
|
|
|
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)
|
2026-03-20 01:51:08 +01:00
|
|
|
this.markersById = {}
|
2026-03-18 13:21:19 +01:00
|
|
|
this.refreshMarkers()
|
2026-03-18 13:44:30 +01:00
|
|
|
|
2026-03-20 01:51:08 +01:00
|
|
|
var self = this
|
|
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
if (self.map) self.map.invalidateSize()
|
|
|
|
|
}, 200)
|
|
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
if (self.map) self.map.invalidateSize()
|
|
|
|
|
}, 500)
|
|
|
|
|
|
|
|
|
|
window.mapFocus = function(id) {
|
|
|
|
|
self.focusFormation(id)
|
|
|
|
|
}
|
2026-03-18 13:21:19 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onUpdated() {
|
|
|
|
|
this.refreshMarkers()
|
2026-03-18 13:44:30 +01:00
|
|
|
|
2026-03-20 01:51:08 +01:00
|
|
|
var self = this
|
|
|
|
|
|
2026-03-18 13:44:30 +01:00
|
|
|
if (this.map) {
|
2026-03-20 01:51:08 +01:00
|
|
|
setTimeout(function() {
|
|
|
|
|
self.map.invalidateSize()
|
|
|
|
|
}, 100)
|
|
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
self.map.invalidateSize()
|
|
|
|
|
}, 300)
|
2026-03-18 13:44:30 +01:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onBeforeUnmount() {
|
|
|
|
|
if (this.map) {
|
|
|
|
|
this.map.remove()
|
|
|
|
|
this.map = null
|
|
|
|
|
}
|
2026-03-20 01:51:08 +01:00
|
|
|
window.mapFocus = null
|
2026-03-18 13:21:19 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
refreshMarkers() {
|
|
|
|
|
if (!this.map || !this.markersLayer) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.markersLayer.clearLayers()
|
2026-03-20 01:51:08 +01:00
|
|
|
this.markersById = {}
|
2026-03-18 13:21:19 +01:00
|
|
|
|
2026-03-20 01:51:08 +01:00
|
|
|
var points = []
|
|
|
|
|
var results = this.props.results || []
|
2026-03-18 13:21:19 +01:00
|
|
|
|
2026-03-20 01:51:08 +01:00
|
|
|
for (var i = 0; i < results.length; i++) {
|
|
|
|
|
var 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-20 01:51:08 +01:00
|
|
|
var marker = L.marker([f.latitude, f.longitude])
|
|
|
|
|
marker.bindPopup('<b>' + f.nom + '</b><br>' + f.ville)
|
2026-03-18 13:21:19 +01:00
|
|
|
marker.addTo(this.markersLayer)
|
|
|
|
|
|
2026-03-20 01:51:08 +01:00
|
|
|
this.markersById[f.id] = marker
|
2026-03-18 13:21:19 +01:00
|
|
|
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)
|
|
|
|
|
}
|
2026-03-20 01:51:08 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
focusFormation(id) {
|
|
|
|
|
var marker = this.markersById[id]
|
|
|
|
|
|
|
|
|
|
if (marker && this.map) {
|
|
|
|
|
var mapEl = this.$('div[ref="map"]')
|
|
|
|
|
if (mapEl) {
|
|
|
|
|
mapEl.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var self = this
|
|
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
self.map.invalidateSize()
|
|
|
|
|
self.map.setView(marker.getLatLng(), 13, { animate: true })
|
|
|
|
|
marker.openPopup()
|
|
|
|
|
}, 400)
|
|
|
|
|
}
|
2026-03-18 13:21:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2026-03-20 01:51:08 +01:00
|
|
|
</map-view>
|