修复 一进入地图十字准星初始化 的位置 偏移很远电的问题
This commit is contained in:
@@ -169,15 +169,30 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
|||||||
// 示例:切换到导航模式
|
// 示例:切换到导航模式
|
||||||
_traceManager.setMode(TPMode.LOCATION);
|
_traceManager.setMode(TPMode.LOCATION);
|
||||||
|
|
||||||
|
// 🔥 核心修复:使用 addPostFrameCallback 延迟获取地图中心(渲染完成后执行)
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (mounted && _mapController.camera != null) {
|
||||||
|
final originalCenter = _mapController.camera!.center;
|
||||||
|
final highPrecisionCenter = LatLng(originalCenter.latitude, originalCenter.longitude);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_mapCenter = highPrecisionCenter;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 兜底:使用默认坐标初始化地图中心
|
||||||
|
final defaultCenter = _getDefaultValidCenter();
|
||||||
|
setState(() {
|
||||||
|
_mapCenter = defaultCenter;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 监听地图移动事件,实时更新连线
|
// 监听地图移动事件,实时更新连线
|
||||||
_mapController.mapEventStream.listen((event) {
|
_mapController.mapEventStream.listen((event) {
|
||||||
if (event is MapEventMove || event is MapEventMoveEnd) {
|
if (event is MapEventMove || event is MapEventMoveEnd) {
|
||||||
if (mounted && _mapController.camera != null) {
|
if (mounted && _mapController.camera != null) {
|
||||||
final originalCenter = _mapController.camera!.center;
|
final originalCenter = _mapController.camera!.center;
|
||||||
final highPrecisionCenter = LatLng(
|
final highPrecisionCenter = LatLng(originalCenter.latitude, originalCenter.longitude);
|
||||||
originalCenter.latitude, // 原始纬度(保留全部小数位)
|
|
||||||
originalCenter.longitude, // 原始经度(保留全部小数位)
|
|
||||||
);
|
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_mapCenter = highPrecisionCenter;
|
_mapCenter = highPrecisionCenter;
|
||||||
@@ -186,7 +201,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增:手动清除本地存储数据
|
// 新增:手动清除本地存储数据
|
||||||
Future<void> _clearLocalData() async {
|
Future<void> _clearLocalData() async {
|
||||||
try {
|
try {
|
||||||
@@ -1176,7 +1190,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
|||||||
polylines: [
|
polylines: [
|
||||||
Polyline(
|
Polyline(
|
||||||
points: gcjPathPoints, // 转换后的GCJ02坐标
|
points: gcjPathPoints, // 转换后的GCJ02坐标
|
||||||
color: const Color.fromARGB(255, 223, 228, 116), // 折线颜色(可自定义)
|
color: const Color.fromARGB(255, 255, 204, 0), // 金黄色(更醒目)
|
||||||
strokeWidth: 1.0, // 折线宽度
|
strokeWidth: 1.0, // 折线宽度
|
||||||
isDotted: false, // 非虚线(Line模式)
|
isDotted: false, // 非虚线(Line模式)
|
||||||
borderColor: Colors.white, // 可选:添加白色描边,提升辨识度
|
borderColor: Colors.white, // 可选:添加白色描边,提升辨识度
|
||||||
@@ -1453,6 +1467,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
|||||||
await context.read<DevicesCubit>().stopRoutePlanning();
|
await context.read<DevicesCubit>().stopRoutePlanning();
|
||||||
//修改App的状态
|
//修改App的状态
|
||||||
debugPrint('停止作业:${_selectedPlot!.plotName}');
|
debugPrint('停止作业:${_selectedPlot!.plotName}');
|
||||||
|
|
||||||
///ToastUtils.showError(context, '作业已停止');
|
///ToastUtils.showError(context, '作业已停止');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1463,7 +1478,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
|||||||
});
|
});
|
||||||
context.read<DevicesCubit>().updateAppState(AppState.routePlanning);
|
context.read<DevicesCubit>().updateAppState(AppState.routePlanning);
|
||||||
await context.read<DevicesCubit>().resumeRoutePlanning();
|
await context.read<DevicesCubit>().resumeRoutePlanning();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showDeleteConfirmDialog(PlotData plot, Function(PlotData) onDelete) {
|
void _showDeleteConfirmDialog(PlotData plot, Function(PlotData) onDelete) {
|
||||||
@@ -1805,7 +1819,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
|||||||
outerPositions = _robotModeWgsPoints.map((latLng) {
|
outerPositions = _robotModeWgsPoints.map((latLng) {
|
||||||
return work_area_model.Position(lat: latLng.latitude, lon: latLng.longitude);
|
return work_area_model.Position(lat: latLng.latitude, lon: latLng.longitude);
|
||||||
}).toList();
|
}).toList();
|
||||||
} else if(_currentRobotMode == RobotMode.point && _markedPoints.isNotEmpty) {
|
} else if (_currentRobotMode == RobotMode.point && _markedPoints.isNotEmpty) {
|
||||||
// Point模式:十字准星的GCJ02坐标 → 转换为WGS84
|
// Point模式:十字准星的GCJ02坐标 → 转换为WGS84
|
||||||
outerPositions = _markedPoints.map((latLng) {
|
outerPositions = _markedPoints.map((latLng) {
|
||||||
final wgs84Point = gcj02ToWgs84(latLng.latitude, latLng.longitude);
|
final wgs84Point = gcj02ToWgs84(latLng.latitude, latLng.longitude);
|
||||||
@@ -1836,7 +1850,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
|||||||
}).toList();
|
}).toList();
|
||||||
positionList.add(innerPositionList);
|
positionList.add(innerPositionList);
|
||||||
}
|
}
|
||||||
} else if(_currentRobotMode == RobotMode.point && _obstacleHoles.isNotEmpty) {
|
} else if (_currentRobotMode == RobotMode.point && _obstacleHoles.isNotEmpty) {
|
||||||
for (var holePoints in _obstacleHoles) {
|
for (var holePoints in _obstacleHoles) {
|
||||||
List<work_area_model.Position> innerPositionList = [];
|
List<work_area_model.Position> innerPositionList = [];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user