Browse Source

fix trace add multiple marker issue

Groot 6 months ago
parent
commit
c6d42ed63c

+ 7 - 2
plugins/map_mapkit_ios/ios/Classes/MapView/ViewModel/MapViewModel.swift

@@ -63,8 +63,13 @@ class MapViewModel: NSObject, ObservableObject, MapCapability {
             result(paramsDecodeError)
             return
         }
-
-        self.markers = markers
+        // 使用字典优化查找性能
+        var markerDict = Dictionary(uniqueKeysWithValues: self.markers.map { ($0.id, $0) })
+        
+        markerDict.merge(Dictionary(uniqueKeysWithValues: markers.map { ($0.id, $0) }), uniquingKeysWith: { _, new in new })
+        
+        // 转换回数组
+        self.markers = Array(markerDict.values)
         result(nil)
     }