"use client"; import "leaflet/dist/leaflet.css"; import "leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.css"; import L from "leaflet"; import "leaflet-defaulticon-compatibility"; import { MapContainer, TileLayer, Marker, Popup, LayersControl, LayerGroup, } from "react-leaflet"; import { LatLngLiteral } from "leaflet"; import { TournamentDataProps } from "@/types"; export default function TournamentMap({ tournamentData }: TournamentDataProps) { const center: LatLngLiteral = { lat: 47.0844, lng: 2.3964 }; // TODO consider putting in page.tsx so that it is SSR // TODO move to own hook/util // TODO wrap in useEffect on initial load [] function layerGroups(timeControl: string, colour: string) { const filteredTournaments = tournamentData.filter( (t) => t.time_control === timeControl ); const iconOptions = new L.Icon({ iconUrl: `images/leaflet/marker-icon-2x-${colour}.png`, shadowUrl: "images/leaflet/marker-shadow.png", iconSize: [25, 41], iconAnchor: [12, 41], popupAnchor: [1, -34], shadowSize: [41, 41], }); return ( {filteredTournaments.map((t) => { const coordinates = { lat: t.coordinates[0] + Math.random() * (-0.01 - 0.01) + 0.01, lng: t.coordinates[1] + Math.random() * (-0.01 - 0.01) + 0.01, }; return (

{t.date}
{t.tournament}

géolocalisation approximative
); })}
); } const classicalMarkers = layerGroups("Cadence Lente", "green"); const rapidMarkers = layerGroups("Rapide", "blue"); const blitzMarkers = layerGroups("Blitz", "yellow"); const otherMarkers = layerGroups("1h KO", "red"); return (
{classicalMarkers} {rapidMarkers} {blitzMarkers} {otherMarkers}
); }