终于解决了 第二次作业之后的 路径不清除的问题 ,一直保留着上一次作业发送的完成点
This commit is contained in:
@@ -660,11 +660,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
// 3. 打印文件/Blob 字段 (核心:这里包含 file 和 workRecord)
|
||||
debugPrint('📁 上传文件/Blob 数量: ${request.files.length}');
|
||||
for (var file in request.files) {
|
||||
debugPrint('------------------------------------');
|
||||
debugPrint(' 字段名 (name): ${file.field}');
|
||||
debugPrint(' 文件名 (filename): ${file.filename}');
|
||||
debugPrint(' 内容类型 (contentType): ${file.contentType}');
|
||||
|
||||
// 特殊处理:如果是 workRecord,打印其内容
|
||||
if (file.field == 'workRecord' && file is http.MultipartFile) {
|
||||
// 将 ByteStream 转为 Uint8List 以查看内容
|
||||
@@ -685,7 +680,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
});
|
||||
}
|
||||
}
|
||||
debugPrint('====================================');
|
||||
}
|
||||
|
||||
Future<void> _savePlotData(String plotName, String? imgBase64) async {
|
||||
@@ -697,11 +691,9 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
//ToastUtils.showError(context, '用户ID为空,无法保存!');
|
||||
return;
|
||||
}
|
||||
debugPrint("===打印生成的路径开始 ");
|
||||
for (var i = 0; i < typedPathList.length; i++) {
|
||||
debugPrint(typedPathList[i].toString());
|
||||
}
|
||||
debugPrint("===打印生成的路径结束");
|
||||
// 2. 构造 SavePath 数据 (严格对应你的 JS 结构)
|
||||
final Map<String, dynamic> savePath = {
|
||||
//'img': imgBase64 ?? '', // 截图的 Base64 字符串
|
||||
@@ -771,7 +763,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
|
||||
final http.StreamedResponse response = await request.send();
|
||||
final String responseBody = await response.stream.bytesToString();
|
||||
debugPrint('保存地块响应体: $responseBody');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
_showPageToast(message: "地块「$plotName」保存成功!", type: ToastType.success);
|
||||
@@ -1269,7 +1260,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
|
||||
List<dynamic> outerList = [];
|
||||
final rawOuter = parsedJson['outer'];
|
||||
debugPrint("$rawOuter rawOuterrawOuterrawOuter");
|
||||
if (rawOuter is String) {
|
||||
try {
|
||||
outerList = jsonDecode(rawOuter) as List;
|
||||
@@ -1406,7 +1396,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
_traceManager.upsert(_currentWgsLatLng as PlotPoint, TPAction.UPDATE);
|
||||
tracePoint = _traceManager.getTracePoint();
|
||||
gctracePoint = batchWgs84ToGcj02(tracePoint!);
|
||||
_logger.log("[转换后gctracePoint]: $gctracePoint");
|
||||
_logger.log("[当前轨迹模式][转换后gctracePoint]: ${gctracePoint!.length}");
|
||||
_logger.log("[当前轨迹模式]:${_traceManager.getMode()}"); // 这里必须加 ()
|
||||
|
||||
//_currentLatLng = gcjPoint; // ✅ 状态变量在setState内更新
|
||||
@@ -1637,9 +1627,11 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
],
|
||||
),
|
||||
|
||||
if (gctracePoint!.isNotEmpty)
|
||||
// 只在 ≥2 个点时才显示图层,否则直接消失!
|
||||
if (gctracePoint != null && gctracePoint!.length >= 2)
|
||||
PolylineLayer(
|
||||
polylines: [Polyline(points: gctracePoint!, color: Color.fromARGB(255, 6, 187, 232), strokeWidth: 3, isDotted: false)],
|
||||
key: const ValueKey('trace_polyline'),
|
||||
polylines: [Polyline(points: gctracePoint!, color: const Color.fromARGB(255, 6, 187, 232), strokeWidth: 3)],
|
||||
),
|
||||
|
||||
/// 当前定位 Marker
|
||||
@@ -1700,20 +1692,28 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
|
||||
/// 开始作业
|
||||
void _startWork() async {
|
||||
_traceManager.reset();
|
||||
|
||||
if (startWorkList.isEmpty) {
|
||||
_showPageToast(message: "作业列表为空,请重新选择路径", type: ToastType.info);
|
||||
//ToastUtils.showInfo(context, '作业列表为空,请重新选择路径');
|
||||
return;
|
||||
}
|
||||
_traceManager.setMode(TPMode.NAVIGATION);
|
||||
_traceManager.setMode(TPMode.LOCATION);
|
||||
//_traceManager.reset();
|
||||
tracePoint = _traceManager.getTracePoint();
|
||||
gctracePoint = batchWgs84ToGcj02(tracePoint!);
|
||||
_logger.log("[当前轨迹模式][转换后gctracePoint]开始作业: $tracePoint");
|
||||
_logger.log("[当前轨迹模式][转换后gctracePoint]开始作业: $gctracePoint");
|
||||
_logger.log("[当前轨迹模式][转换后gctracePoint]开始作业= ${gctracePoint!.length}");
|
||||
|
||||
setState(() {
|
||||
isStopWork = false;
|
||||
|
||||
isStartWork = true; // 🔥 关键:停止作业标志
|
||||
_workStatus = WorkStatus.working;
|
||||
_traceManager.reset();
|
||||
tracePoint?.clear();
|
||||
gctracePoint?.clear();
|
||||
//_traceManager.setMode(TPMode.NAVIGATION);
|
||||
});
|
||||
|
||||
// 🔥 核心修复:先更新 AppState 为 routePlanning
|
||||
@@ -1728,9 +1728,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
|
||||
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);
|
||||
|
||||
@@ -1758,23 +1755,32 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
isStartWork = false; // 🔥 关键:停止作业标志
|
||||
isStartWork = false;
|
||||
_workStatus = WorkStatus.idle;
|
||||
_showHeadingWarn = false;
|
||||
_showControlModeWarn = false;
|
||||
isStopWork = true; //已经点击过停止
|
||||
isStopWork = true;
|
||||
isreceiveFirstCompletePoint = false;
|
||||
|
||||
// 1. 立刻切换模式(阻止新的点再进入 NAVIGATION 逻辑)
|
||||
_traceManager.setMode(TPMode.LOCATION);
|
||||
});
|
||||
}
|
||||
|
||||
await context.read<DevicesCubit>().stopRoutePlanning();
|
||||
_saveDataToLocal();
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
// 2. 延迟后重置 + 清空(彻底绝杀残留点)
|
||||
_traceManager.reset();
|
||||
tracePoint?.clear();
|
||||
gctracePoint?.clear();
|
||||
tracePoint = [];
|
||||
gctracePoint = [];
|
||||
});
|
||||
}
|
||||
|
||||
//context.read<DevicesCubit>().updateAppState(AppState.none);
|
||||
await context.read<DevicesCubit>().stopRoutePlanning();
|
||||
|
||||
_saveDataToLocal(); // 🔥 保存暂停状态
|
||||
_showPageToast(message: "作业已停止", type: ToastType.error);
|
||||
}
|
||||
|
||||
@@ -2113,9 +2119,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
|
||||
// ========== 抽象:生成路径的核心函数 ==========
|
||||
Future<void> _generatePath({bool showTips = true}) async {
|
||||
debugPrint("机器打点孔洞_obstacleHoles$_obstacleHoles");
|
||||
debugPrint("机器打点孔洞_robotModeObsWgsPoints$_robotModeObsWgsPoints");
|
||||
|
||||
if (_currentWorkMode == WorkMode.custom) {
|
||||
setState(() {
|
||||
_saveBoxOpen = true;
|
||||
@@ -2338,16 +2341,21 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
LatLng? targetLatLng;
|
||||
if (arriLatitude != null && arriLongitude != null) {
|
||||
targetLatLng = LatLng(arriLatitude, arriLongitude);
|
||||
_logger.log("当前轨迹模式: ${_traceManager.getMode()},收到完成点坐标: $targetLatLng");
|
||||
if (__isValidLatLng(targetLatLng)) {
|
||||
//debugPrint("${targetLatLng}收到完成点arriLatitude");
|
||||
if (!isreceiveFirstCompletePoint && isStartWork && _workStatus == WorkStatus.working) {
|
||||
debugPrint("收到完成点arriLatitude");
|
||||
|
||||
//if (!isreceiveFirstCompletePoint && isStartWork && _workStatus == WorkStatus.working) {
|
||||
debugPrint("收到完成点arriLatitude");
|
||||
if (_traceManager.getMode() != TPMode.NAVIGATION) {
|
||||
_traceManager.setMode(TPMode.NAVIGATION);
|
||||
isreceiveFirstCompletePoint = true;
|
||||
debugPrint("切换到导航模式");
|
||||
}
|
||||
|
||||
_traceManager.upsert(targetLatLng, TPAction.ADD);
|
||||
isreceiveFirstCompletePoint = true;
|
||||
//}
|
||||
if (isStartWork && _workStatus == WorkStatus.working) {
|
||||
_traceManager.upsert(targetLatLng, TPAction.ADD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2366,11 +2374,15 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
_workStatus = WorkStatus.idle;
|
||||
isStopWork = true;
|
||||
isreceiveFirstCompletePoint = false;
|
||||
|
||||
tracePoint = [];
|
||||
gctracePoint = [];
|
||||
tracePoint?.clear();
|
||||
gctracePoint?.clear();
|
||||
});
|
||||
_showPageToast(message: "作业已停止", type: ToastType.error);
|
||||
tracePoint = [];
|
||||
gctracePoint = [];
|
||||
// 延迟重置轨迹管理器
|
||||
|
||||
// 延迟重置轨迹管理器
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
if (mounted) {
|
||||
_traceManager.setMode(TPMode.LOCATION);
|
||||
@@ -2600,7 +2612,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
setState(() {
|
||||
_directionBoxOpen = true;
|
||||
});
|
||||
debugPrint('外部处理设置按钮点击');
|
||||
},
|
||||
onLandTap: () {
|
||||
debugPrint('外部处理地块标签点击');
|
||||
@@ -2621,12 +2632,9 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
initialOptimalHeading: true,
|
||||
initialDirection: 0.0,
|
||||
onValueChanged: (result) {
|
||||
debugPrint('最优航向:${result['optimalHeading']},角度:${result['direction']}');
|
||||
_angle = result['optimalHeading'] == true ? -1 : result['direction'];
|
||||
|
||||
debugPrint('外部处理航线方向设置,当前角度:${_angle}');
|
||||
if (_markedPoints.length >= 3 && _currentWorkMode != null) {
|
||||
debugPrint('外部处理航线方向设置11222:${_angle}');
|
||||
_generatePath(showTips: false);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user