diff --git a/modules/holidays/holidays.js b/modules/holidays/holidays.js index 6c0eb5c..35df442 100644 --- a/modules/holidays/holidays.js +++ b/modules/holidays/holidays.js @@ -151,6 +151,7 @@ document.addEventListener("DOMContentLoaded", () => { function initDetailMap() { if (typeof L === "undefined" || typeof MAP_POINTS === "undefined") return; + // 1. Nettoyage de l'ancienne carte if (detailMap !== null) { detailMap.remove(); detailMap = null; @@ -180,6 +181,7 @@ function initDetailMap() { const latlngs = []; const bounds = L.latLngBounds(); + // 2. Placement des marqueurs d'étapes MAP_POINTS.forEach((pt, index) => { const pos = [pt.lat, pt.lng]; latlngs.push(pos); @@ -222,6 +224,7 @@ function initDetailMap() { const mapPadding = window.innerWidth < 768 ? [20, 20] : [50, 50]; + // 3. Tracés OSRM et calculs if (latlngs.length === 1) { detailMap.setView(latlngs[0], 12); } else if (latlngs.length > 1) { @@ -254,6 +257,10 @@ function initDetailMap() { Promise.all(routePromises).then((results) => { results.sort((a, b) => a.index - b.index); + // Compteur global de distance + let totalTripDistance = 0; + + // Détection de l'étape de retour (Ligne Orange) let returnStartIndex = latlngs.length - 2; if ( typeof window.GLOBAL_RETURN_STEP_ID !== "undefined" && @@ -292,8 +299,10 @@ function initDetailMap() { lineJoin: "round", }).addTo(detailMap); - // 🔥 CALCUL AUTO DU COUT ET KILOMÈTRES + // CALCUL AUTO DU COUT ET KILOMÈTRES const distanceKm = res.data.routes[0].distance / 1000; + totalTripDistance += distanceKm; + const fuelL100 = window.VEHICLE_CONSUMPTION || 7; const fuelPrice = window.FUEL_PRICE || 1.85; const cost = (distanceKm / 100) * fuelL100 * fuelPrice; @@ -321,7 +330,7 @@ function initDetailMap() {