多角色的配置适配
This commit is contained in:
@@ -183,6 +183,9 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
|
||||
LatLng _mapCenter = const LatLng(39.9042, 116.4074);
|
||||
double _headingAngle = 0.0; // 当前机器航向角(单位:度)
|
||||
|
||||
// 🔥 地图 zoom 日志节流:上次已打印过的 zoom 值(变化 ≥ 0.1 才再打)
|
||||
double? _lastLoggedZoom;
|
||||
List typedPathList =
|
||||
<work_area_model.DeviceAddPathPointModel>[]; // 存储生成路径的坐标列表(已转换为LatLng)
|
||||
|
||||
@@ -274,6 +277,34 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 🔥 新增:zoom 变化日志(节流)
|
||||
// 用途:方便开发者手动 pinch/双击缩放到“理想级别”,从日志里读出 zoom 数值,
|
||||
// 反向调整 fitBounds 的 maxZoom(或其他缩放相关参数)。
|
||||
// 节流策略:只有 zoom 变化 ≥ 0.1 才打一次,避免拖拽/缩放过程中刷屏。
|
||||
// 事件来源(event.source)可区分“用户手势”还是“代码调用”:
|
||||
// - dragUpdate / pinchZoomUpdate / doubleTapZoomAnimation* → 用户交互
|
||||
// - custom → controller.move / fitBounds 等代码调用
|
||||
if (mounted && _mapController.camera != null) {
|
||||
final camera = _mapController.camera!;
|
||||
final currentZoom = camera.zoom;
|
||||
final shouldLog =
|
||||
_lastLoggedZoom == null ||
|
||||
(currentZoom - _lastLoggedZoom!).abs() >= 0.1;
|
||||
if (shouldLog) {
|
||||
final delta =
|
||||
_lastLoggedZoom == null
|
||||
? 'init'
|
||||
: '${currentZoom > _lastLoggedZoom! ? "↑放大" : "↓缩小"} '
|
||||
'${(currentZoom - _lastLoggedZoom!).toStringAsFixed(2)}';
|
||||
debugPrint(
|
||||
'🔍 [地图缩放] zoom=${currentZoom.toStringAsFixed(3)} ($delta), '
|
||||
'center=(${camera.center.latitude.toStringAsFixed(6)}, ${camera.center.longitude.toStringAsFixed(6)}), '
|
||||
'source=${event.source}',
|
||||
);
|
||||
_lastLoggedZoom = currentZoom;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 🌐 场站高清图层:监听动态范围更新 + 触发一次 GetCapabilities 刷新
|
||||
@@ -687,6 +718,47 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 🔥 选中路线任务时,自动校验"上次执行的任务"是否仍然存在
|
||||
/// 若任务已被取消/完成/不存在,则清除当前任务,避免面板显示过期任务卡片
|
||||
Future<void> _validateCurrentTaskOnSelect() async {
|
||||
try {
|
||||
final targetDevice =
|
||||
context.read<RemoteControlCubit>().state.targetDevice;
|
||||
final deviceId = targetDevice?.deviceName;
|
||||
if (deviceId == null || deviceId.isEmpty) return;
|
||||
|
||||
final taskCubit = sl<DeviceTaskCubit>();
|
||||
|
||||
// 优先取内存中的 taskId,其次从本地恢复(仅用于存在性校验,不提前构造卡片,避免闪现假任务)
|
||||
var previousTaskId = taskCubit.state.currentTaskId;
|
||||
if (previousTaskId == null) {
|
||||
previousTaskId = await _restoreTaskIdFromLocal(deviceId);
|
||||
}
|
||||
|
||||
// 没有历史任务,无需校验,也不展示卡片
|
||||
if (previousTaskId == null) return;
|
||||
|
||||
debugPrint(
|
||||
'🔄 [选中校验] 校验上次任务是否存在, deviceId=$deviceId, taskId=$previousTaskId',
|
||||
);
|
||||
await taskCubit.fetchAndFilterTask(deviceId);
|
||||
|
||||
// 🔥 查询后如果上次的任务已不在活跃任务中,清除当前任务,卡片不再展示
|
||||
final stillExists = taskCubit.state.activeTasks.any(
|
||||
(t) => t.id == previousTaskId,
|
||||
);
|
||||
if (!stillExists) {
|
||||
debugPrint('🔄 [选中校验] 任务已不存在,清除当前任务与本地缓存');
|
||||
taskCubit.clearCurrentTask();
|
||||
await _clearTaskIdFromLocal(deviceId);
|
||||
} else {
|
||||
debugPrint('🔄 [选中校验] 任务仍存在,保留显示');
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('🔄 [选中校验] 校验失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 新增:计算坐标列表的边界范围 ==========
|
||||
LatLngBounds? calculateBounds(List<LatLng> points) {
|
||||
if (points.isEmpty) return null;
|
||||
@@ -1833,6 +1905,9 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
_selectedPlot = plot;
|
||||
});
|
||||
|
||||
// 🔥 选中任务时自动校验上次的任务是否还存在:不存在则不展示(等同手动刷新)
|
||||
_validateCurrentTaskOnSelect();
|
||||
|
||||
try {
|
||||
_traceManager.reset();
|
||||
|
||||
@@ -2081,7 +2156,25 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
'🗺️ [选中地块] 准备移动地图: allPoints=${allPoints.length}, gcjPathPoints=${gcjPathPoints.length}, gcjOuterPoints=${gcjOuterPoints.length}',
|
||||
);
|
||||
if (allPoints.isNotEmpty) {
|
||||
moveMapToPointsCenter(allPoints);
|
||||
// 🔥 选中路线时自动定位到路径区域:
|
||||
// - center = bounds.center = 金黄线(gcjPathPoints)+ 灰色边框(gcjOuterPoints)所有点的
|
||||
// bounding box 几何中心,保证路径永远居中,不会因屏幕当前位置而偏移
|
||||
// - zoom = 21.0 固定值(开发者实测的理想级别):不管路径大小都缩到同一级别,视觉一致
|
||||
// - ⚠️ zoom=21 超过 ESRI 底图 19 级上限,底图可能白或靠场站高清叠加层显示(开发者已确认可接受)
|
||||
// - 一次性操作,不锁交互:用户之后仍可自由 pinch/drag 缩放平移
|
||||
final bounds = calculateBounds(allPoints);
|
||||
if (bounds != null) {
|
||||
const double targetZoom = 21.0;
|
||||
final zoomBefore = _mapController.camera?.zoom;
|
||||
_mapController.move(bounds.center, targetZoom);
|
||||
debugPrint(
|
||||
'🗺️ [选中地块] move 完成: zoom=$zoomBefore → $targetZoom, '
|
||||
'center=${bounds.center} (路径几何中心)',
|
||||
);
|
||||
} else {
|
||||
debugPrint('⚠️ [选中地块] bounds 计算失败,回退到仅居中(保持原缩放)');
|
||||
moveMapToPointsCenter(allPoints);
|
||||
}
|
||||
} else {
|
||||
debugPrint('❌ [选中地块] allPoints 为空,无法移动地图!');
|
||||
}
|
||||
@@ -3262,8 +3355,10 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
gctracePoint?.clear();
|
||||
tracePoint = [];
|
||||
gctracePoint = [];
|
||||
// 🔥 取消任务后消除规划路径显示,只保留原先的边界框(gcjOuterPoints)
|
||||
gcjPathPoints = [];
|
||||
});
|
||||
debugPrint('[停止作业] 最终 setState 完成,轨迹已清空');
|
||||
debugPrint('[停止作业] 最终 setState 完成,轨迹与路径已清空,保留边界框');
|
||||
}
|
||||
|
||||
debugPrint('══════════ [停止作业] 结束 ══════════');
|
||||
|
||||
Reference in New Issue
Block a user