I have to show clasterized placemarks in my app. When I add placemarks via ddPlacemarkWithPoint:
it works. But when I need to remove some of them I get a problem. YMKClusterizedPlacemarkCollection
has only clean
method which removes all marks. If I remove all marks and then add a part of them back I see the blinking pins on my map. Then I try to remove mark from mapView.map.mapObjects
via removeWithMapObject:
. And this fires an exception and a crash.
*** Assertion failure in -[YMKMapObjectCollection removeWithMapObject:], ../../../../../../../../idl/ios/impl/YandexMapKit/YMKMapObjectCollection_Binding.mm:398
Here's my "empty" app that reproduces the issue:
@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)
}
}