1

MKAnnotationViews documentation says

Managing Collisions Between Annotation Views

var collisionMode: MKAnnotationView.CollisionMode

The collision mode to use when interpreting the collision frame rectangle.

enum MKAnnotationView.CollisionMode

Constants indicating how to interpret the collision frame rectangle of an annotation view.

I'd like to debug some collision behaviour that I don't understand.

So how do I get the collision frame rectangle that is referenced in the MapKit documentation? I'll probably try to draw this rectangle for visual debugging.

How do I set the collision frame rectangle? Maybe not directly, but which of the many involved views determines this rectangle?

This is the only reference of this term that I found in MapKit

Edit

Is this collision frame rectangle only used to make clusters or is it also used to hide the cluster with a lower display priority?

I have two AnnotationViews visually drawn on top of each other. One has displayPriority = .required, one has displayPriority = .defaultHigh. One should disappear. But where are their collision frame rectangles? Do they really overlap?

Gerd Castan
  • 6,275
  • 3
  • 44
  • 89

1 Answers1

2

I found an explanation here. It says:
collisionMode: An MKAnnotationView.CollisionMode. Two annotation views with the same clusteringIdentifier will be replaced by a cluster annotation if the map is zoomed out so far that they collide.
But what constitutes a collision between two annotation views? To know that, we need a collision edge. It might be:
.rectangle: The edge is the view’s frame.
.circle: The edge is the largest circle inscribable in and centered within the view’s frame.

EDIT:

The docs say: The most efficient way to provide the content for an annotation view is to set its image property. The annotation view sizes itself automatically to the image you specify and draws that image for its contents. Additionally, there are other properties that may influence the frame property. So it is this automatically adjusted framethat determines the collision frame.

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116
  • I found the same reference before I asked this question. Which of the many views used by an AnnotationView is the one that is used? If it is the annotationView itself, what determines its frame? – Gerd Castan Apr 13 '19 at 19:26
  • Ah, I missed that. Thanks. This information is sufficient for me to debug. I set images for both and the images are drawn on top of each other. – Gerd Castan Apr 13 '19 at 19:42
  • Did my answer solve your problem? If so, pls accept it so that the question is closed. – Reinhard Männer Apr 15 '19 at 05:36
  • Yes, I was able to interpret the frames. (Still don't understand why Mapkit draws overlapping annotations in some edge cases - but that's a different question) – Gerd Castan Apr 15 '19 at 08:46
  • thanks for this @ReinhardMänner and guys. it really is increedibly unclear how to just set the frame size. if you just "set the frame" to say 0,0,100,100 in prepareForDisplay, that does *seem* to work. But who knows. – Fattie Jun 11 '21 at 16:17