修复 一进入地图十字准星初始化 的位置 偏移很远电的问题
This commit is contained in:
@@ -169,15 +169,30 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
// 示例:切换到导航模式
|
||||
_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) {
|
||||
if (event is MapEventMove || event is MapEventMoveEnd) {
|
||||
if (mounted && _mapController.camera != null) {
|
||||
final originalCenter = _mapController.camera!.center;
|
||||
final highPrecisionCenter = LatLng(
|
||||
originalCenter.latitude, // 原始纬度(保留全部小数位)
|
||||
originalCenter.longitude, // 原始经度(保留全部小数位)
|
||||
);
|
||||
final highPrecisionCenter = LatLng(originalCenter.latitude, originalCenter.longitude);
|
||||
|
||||
setState(() {
|
||||
_mapCenter = highPrecisionCenter;
|
||||
@@ -186,7 +201,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 新增:手动清除本地存储数据
|
||||
Future<void> _clearLocalData() async {
|
||||
try {
|
||||
@@ -1154,10 +1168,10 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
TileLayer(
|
||||
//urlTemplate:
|
||||
// "https://webst02.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=2&style=7&key=bbb1f0f20eed6bf679eddf2625630aba",
|
||||
urlTemplate:
|
||||
'https://webrd02.is.autonavi.com/appmaptile'
|
||||
'?style=8&x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=1'
|
||||
'&key=bbb1f0f20eed6bf679eddf2625630aba',
|
||||
urlTemplate:
|
||||
'https://webrd02.is.autonavi.com/appmaptile'
|
||||
'?style=8&x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=1'
|
||||
'&key=bbb1f0f20eed6bf679eddf2625630aba',
|
||||
// 🔥 修复:适配高DPI(替代pixelRatio)
|
||||
// tileSize: 512, // 高清瓦片尺寸(默认256,改为512适配scale=2)
|
||||
tileProvider: NetworkTileProvider(
|
||||
@@ -1176,7 +1190,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
polylines: [
|
||||
Polyline(
|
||||
points: gcjPathPoints, // 转换后的GCJ02坐标
|
||||
color: const Color.fromARGB(255, 223, 228, 116), // 折线颜色(可自定义)
|
||||
color: const Color.fromARGB(255, 255, 204, 0), // 金黄色(更醒目)
|
||||
strokeWidth: 1.0, // 折线宽度
|
||||
isDotted: false, // 非虚线(Line模式)
|
||||
borderColor: Colors.white, // 可选:添加白色描边,提升辨识度
|
||||
@@ -1453,6 +1467,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
await context.read<DevicesCubit>().stopRoutePlanning();
|
||||
//修改App的状态
|
||||
debugPrint('停止作业:${_selectedPlot!.plotName}');
|
||||
|
||||
///ToastUtils.showError(context, '作业已停止');
|
||||
}
|
||||
|
||||
@@ -1463,7 +1478,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
});
|
||||
context.read<DevicesCubit>().updateAppState(AppState.routePlanning);
|
||||
await context.read<DevicesCubit>().resumeRoutePlanning();
|
||||
|
||||
}
|
||||
|
||||
void _showDeleteConfirmDialog(PlotData plot, Function(PlotData) onDelete) {
|
||||
@@ -1805,7 +1819,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
outerPositions = _robotModeWgsPoints.map((latLng) {
|
||||
return work_area_model.Position(lat: latLng.latitude, lon: latLng.longitude);
|
||||
}).toList();
|
||||
} else if(_currentRobotMode == RobotMode.point && _markedPoints.isNotEmpty) {
|
||||
} else if (_currentRobotMode == RobotMode.point && _markedPoints.isNotEmpty) {
|
||||
// Point模式:十字准星的GCJ02坐标 → 转换为WGS84
|
||||
outerPositions = _markedPoints.map((latLng) {
|
||||
final wgs84Point = gcj02ToWgs84(latLng.latitude, latLng.longitude);
|
||||
@@ -1836,15 +1850,15 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
}).toList();
|
||||
positionList.add(innerPositionList);
|
||||
}
|
||||
} else if(_currentRobotMode == RobotMode.point && _obstacleHoles.isNotEmpty) {
|
||||
for (var holePoints in _obstacleHoles) {
|
||||
} else if (_currentRobotMode == RobotMode.point && _obstacleHoles.isNotEmpty) {
|
||||
for (var holePoints in _obstacleHoles) {
|
||||
List<work_area_model.Position> innerPositionList = [];
|
||||
|
||||
// Point模式:GCJ02→WGS84转换
|
||||
innerPositionList = holePoints.map((latLng) {
|
||||
final wgs84Point = gcj02ToWgs84(latLng.latitude, latLng.longitude);
|
||||
return work_area_model.Position(lat: wgs84Point.latitude, lon: wgs84Point.longitude);
|
||||
}).toList();
|
||||
final wgs84Point = gcj02ToWgs84(latLng.latitude, latLng.longitude);
|
||||
return work_area_model.Position(lat: wgs84Point.latitude, lon: wgs84Point.longitude);
|
||||
}).toList();
|
||||
positionList.add(innerPositionList);
|
||||
}
|
||||
}
|
||||
@@ -2038,22 +2052,22 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
|
||||
/// 核心:地图正中心固定定位标
|
||||
if (_currentRobotMode == RobotMode.point)
|
||||
Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
child: Center(
|
||||
// 自定义十字标(中心精准对齐地图中心)
|
||||
child: SizedBox(
|
||||
width: 16, // 十字整体宽度
|
||||
height: 16, // 十字整体高度
|
||||
child: CustomPaint(
|
||||
painter: CrosshairPainter(), // 自定义十字画笔
|
||||
Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
child: Center(
|
||||
// 自定义十字标(中心精准对齐地图中心)
|
||||
child: SizedBox(
|
||||
width: 16, // 十字整体宽度
|
||||
height: 16, // 十字整体高度
|
||||
child: CustomPaint(
|
||||
painter: CrosshairPainter(), // 自定义十字画笔
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
//保存按钮
|
||||
if (_saveBoxOpen)
|
||||
|
||||
Reference in New Issue
Block a user