()
| 480 | |
| 481 | // Fallback map rendering if ROS2D fails |
| 482 | const tryFallbackMapRendering = () => { |
| 483 | console.log('Trying fallback map rendering...'); |
| 484 | |
| 485 | // Clean up any existing fallback |
| 486 | if (fallbackCleanupRef.current) { |
| 487 | fallbackCleanupRef.current(); |
| 488 | fallbackCleanupRef.current = null; |
| 489 | } |
| 490 | |
| 491 | const mapListener = new ROSLIB.Topic({ |
| 492 | ros: connection.ros!, |
| 493 | name: showCostmap ? '/move_base/global_costmap/costmap' : '/map', |
| 494 | messageType: 'nav_msgs/OccupancyGrid' |
| 495 | }); |
| 496 | |
| 497 | let mapInfo: any = null; |
| 498 | let mapCanvas: HTMLCanvasElement | null = null; |
| 499 | let robotMarker: HTMLDivElement | null = null; |
| 500 | let handleMouseMove: ((e: MouseEvent) => void) | null = null; |
| 501 | let handleMouseUp: (() => void) | null = null; |
| 502 | |
| 503 | // Use a state object to ensure closures work properly |
| 504 | const state = { |
| 505 | scale: 1, |
| 506 | translateX: 0, |
| 507 | translateY: 0, |
| 508 | isDragging: false, |
| 509 | dragStartX: 0, |
| 510 | dragStartY: 0, |
| 511 | viewport: null as HTMLDivElement | null |
| 512 | }; |
| 513 | |
| 514 | mapListener.subscribe((message: any) => { |
| 515 | if (message.info && message.data) { |
| 516 | console.log('Fallback: Map data received, attempting manual render', { |
| 517 | width: message.info.width, |
| 518 | height: message.info.height, |
| 519 | resolution: message.info.resolution, |
| 520 | origin: message.info.origin |
| 521 | }); |
| 522 | |
| 523 | mapInfo = message.info; |
| 524 | |
| 525 | const container = document.getElementById('ros2d-map'); |
| 526 | if (!container) return; |
| 527 | |
| 528 | // Clear container |
| 529 | container.innerHTML = ''; |
| 530 | |
| 531 | // Create main wrapper with overflow hidden |
| 532 | const mainWrapper = document.createElement('div'); |
| 533 | mainWrapper.style.position = 'relative'; |
| 534 | mainWrapper.style.width = '100%'; |
| 535 | mainWrapper.style.height = '100%'; |
| 536 | mainWrapper.style.overflow = 'hidden'; |
| 537 | mainWrapper.style.backgroundColor = '#1a1a1a'; |
| 538 | mainWrapper.style.cursor = 'grab'; |
| 539 | mainWrapper.style.userSelect = 'none'; |
nothing calls this directly
no test coverage detected