From 70a344485bd0c9b68ac91f72ed23ec5bfa998b09 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 25 十一月 2021 19:30:25 +0800
Subject: [PATCH] 功能完善

---
 lib/utils/map_util.dart |   74 +++++++++++++++++++++++++++++++++++--
 1 files changed, 70 insertions(+), 4 deletions(-)

diff --git a/lib/utils/map_util.dart b/lib/utils/map_util.dart
index 007eea9..e858bd3 100644
--- a/lib/utils/map_util.dart
+++ b/lib/utils/map_util.dart
@@ -4,7 +4,10 @@
 import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart';
 import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart';
 import 'package:locations/model/map/map_model.dart';
+import 'package:locations/ui/widget/map_marker.dart';
+import 'package:locations/utils/ui_constant.dart';
 
+///鍦板浘宸ュ叿绫�
 class MapUtil {
   ///鐢荤嚎
   ///https://lbs.baidu.com/index.php?title=flutter/loc/render-map/ployline
@@ -106,9 +109,16 @@
 
   static Future<BMFMarker> addMarker(
       BMFMapController? _mapController, BMFCoordinate position, String icon,
-      {String identifier = "flutter_marker",int zIndex=0,BMFPoint? offset}) async {
-    BMFMarker marker =
-        BMFMarker(position: position, identifier: identifier, icon: icon,zIndex: zIndex,centerOffset: offset);
+      {String identifier = "flutter_marker",
+      int zIndex = 0,
+      BMFPoint? offset}) async {
+    BMFMarker marker = BMFMarker(
+        position: position,
+        identifier: identifier,
+        icon: icon,
+        zIndex: zIndex,
+        centerOffset: offset);
+
     /// 娣诲姞Marker
     await _mapController?.addMarker(marker);
     return marker;
@@ -118,7 +128,8 @@
     _mapController!.removeMarker(marker);
   }
 
-  static removeMarkers(BMFMapController? _mapController, List<BMFMarker> markers) {
+  static removeMarkers(
+      BMFMapController? _mapController, List<BMFMarker> markers) {
     _mapController!.removeMarkers(markers);
   }
 
@@ -126,3 +137,58 @@
     _mapController!.cleanAllMarkers();
   }
 }
+
+///璺緞褰曞埗绠$悊
+///
+class TravelRECManager {
+  BMFMapController? mapController;
+  List<BMFCoordinate> positionList = [];
+  List<BMFMarker> startMarkers = [];
+
+  TravelRECManager(this.mapController);
+
+  //鐢昏捣濮嬬偣
+  _addStartMarker(BMFCoordinate position) {}
+
+  //鐢昏矾寰�
+  _drawLine(BMFCoordinate start, BMFCoordinate end) {
+    MapUtil.drawLine([start, end], ColorConstant.theme, mapController);
+  }
+
+  //寮�濮嬪綍鍒�
+  startREC(BMFCoordinate currentPosition) {
+    positionList.clear();
+    positionList.add(currentPosition);
+
+    //鐢昏捣濮嬬偣
+    MapMarkerUtil.addTravelStartMarker(
+        mapController, currentPosition!)
+        .then((value) {
+      startMarkers = value;
+    });
+  }
+
+  //娣诲姞浣嶇疆
+  addLocation(BMFCoordinate lication) async {
+    if (positionList.length < 1) {
+      return;
+    }
+    //璁$畻璺濈锛屽鏋滆窛绂诲湪10绫冲唴灏变笉娣诲姞鍒版暟缁�
+    double? distance = await BMFCalculateUtils.getLocationDistance(
+        positionList[positionList.length - 1], lication);
+    if (distance != null && distance >= 10) {
+      //涓婁紶浣嶇疆
+      positionList.add(lication);
+      _drawLine(positionList[positionList.length - 2],
+          positionList[positionList.length - 1]);
+    }
+  }
+
+  //鍋滄褰曞埗
+  stopREC() {
+    //娓呴櫎鏁版嵁
+    positionList.clear();
+    //鍒犻櫎绾�
+    mapController!.cleanAllMarkers();
+  }
+}

--
Gitblit v1.8.0