import { useEffect, useState } from "react"; import { MapContainer, Marker, TileLayer, Tooltip, Polyline, Polygon } from "react-leaflet"; import "leaflet/dist/leaflet.css"; import { MapPan } from "@/components/mapUtils"; import useLocation from "@/hook/useLocation"; import useAdmin from "@/hook/useAdmin"; import { GameState } from "@/util/gameState"; const DEFAULT_ZOOM = 14; const positionIcon = new L.Icon({ iconUrl: '/icons/location.png', iconSize: [30, 30], iconAnchor: [15, 15], popupAnchor: [0, -15], shadowSize: [30, 30], }); export default function LiveMap() { const location = useLocation(Infinity); const [timeLeftNextZone, setTimeLeftNextZone] = useState(null); const { zoneExtremities, teams, nextZoneDate, getTeam, gameState } = useAdmin(); // Remaining time before sending position useEffect(() => { if (nextZoneDate) { const updateTime = () => { setTimeLeftNextZone(Math.max(0, Math.floor((nextZoneDate - Date.now()) / 1000))); }; updateTime(); const interval = setInterval(updateTime, 1000); return () => clearInterval(interval); } }, [nextZoneDate]); function formatTime(time) { // time is in seconds if (time < 0) return "00:00"; const minutes = Math.floor(time / 60); const seconds = Math.floor(time % 60); return String(minutes).padStart(2,"0") + ":" + String(seconds).padStart(2,"0"); } function Arrow({pos1, pos2}) { if (pos1 && pos2) { return ( ) } else { return null; } } return (
{gameState == GameState.PLAYING &&

{`Next zone in : ${formatTime(timeLeftNextZone)}`}

} {gameState == GameState.PLAYING && zoneExtremities.begin && } {gameState == GameState.PLAYING && zoneExtremities.end && } {teams.map((team) => team.currentLocation && !team.captured && {team.name} )}
) }