diff --git a/lib/features/home/presentation/widgets/map/testmap_pages.dart b/lib/features/home/presentation/widgets/map/testmap_pages.dart index 74a08139..97e28176 100644 --- a/lib/features/home/presentation/widgets/map/testmap_pages.dart +++ b/lib/features/home/presentation/widgets/map/testmap_pages.dart @@ -90,7 +90,6 @@ class _MapPageEnterpriseState extends State { LatLng? _currentLatLng; //gc格式 LatLng? _currentWgsLatLng; - StreamSubscription? _positionSub; bool _isPanelOpen = false; // 控制面板显示/隐藏 bool _directionBoxOpen = false; //航线面板显示/隐藏 bool _saveBoxOpen = false; //保存按钮显示/隐藏 @@ -101,7 +100,7 @@ class _MapPageEnterpriseState extends State { // 新增:控制底部作业面板显示 bool _isWorkPanelOpen = false; bool _isWorkAreaCompleted = false; - RobotMode _currentRobotMode = RobotMode.point; //打点模式 + RobotMode _currentRobotMode = RobotMode.robot; //打点模式 AreaMode _currentAreaMode = AreaMode.work; //作业区域还是障碍物区域 WorkMode? _currentWorkMode = WorkMode.bow; // 当前作业模式 // 新增:存储转换后的path和outer坐标 @@ -121,9 +120,9 @@ class _MapPageEnterpriseState extends State { List typedPathList = []; // 存储生成路径的坐标列表(已转换为LatLng) // ========== 障碍物模式核心状态 ========== - List> _obstacleHoles = []; // 存储多组障碍物打点(嵌套数组:每组是一个空洞) + List> _obstacleHoles = []; // 存储多组障碍物打点(嵌套数组:每组是一个障碍物) - List> _obstacleWgsHoles = []; // 存储多组障碍物打点(嵌套数组:每组是一个空洞) + List> _obstacleWgsHoles = []; // 存储多组障碍物打点(嵌套数组:每组是一个障碍物) List _currentObstaclePoints = []; // 当前正在绘制的障碍物打点 bool _isObstacleEditing = false; // 是否处于障碍物编辑状态 @@ -543,7 +542,7 @@ class _MapPageEnterpriseState extends State { return; } - // 2. 空洞模式(逻辑不变,Robot模式下障碍物打点和Point模式一致) + // 2. 障碍物模式(逻辑不变,Robot模式下障碍物打点和Point模式一致) if (_currentAreaMode == AreaMode.obstacle) { if (_currentObstaclePoints.isNotEmpty) { _currentObstaclePoints.removeLast(); @@ -551,7 +550,7 @@ class _MapPageEnterpriseState extends State { if (_currentObstaclePoints.isEmpty) { _isObstacleEditing = false; } - ToastUtils.showInfo(context, '已撤回当前空洞最后一个点,剩余${_currentObstaclePoints.length}个点'); + ToastUtils.showInfo(context, '已撤回当前障碍物最后一个点,剩余${_currentObstaclePoints.length}个点'); return; } @@ -560,11 +559,11 @@ class _MapPageEnterpriseState extends State { if (_isWorkAreaCompleted) { _generatePath(showTips: false); } - ToastUtils.showInfo(context, '已撤回上一个完整空洞,剩余${_obstacleHoles.length}个空洞'); + ToastUtils.showInfo(context, '已撤回上一个完整障碍物,剩余${_obstacleHoles.length}个障碍物'); return; } - ToastUtils.showInfo(context, '暂无空洞可撤回'); + ToastUtils.showInfo(context, '暂无障碍物可撤回'); } }); } @@ -596,21 +595,21 @@ class _MapPageEnterpriseState extends State { //ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('已清空所有作业区域点和路径'))); } - // 2. 空洞模式:清空所有空洞 + 恢复UI + 重新生成路径 + // 2. 障碍物模式:清空所有障碍物 + 恢复UI + 重新生成路径 else if (_currentAreaMode == AreaMode.obstacle) { if (_obstacleHoles.isEmpty && _currentObstaclePoints.isEmpty) { - ToastUtils.showInfo(context, '暂无空洞可删除'); + ToastUtils.showInfo(context, '暂无障碍物可删除'); return; } _obstacleHoles.clear(); _currentObstaclePoints.clear(); _robotModeObsWgsPoints.clear(); _isObstacleEditing = false; - // 清空后重新生成路径(无空洞) + // 清空后重新生成路径(无障碍物) if (_isWorkAreaCompleted) { _generatePath(showTips: false); } - ToastUtils.showSuccess(context, '已清空所有空洞'); + ToastUtils.showSuccess(context, '已清空所有障碍物'); } }); } @@ -635,30 +634,22 @@ class _MapPageEnterpriseState extends State { Future _initLocationEnterprise() async { // 1. 设置轨迹模式为 LOCATION(核心:确保模式正确) _traceManager.setMode(TPMode.LOCATION); - - // 2. 清空旧的定位监听(如果有) - await _positionSub?.cancel(); - _positionSub = null; - - // 3. 初始化默认坐标(可选,避免地图空白) - setState(() { - _currentLatLng = const LatLng(39.9042, 116.4074); // 北京默认坐标 - }); } // ========== 新增:页面刷新初始化方法 ========== Future _handleRefresh() async { // 防止重复刷新 if (_isRefreshing) return; + // 🔥 保存当前定位(刷新前先记录) + final savedCurrentLatLng = _currentLatLng; + final savedCurrentWgsLatLng = _currentWgsLatLng; + final savedMapCenter = _mapCenter; setState(() { _isRefreshing = true; // 标记开始刷新 }); try { - // 1. 取消旧的定位监听 - await _positionSub?.cancel(); - // 2. 重置所有页面状态(恢复初始值) setState(() { _traceManager.setMode(TPMode.LOCATION); @@ -693,8 +684,9 @@ class _MapPageEnterpriseState extends State { // 重置参数 _workDistance = 0.0; _angle = 0.0; - _mapCenter = const LatLng(39.9042, 116.4074); - _currentLatLng = null; + _currentLatLng = savedCurrentLatLng; + _currentWgsLatLng = savedCurrentWgsLatLng; + _mapCenter = savedMapCenter ?? _currentLatLng ?? const LatLng(39.9042, 116.4074); }); // 3. 重新初始化定位 @@ -704,13 +696,16 @@ class _MapPageEnterpriseState extends State { _traceManager.reset(); // 5. 重新加载作业记录(保持数据最新) - final userId = context.read().state.user?.userId ?? ""; - if (userId.isNotEmpty) { - await context.read().loadWorkRecords(userId); - } + // final userId = context.read().state.user?.userId ?? ""; + // if (userId.isNotEmpty) { + // await context.read().loadWorkRecords(userId); + // } - // 6. 重置地图视角到初始位置 - _mapController.move(const LatLng(39.9042, 116.4074), 17); + if (savedCurrentLatLng != null) { + _mapController.move(savedCurrentLatLng, _mapController.camera?.zoom ?? 17); + } else { + _mapController.move(const LatLng(39.9042, 116.4074), 17); + } // 刷新成功提示 if (mounted) { @@ -840,7 +835,6 @@ class _MapPageEnterpriseState extends State { @override void dispose() { - _positionSub?.cancel(); _traceManager.reset(); _mapController.dispose(); super.dispose(); @@ -1192,8 +1186,8 @@ class _MapPageEnterpriseState extends State { mapController: _mapController, options: MapOptions( initialCenter: __isValidLatLng(_currentLatLng) ? _currentLatLng! : initCenter, - initialZoom: 18, - maxZoom: 18, + initialZoom: 22, + maxZoom: 22, minZoom: 3, enableScrollWheel: true, onTap: (_, __) {}, // 空实现,禁用地图点击响应 @@ -1935,7 +1929,6 @@ class _MapPageEnterpriseState extends State { final gcjPoint = wgs84ToGcj02(wgs84Lat, wgs84Lon); return LatLng(gcjPoint.latitude, gcjPoint.longitude); }).toList(); - // 外边界保持原有逻辑 gcjOuterPoints = List.from(_markedPoints); }); @@ -2054,22 +2047,23 @@ class _MapPageEnterpriseState extends State { ), /// 核心:地图正中心固定定位标 - Positioned( - left: 0, - right: 0, - top: 0, - bottom: 0, - child: Center( - // 自定义十字标(中心精准对齐地图中心) - child: SizedBox( - width: 16, // 十字整体宽度 - height: 16, // 十字整体高度 - child: CustomPaint( - painter: CrosshairPainter(), // 自定义十字画笔 + if (_currentRobotMode == RobotMode.point) + Positioned( + left: 0, + right: 0, + top: 0, + bottom: 0, + child: Center( + // 自定义十字标(中心精准对齐地图中心) + child: SizedBox( + width: 16, // 十字整体宽度 + height: 16, // 十字整体高度 + child: CustomPaint( + painter: CrosshairPainter(), // 自定义十字画笔 + ), ), ), ), - ), //保存按钮 if (_saveBoxOpen) @@ -2136,8 +2130,8 @@ class _MapPageEnterpriseState extends State { right: 0, bottom: 0, child: BottomOperationPanel( - initialRobotMode: RobotMode.point, - initialAreaMode: AreaMode.work, + initialRobotMode: _currentRobotMode, + initialAreaMode: _currentAreaMode, initialWorkMode: _currentWorkMode!, canUndo: _isWorkAreaCompleted && _currentAreaMode == AreaMode.work ? false : true, onComplete: () async { diff --git a/lib/features/home/presentation/widgets/startpoint_area.dart b/lib/features/home/presentation/widgets/startpoint_area.dart index c323acfe..e1efc38c 100644 --- a/lib/features/home/presentation/widgets/startpoint_area.dart +++ b/lib/features/home/presentation/widgets/startpoint_area.dart @@ -28,7 +28,7 @@ class BottomOperationPanel extends StatefulWidget { const BottomOperationPanel({ super.key, - this.initialRobotMode = RobotMode.point, + this.initialRobotMode = RobotMode.robot, this.initialAreaMode = AreaMode.work, this.initialSelectedTab = '地块', // 默认选中地块 this.initialWorkMode = WorkMode.bow,