"use client"; import { useEffect, useState } from "react"; import L from "leaflet"; import { MapContainer, TileLayer, Marker, Popup, ZoomControl } from "react-leaflet"; // Import leaflet CSS import "leaflet/dist/leaflet.css"; // Add declaration for Leaflet's Icon.Default declare module 'leaflet' { namespace Icon { interface Default { _getIconUrl?: string; } } } interface CountryData { name: string; count: number; position: [number, number]; // latitude, longitude } interface MapComponentProps { countries: CountryData[]; onCountrySelect: (country: string) => void; selectedCountry: string | null; } // Fix Leaflet default icon path issues function fixLeafletIcons() { // Delete to prevent duplicate icon definitions delete L.Icon.Default.prototype._getIconUrl; // Set paths to the images L.Icon.Default.mergeOptions({ iconRetinaUrl: "https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon-2x.png", iconUrl: "https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon.png", shadowUrl: "https://unpkg.com/leaflet@1.9.4/dist/images/marker-shadow.png", }); } export function MapComponent({ countries, onCountrySelect, selectedCountry }: MapComponentProps) { const [isClient, setIsClient] = useState(false); useEffect(() => { // Fix Leaflet icons on client side fixLeafletIcons(); setIsClient(true); }, []); // Get custom icon based on count const getMarkerIcon = (count: number, isSelected: boolean) => { const size = Math.min(Math.max(20, count * 5), 40); return L.divIcon({ html: `
${count}
`, className: '', iconSize: [size, size], iconAnchor: [size/2, size/2] }); }; if (!isClient) { return (

Loading map...

); } return ( {countries.map((country) => ( onCountrySelect(country.name) }} >
{country.name}
{country.count} news articles
))}
); }