fix for map first load

This commit is contained in:
Roozbeh Karimi 2025-10-06 14:44:00 -04:00
parent befab94352
commit 0f8e57e93b

View File

@ -125,6 +125,23 @@ const FlightsLayer = ({ flightsData, updateInterval = 5000 }) => {
return null; return null;
}; };
const InitialBounds = ({ setBoundries }) => {
const map = useMap();
useEffect(() => {
// Wait for map to be ready, then set initial bounds
map.whenReady(() => {
const bounds = map.getBounds();
setBoundries({
southWest: bounds.getSouthWest(),
northEast: bounds.getNorthEast(),
});
});
}, [map, setBoundries]);
return null;
};
const createPlaneIcon = (heading = 0) => { const createPlaneIcon = (heading = 0) => {
const html = ` const html = `
<div style=" <div style="
@ -220,6 +237,7 @@ const MapView = () => {
worldCopyJump={true} worldCopyJump={true}
> >
<TileLayer url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" /> <TileLayer url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" />
<InitialBounds setBoundries={setBoundaries} />
<FlightsLayer flightsData={flights} updateInterval={2000} /> <FlightsLayer flightsData={flights} updateInterval={2000} />
<MapBounds setBoundries={setBoundaries} /> <MapBounds setBoundries={setBoundaries} />
</MapContainer> </MapContainer>