"use client" import {MapContainer, Marker, Popup, TileLayer} from "react-leaflet" import {Icon} from "leaflet" import "leaflet/dist/leaflet.css" // 修复 Leaflet 默认图标问题 const createCustomIcon = (status: string) => { const colors = { normal: "#52c41a", warning: "#faad14", error: "#f5222d", maintenance: "#722ed1", } return new Icon({ iconUrl: `data:image/svg+xml;base64,${btoa(` `)}`, iconSize: [25, 25], iconAnchor: [12.5, 12.5], popupAnchor: [0, -12.5], }) } interface Device { id: number name: string type: string status: string location: string lat: number lng: number battery: number signal: number } interface MapViewProps { devices: Device[] showRealTimeData?: boolean } export default function MapView({ devices, showRealTimeData = false }: MapViewProps) { const center: [number, number] = [39.9042, 116.4074] // 北京中心 return ( {devices.map((device) => ( {device.name} 位置: {device.location} 状态: {device.status === "normal" ? "正常" : device.status === "warning" ? "告警" : device.status === "error" ? "故障" : "维修中"} 电池: {device.battery}% 信号: {device.signal}% {showRealTimeData && ( 实时数据: 倾斜角度: 2.3° 位移距离: 0.8mm 震动强度: 18dB )} ))} ) }
位置: {device.location}
状态: {device.status === "normal" ? "正常" : device.status === "warning" ? "告警" : device.status === "error" ? "故障" : "维修中"}
电池: {device.battery}%
信号: {device.signal}%
实时数据:
倾斜角度: 2.3°
位移距离: 0.8mm
震动强度: 18dB