Files
public-html2/parcoursup/components/map-view.riot
T

53 lines
1.3 KiB
Plaintext
Raw Normal View History

<map-view>
<div class="map-box">
<h3>Carte des formations</h3>
2026-03-31 17:58:49 +02:00
<div id="map"></div>
</div>
<script>
export default {
2026-03-21 13:47:09 +01:00
onMounted() {
2026-03-31 17:58:49 +02:00
this.map = L.map(this.root.querySelector('#map')).setView([46.8, 2.5], 6)
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; OpenStreetMap contributors'
2026-03-31 17:58:49 +02:00
}).addTo(this.map)
2026-03-31 17:58:49 +02:00
this.markersLayer = L.layerGroup().addTo(this.map)
this.refreshMarkers()
},
onUpdated() {
2026-03-31 17:58:49 +02:00
this.refreshMarkers()
2026-03-18 13:44:30 +01:00
},
2026-03-31 17:58:49 +02:00
refreshMarkers() {
if (!this.map || !this.markersLayer) {
return
}
2026-03-31 17:58:49 +02:00
this.markersLayer.clearLayers()
2026-03-31 17:58:49 +02:00
const points = []
2026-03-31 17:58:49 +02:00
for (let i = 0; i < this.props.results.length; i++) {
const f = this.props.results[i]
2026-03-31 17:58:49 +02:00
if (f.latitude && f.longitude) {
const marker = L.marker([f.latitude, f.longitude])
marker.bindPopup(`<b>${f.nom}</b><br>${f.ville}`)
marker.addTo(this.markersLayer)
2026-03-31 17:58:49 +02:00
points.push([f.latitude, f.longitude])
}
}
2026-03-31 17:58:49 +02:00
if (points.length > 0) {
this.map.fitBounds(points, { padding: [20, 20] })
} else {
2026-03-31 17:58:49 +02:00
this.map.setView([46.8, 2.5], 6)
2026-03-20 01:51:08 +01:00
}
}
2026-03-31 17:58:49 +02:00
}
</script>
2026-03-31 17:58:49 +02:00
</map-view>