import { Airport, AirportCategory } from '@lib/airport.types.ts'; import { Marker, Popup } from 'react-leaflet'; import L from 'leaflet'; import { useRef } from 'react'; import { getMarkerColor } from '@lib/metar.types.ts'; import { LayerInfo } from '@/App.tsx'; export default function AirportMarker({ index, airport, setAirport, selectedLayer }: { index: number; airport: Airport; setAirport: (airport: Airport) => void; selectedLayer: LayerInfo; }) { const icon = createCustomIcon(airport, selectedLayer); const markerRef = useRef(null); return ( setAirport(airport), mouseover: () => markerRef.current?.openPopup(), mouseout: () => markerRef.current?.closePopup() }} > {airport.icao} - {airport.name} ); } function createCustomIcon(airport: Airport, selectedLayer: LayerInfo): L.DivIcon { if (airport.category === AirportCategory.HELIPORT) { return L.divIcon({ html: `
H
`, className: '', iconSize: [20, 20], iconAnchor: [10, 10] }); } else { // Default to a filled circle. const flightCategory = airport.latest_metar?.flight_category || 'UNKN'; const color = getMarkerColor(flightCategory); if (flightCategory == 'UNKN') { return L.divIcon({ html: `
`, className: '', iconSize: [20, 20], iconAnchor: [10, 10] }); } else { return L.divIcon({ html: `
`, className: '', iconSize: [20, 20], iconAnchor: [10, 10] }); } } }