MCPcopy Create free account
hub / github.com/botbotrobotics/BotBrain / MapView

Function MapView

frontend/src/components/map-view.tsx:29–982  ·  view source on GitHub ↗
({ className = '' }: MapViewProps)

Source from the content-addressed store, hash-verified

27}
28
29export default function MapView({ className = '' }: MapViewProps) {
30 const { connection } = useRobotConnection();
31 const { t } = useLanguage();
32 const mapContainerRef = useRef<HTMLDivElement>(null);
33 const viewerRef = useRef<any>(null);
34 const gridClientRef = useRef<any>(null);
35 const robotMarkerRef = useRef<any>(null);
36 const [mapError, setMapError] = useState<string | null>(null);
37 const [isMapLoaded, setIsMapLoaded] = useState(false);
38 const [showCostmap, setShowCostmap] = useState(false);
39 const tryFallbackMapRenderingRef = useRef<(() => void) | null>(null);
40 const fallbackCleanupRef = useRef<(() => void) | null>(null);
41
42 useEffect(() => {
43 if (!connection.ros || !connection.online || !mapContainerRef.current) {
44 return;
45 }
46
47 setMapError(null);
48 setIsMapLoaded(false);
49
50 // List available topics to help debug
51 const listTopics = () => {
52 if (connection.ros && connection.online) {
53 const topicsClient = new ROSLIB.Service({
54 ros: connection.ros,
55 name: '/rosapi/topics',
56 serviceType: 'rosapi/Topics'
57 });
58
59 topicsClient.callService({}, (result: any) => {
60 console.log('Available ROS topics:', result.topics);
61 const mapRelatedTopics = result.topics.filter((topic: string) =>
62 topic.includes('map') || topic.includes('costmap') || topic.includes('grid')
63 );
64 console.log('Map-related topics:', mapRelatedTopics);
65
66 // Check for common map topics
67 const commonMapTopics = ['/map', '/map_metadata', '/move_base/global_costmap/costmap'];
68 const availableMapTopics = commonMapTopics.filter(topic => result.topics.includes(topic));
69 if (availableMapTopics.length === 0) {
70 console.warn('No standard map topics found. You may need to run a map server or navigation stack.');
71 setMapError('No map topics available. Please ensure map_server or navigation is running.');
72 } else {
73 console.log('Found map topics:', availableMapTopics);
74 }
75 }, (error: any) => {
76 console.warn('Could not list topics:', error);
77 });
78 }
79 };
80
81 listTopics();
82
83 // Dynamically load the required scripts
84 const loadScripts = async () => {
85 try {
86 // Make ROSLIB available globally for ros2d

Callers

nothing calls this directly

Calls 6

useRobotConnectionFunction · 0.90
useLanguageFunction · 0.90
loadScriptsFunction · 0.85
tFunction · 0.85
logMethod · 0.80
listTopicsFunction · 0.70

Tested by

no test coverage detected