孔洞逻辑完成

This commit is contained in:
mmc
2026-03-03 09:40:29 +08:00
parent bb16a532ec
commit ca90d8dc05
7 changed files with 134 additions and 116 deletions

View File

@@ -544,6 +544,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
// 重置选中状态
_selectedPlot = null;
_selectedPlotPath = null;
// 重置作业模式
@@ -1364,33 +1365,30 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
sideWidth: _workDistance,
);
// ========== 核心新增:转换障碍物为holes参数 ==========
final holes = <work_area_model.HoleBoundary>[];
work_area_model.HoleBoundary? holeBoundary;
if (_obstacleHoles.isNotEmpty) {
// 1. 构造二维 Position 数组
List<List<work_area_model.Position>> positionList = [];
for (var holePoints in _obstacleHoles) {
// 转换每组障碍物点为WGS84坐标系
final holePosition = holePoints.map((latLng) {
List<work_area_model.Position> innerPositionList = holePoints.map((latLng) {
final wgs84Point = gcj02ToWgs84(latLng.latitude, latLng.longitude);
return work_area_model.Position(lat: wgs84Point.latitude, lon: wgs84Point.longitude);
}).toList();
// 添加到holes数组(sideWidth固定为0)
holes.add(work_area_model.HoleBoundary(position: holePosition, sideWidth: 0.0));
positionList.add(innerPositionList);
}
}
try {
// 将holes转换为普通Map,便于JSON序列化
final holesJson = holes.map((hole) {
return {
'sideWidth': hole.sideWidth,
'position': hole.position.map((p) => {'lat': p.lat, 'lon': p.lon}).toList(),
};
}).toList();
// 格式化打印JSON(带缩进,更易读)
debugPrint('holes参数(JSON格式):\n${const JsonEncoder.withIndent(' ').convert(holesJson)}');
} catch (e) {
debugPrint('holes转JSON失败:$e');
// 2. 创建 HoleBoundary 对象(无外层 Map)
holeBoundary = work_area_model.HoleBoundary(position: positionList, sideWidth: 0.0);
}
// 🔥 第二步:构造符合方法参数要求的 Map<String, HoleBoundary>
// 用一个临时 Map 来满足类型要求,后续在 Cubit 中取值即可
Map<String, work_area_model.HoleBoundary> holes = {};
if (holeBoundary != null) {
holes = {'tempKey': holeBoundary}; // 键名任意,仅为满足类型要求
}
final workType = _currentWorkMode == WorkMode.bow ? 0 : 2;
@@ -1399,7 +1397,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
reference: referencePoint,
heading: heading,
outer: outerBoundary,
holes: holes, // 传入障碍物参数
holes: holes.isNotEmpty ? holes : {}, // 无障碍物时传空对象
workType: workType,
);
@@ -1560,7 +1558,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
),
],
),
if (_obstacleHoles.isNotEmpty)
if (_obstacleHoles.isNotEmpty && _isObstacleEditing)
PolygonLayer(
polygons: _obstacleHoles.map((holePoints) {
return Polygon(
@@ -1591,7 +1589,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
),
// 3. 障碍物打点标记(红色)
if (_currentAreaMode == AreaMode.obstacle)
if (_currentAreaMode == AreaMode.obstacle && _isObstacleEditing)
MarkerLayer(
markers: [
// 已完成的障碍物打点
@@ -1653,42 +1651,42 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
),
],
),
if (!_isWorkAreaCompleted)
/// 历史打点的绿色标记
MarkerLayer(
markers: _markedPoints.asMap().entries.map((entry) {
int index = entry.key + 1; // 打点序号(从1开始)
LatLng point = entry.value;
/// 历史打点的绿色标记
MarkerLayer(
markers: _markedPoints.asMap().entries.map((entry) {
int index = entry.key + 1; // 打点序号(从1开始)
LatLng point = entry.value;
return Marker(
point: point,
width: 80,
height: 40,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 8), // 向下偏移8px(抵消默认的顶部对齐)
// 绿色打点标记
Container(
width: 16,
height: 16,
decoration: const BoxDecoration(
color: Color(0xFF00C853), // 绿色主题色
shape: BoxShape.circle,
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 2)],
),
child: Center(
child: Text(
'$index',
style: const TextStyle(color: Colors.white, fontSize: 10, fontWeight: FontWeight.bold),
return Marker(
point: point,
width: 80,
height: 40,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 8), // 向下偏移8px(抵消默认的顶部对齐)
// 绿色打点标记
Container(
width: 16,
height: 16,
decoration: const BoxDecoration(
color: Color(0xFF00C853), // 绿色主题色
shape: BoxShape.circle,
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 2)],
),
child: Center(
child: Text(
'$index',
style: const TextStyle(color: Colors.white, fontSize: 10, fontWeight: FontWeight.bold),
),
),
),
),
],
),
);
}).toList(),
),
],
),
);
}).toList(),
),
],
),
),