From 9e5b6097923551e38fea0125a9c93548a365db2c Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Wed, 11 Mar 2026 11:24:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E4=B8=80=E8=BF=9B?= =?UTF-8?q?=E5=85=A5=E5=9C=B0=E5=9B=BE=E5=8D=81=E5=AD=97=E5=87=86=E6=98=9F?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=20=E7=9A=84=E4=BD=8D=E7=BD=AE=20?= =?UTF-8?q?=E5=81=8F=E7=A7=BB=E5=BE=88=E8=BF=9C=E7=94=B5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../widgets/map/testmap_pages.dart | 74 +++++++++++-------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/lib/features/home/presentation/widgets/map/testmap_pages.dart b/lib/features/home/presentation/widgets/map/testmap_pages.dart index 4842bae9..25560814 100644 --- a/lib/features/home/presentation/widgets/map/testmap_pages.dart +++ b/lib/features/home/presentation/widgets/map/testmap_pages.dart @@ -169,15 +169,30 @@ class _MapPageEnterpriseState extends State { // 示例:切换到导航模式 _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 { } }); } - // 新增:手动清除本地存储数据 Future _clearLocalData() async { try { @@ -1154,10 +1168,10 @@ class _MapPageEnterpriseState extends State { 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 { 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 { await context.read().stopRoutePlanning(); //修改App的状态 debugPrint('停止作业:${_selectedPlot!.plotName}'); + ///ToastUtils.showError(context, '作业已停止'); } @@ -1463,7 +1478,6 @@ class _MapPageEnterpriseState extends State { }); context.read().updateAppState(AppState.routePlanning); await context.read().resumeRoutePlanning(); - } void _showDeleteConfirmDialog(PlotData plot, Function(PlotData) onDelete) { @@ -1805,7 +1819,7 @@ class _MapPageEnterpriseState extends State { 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 { }).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 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 { /// 核心:地图正中心固定定位标 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)