cmyr / kingpin

A drop-in MapKit/MKAnnotation pin clustering library for MKMapView on iOS

Home Page:http://itsbonczek.github.com/kingpin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

kingpin

Build Status

A drop-in MKAnnotation clustering library for iOS

features

  • Uses a 2-d tree under the hood for maximum performance
  • No subclassing required, making the library easy to integrate with existing projects.

usage

Create an instance of a KPTreeController:

self.treeController = [[KPTreeController alloc] initWithMapView:self.mapView]

Set the controller's annotations:

[self.treeController setAnnotations:[self annotations]];

Handle the clusters:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    
    KPAnnotation *a = (KPAnnotation *)annotation;
    
    MKPinAnnotationView *v = 
      (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pin"];
    
    if(!v){
        v = [[MKPinAnnotationView alloc] initWithAnnotation:a reuseIdentifier:@"pin"];
    }
    
    v.pinColor = (a.annotations.count > 1 ? MKPinAnnotationColorPurple : MKPinAnnotationColorRed);
    
    return v;
    
}

Note: You can gain access to the cluster's annotations via -[KPAnnotation annotations].

Refresh visible annotations as needed:

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    [self.treeController refresh:self.animationSwitch.on];
}

This is typically done in -mapView:regionDidChangeAnimated:

versions

All versions are tagged accordingly

0.1.1

  • support for multiple tree controllers

0.1.2

  • support for 3D maps

demo

Check out the tester target in kingpin.xcodeproj

licence

Apache 2.0

About

A drop-in MapKit/MKAnnotation pin clustering library for MKMapView on iOS

http://itsbonczek.github.com/kingpin

License:Apache License 2.0