fix map
This commit is contained in:
@@ -1282,3 +1282,11 @@ input[type="date"]::-webkit-calendar-picker-indicator:hover {
|
|||||||
.hol-step-dates {
|
.hol-step-dates {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
.leaflet-container img.leaflet-tile {
|
||||||
|
pointer-events: none !important;
|
||||||
|
user-select: none !important;
|
||||||
|
-moz-user-select: none !important;
|
||||||
|
}
|
||||||
|
#tripMap {
|
||||||
|
touch-action: none;
|
||||||
|
}
|
||||||
|
|||||||
@@ -270,26 +270,43 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
function initDetailMap() {
|
function initDetailMap() {
|
||||||
if (typeof L === "undefined" || typeof MAP_POINTS === "undefined") return;
|
if (typeof L === "undefined" || typeof MAP_POINTS === "undefined") return;
|
||||||
|
|
||||||
const mapContainer = L.DomUtil.get("tripMap");
|
// 1. 🧹 NETTOYAGE PROPRE : On détruit l'ancienne instance si elle existe (Évite le bug de la souris bloquée)
|
||||||
if (mapContainer !== null && mapContainer._leaflet_id) {
|
if (detailMap !== null) {
|
||||||
mapContainer._leaflet_id = null;
|
detailMap.remove();
|
||||||
|
detailMap = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
detailMap = L.map("tripMap");
|
const mapContainer = document.getElementById("tripMap");
|
||||||
|
if (!mapContainer) return;
|
||||||
|
|
||||||
|
// 2. 🛡️ BOUCLIER FIREFOX DESKTOP : Empêche le drag natif HTML5 de voler le clic
|
||||||
|
mapContainer.style.touchAction = "none";
|
||||||
|
mapContainer.ondragstart = function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
};
|
||||||
|
|
||||||
|
// 3. 🛠️ INITIALISATION DE LA CARTE
|
||||||
|
detailMap = L.map("tripMap", {
|
||||||
|
tap: false, // Désactive le tap simulé (anti-warning mobile/Firefox)
|
||||||
|
dragging: true, // Force l'autorisation du déplacement à la souris
|
||||||
|
});
|
||||||
|
|
||||||
L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
||||||
maxZoom: 19,
|
maxZoom: 19,
|
||||||
attribution:
|
attribution:
|
||||||
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
||||||
}).addTo(detailMap);
|
}).addTo(detailMap);
|
||||||
|
|
||||||
|
// Cas : Aucun point
|
||||||
if (MAP_POINTS.length === 0) {
|
if (MAP_POINTS.length === 0) {
|
||||||
detailMap.setView([46.6, 2.4], 5);
|
detailMap.setView([46.6, 2.4], 5); // France par défaut
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const latlngs = [];
|
const latlngs = [];
|
||||||
const bounds = L.latLngBounds();
|
const bounds = L.latLngBounds();
|
||||||
|
|
||||||
|
// 4. PLACEMENT DES MARQUEURS
|
||||||
MAP_POINTS.forEach((pt, index) => {
|
MAP_POINTS.forEach((pt, index) => {
|
||||||
const pos = [pt.lat, pt.lng];
|
const pos = [pt.lat, pt.lng];
|
||||||
latlngs.push(pos);
|
latlngs.push(pos);
|
||||||
@@ -299,20 +316,25 @@ function initDetailMap() {
|
|||||||
|
|
||||||
const marker = L.circleMarker(pos, {
|
const marker = L.circleMarker(pos, {
|
||||||
color: color,
|
color: color,
|
||||||
radius: 8,
|
radius: window.innerWidth < 768 ? 6 : 8,
|
||||||
fillOpacity: 1,
|
fillOpacity: 1,
|
||||||
fillColor: "white",
|
fillColor: "white",
|
||||||
weight: 3,
|
weight: 3,
|
||||||
}).addTo(detailMap);
|
}).addTo(detailMap);
|
||||||
|
|
||||||
marker.bindPopup(`
|
const stepLabel = window.I18N
|
||||||
<div style="text-align:center;">
|
? window.I18N["hdl_js_step_label"]
|
||||||
<div style="font-size:0.75rem; color:#64748b; margin-bottom:2px; font-weight:bold;">${tr("hdl_js_step_label")} ${index + 1}</div>
|
: tr("hdl_js_step_label");
|
||||||
<strong style="font-size:1rem; color:#0f172a;">${pt.location_name}</strong><br>
|
|
||||||
<span style="font-weight:bold; color:${color};">${parseFloat(pt.total_amount).toFixed(2)} €</span>
|
|
||||||
</div>
|
|
||||||
`);
|
|
||||||
|
|
||||||
|
marker.bindPopup(`
|
||||||
|
<div style="text-align:center;">
|
||||||
|
<div style="font-size:0.75rem; color:#64748b; margin-bottom:2px; font-weight:bold;">${stepLabel} ${index + 1}</div>
|
||||||
|
<strong style="font-size:1rem; color:#0f172a;">${pt.location_name}</strong><br>
|
||||||
|
<span style="font-weight:bold; color:${color};">${parseFloat(pt.total_amount).toFixed(2)} €</span>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Animation au clic sur le marqueur
|
||||||
marker.on("click", function () {
|
marker.on("click", function () {
|
||||||
const card = document.getElementById("step-card-" + pt.sort_order);
|
const card = document.getElementById("step-card-" + pt.sort_order);
|
||||||
if (card) {
|
if (card) {
|
||||||
@@ -328,7 +350,14 @@ function initDetailMap() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (latlngs.length > 1) {
|
const mapPadding = window.innerWidth < 768 ? [20, 20] : [50, 50];
|
||||||
|
|
||||||
|
// 5. CENTRAGE ET TRACÉS (OSRM)
|
||||||
|
if (latlngs.length === 1) {
|
||||||
|
detailMap.setView(latlngs[0], 12);
|
||||||
|
} else if (latlngs.length > 1) {
|
||||||
|
detailMap.fitBounds(bounds, { padding: mapPadding });
|
||||||
|
|
||||||
const routePromises = [];
|
const routePromises = [];
|
||||||
|
|
||||||
for (let i = 0; i < latlngs.length - 1; i++) {
|
for (let i = 0; i < latlngs.length - 1; i++) {
|
||||||
@@ -365,14 +394,15 @@ function initDetailMap() {
|
|||||||
results.forEach((res) => {
|
results.forEach((res) => {
|
||||||
const i = res.index;
|
const i = res.index;
|
||||||
let routeColor = "#3b82f6";
|
let routeColor = "#3b82f6";
|
||||||
let routeWeight = 6;
|
let routeWeight = window.innerWidth < 768 ? 4 : 6;
|
||||||
let routeDash = null;
|
let routeDash = null;
|
||||||
|
|
||||||
if (i >= returnStartIndex) {
|
if (i >= returnStartIndex) {
|
||||||
routeColor = "#f97316";
|
routeColor = "#f97316";
|
||||||
routeWeight = 3;
|
routeWeight = window.innerWidth < 768 ? 3 : 4;
|
||||||
routeDash = "10, 10";
|
routeDash = "10, 10";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.data && res.data.code === "Ok" && res.data.routes.length > 0) {
|
if (res.data && res.data.code === "Ok" && res.data.routes.length > 0) {
|
||||||
const routeCoords = res.data.routes[0].geometry.coordinates.map(
|
const routeCoords = res.data.routes[0].geometry.coordinates.map(
|
||||||
(c) => [c[1], c[0]],
|
(c) => [c[1], c[0]],
|
||||||
@@ -390,13 +420,25 @@ function initDetailMap() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
detailMap.fitBounds(bounds, { padding: [50, 50] });
|
|
||||||
// Lancement de la météo pour chaque étape
|
|
||||||
if (typeof MAP_POINTS !== "undefined") {
|
|
||||||
MAP_POINTS.forEach((pt) => loadWeatherForStep(pt));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 6. LANCEMENT DE LA MÉTÉO
|
||||||
|
if (typeof MAP_POINTS !== "undefined") {
|
||||||
|
MAP_POINTS.forEach((pt) => {
|
||||||
|
if (typeof loadWeatherForStep === "function") {
|
||||||
|
loadWeatherForStep(pt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7. FIX FINAL : Force Leaflet à recalculer sa taille une fois le DOM stabilisé
|
||||||
|
setTimeout(() => {
|
||||||
|
if (detailMap) {
|
||||||
|
detailMap.invalidateSize();
|
||||||
|
}
|
||||||
|
}, 300);
|
||||||
|
|
||||||
|
// Fonction utilitaire locale
|
||||||
function drawFallbackLine(coords, color, weight) {
|
function drawFallbackLine(coords, color, weight) {
|
||||||
L.polyline(coords, {
|
L.polyline(coords, {
|
||||||
color: color,
|
color: color,
|
||||||
@@ -405,12 +447,19 @@ function initDetailMap() {
|
|||||||
opacity: 0.7,
|
opacity: 0.7,
|
||||||
}).addTo(detailMap);
|
}).addTo(detailMap);
|
||||||
}
|
}
|
||||||
detailMap.fitBounds(bounds, { padding: [50, 50] });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function panMapTo(lat, lng) {
|
function panMapTo(lat, lng) {
|
||||||
if (detailMap) {
|
if (detailMap) {
|
||||||
detailMap.setView([lat, lng], 14, { animate: true });
|
detailMap.setView([lat, lng], 14, { animate: true });
|
||||||
|
|
||||||
|
// 🛠️ ERGONOMIE MOBILE : Auto-scroll vers la carte si on est sur petit écran
|
||||||
|
if (window.innerWidth < 768) {
|
||||||
|
const mapDiv = document.getElementById("tripMap");
|
||||||
|
if (mapDiv) {
|
||||||
|
mapDiv.scrollIntoView({ behavior: "smooth", block: "start" });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,8 +142,7 @@ $pctSaved = $cost > 0 ? min(100 - $pctPaid, ($saved / $cost) * 100) : 0;
|
|||||||
</div>
|
</div>
|
||||||
<button class="pf-btn pf-btn-small" onclick="openCheckpointModal('add')"><?= tr('hdl_btn_add_step') ?></button>
|
<button class="pf-btn pf-btn-small" onclick="openCheckpointModal('add')"><?= tr('hdl_btn_add_step') ?></button>
|
||||||
</div>
|
</div>
|
||||||
<div id="tripMap" style="flex:1; width:100%; background:#f1f5f9;"></div>
|
<div id="tripMap" style="flex:1; width:100%; min-height: 400px; background:#f1f5f9; position: relative; z-index: 1;"></div> </div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="hol-panel">
|
<div class="hol-panel">
|
||||||
<div class="hol-panel-header">
|
<div class="hol-panel-header">
|
||||||
|
|||||||
Reference in New Issue
Block a user