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