I have created a screen recording video that visualises the issue, but I won't post the link here. Please feel free to ask.
Here’s my problem: I want to have a map that can switch between two states: either display a certain set of annotations as regular balloon shaped MKMarkerAnnotationView markers on a map, or display a different set of annotations as MKAnnotationView (either a custom subclass with some drawing or the default class with an image property; it doesn't make a difference).
So far so good, but one observation so far, that I don't understand: MKMarkerAnnotationView have the ability to auto-hide themselves when they get too close to another annotation view that has its collisionMode property not set to .none. How is this achieved? Does the MKMapView do this or is a MKMarkerAnnotationView aware of its surroundings (I don’t think so)? I can't find a way to create the same effect for any other kind of annotation view (MKAnnotationView), they would always overlap.
The bug: When my app is in said state where it displays annotations as MKAnnotationView (e.g. an image) and I switch back to display MKMarkerAnnotationView the map appears to retain ”ghost“ collision frames (or something) on the map of all MKAnnotationViews that are supposed to be removed. Those invisible collision areas will remain statically on the map view even when the user moves the map region around. This means, wherever there had been an MKAnnotationView on the screen just before the related annotations were removed, the now displayed MKMarkerAnnotationView markers will auto-hide when they come close to those areas even if there is nothing in the way.
To be clear, I call mapView.removeAnnotations(annotations) to remove all annotations and I double-checked in debugging that no more annotations are on the mapView, yet somewhere, somehow internally the mapView seems to retain the collision areas/frames in absolute point coordinates relative to the view on screen (not to earth coordinates) as they don't move with further map movement.
Is there anything else I have to do after calling mapView.removeAnnotations to properly clear the map view?
This happens in the simulator and on device with iOS 14.2, iOS 13, but it does not happen in the simulator with iOS 12.
Additionally, I can confirm that when I set the collisionMode property of the MKAnnotationViews to .none (supported in iOS 14 only), this issue does not occur (pretty much as expected).
The whole auto-hiding and collision stuff is a bit of a mystery to me and I could find little about it in the documentation. Any help would be much appreciated! Thanks!