import maplibregl from "maplibre-gl"; /** * Supprime tous les marqueurs */ export function clearAllMarkers(markersRef, expandedElRef) { if (markersRef.current) { for (const m of markersRef.current) { try { m.marker.remove(); } catch { // ignore } } } markersRef.current = []; if (expandedElRef) { expandedElRef.current = null; } } /** * Crée un marqueur pour un post : * - état compact : petite bulle + pointe * - état étendu : gros post (carte) comme sur ton dessin */ export function createMarkerForPost(post, mapRef, markersRef, expandedElRef) { const map = mapRef.current; if (!map) return; // --- coordonnées --- const lat = typeof post.lat === "number" ? post.lat : typeof post.Lat === "number" ? post.Lat : typeof post.latitude === "number" ? post.latitude : null; const lon = typeof post.lon === "number" ? post.lon : typeof post.Lon === "number" ? post.Lon : typeof post.longitude === "number" ? post.longitude : null; if (lat == null || lon == null) { console.warn("post sans coordonnée:", post); return; } const title = (post.title || post.Title || "").trim() || "Untitled"; const body = (post.snippet || post.Snippet || "").trim() || (post.body || post.Body || "").trim() || title; const author = (post.author || post.Author || "").trim() || "unknown"; const created = (post.created_at || post.CreatedAt || "").toString().slice(0, 19); const category = (post.category || post.Category || "").toUpperCase() || ""; const subCat = (post.sub_category || post.SubCategory || "").toString(); const root = document.createElement("div"); root.className = "post-pin post-pin--compact"; function renderCompact() { root.className = "post-pin post-pin--compact"; root.innerHTML = `