import type { LucideIcon } from "lucide-react"; import { cn } from "@/shared/ui/cn"; import { MAP_ICON_CELL_RADIUS_CLASS_NAME, MAP_MAJOR_PANEL_RADIUS_CLASS_NAME, MAP_TOOL_PANEL_SURFACE_CLASS_NAME } from "./map-control-styles"; export type MapLegendItem = { id: string; label: string; description?: string; color: string; layerControlId?: string; group?: string; groupLabel?: string; groupDescription?: string; groupLayout?: "list" | "grid"; icon?: LucideIcon; imageSrc?: string; lineWidth?: number; shape?: "line" | "dashed-line" | "dash-dot-line" | "dot" | "ring" | "square" | "area"; }; type MapLegendProps = { title?: string; items: MapLegendItem[]; className?: string; }; export function MapLegend({ title = "图例", items, className = "" }: MapLegendProps) { return (

{title}

当前地图符号与分级

); } type MapLegendListProps = { items: MapLegendItem[]; className?: string; }; export function MapLegendList({ items, className = "" }: MapLegendListProps) { const groups = groupLegendItems(items); if (groups.length === 0) { return (

暂无可见业务图层

请先在图层面板中打开需要查看的内容。

); } return (
{groups.map((group) => (
{group.label} {group.description ? ( {group.description} ) : null} {group.items.length} 类
))}
); } function groupLegendItems(items: MapLegendItem[]) { const groups = new Map(); items.forEach((item) => { const id = item.group ?? "legend"; const existing = groups.get(id); if (existing) { existing.items.push(item); return; } groups.set(id, { id, label: item.groupLabel ?? "地图符号", description: item.groupDescription, layout: item.groupLayout ?? "list", items: [item] }); }); return [...groups.values()]; } function LegendItem({ item, compact }: { item: MapLegendItem; compact: boolean }) { const Icon = item.icon; return (
  • {item.label} {compact && item.description ? ( {item.description} ) : null} {!compact && item.description ? ( {item.description} ) : null}
  • ); } export function MapLegendSwatch({ color, shape = "dot", lineWidth = 3 }: Pick) { if (shape === "line" || shape === "dashed-line" || shape === "dash-dot-line") { const dashArray = shape === "dashed-line" ? "5 3" : shape === "dash-dot-line" ? "8 3 2 3" : undefined; return ( ); } if (shape === "square") { return ; } if (shape === "area") { return ( ); } if (shape === "ring") { return ; } return ; }