diff --git a/client/src/pages/MapView.jsx b/client/src/pages/MapView.jsx index f0f8862..66da243 100644 --- a/client/src/pages/MapView.jsx +++ b/client/src/pages/MapView.jsx @@ -109,6 +109,7 @@ const MapView = () => { const [mapCenter, setMapCenter] = useState([59.3293, 18.0686]); // Default to Stockholm center const [mapZoom, setMapZoom] = useState(10); // Default zoom level const [mapBounds, setMapBounds] = useState(null); + const [isInitialLoad, setIsInitialLoad] = useState(true); // Track if this is the first load const [showDroneDetections, setShowDroneDetections] = useState(true); const [droneDetectionHistory, setDroneDetectionHistory] = useState([]); const { recentDetections, deviceStatus } = useSocket(); @@ -166,6 +167,10 @@ const MapView = () => { const fetchDevices = async () => { try { + // Debug: Check if token exists before making request + const token = localStorage.getItem('token'); + console.log('MapView: fetchDevices - Token exists:', !!token, 'Token length:', token?.length); + const response = await api.get('/devices/map'); const deviceData = response.data.data; @@ -192,10 +197,13 @@ const MapView = () => { setMapBounds(bounds); - // Set center to the middle of all devices - const centerLat = (minLat + maxLat) / 2; - const centerLon = (minLon + maxLon) / 2; - setMapCenter([centerLat, centerLon]); + // Only set center on initial load, not on periodic refreshes + if (isInitialLoad) { + const centerLat = (minLat + maxLat) / 2; + const centerLon = (minLon + maxLon) / 2; + setMapCenter([centerLat, centerLon]); + setIsInitialLoad(false); // Mark that initial load is complete + } } } catch (error) { console.error('Error fetching devices:', error); diff --git a/client/src/services/api.js b/client/src/services/api.js index 574134c..2b5e835 100644 --- a/client/src/services/api.js +++ b/client/src/services/api.js @@ -33,6 +33,9 @@ api.interceptors.request.use( const token = localStorage.getItem('token'); if (token) { config.headers.Authorization = `Bearer ${token}`; + console.log('🔑 API Request: Token added to', config.url, 'Token length:', token.length); + } else { + console.warn('⚠️ API Request: No token found for', config.url); } return config; },