修复单点 开始作业的绘制 ,优化一些小问题
This commit is contained in:
@@ -762,6 +762,11 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
});
|
||||
|
||||
try {
|
||||
if (_currentLatLng != null && _isValidLatLng(_currentLatLng!.latitude, _currentLatLng!.longitude)) {
|
||||
_mapController.move(_currentLatLng!, 18);
|
||||
} else {
|
||||
_mapController.move(_currentLatLng!, 18);
|
||||
}
|
||||
// 2. 重置所有页面状态(恢复初始值)
|
||||
setState(() {
|
||||
_traceManager.setMode(TPMode.LOCATION);
|
||||
@@ -815,21 +820,8 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
});
|
||||
_clearLocalData();
|
||||
|
||||
// 3. 重新初始化定位
|
||||
await _initLocationEnterprise();
|
||||
|
||||
// 4. 重置轨迹管理器
|
||||
_traceManager.reset();
|
||||
if (_currentLatLng != null && _isValidLatLng(_currentLatLng!.latitude, _currentLatLng!.longitude)) {
|
||||
_mapController.move(_currentLatLng!, savedZoom);
|
||||
} else {
|
||||
// 使用兜底的有效坐标(确保在高德瓦片覆盖范围内)
|
||||
final defaultCenter = _getDefaultValidCenter();
|
||||
_mapController.move(defaultCenter, 17.0);
|
||||
_currentLatLng = null;
|
||||
_currentWgsLatLng = null;
|
||||
_mapCenter = defaultCenter;
|
||||
}
|
||||
|
||||
// 5. 重新加载作业记录(保持数据最新)
|
||||
// final userId = context.read<AppUserCubit>().state.user?.userId ?? "";
|
||||
@@ -837,7 +829,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
// await context.read<DevicesCubit>().loadWorkRecords(userId);
|
||||
// }
|
||||
|
||||
_mapController.move(_getDefaultValidCenter(), savedZoom);
|
||||
// 刷新成功提示
|
||||
if (mounted) {
|
||||
ToastUtils.showSuccess(context, '页面已刷新完成');
|
||||
@@ -845,7 +836,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
}
|
||||
} catch (e) {
|
||||
// 错误处理
|
||||
debugPrint('刷新失败:$e');
|
||||
if (mounted) {
|
||||
ToastUtils.showError(context, '刷新失败:${e.toString().substring(0, 50)}');
|
||||
//ScaffoldMessenger.of(
|
||||
@@ -890,7 +880,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
});
|
||||
_saveDataToLocal();
|
||||
|
||||
debugPrint('完成障碍物绘制,当前障碍物组数:${_obstacleHoles.length}');
|
||||
ToastUtils.showSuccess(context, '已添加第${_obstacleHoles.length}个障碍物区域');
|
||||
}
|
||||
|
||||
@@ -1048,15 +1037,12 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
} else {
|
||||
outerList = [];
|
||||
}
|
||||
if (_currentWorkMode == WorkMode.bow) {
|
||||
if (workMode == "弓字模式") {
|
||||
startWorkList = pathList;
|
||||
} else {
|
||||
startWorkList = outerList;
|
||||
}
|
||||
// ========== 修复结束 ==========
|
||||
|
||||
debugPrint('解析后的路径数据: pathList=$pathList, 长度=${pathList.length}');
|
||||
debugPrint('解析后的外边界数据: outerList=$outerList, 长度=${outerList.length}');
|
||||
List<LatLng> newPathPoints = [];
|
||||
List<LatLng> newOuterPoints = [];
|
||||
for (var item in pathList) {
|
||||
@@ -1489,13 +1475,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
|
||||
/// 开始作业
|
||||
void _startWork() async {
|
||||
debugPrint('🔵 _startWork 方法被调用了!');
|
||||
|
||||
debugPrint('📊 startWorkList 类型:${startWorkList.runtimeType}');
|
||||
debugPrint('📊 startWorkList 长度:${startWorkList.length}');
|
||||
debugPrint('📊 startWorkList 内容:$startWorkList');
|
||||
if (startWorkList.isEmpty) {
|
||||
debugPrint('🚀 作业列表为空');
|
||||
ToastUtils.showInfo(context, '作业列表为空,请重新选择路径');
|
||||
return;
|
||||
}
|
||||
@@ -1516,21 +1496,12 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
//}).toList();
|
||||
|
||||
// 步骤2:将 List 转换为 Queue(队列)
|
||||
debugPrint('⚙️ 开始类型转换...');
|
||||
final List<work_area_model.DeviceAddPathPointModel> typedList = startWorkList.whereType<Map<String, dynamic>>().map((item) {
|
||||
return work_area_model.DeviceAddPathPointModel(latitude: (item['lat'] as num).toDouble(), longitude: (item['lon'] as num).toDouble());
|
||||
return work_area_model.DeviceAddPathPointModel(latitude: (item['lat'] as num).toDouble(), longitude: (item['lon'] ?? item["lng"] as num).toDouble());
|
||||
}).toList();
|
||||
|
||||
debugPrint("===打印发送开始作业的路径开始 ");
|
||||
for (var i = 0; i < typedList.length; i++) {
|
||||
debugPrint(typedList[i].toString());
|
||||
}
|
||||
debugPrint("===打印发送开始作业的路径结束");
|
||||
final Queue<work_area_model.DeviceAddPathPointModel> pathQueue = Queue.from(typedList);
|
||||
|
||||
debugPrint('🚀 开始作业:${_selectedPlot?.plotName ?? "未命名"},路径点数量:${pathQueue.length}');
|
||||
debugPrint('第一个点 WGS84: ${pathQueue.first.latitude}, ${pathQueue.first.longitude}');
|
||||
|
||||
// 步骤 3:调用 Cubit 方法(类型匹配)
|
||||
await context.read<DevicesCubit>().startRoutePlanning(pathQueue);
|
||||
context.read<DevicesCubit>().updateAppState(AppState.routePlanning);
|
||||
@@ -1547,7 +1518,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
});
|
||||
context.read<DevicesCubit>().updateAppState(AppState.none);
|
||||
await context.read<DevicesCubit>().pauseRoutePlanning();
|
||||
debugPrint('暂停作业:${_selectedPlot!.plotName}');
|
||||
}
|
||||
|
||||
void _stopWork() async {
|
||||
@@ -1557,10 +1527,9 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
_showHeadingWarn = false;
|
||||
_showControlModeWarn = false;
|
||||
});
|
||||
_traceManager.setMode(TPMode.LOCATION);
|
||||
context.read<DevicesCubit>().updateAppState(AppState.none);
|
||||
await context.read<DevicesCubit>().stopRoutePlanning();
|
||||
//修改App的状态
|
||||
debugPrint('停止作业:${_selectedPlot!.plotName}');
|
||||
|
||||
ToastUtils.showError(context, '作业已停止');
|
||||
}
|
||||
@@ -1590,7 +1559,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
Widget _buildWorkPanel() {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
// 无选中地块或无路径数据时返回空
|
||||
if (_selectedPlot == null || state.pathData == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
@@ -2002,7 +1970,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
|
||||
// 4. 处理生成结果(原有逻辑不变)
|
||||
final cubitState = context.read<DevicesCubit>().state;
|
||||
print('${cubitState.generatedPath},路径生成结果');
|
||||
|
||||
if (cubitState.errorMessage != null) {
|
||||
if (showTips) {
|
||||
@@ -2052,14 +2019,12 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
_videoStreamUrl = "webrtc://${TCPConsts.TCP_IP}/live/livestream/$deviceId?token=${userState.user!.token}";
|
||||
} else {
|
||||
_videoStreamUrl = '';
|
||||
print("设备未选中或用户未登录,无法生成视频流地址");
|
||||
}
|
||||
return BlocBuilder<DeviceStatusBloc, DeviceStatusState>(
|
||||
builder: (context, state) {
|
||||
final devicesState = context.watch<DevicesCubit>().state;
|
||||
// 2. 读取 isFinishWork 数据(修正拼写,设置默认值)
|
||||
bool isFinishWork = devicesState.isFinshWork ?? false;
|
||||
print("$isFinishWork 完成信号");
|
||||
// 初始化默认值
|
||||
String yaw = '--';
|
||||
String satelliteCnt = '--';
|
||||
@@ -2071,6 +2036,9 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
DeviceStatusUpdated? updatedState;
|
||||
if (isFinishWork) {
|
||||
_workStatus = WorkStatus.idle;
|
||||
ToastUtils.showError(context, '作业已停止');
|
||||
isStartWork = false;
|
||||
_traceManager.setMode(TPMode.LOCATION);
|
||||
}
|
||||
|
||||
if (state is DeviceStatusUpdated) {
|
||||
|
||||
Reference in New Issue
Block a user