import { useGame } from "@/hooks/useGame"
import { useLastOwnLocation, useLastPlayerLocations } from "@/hooks/useLocation"
import { PlayerLocation } from "@/utils/features/location/locationSlice"
import { circle } from "@turf/circle"
import { type Map as MaplibreGLMap } from "maplibre-gl"
import { RLayer, RMap, RMarker, RNavigationControl, RSource, useMap } from "maplibre-react-components"
import { useMemo, useState } from "react"
export default function Map() {
return (
)
}
function UserLocation() {
const userLocation = useLastOwnLocation()
const [firstUserPositionFetched, setFirstUserPositionFetched] = useState(false)
const map: MaplibreGLMap = useMap()
if (userLocation != null && !firstUserPositionFetched) {
setFirstUserPositionFetched(true)
map.flyTo({center: [userLocation.coords.longitude, userLocation.coords.latitude], zoom: 15})
}
const accuracyCircle = circle([userLocation?.coords.longitude ?? 0, userLocation?.coords.latitude ?? 0], userLocation?.coords.accuracy ?? 0, {steps: 64, units: 'meters'})
const marker = userLocation ? : <>>
return <>
{marker}
>
}
function PlayerLocationsMarkers() {
const game = useGame()
const lastPlayerLocations = useLastPlayerLocations()
return lastPlayerLocations
// .filter(playerLoc => playerLoc.playerId !== game.playerId)
.map(playerLoc => )
}
function PlayerLocationMarker({ playerLocation }: { playerLocation: PlayerLocation }) {
const map: MaplibreGLMap = useMap()
const accuracyCircle = useMemo(() => circle(
[playerLocation.longitude, playerLocation.latitude],
playerLocation.accuracy,
{steps: 64, units: 'meters'}), [playerLocation])
return <>
>
}