Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/satellite-dish.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions src/components/panels/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React, { useEffect, useState } from 'react';
import { MapContainer, TileLayer, Marker, Popup, Polyline } from 'react-leaflet';
import L from 'leaflet';
import antennaMarker from "@/../public/satellite-dish.svg";
import { useWaypoints, LatLngTuple } from '@/contexts/WaypointContext';
import BreadcrumbTrail from '../BreadCrumbTrail';
import WaypointCreatorWindow from '../WaypointCreatorWindow';
Expand All @@ -20,13 +21,32 @@ const getCustomIcon = (color: string) =>
iconAnchor: [10, 10],
});

const getAntennaIcon = (heading: number) =>
L.divIcon({
html: `
<img
src="${antennaMarker.src}"
style="
width: 60px;
height: 60px;
transform: rotate(${heading - 45}deg); // needed to align svg north, not bothered to edit svg
"
/>
`,
className: '',
iconSize: [30, 30],
iconAnchor: [15, 15],
});

type MapViewProps = {
offline: boolean;
};

const MapView: React.FC<MapViewProps> = ({offline}) => {
const { ros } = useROS();
const [droneLoc, setDroneLoc] = useState<LatLngTuple>([0, 0]);
const [antennaLoc, setAntennaLoc] = useState<LatLngTuple>([45.385172, -75.698283]);
const [antennaHead, setAntennaHead] = useState<number>(0);
const { waypoints } = useWaypoints();
const { NEXT_PUBLIC_TILE_SERVER } = useEnvContext();
const tileServer = NEXT_PUBLIC_TILE_SERVER || "localhost:80";
Expand All @@ -40,16 +60,45 @@ const MapView: React.FC<MapViewProps> = ({offline}) => {
messageType: 'sensor_msgs/NavSatFix',
});

const antennaFixTopic = new ROSLIB.Topic({
ros,
name: '/base_station/fix',
messageType: 'sensor_msgs/NavSatFix',
});

const antennaBearingTopic = new ROSLIB.Topic({
ros,
name: '/antenna/tracker_bearing',
messageType: 'std_msgs/Float32',
});

const handleDrone = (message: any) => {
// Assuming the /fix message contains 'latitude' and 'longitude'
const { latitude, longitude } = message;
setDroneLoc([latitude, longitude]);
};

const handleAntennaFix = (message: any) => {
// Assuming the /fix message contains 'latitude' and 'longitude'
const { latitude, longitude } = message;
setAntennaLoc([latitude, longitude]);
};

const handleAntennaBearing = (message: any) => {
// Assuming the message contains float32
const angle = message.data * 360;
setAntennaHead(angle);
};

droneTopic.subscribe(handleDrone);
antennaFixTopic.subscribe(handleAntennaFix);
antennaBearingTopic.subscribe(handleAntennaBearing);
return () => {
droneTopic.unsubscribe(handleDrone);
antennaFixTopic.unsubscribe(handleAntennaFix);
antennaBearingTopic.unsubscribe(handleAntennaBearing);
};

}, [ros]);

return (
Expand All @@ -66,6 +115,7 @@ const MapView: React.FC<MapViewProps> = ({offline}) => {
/>
<MapInteractionHandler />
<Marker position={droneLoc} icon={getCustomIcon("#4657F2")}/>
<Marker position={antennaLoc} icon={getAntennaIcon(antennaHead)}/>
{waypoints.map((wp, index) => (
<Marker key={index} position={wp.coordinate} icon={getCustomIcon(wp.color)}>
<Popup>
Expand Down
Loading