Lou·Ka — tous les logements à louer du Québec, un seul endroit.
HTML 98.9%
Python 0.6%
1// -----------------------------------------------------------------------------2// Lou-Ka — Agrégateur de logements à louer (province de Québec)3// Auteur : Simon-Pierre Boucher — contact@spboucher.ai4// components/MetroLignes.tsx : couche « lignes de métro » des cartes Ka Maps5// Tracés du métro de Montréal (lignes verte, orange, jaune, bleue) et du6// REM, chacun dans sa couleur officielle (source : OpenStreetMap, fichier7// statique /metro-lignes.geojson). À placer comme enfant d'une carte8// Ka Maps (KaSpotlightMap / KaMapView) — s'appuie sur useKaMap().9// -----------------------------------------------------------------------------10import { useEffect } from "react";11import { useKaMap } from "@groupe-ka/ka-maps/react";1213const SRC = "metro-lignes";1415export default function MetroLignes() {16 const ka = useKaMap();17 useEffect(() => {18 if (!ka) return;19 const map = (ka as unknown as { map: mapboxgl.Map }).map;20 if (!map) return;2122 const ajouter = () => {23 if (map.getSource(SRC)) return;24 map.addSource(SRC, { type: "geojson", data: "/metro-lignes.geojson" });25 // liseré clair sous le trait pour la lisibilité sur tout fond26 map.addLayer({27 id: `${SRC}-case`, type: "line", source: SRC,28 paint: { "line-color": "#ffffff", "line-width": 5,29 "line-opacity": 0.55 },30 layout: { "line-cap": "round", "line-join": "round" },31 });32 map.addLayer({33 id: `${SRC}-trait`, type: "line", source: SRC,34 paint: { "line-color": ["get", "couleur"], "line-width": 2.6,35 "line-opacity": 0.9 },36 layout: { "line-cap": "round", "line-join": "round" },37 });38 };39 if (map.isStyleLoaded()) ajouter();40 map.on("load", ajouter);41 map.on("style.load", ajouter); // ré-ajout si le fond change42 return () => {43 map.off("load", ajouter);44 map.off("style.load", ajouter);45 try {46 if (map.getLayer(`${SRC}-trait`)) map.removeLayer(`${SRC}-trait`);47 if (map.getLayer(`${SRC}-case`)) map.removeLayer(`${SRC}-case`);48 if (map.getSource(SRC)) map.removeSource(SRC);49 } catch { /* carte déjà détruite */ }50 };51 }, [ka]);52 return null;53}54