3

I'm working on a map with more than 5000 pins. Everytime I change the region I add or remove annotationViews based on how much zoom there is.

The only problem is this (extreme test):

Callout being eaten alive

When there is little more space between the pins the callout moves ontop, but often the red pins is ontop.
I'm only using basic MKPinAnnotationView. No custom callout. I did try implementing the Z-ordering-category by Aaron Z-ordering of MKAnnotationViews but didn't seems to help.

EDIT:

I haven't solved it yet, but I do have some thoughts.

MapKit is poorly written. MapView has the responsibility to order views so at least the selected one stays on top.

Maybe it's too many annotations for mapView to handle.

HOW TO REPLICATE

just add 5000 annotations.

-(void)addAnnotations
{
   NSMutableArray *annotations = [NSMutableArray array];

   for(int i=0;i<5000;i++) {
       CGFloat latDelta = rand()*0.125/RAND_MAX - 0.02;
       CGFloat lonDelta = rand()*0.130/RAND_MAX - 0.08;

       CGFloat lat = 59.189358;
       CGFloat lng = 18.267839;

       CLLocationCoordinate2D newCoord = {lat+latDelta, lng+lonDelta};

       DTSAnnotation *annotation = [DTSAnnotation annotationWithCoord:newCoord];

       [annotation setTitle:@"."];

       [annotations addObject:annotation];
   }
   [[self mapView]addAnnotations:annotations];
}
Community
  • 1
  • 1
Toydor
  • 2,277
  • 4
  • 30
  • 48
  • 1
    A hacky way to fix it is adding mapView:didSelectAnnotationView: with a call to [view.superview bringSubviewToFront:view]; and push the annotation view back in mapView:viewForAnnotation: when you add it. You should cluster those pins, it becomes hard to chose one. – Jano Jan 23 '13 at 21:25

1 Answers1

3

You can fix this by setting the zPosition for the view in the didSelect and didDselect map view delegate methods:

public func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!)
    {
        view.layer.zPosition = 0
    }

    public func mapView(mapView: MKMapView!, didDeselectAnnotationView view: MKAnnotationView!)
    {
        view.layer.zPosition = -1
    }
valheru
  • 2,552
  • 3
  • 20
  • 40