路径规划

This commit is contained in:
mmc
2026-04-01 12:54:44 +08:00
parent dc54d7857f
commit 83ac544b0f
2 changed files with 37 additions and 16 deletions

View File

@@ -181,6 +181,8 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
// 示例:切换到导航模式
_traceManager.setMode(TPMode.LOCATION);
tracePoint = [];
gctracePoint = [];
// 🔥 核心修复:使用 addPostFrameCallback 延迟获取地图中心(渲染完成后执行)
WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -715,7 +717,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
'planModel': _currentWorkMode == WorkMode.bow ? 0 : 2, // 作业模式值
};
debugPrint("$savePath savePath");
// 3. 构造 workRecord (包裹一层)
final Map<String, dynamic> workRecord = {
@@ -775,6 +776,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
_obstacleHoles.clear();
_isPanelOpen = false; // 关闭操作面板
_directionBoxOpen = false;
_isWorkAreaCompleted = false; // 重置作业区域完成状态
});
} else {
@@ -932,10 +934,15 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
if (_currentLatLng != null && _isValidLatLng(_currentLatLng!.latitude, _currentLatLng!.longitude)) {
_mapController.move(_currentLatLng!, 18);
}
_traceManager.setMode(TPMode.LOCATION);
_traceManager.reset();
setState(() {
_traceManager.setMode(TPMode.LOCATION);
isreceiveFirstCompletePoint = false;
tracePoint?.clear();
gctracePoint?.clear();
tracePoint = [];
gctracePoint = [];
// 清空所有绘制数据
_markedPoints.clear();
@@ -955,6 +962,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
_showControlModeWarn = false; // 关闭远程模式警告
_showHeadingWarn = false; // 关闭航向警告
_isPanelOpen = false; // 关闭底部操作面板
_directionBoxOpen = false; // 关闭航线方向面板
_isListBoxOpen = false; // 关闭地块列表面板
_isWorkPanelOpen = false; // 关闭作业面板
@@ -984,7 +992,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
});
_clearLocalData();
_traceManager.reset();
if (mounted) {
_showPageToast(message: "页面已刷新完成", type: ToastType.success);
@@ -1145,6 +1152,8 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
// 【优化1】第一步就UI响应,不卡手
setState(() {
_isListBoxOpen = false;
_isPanelOpen = false;
_directionBoxOpen = false;
gcjPathPoints = [];
gcjOuterPoints = [];
_selectedPlot = plot;
@@ -1161,6 +1170,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
setState(() {
_isWorkPanelOpen = true;
_isPanelOpen = false;
_directionBoxOpen = false;
});
return;
}
@@ -1170,6 +1180,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
setState(() {
_isWorkPanelOpen = true;
_isPanelOpen = false;
_directionBoxOpen = false;
});
return;
}
@@ -1181,6 +1192,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
setState(() {
_isWorkPanelOpen = true;
_isPanelOpen = false;
_directionBoxOpen = false;
});
return;
}
@@ -1191,11 +1203,13 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
setState(() {
_isWorkPanelOpen = true;
_isPanelOpen = false;
_directionBoxOpen = false;
});
return;
}
workMode = parsedJson['planModel'] == WorkMode.bow.value ? "弓字模式" : "自定义模式";
_currentWorkMode = parsedJson['planModel'] == WorkMode.bow.value ? WorkMode.bow : WorkMode.custom;
// 【优化4】统一 path/outer 解析逻辑,不重复代码
List<dynamic> pathList = [];
@@ -1249,6 +1263,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
gcjOuterPoints = newOuterPoints;
_isWorkPanelOpen = true;
_isPanelOpen = false;
_directionBoxOpen = false;
});
// 最后移动地图
@@ -1265,6 +1280,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
gcjOuterPoints = [];
_isWorkPanelOpen = true;
_isPanelOpen = false;
_directionBoxOpen = false;
});
} finally {
_saveDataToLocal();
@@ -1413,11 +1429,11 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
),
],
),
if (gcjPathPoints.isNotEmpty && _currentWorkMode == WorkMode.custom)
if (gcjOuterPoints.isNotEmpty && _currentWorkMode == WorkMode.custom)
PolylineLayer(
polylines: [
Polyline(
points: gcjPathPoints, // 转换后的GCJ02坐标
points: gcjOuterPoints, // 转换后的GCJ02坐标
color: Colors.green, // 内部填充色(透明)
strokeWidth: 3.0, // 折线宽度
isDotted: false, // 非虚线(Line模式)
@@ -1704,10 +1720,13 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
//context.read<DevicesCubit>().updateAppState(AppState.none);
await context.read<DevicesCubit>().stopRoutePlanning();
_traceManager.reset();
_saveDataToLocal(); // 🔥 保存暂停状态
_showPageToast(message: "作业已停止", type: ToastType.error);
_traceManager.setMode(TPMode.LOCATION);
_traceManager.reset();
tracePoint = [];
gctracePoint = [];
}
/// 继续作业
@@ -2298,12 +2317,14 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
isreceiveFirstCompletePoint = false;
});
_showPageToast(message: "作业已停止", type: ToastType.error);
tracePoint = [];
gctracePoint = [];
// 延迟重置轨迹管理器
Future.delayed(const Duration(seconds: 1), () {
if (mounted) {
_traceManager.reset();
_traceManager.setMode(TPMode.LOCATION);
_traceManager.reset();
}
});
}

View File

@@ -132,10 +132,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.4.1"
version: "1.4.0"
checked_yaml:
dependency: transitive
description:
@@ -811,18 +811,18 @@ packages:
dependency: transitive
description:
name: matcher
sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861
sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.19"
version: "0.12.17"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.13.0"
version: "0.11.1"
meta:
dependency: transitive
description:
@@ -1280,10 +1280,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a"
sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.7.10"
version: "0.7.7"
time:
dependency: transitive
description: