observatory

This commit is contained in:
alma 2025-05-04 17:04:54 +02:00
parent 125c16b6f6
commit 506e9f8f05
2 changed files with 19 additions and 8 deletions

View File

@ -119,6 +119,7 @@ export function ObservatoryMap({
selectedCountry selectedCountry
}: ObservatoryMapProps) { }: ObservatoryMapProps) {
const [isMounted, setIsMounted] = useState(false); const [isMounted, setIsMounted] = useState(false);
const [mapKey, setMapKey] = useState(Date.now()); // Unique key for map container
// We'll need the Leaflet CSS // We'll need the Leaflet CSS
useEffect(() => { useEffect(() => {
@ -154,6 +155,12 @@ export function ObservatoryMap({
} }
setIsMounted(true); setIsMounted(true);
// Return cleanup function
return () => {
// Generate a new key if the component is unmounted and remounted
setMapKey(Date.now());
};
}, []); }, []);
// Prepare countries with coordinates // Prepare countries with coordinates
@ -210,6 +217,7 @@ export function ObservatoryMap({
return ( return (
<div className="w-full h-full"> <div className="w-full h-full">
<MapContainer <MapContainer
key={mapKey} // Add a unique key to ensure the map is only initialized once
center={[20, 0]} // Center of the world center={[20, 0]} // Center of the world
zoom={2} zoom={2}
style={{ height: '100%', width: '100%' }} style={{ height: '100%', width: '100%' }}

View File

@ -186,14 +186,17 @@ export function ObservatoryView() {
</div> </div>
</div> </div>
<div className="flex-grow"> <div className="flex-grow">
<ObservatoryMap {!loading && (
countries={Object.entries(countriesMap).map(([name, items]) => ({ <ObservatoryMap
name, key="observatory-map"
count: items.length countries={Object.entries(countriesMap).map(([name, items]) => ({
}))} name,
onCountrySelect={handleCountrySelect} count: items.length
selectedCountry={selectedCountry} }))}
/> onCountrySelect={handleCountrySelect}
selectedCountry={selectedCountry}
/>
)}
</div> </div>
</div> </div>
</div> </div>