3

我必须在我的应用程序中显示分类地标。当我通过ddPlacemarkWithPoint:它添加地标时。但是当我需要删除其中一些时,我遇到了问题。YMKClusterizedPlacemarkCollection只有clean删除所有标记的方法。如果我删除所有标记,然后将其中的一部分添加回来,我会在地图上看到闪烁的图钉。然后我尝试从mapView.map.mapObjectsvia中删除标记removeWithMapObject:。这会引发异常和崩溃。 *** Assertion failure in -[YMKMapObjectCollection removeWithMapObject:], ../../../../../../../../idl/ios/impl/YandexMapKit/YMKMapObjectCollection_Binding.mm:398

这是重现该问题的“空”应用程序:

    @IBOutlet var mapView: YMKMapView!

    var mapWindow: YMKMapWindow! {
        return mapView.mapWindow
    }
    var map: YMKMap! {
        return mapWindow.map
    }
    var placemarks = [YMKPlacemarkMapObject]()

    var placemarksCollection: YMKClusterizedPlacemarkCollection!

    override func viewDidLoad() {
        super.viewDidLoad()

        setupMap()
        addClusters()
//        addPointsOnMap()
        addPointsToCollection()
        DispatchQueue.main.asyncAfter(deadline: .now() + 3.5) {
            self.removePoints()
        }
    }

    func setupMap() {
        let cameraPosition = YMKCameraPosition(target: YMKPoint.moscow,
                                               zoom: 13,
                                               azimuth: 0,
                                               tilt: 0)
        map.isDebugInfoEnabled = true
        map.move(
            with: cameraPosition,
            animationType: YMKAnimation(type: .smooth, duration: 0.3),
            cameraCallback: nil)
    }

    func addClusters() {
        placemarksCollection = map.mapObjects.addClusterizedPlacemarkCollection(with: self)
    }

    func addPointsOnMap() {
        for _ in 0..<5 {
            let placemark = map.mapObjects.addPlacemark(with: YMKPoint(latitude: YMKPoint.moscow.latitude + Double(arc4random() % 10)/1000, longitude: YMKPoint.moscow.longitude + Double(arc4random() % 10)/1000))
            placemarks.append(placemark)
        }
    }

    func addPointsToCollection() {
        for _ in 0..<5 {
            let placemark = placemarksCollection.addPlacemark(with: YMKPoint(latitude: YMKPoint.moscow.latitude + Double(arc4random() % 10)/1000, longitude: YMKPoint.moscow.longitude + Double(arc4random() % 10)/1000))
            placemarks.append(placemark)
        }
        placemarksCollection.clusterPlacemarks(withClusterRadius: 60, minZoom: 10)
    }

    func removePoints() {
        if let placemark = placemarks.last {
            map.mapObjects.remove(with: placemark)
        }
    }
4

1 回答 1

0

自 4.0.0 版以来,添加了从集群中删除标记的可能性。
此外,Yandex 团队将包名称从 更改com.yandex.android:mapkitcom.yandex.android:maps.mobile.

于 2021-04-30T12:22:28.063 回答