// ----------------------------------------------------------------------------- // Lou-Ka — Agrégateur de logements à louer (province de Québec) // Auteur : Simon-Pierre Boucher — contact@spboucher.ai // components/MetroLignes.tsx : couche « lignes de métro » des cartes Ka Maps // Tracés du métro de Montréal (lignes verte, orange, jaune, bleue) et du // REM, chacun dans sa couleur officielle (source : OpenStreetMap, fichier // statique /metro-lignes.geojson). À placer comme enfant d'une carte // Ka Maps (KaSpotlightMap / KaMapView) — s'appuie sur useKaMap(). // ----------------------------------------------------------------------------- import { useEffect } from "react"; import { useKaMap } from "@groupe-ka/ka-maps/react"; const SRC = "metro-lignes"; export default function MetroLignes() { const ka = useKaMap(); useEffect(() => { if (!ka) return; const map = (ka as unknown as { map: mapboxgl.Map }).map; if (!map) return; const ajouter = () => { if (map.getSource(SRC)) return; map.addSource(SRC, { type: "geojson", data: "/metro-lignes.geojson" }); // liseré clair sous le trait pour la lisibilité sur tout fond map.addLayer({ id: `${SRC}-case`, type: "line", source: SRC, paint: { "line-color": "#ffffff", "line-width": 5, "line-opacity": 0.55 }, layout: { "line-cap": "round", "line-join": "round" }, }); map.addLayer({ id: `${SRC}-trait`, type: "line", source: SRC, paint: { "line-color": ["get", "couleur"], "line-width": 2.6, "line-opacity": 0.9 }, layout: { "line-cap": "round", "line-join": "round" }, }); }; if (map.isStyleLoaded()) ajouter(); map.on("load", ajouter); map.on("style.load", ajouter); // ré-ajout si le fond change return () => { map.off("load", ajouter); map.off("style.load", ajouter); try { if (map.getLayer(`${SRC}-trait`)) map.removeLayer(`${SRC}-trait`); if (map.getLayer(`${SRC}-case`)) map.removeLayer(`${SRC}-case`); if (map.getSource(SRC)) map.removeSource(SRC); } catch { /* carte déjà détruite */ } }; }, [ka]); return null; }