diff --git a/client/src/pages/MapView.jsx b/client/src/pages/MapView.jsx index c6185dd..a6cd8dc 100644 --- a/client/src/pages/MapView.jsx +++ b/client/src/pages/MapView.jsx @@ -139,7 +139,7 @@ const MapView = () => { const newDetection = { ...latestDetection, timestamp: Date.now(), - id: `${latestDetection.device_id}-${latestDetection.drone_id}-${latestDetection.device_timestamp}` + id: `${latestDetection.device_id}-${latestDetection.drone_id || 'unknown'}-${latestDetection.device_timestamp || Date.now()}` }; console.log('MapView: Adding to history:', newDetection); @@ -393,14 +393,25 @@ const MapView = () => { const dashPattern = getDashPattern(detection.drone_type, droneIndex, totalDrones); const [latOffset, lonOffset] = getPositionOffset(droneIndex, totalDrones); + // Ensure coordinates are numbers and properly calculated + const baseLat = parseFloat(detection.geo_lat) || 0; + const baseLon = parseFloat(detection.geo_lon) || 0; + const centerLat = baseLat + latOffset; + const centerLon = baseLon + lonOffset; + + console.log('MapView: Coordinate calculation - baseLat:', baseLat, 'baseLon:', baseLon, 'latOffset:', latOffset, 'lonOffset:', lonOffset, 'centerLat:', centerLat, 'centerLon:', centerLon); + + // Validate coordinates before rendering + if (!isFinite(centerLat) || !isFinite(centerLon) || centerLat < -90 || centerLat > 90 || centerLon < -180 || centerLon > 180) { + console.error('MapView: Invalid coordinates detected, skipping ring:', centerLat, centerLon); + return null; + } + return ( {/* Detection Ring around Detector (NOT drone position) */} { {totalDrones > 1 && age < 5 && ( // Show labels for recent detections with multiple drones