From 9583968a565b01ec1902b44791d18daaa11b48bd Mon Sep 17 00:00:00 2001 From: huixiang_app <953969641@qq.com> Date: Wed, 6 Sep 2023 10:52:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E5=BE=84=E4=B8=8D=E6=A0=B9=E6=8D=AEPa?= =?UTF-8?q?dding=E5=B1=9E=E6=80=A7=E6=9B=B4=E6=94=B9=EF=BC=8C=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E6=A0=B9=E6=8D=AEx=E8=BD=B4=E5=92=8Cy=E8=BD=B4?= =?UTF-8?q?=E7=9A=84=E6=9E=81=E5=80=BC=E5=B7=AE=E8=AE=A1=E7=AE=97=E5=87=BA?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E8=8C=83=E5=9B=B4=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/union/location_map_page.dart | 44 ++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/union/location_map_page.dart b/lib/union/location_map_page.dart index 4ec95009..2d0eaff1 100644 --- a/lib/union/location_map_page.dart +++ b/lib/union/location_map_page.dart @@ -461,12 +461,6 @@ class _LocationMap extends State with WidgetsBindingObserver { _mapController.cleanAllMarkers(); if (polylineId != null) _mapController.removeOverlay(polylineId); - BMFCoordinate startLocation = BMFCoordinate( - coordinates.first.latitude, coordinates.first.longitude); - - BMFCoordinate endLocation = - BMFCoordinate(coordinates.last.latitude, coordinates.last.longitude); - /// 创建polyline BMFPolyline colorsPolyline = BMFPolyline( // id: polylineOptions.hashCode.toString(), @@ -486,7 +480,8 @@ class _LocationMap extends State with WidgetsBindingObserver { /// 添加polyline _mapController.addPolyline(colorsPolyline); var startBmfMarker = BMFMarker.icon( - position: startLocation, + position: BMFCoordinate( + coordinates.first.latitude, coordinates.first.longitude), centerOffset: BMFPoint(0.5, 0.7), enabled: false, icon: "assets/image/icon_start.png", @@ -495,19 +490,40 @@ class _LocationMap extends State with WidgetsBindingObserver { _mapController.addMarker(startBmfMarker); var terminalBmfMarker = BMFMarker.icon( - position: endLocation, + position: BMFCoordinate( + coordinates.last.latitude, coordinates.last.longitude), centerOffset: BMFPoint(0.5, 0.7), enabled: false, icon: "assets/image/icon_end.png", draggable: false, ); _mapController.addMarker(terminalBmfMarker); - _mapController.setVisibleMapRectWithPadding( - visibleMapBounds: BMFCoordinateBounds( - northeast: startLocation, southwest: endLocation), - animated: true, - insets: - EdgeInsets.only(top: 500.h, bottom: 200.h, left: 200.w, right: 200.w)); + + double maxLatitude = 0, + minLatitude = 0, + maxLongitude = 0, + minLongitude = 0; + coordinates.forEach((element) { + if (element.latitude > maxLatitude) maxLatitude = element.latitude; + if (minLatitude == 0) + minLatitude = element.latitude; + else if (element.latitude < minLatitude) minLatitude = element.latitude; + + if (element.longitude > maxLongitude) maxLongitude = element.longitude; + if (minLongitude == 0) + minLongitude = element.longitude; + else if (element.longitude < minLongitude) + minLongitude = element.longitude; + }); + _mapController.setVisibleMapBounds( + BMFCoordinateBounds( + northeast: BMFCoordinate( + maxLatitude + ((maxLatitude - minLatitude) * 0.8), + maxLongitude + ((maxLongitude - minLongitude) / 2)), + southwest: BMFCoordinate( + minLatitude - ((maxLatitude - minLatitude) * 0.2), + minLongitude - ((maxLongitude - minLongitude) / 2))), + true); hours = needHours == 0 ? "" : "$needHours小时"; minutes = needMinutes == 0 ? "" : "$needMinutes分钟";