Fix jwt-token

This commit is contained in:
2025-08-19 04:19:29 +02:00
parent 0cb59f1b25
commit 060cc125e3

View File

@@ -25,15 +25,15 @@ Icon.Default.mergeOptions({
shadowUrl, shadowUrl,
}); });
// Component to handle dynamic map bounds // Component to handle dynamic map bounds - only on initial load
const FitBounds = ({ bounds }) => { const FitBounds = ({ bounds, shouldFit }) => {
const map = useMap(); const map = useMap();
useEffect(() => { useEffect(() => {
if (bounds && bounds.length === 2) { if (bounds && bounds.length === 2 && shouldFit) {
map.fitBounds(bounds, { padding: [20, 20] }); map.fitBounds(bounds, { padding: [20, 20] });
} }
}, [bounds, map]); }, [bounds, map, shouldFit]);
return null; return null;
}; };
@@ -109,6 +109,7 @@ const MapView = () => {
const [mapCenter, setMapCenter] = useState([59.3293, 18.0686]); // Default to Stockholm center const [mapCenter, setMapCenter] = useState([59.3293, 18.0686]); // Default to Stockholm center
const [mapZoom, setMapZoom] = useState(10); // Default zoom level const [mapZoom, setMapZoom] = useState(10); // Default zoom level
const [mapBounds, setMapBounds] = useState(null); const [mapBounds, setMapBounds] = useState(null);
const [shouldFitBounds, setShouldFitBounds] = useState(false);
const [isInitialLoad, setIsInitialLoad] = useState(true); // Track if this is the first load const [isInitialLoad, setIsInitialLoad] = useState(true); // Track if this is the first load
const [showDroneDetections, setShowDroneDetections] = useState(true); const [showDroneDetections, setShowDroneDetections] = useState(true);
const [droneDetectionHistory, setDroneDetectionHistory] = useState([]); const [droneDetectionHistory, setDroneDetectionHistory] = useState([]);
@@ -198,10 +199,16 @@ const MapView = () => {
// Only set bounds and center on initial load, not on periodic refreshes // Only set bounds and center on initial load, not on periodic refreshes
if (isInitialLoad) { if (isInitialLoad) {
setMapBounds(bounds); setMapBounds(bounds);
setShouldFitBounds(true);
const centerLat = (minLat + maxLat) / 2; const centerLat = (minLat + maxLat) / 2;
const centerLon = (minLon + maxLon) / 2; const centerLon = (minLon + maxLon) / 2;
setMapCenter([centerLat, centerLon]); setMapCenter([centerLat, centerLon]);
setIsInitialLoad(false); // Mark that initial load is complete setIsInitialLoad(false); // Mark that initial load is complete
// Disable bounds fitting after a short delay to allow initial fit
setTimeout(() => {
setShouldFitBounds(false);
}, 1000);
} }
} }
} catch (error) { } catch (error) {
@@ -284,7 +291,7 @@ const MapView = () => {
zoom={mapZoom} zoom={mapZoom}
className="h-full w-full" className="h-full w-full"
> >
<FitBounds bounds={mapBounds} /> {shouldFitBounds && <FitBounds bounds={mapBounds} shouldFit={shouldFitBounds} />}
<TileLayer <TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"