浏览代码

[new]轨迹详情界面增加我的定位功能

zk 5 月之前
父节点
当前提交
9a3b9c2d50

+ 0 - 1
lib/module/main/main_controller.dart

@@ -324,7 +324,6 @@ class MainController extends BaseController {
   }
 
   void onViewTraceClick(UserInfo userInfo) {
-    print("userInfosfsdf--${userInfo}");
     if (!accountRepository.isLogin.value) {
       showTraceTipsDialog(onConfirm: () {
         LoginPage.start();

+ 76 - 0
lib/module/track/track_controller.dart

@@ -11,8 +11,12 @@ import 'package:location/data/repositories/account_repository.dart';
 import 'package:location/data/repositories/friends_repository.dart';
 import 'package:location/data/repositories/track_repository.dart';
 import 'package:location/handler/error_handler.dart';
+import 'package:location/resource/string.gen.dart';
 import 'package:sliding_sheet2/sliding_sheet2.dart';
 import '../../data/bean/user_info.dart';
+import '../../dialog/location_permission_dialog.dart';
+import '../../sdk/map/map_helper.dart';
+import '../../utils/permission_util.dart';
 
 @injectable
 class TrackController extends BaseController
@@ -33,6 +37,10 @@ class TrackController extends BaseController
 
   final Rxn<TrackDays> currentTrackDay = Rxn();
 
+  final RxDouble _sheetProgress = 0.0.obs;
+
+  double get sheetProgress => _sheetProgress.value;
+
   final mapPadding =
       MapPadding(left: 50.w, top: 100.w, right: 50.w, bottom: Get.height / 2);
 
@@ -136,11 +144,79 @@ class TrackController extends BaseController
   }
 
   void _clearSelectMapMarker() {
+    mapController.removeMarker(Constants.mineLocationId);
     mapController.removePolyline(Constants.traceSelectLineId);
     mapController.removeMarker(Constants.tracePopupId);
     mapController.removeMarker(Constants.traceErrorId);
   }
 
+  setSheetProgress(double progress) {
+    _sheetProgress.value = progress;
+  }
+
+  void onCurrentLocationClick() async {
+    //权限检查
+    bool isGranted = await PermissionUtil.checkLocationPermission();
+    if (!isGranted) {
+      LocationPermissionDialog.show(onNextStep: _requestLocationPermission);
+    } else {
+      _updateCurrentLocation();
+    }
+  }
+
+  void _updateCurrentLocation() {
+    var lastLocation = MapHelper.getLastLocation();
+    if (lastLocation == null) {
+      locationListener(MapLocation location) {
+        MapHelper.removeLocationListener(locationListener);
+        showMineLocationMarker(location);
+      }
+
+      MapHelper.addLocationListener(locationListener);
+    } else {
+      showMineLocationMarker(lastLocation);
+    }
+  }
+
+  void showMineLocationMarker(MapLocation location) {
+    _clearSelectMapMarker();
+    Marker mineMarker = Marker(
+        id: Constants.mineLocationId,
+        latitude: location.latitude,
+        longitude: location.longitude,
+        isSelected: false,
+        customAvatarUrl: accountRepository.mineUserInfo.value.avatar,
+        markerName: StringName.locationMine,
+        markerType: MarkerType.mine);
+    mapController.updateOrAddMarker(mineMarker);
+    animateCamera(latitude: location.latitude, longitude: location.longitude);
+  }
+
+  void animateCamera({required double? latitude, required double? longitude}) {
+    mapController.animateCamera(
+        CameraPosition(longitude: longitude, latitude: latitude, zoom: 18));
+  }
+
+  void _requestLocationPermission() async {
+    bool isGranted = await PermissionUtil.requestLocationPermission();
+    if (isGranted) {
+      _showLocationAlways();
+      _updateCurrentLocation();
+    }
+  }
+
+  void _showLocationAlways() async {
+    bool isGranted = await PermissionUtil.checkShowLocationAlways();
+    if (!isGranted) {
+      LocationAlwaysPermissionDialog.show(onNextStep: () async {
+        isGranted = await PermissionUtil.requestShowLocationAlways();
+        if (isGranted) {
+          _updateCurrentLocation();
+        }
+      });
+    }
+  }
+
   @override
   void onClose() {
     super.onClose();

+ 32 - 0
lib/module/track/track_page.dart

@@ -13,6 +13,7 @@ import 'package:location/resource/colors.gen.dart';
 import 'package:location/utils/common_expand.dart';
 import 'package:location/utils/common_style.dart';
 import 'package:sliding_sheet2/sliding_sheet2.dart';
+import '../../resource/assets.gen.dart';
 import '../../router/app_pages.dart';
 import '../../utils/fixed_size_tab_indicator.dart';
 import '../../widget/common_view.dart';
@@ -41,7 +42,11 @@ class TrackPage extends BasePage<TrackController> {
           ),
         ),
         buildBackBtnView(),
+        buildMapFunView(),
         SlidingSheet(
+          listener: (SheetState state) {
+            controller.setSheetProgress(state.progress);
+          },
           color: ColorName.white,
           controller: controller.sheetController,
           elevation: 10,
@@ -68,6 +73,33 @@ class TrackPage extends BasePage<TrackController> {
     );
   }
 
+  Widget buildMapFunView() {
+    return Obx(() {
+      return Positioned(
+        right: 0.w,
+        bottom: 110.w + controller.sheetProgress * 0.77.sh,
+        child: Column(
+          children: [
+            GestureDetector(
+              onTap: controller.onCurrentLocationClick,
+              child: Container(
+                  margin: EdgeInsets.only(right: 12.w),
+                  child: Opacity(
+                    opacity: controller.sheetProgress < 0.6
+                        ? 1.0
+                        : 1.0 -
+                            ((controller.sheetProgress - 0.6) / 0.4)
+                                .clamp(0.0, 1.0),
+                    child: Assets.images.iconMainRefreshMineLocation
+                        .image(width: 42.w, height: 42.w),
+                  )),
+            ),
+          ],
+        ),
+      );
+    });
+  }
+
   Widget buildBackBtnView() {
     return SafeArea(
       child: GestureDetector(

+ 2 - 2
plugins/map/lib/src/core/map_controller.dart

@@ -177,7 +177,7 @@ class MapController
 
   @override
   void removeMarker(String markerId) {
-    if (_isDisposed || markerId.isEmpty) return;
+    if (_isDisposed) return;
     final params = {
       'method': MapConstants.methodMarkerRemoveMarker,
       'args': {'markerId': markerId}
@@ -192,7 +192,7 @@ class MapController
 
   @override
   void removePolyline(String lineId) {
-    if (_isDisposed || lineId.isEmpty) return;
+    if (_isDisposed) return;
     final params = {
       'method': MapConstants.methodRemovePolyline,
       'args': {'lineId': lineId}

+ 1 - 4
plugins/map_amap_android/android/src/main/java/com/atmob/map_amap_android/overlays/marker/MarkersController.java

@@ -93,14 +93,11 @@ public class MarkersController implements MyMethodCallHandler, AMap.OnMarkerClic
             return;
         }
         String markerId = ParamUtil.getString(arguments, "markerId");
-        if (TextUtils.isEmpty(markerId)) {
-            result.error("-1", "removeMarker.markerId is empty", null);
-            return;
-        }
         Marker marker = currentMarkers.get(markerId);
         if (marker != null) {
             marker.remove();
             currentMarkers.remove(markerId);
+            LogUtil.i(TAG, "removeMarker===>成功删除marker:" + markerId);
         }
         result.success(null);
     }