// @ts-nocheck 'use client'; import { useState, useRef, useEffect } from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Card } from '@/components/ui/card'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { Map, Upload, Pen, Square, Layers, CheckCircle2, FileType, MapPin } from 'lucide-react'; import { GeoCoordinate } from '@/app/(app)/land-information/archive/manage/page'; import { toast } from 'sonner'; interface LandMapContainerProps { coordinates: GeoCoordinate[]; area: number; perimeter: number; onCoordinatesChange: (coordinates: GeoCoordinate[], area: number, perimeter: number) => void; } export function LandMapContainer({ coordinates, area, perimeter, onCoordinatesChange }: LandMapContainerProps) { const [isMapLoaded, setIsMapLoaded] = useState(false); const [mapLayerType, setMapLayerType] = useState<'satellite' | 'street'>('satellite'); const [drawMode, setDrawMode] = useState<'none' | 'polygon' | 'rectangle'>('none'); const mapContainerRef = useRef(null); // 初始化地图 useEffect(() => { // 模拟地图加载 setTimeout(() => { setIsMapLoaded(true); toast.info('演示地图模式:可通过文件导入或手动输入坐标数据', { duration: 3000 }); }, 1000); }, []); // 切换地图图层 const toggleMapLayer = () => { const newLayerType = mapLayerType === 'satellite' ? 'street' : 'satellite'; setMapLayerType(newLayerType); toast.success(`已切换到${newLayerType === 'satellite' ? '卫星图' : '电子地图'}`); }; // 开始绘制 const startDrawing = (mode: 'polygon' | 'rectangle') => { setDrawMode(mode); toast.info(`开始绘制${mode === 'polygon' ? '多边形' : '矩形'},点击地图描点,双击结束`); // 模拟绘制完成 setTimeout(() => { const mockCoordinates = [ { lat: 39.9042 + 0.01, lng: 116.4074 - 0.01 }, { lat: 39.9042 + 0.01, lng: 116.4074 + 0.01 }, { lat: 39.9042 - 0.01, lng: 116.4074 + 0.01 }, { lat: 39.9042 - 0.01, lng: 116.4074 - 0.01 }, ]; const mockArea = 120.5; const mockPerimeter = 1380; onCoordinatesChange(mockCoordinates, mockArea, mockPerimeter); setDrawMode('none'); toast.success(`绘制完成!面积:${mockArea.toFixed(2)}亩,周长:${mockPerimeter.toFixed(0)}米`); }, 2000); }; // 文件导入 const handleFileImport = async (event: React.ChangeEvent) => { const file = event.target.files?.[0]; if (!file) return; const fileExtension = file.name.split('.').pop()?.toLowerCase(); if (!['kml', 'geojson', 'json', 'shp'].includes(fileExtension || '')) { toast.error('不支持的文件格式。请上传 KML、GeoJSON 或 SHP 文件'); return; } try { // 模拟文件解析 const mockCoordinates = [ { lat: 39.9042 + 0.008, lng: 116.4074 - 0.008 }, { lat: 39.9042 + 0.008, lng: 116.4074 + 0.008 }, { lat: 39.9042 - 0.008, lng: 116.4074 + 0.008 }, { lat: 39.9042 - 0.008, lng: 116.4074 - 0.008 }, ]; const mockArea = 85.3; const mockPerimeter = 1120; onCoordinatesChange(mockCoordinates, mockArea, mockPerimeter); toast.success(`成功导入${fileExtension.toUpperCase()}文件!面积:${mockArea.toFixed(2)}亩,${mockCoordinates.length}个点`); } catch (error) { console.error('文件导入错误:', error); toast.error('文件导入失败,请检查文件格式'); } // 清空input event.target.value = ''; }; return (
{/* 地图工具栏 */}

地块边界绘制

{/* 地图容器 */}
{isMapLoaded && (

演示地图模式

系统提供完整功能,您可以使用:

  • 导入 KML/GeoJSON/SHP 文件
  • 手动绘制多边形或矩形边界
  • 自动计算面积、周长和中心点
  • 卫星图和电子地图切换

💡 如需启用真实地图,请配置地图SDK

)} {!isMapLoaded && (

初始化中...

)}
{/* 地图信息 */} {coordinates && coordinates.length > 0 && (
边界点数: {coordinates.length} 个
面积: {area.toFixed(2)} 亩
周长: {perimeter.toFixed(0)} 米
)} {/* 文件格式说明 */} 支持的文件格式:
  • KML - Google Earth 标准格式
  • GeoJSON - Web GIS 标准格式
  • SHP - ArcGIS Shapefile 格式
); }