({
onZoomIn,
onZoomOut,
onStyleChange,
onToggleLayers,
onToggleDraw,
onResetNorth,
onLocateUser,
onToggleNdvi,
isDrawing,
showFields = true,
showNdvi = false,
defaultStyle = "dark",
}: MapToolbarProps)
| 21 | } |
| 22 | |
| 23 | const MapToolbar = ({ |
| 24 | onZoomIn, |
| 25 | onZoomOut, |
| 26 | onStyleChange, |
| 27 | onToggleLayers, |
| 28 | onToggleDraw, |
| 29 | onResetNorth, |
| 30 | onLocateUser, |
| 31 | onToggleNdvi, |
| 32 | |
| 33 | isDrawing, |
| 34 | showFields = true, |
| 35 | showNdvi = false, |
| 36 | defaultStyle = "dark", |
| 37 | }: MapToolbarProps) => { |
| 38 | const [currentStyle, setCurrentStyle] = useState<MapStyle>(defaultStyle); |
| 39 | |
| 40 | const handleStyleToggle = () => { |
| 41 | const next: MapStyle = currentStyle === "dark" ? "satellite" : "dark"; |
| 42 | setCurrentStyle(next); |
| 43 | onStyleChange?.(next); |
| 44 | }; |
| 45 | |
| 46 | const items = [ |
| 47 | { icon: Layers, onClick: onToggleLayers ?? (() => {}), label: showFields ? "Hide Regions" : "Show Regions", active: showFields }, |
| 48 | { icon: Plus, onClick: onZoomIn, label: "Zoom In" }, |
| 49 | { icon: Minus, onClick: onZoomOut, label: "Zoom Out" }, |
| 50 | { icon: Map, onClick: handleStyleToggle, label: currentStyle === "dark" ? "Satellite" : "Dark Mode", active: currentStyle === "satellite" }, |
| 51 | { icon: PenTool, onClick: onToggleDraw ?? (() => {}), label: "Draw Region", active: isDrawing }, |
| 52 | { icon: Satellite, onClick: onToggleNdvi ?? (() => {}), label: showNdvi ? "Hide NDVI" : "NDVI Overlay", active: showNdvi }, |
| 53 | { icon: Compass, onClick: onResetNorth ?? (() => {}), label: "Reset North" }, |
| 54 | { icon: LocateFixed, onClick: onLocateUser ?? (() => {}), label: "My Location" }, |
| 55 | ]; |
| 56 | |
| 57 | return ( |
| 58 | <TooltipProvider delayDuration={200}> |
| 59 | <div className="absolute left-4 top-1/2 -translate-y-1/2 flex flex-col gap-2 z-10 opacity-85"> |
| 60 | {items.map(({ icon: Icon, onClick, label, active }) => ( |
| 61 | <Tooltip key={label}> |
| 62 | <TooltipTrigger asChild> |
| 63 | <button |
| 64 | onClick={onClick} |
| 65 | className={`w-10 h-10 rounded-lg backdrop-blur-sm border border-border flex items-center justify-center transition-colors ${ |
| 66 | active ? "text-primary bg-accent" : "text-foreground" |
| 67 | }`} |
| 68 | style={{ backgroundColor: active ? undefined : "#041009" }} |
| 69 | > |
| 70 | <Icon className="w-4 h-4" /> |
| 71 | </button> |
| 72 | </TooltipTrigger> |
| 73 | <TooltipContent side="right"> |
| 74 | {label} |
| 75 | </TooltipContent> |
| 76 | </Tooltip> |
| 77 | ))} |
| 78 | </div> |
| 79 | </TooltipProvider> |
| 80 | ); |
nothing calls this directly
no outgoing calls
no test coverage detected