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

121 lines
3.0 KiB
Plaintext
Raw Normal View History

<map-view>
<div class="map-box">
<h3>Carte des formations</h3>
2026-04-01 19:48:25 +02:00
<div class="map" ref="carte"></div>
</div>
<script>
export default {
2026-04-01 19:48:25 +02:00
2026-03-21 13:47:09 +01:00
onMounted() {
2026-04-01 19:48:25 +02:00
var divCarte = this.$('div[ref="carte"]');
this.carte = L.map(divCarte).setView([46.8, 2.5], 6);
this.groupeMarqueurs = L.layerGroup().addTo(this.carte);
this.marqueursIndex = {};
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; OpenStreetMap contributors'
2026-04-01 19:48:25 +02:00
}).addTo(this.carte);
2026-04-01 19:48:25 +02:00
this.afficherMarqueurs();
var composant = this;
setTimeout(function() {
if (composant.carte) {
composant.carte.invalidateSize();
}
}, 200);
setTimeout(function() {
if (composant.carte) {
composant.carte.invalidateSize();
}
}, 500);
window.mapFocus = function(id) {
composant.centrerSurFormation(id);
};
},
onUpdated() {
2026-04-01 19:48:25 +02:00
this.afficherMarqueurs();
var composant = this;
if (this.carte) {
setTimeout(function() {
composant.carte.invalidateSize();
}, 100);
setTimeout(function() {
composant.carte.invalidateSize();
}, 300);
}
2026-03-18 13:44:30 +01:00
},
2026-04-01 19:48:25 +02:00
onBeforeUnmount() {
if (this.carte) {
this.carte.remove();
this.carte = null;
}
window.mapFocus = null;
},
afficherMarqueurs() {
if (!this.carte || !this.groupeMarqueurs) {
return;
}
2026-04-01 19:48:25 +02:00
this.groupeMarqueurs.clearLayers();
this.marqueursIndex = {};
2026-04-01 19:48:25 +02:00
var coordonnees = [];
var formations = this.props.results || [];
2026-04-01 19:48:25 +02:00
for (var i = 0; i < formations.length; i++) {
var f = formations[i];
2026-04-01 19:48:25 +02:00
if (f.latitude != null && f.longitude != null) {
var marqueur = L.marker([f.latitude, f.longitude]);
marqueur.bindPopup('<b>' + f.nom + '</b><br>' + f.ville);
marqueur.addTo(this.groupeMarqueurs);
2026-04-01 19:48:25 +02:00
this.marqueursIndex[f.id] = marqueur;
coordonnees.push([f.latitude, f.longitude]);
}
}
2026-04-01 19:48:25 +02:00
if (coordonnees.length > 0) {
this.carte.fitBounds(coordonnees, { padding: [20, 20] });
} else {
2026-04-01 19:48:25 +02:00
this.carte.setView([46.8, 2.5], 6);
}
},
centrerSurFormation(id) {
var marqueur = this.marqueursIndex[id];
if (marqueur && this.carte) {
var divCarte = this.$('div[ref="carte"]');
if (divCarte) {
divCarte.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
var composant = this;
setTimeout(function() {
composant.carte.invalidateSize();
composant.carte.setView(marqueur.getLatLng(), 13, { animate: true });
marqueur.openPopup();
}, 400);
2026-03-20 01:51:08 +01:00
}
}
2026-04-01 19:48:25 +02:00
};
</script>
2026-04-01 19:48:25 +02:00
</map-view>