点击完成生成路径 完成
This commit is contained in:
@@ -11,6 +11,7 @@ import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/core/network/net_message_dispatcher.dart';
|
||||
import 'package:maibu_satabot_v2/core/network/protocol_decoder.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/data/models/device_add_path_point_model.dart' as work_area_model;
|
||||
import 'package:maibu_satabot_v2/features/devices/data/models/device_work_area_param_model.dart' as work_area_model;
|
||||
import 'package:maibu_satabot_v2/features/devices/data/repositories/generate_path_repository_Impl.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/usecases/get_work_record_usecase.dart';
|
||||
@@ -1091,6 +1092,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
|
||||
// 4. 获取生成结果并处理
|
||||
final cubitState = context.read<DevicesCubit>().state;
|
||||
print('${cubitState.generatedPath},路径生成结果');
|
||||
if (cubitState.errorMessage != null) {
|
||||
// 生成失败
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('路径生成失败:${cubitState.errorMessage}'), backgroundColor: Colors.red));
|
||||
@@ -1100,21 +1102,22 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
debugPrint('生成的路径数据:${cubitState.generatedPath}');
|
||||
|
||||
// 可选:将生成的路径转换为地图可显示的坐标(WGS84 → GCJ02)
|
||||
if (cubitState.generatedPath is List) {
|
||||
if (cubitState.generatedPath is List) {
|
||||
setState(() {
|
||||
// 关键:生成的路径是 WGS84,需转回 GCJ02 才能在高德地图正确显示
|
||||
gcjPathPoints = (cubitState.generatedPath as List).map((point) {
|
||||
// 先取 WGS84 坐标
|
||||
double wgs84Lat = safeToDouble(point['lat']) ?? 0.0;
|
||||
double wgs84Lon = safeToDouble(point['lon']) ?? 0.0;
|
||||
// 转换为 GCJ02
|
||||
// 先将 List<dynamic> 转换为 List<DeviceAddPathPointModel>
|
||||
final pathList = cubitState.generatedPath as List;
|
||||
final typedPathList = pathList.whereType<work_area_model.DeviceAddPathPointModel>().toList();
|
||||
|
||||
// 然后使用 .lat 和 .lon 属性访问
|
||||
gcjPathPoints = typedPathList.map((point) {
|
||||
double wgs84Lat = point.latitude;
|
||||
double wgs84Lon = point.longitude;
|
||||
final gcjPoint = wgs84ToGcj02(wgs84Lat, wgs84Lon);
|
||||
return LatLng(gcjPoint.latitude, gcjPoint.longitude);
|
||||
}).toList();
|
||||
// 外边界也转回 GCJ02 显示(可选,保持和地图坐标系一致)
|
||||
|
||||
gcjOuterPoints = _markedPoints;
|
||||
});
|
||||
// 移动地图到生成的路径中心
|
||||
moveMapToPointsCenter(gcjPathPoints);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user