Skip to content

Commit 96163ef

Browse files
authored
Fix bug with previous drone location showing on map (#1126)
* Fix bug with previous drone location showing on map * Address copilot review comments
1 parent 74af708 commit 96163ef

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

gcs/src/components/dashboard/map.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
import {
2525
deletePoiMarker,
2626
emitReposition,
27+
selectConnectedToDrone,
2728
selectPoiMarkers,
2829
} from "../../redux/slices/droneConnectionSlice"
2930
import {
@@ -69,6 +70,7 @@ function MapSectionNonMemo({ passedRef, onDragstart, mapId = "dashboard" }) {
6970
// Redux
7071
const dispatch = useDispatch()
7172
const gpsData = useSelector(selectGPS)
73+
const connectedToDrone = useSelector(selectConnectedToDrone)
7274
const missionItems = useSelector(selectCurrentMissionItems)
7375
const homePosition = useSelector(selectHomePosition) // use actual home position
7476
const flightModeString = useSelector(selectFlightModeString)
@@ -138,14 +140,21 @@ function MapSectionNonMemo({ passedRef, onDragstart, mapId = "dashboard" }) {
138140
}, [contextMenuRef.current])
139141

140142
useEffect(() => {
143+
if (!connectedToDrone) {
144+
setPosition(null)
145+
setFirstCenteredToDrone(false)
146+
return
147+
}
148+
141149
// Check latest gpsData point is valid
142150
if (
143151
isNaN(gpsData.lat) ||
144152
isNaN(gpsData.lon) ||
145153
gpsData.lon === 0 ||
146154
gpsData.lat === 0
147-
)
155+
) {
148156
return
157+
}
149158

150159
// Move drone icon on map
151160
let lat = intToCoord(gpsData.lat)
@@ -159,7 +168,7 @@ function MapSectionNonMemo({ passedRef, onDragstart, mapId = "dashboard" }) {
159168
})
160169
setFirstCenteredToDrone(true)
161170
}
162-
}, [gpsData])
171+
}, [gpsData, connectedToDrone, firstCenteredToDrone, initialViewState.zoom])
163172

164173
useEffect(() => {
165174
setFilteredMissionItems(filterMissionItems(missionItems.missionItems))

gcs/src/redux/middleware/socketMiddleware.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,29 @@ const socketMiddleware = (store) => {
458458
socket.socket.on("disconnected_from_drone", () => {
459459
store.dispatch(setConnected(false))
460460
store.dispatch(setConnectedToSimulator(false))
461+
store.dispatch(
462+
setGpsData({
463+
mavpackettype: "GLOBAL_POSITION_INT",
464+
time_boot_ms: 0,
465+
lat: 0,
466+
lon: 0,
467+
alt: 0,
468+
relative_alt: 0,
469+
vx: 0,
470+
vy: 0,
471+
vz: 0,
472+
hdg: 0,
473+
timestamp: 0,
474+
}),
475+
)
476+
store.dispatch(
477+
setHomePosition({
478+
lat: 0,
479+
lon: 0,
480+
alt: 0,
481+
}),
482+
)
483+
store.dispatch(resetGpsTrack())
461484
store.dispatch(setIsFetchingDashboardMission(false))
462485
store.dispatch(
463486
closeDashboardMissionFetchingNotificationNoSuccessThunk(),
@@ -487,6 +510,13 @@ const socketMiddleware = (store) => {
487510

488511
// Flags that the drone is connected
489512
socket.socket.on("connected_to_drone", (msg) => {
513+
store.dispatch(
514+
setHomePosition({
515+
lat: 0,
516+
lon: 0,
517+
alt: 0,
518+
}),
519+
)
490520
store.dispatch(setDroneAircraftType(msg.aircraft_type)) // There are two aircraftTypes, make sure to not use FLA one haha :D
491521
if (msg.aircraft_type !== 1 && msg.aircraft_type !== 2) {
492522
showErrorNotification("Aircraft not of type quadcopter or plane")

0 commit comments

Comments
 (0)