Groot 6 kuukautta sitten
vanhempi
commit
52c0c935c4

+ 3 - 3
plugins/map_mapkit_ios/ios/Classes/MapView/MapViewController.swift

@@ -22,6 +22,7 @@ class MapViewController: UIViewController {
     init(viewModel: MapViewModel) {
         self.viewModel = viewModel
         super.init(nibName: nil, bundle: nil)
+        mapView.showsUserLocation = false
     }
 
     override func viewDidLoad() {
@@ -44,12 +45,11 @@ class MapViewController: UIViewController {
 
     private func setupMap() {
         mapView.delegate = self
-        mapView.showsUserLocation = true
-        mapView.setUserTrackingMode(.follow, animated: true)
+        mapView.showsUserLocation = false
+        mapView.mapType = .mutedStandard
     }
     
     private func bindViewModel() {
-        // 监听区域变化并更新地图
         viewModel.$currentRegion
             .compactMap { $0 }
             .receive(on: DispatchQueue.main)

+ 2 - 0
plugins/map_mapkit_ios/ios/Classes/MapView/Model/Constans.swift

@@ -11,4 +11,6 @@ struct MapKitConstans {
     static let methodChannelName: String = "com.atmob.flutter_map/map_view_"
     
     static let mapViewId: String = "com.atmob.flutter.map"
+
+    static let userMarkerId: String = "com.atmob.flutter.user_marker"
 }

+ 2 - 4
plugins/map_mapkit_ios/ios/Classes/MapView/Model/MapProtocol.swift

@@ -17,8 +17,6 @@ protocol MapCapability {
     
     var currentRegion: MKCoordinateRegion? { get set }
 
-    var userLocation: CLLocationCoordinate2D? { get set }
-
     var markers: [ATMapMarker] { get set }
 
     var polylines: [ATMapPolyline] { get set }
@@ -38,7 +36,7 @@ protocol MapCapability {
     func handleMapClearMarkers(result: @escaping FlutterResult)
     
     // 处理地图替换所有Marker
-    func handleMapReplaceAllMarkers(args: [String: Any]?, result: @escaping FlutterResult)
+    func handleMapReplaceAllMarkers(args: [[String: Any]]?, result: @escaping FlutterResult)
     
     // 处理Marker点击事件
     func handleMarkerTap(marker: inout ATMapMarker)
@@ -63,7 +61,7 @@ extension MapCapability {
         case .methodMapClear:
             handleMapClearMarkers(result: result)
         case .methodReplaceAllMarkers:
-            handleMapReplaceAllMarkers(args: call.arguments as? [String: Any], result: result)
+            handleMapReplaceAllMarkers(args: call.arguments as? [[String: Any]], result: result)
         case .methodAddPolyline:
             handleMapAddPolyline(args: call.arguments as? [String: Any], result: result)
         default:

+ 16 - 0
plugins/map_mapkit_ios/ios/Classes/MapView/Model/Models.swift

@@ -86,6 +86,22 @@ class ATMapMarker: NSObject, Codable {
     var isSelected: Bool
     var markerType: any MapMarkerSupportType
 
+    init(id: String, markerName: String?, location: CLLocationCoordinate2D, markerType: any MapMarkerSupportType, isSelected: Bool = false) {
+        self.id = id
+        self.markerName = markerName
+        self.latitude = location.latitude
+        self.longitude = location.longitude
+        self.markerType = markerType
+        self.isSelected = isSelected
+    }
+    
+    func update(coordinate: CLLocationCoordinate2D, name: String? = nil, isSelect: Bool) {
+        self.latitude = coordinate.latitude
+        self.longitude = coordinate.longitude
+        self.markerName = name
+        self.isSelected = isSelect
+    }
+
     enum CodingKeys: String, CodingKey {
         case id, markerName, latitude, longitude, isSelected, markerType
     }

+ 3 - 16
plugins/map_mapkit_ios/ios/Classes/MapView/ViewModel/MapViewModel.swift

@@ -12,14 +12,6 @@ import CoreLocation
 import SwiftUI
 import Combine
 
-private let coordinates: [CLLocationCoordinate2D] = [
-    CLLocationCoordinate2D(latitude: 39.90333, longitude: 116.39167), // 北京
-    CLLocationCoordinate2D(latitude: 31.23170, longitude: 121.47264), // 上海
-    CLLocationCoordinate2D(latitude: 22.54554, longitude: 114.05786), // 深圳
-    CLLocationCoordinate2D(latitude: 23.12911, longitude: 113.26437), // 广州
-    CLLocationCoordinate2D(latitude: 30.59276, longitude: 114.30525), // 武汉
-]
-
 class MapViewModel: NSObject, ObservableObject, MapCapability {
 
     var paramsDecodeError: FlutterError? = FlutterError(code: "InvalidArguments", message: "Invalid arguments", details: nil)
@@ -28,9 +20,6 @@ class MapViewModel: NSObject, ObservableObject, MapCapability {
 
     @Published var currentRegion: MKCoordinateRegion?
     
-    // 记录用户位置
-    @Published var userLocation: CLLocationCoordinate2D?
-
     // 地图Marker
     @Published var markers: [ATMapMarker] = []
     
@@ -80,18 +69,16 @@ class MapViewModel: NSObject, ObservableObject, MapCapability {
     }
 
     // 处理地图替换所有Marker
-    func handleMapReplaceAllMarkers(args: [String: Any]?, result: @escaping FlutterResult) {
+    func handleMapReplaceAllMarkers(args: [[String: Any]]?, result: @escaping FlutterResult) {
         defer {
             result(nil)
         }
-        guard let args = args, let markers = args["markers"] as? [[String: Any]] else {
+        guard let args = args, let markers = [ATMapMarker].fromJson(json: args) else {
             result(paramsDecodeError)
             return
         }
 
-        let mapMarkers = markers.compactMap({ ATMapMarker.fromJson(json: $0) })
-
-        self.markers = mapMarkers
+        self.markers = markers
     }
 
     // 处理Marker点击事件