• Stars
    star
    658
  • Rank 68,502 (Top 2 %)
  • Language
    Objective-C
  • License
    Other
  • Created about 12 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

MKMapView with clustering

ADClusterMapView - MKMapView with clustering

ADClusterMapView is a drop-in subclass of MKMapView that displays and animates clusters of annotations. This is very useful in cases where you have to display many annotations on the map. Concept and implementation were described on Applidium's website.

Quick start

  1. Add the content of the ADClusterMapView folder to your iOS project
  2. Link against the MapKit and CoreLocation frameworks if you don't already
  3. Turn your MKMapView instance into a subclass of ADClusterMapView
  4. Set your annotations by calling setAnnotations:. Do not use addAnnotation: or addAnnotations: as they are not supported yet.

ARC

If you are not using ARC in your project, add the -fobjc-arc flag to the files of the library in the Build Phases > Compile Sources section in Xcode.

Displaying custom MKAnnotationView instances

In the mapView:viewForAnnotation: and mapView:viewForClusterAnnotation: implementations of your map view's delegate, you are given an instance of ADClusterAnnotation. You can call [annotation originalAnnotations] to retrieve your original id<MKAnnotation> instances and customize your MKAnnotationView instance like you would do with Map Kit. This is especially useful in the case of a leaf annotation, whose originalAnnotations array obviously contains one and only one object.

Example code:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    MyAnnotationView * pinView = (MyAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"ADClusterableAnnotation"];
    if (!pinView) {
        pinView = [[[MyAnnotationView alloc] initWithAnnotation:annotation
                                                reuseIdentifier:@"ADClusterableAnnotation"]
                   autorelease];
    }
    MyModel * model = [annotation originalAnnotations][0];
    pinView.image = model.image;
    return pinView;
}

Optional delegate methods

We provide you with a few optional methods that you may want to add to your ADClusterMapViewDelegate implementation:

Setting the maximum number of clusters that you want to display at the same time

- (NSInteger)numberOfClustersInMapView:(ADClusterMapView *)mapView; // default: 32

Custom MKAnnotationView instance for clusters

- (MKAnnotationView *)mapView:(ADClusterMapView *)mapView viewForClusterAnnotation:(id <MKAnnotation>)annotation; // default: same as returned by mapView:viewForAnnotation:

Custom title for clusters

- (NSString *)clusterTitleForMapView:(ADClusterMapView *)mapView; // default : @"%d elements"

Set visibility for cluster annotation's subtitle

- (BOOL)shouldShowSubtitleForClusterAnnotationsInMapView:(ADClusterMapView *)mapView; // default: YES

Disminish outliers weight

- (double)clusterDiscriminationPowerForMapView:(ADClusterMapView *)mapView; // This parameter emphasize the discrimination of annotations which are far away from the center of mass. default: 1.0 (no discrimination applied)

Animation callback

- (void)clusterAnimationDidStopForMapView:(ADClusterMapView *)mapView;

Future Work

There are a couple of improvements that could be done. Feel free to send us pull requests if you want to contribute!

  • Add support for annotations addition and removal.
  • Add support for multiple independant trees
  • More?

More Repositories

1

ADTransitionController

UINavigationController with custom transitions
Objective-C
1,188
star
2

OverlayContainer

Non-intrusive iOS UI library to implement overlay based interfaces
Swift
1,149
star
3

ADLivelyTableView

Lively UITableView
Objective-C
743
star
4

Cracking-Siri

Files we used to reverse-engineer Siri
Ruby
575
star
5

Vim

Port of the Vim text editor to the iOS
C
533
star
6

PokemonGo_Android_RE

Java
511
star
7

ADLivelyCollectionView

Drop-in subclass of UICollectionView that lets you add custom animations to any UICollectionView
Objective-C
432
star
8

HeaderListView

Android ListView with sticky headers
Java
313
star
9

AudioModem

Transfer data using microphone/speaker on iOS devices
Objective-C
196
star
10

Shutterbug

Remote image loader with caching for Android
Java
99
star
11

ADZipURLProtocol

Open static website or access data from a zip archive
C
52
star
12

CandyCrushSolver

This is an Android project that helps you solve the game Candy Crush.
Java
47
star
13

zizou

Elo ranking managed through the messaging software Slack
Ruby
13
star
14

D3Android

D3Android is a new library to make charts on Android
Java
12
star
15

bike-share-prediction

Bike-share usage prediction API
Ruby
10
star
16

clarke

Ruby
8
star
17

Apex

An awesome visualization of what's hot on Apple's App Store
JavaScript
4
star
18

clarke-messenger

Ruby
2
star
19

cyril

Bot pairing Slack users connected to the general channel
Ruby
2
star
20

regex_field

Regex field for Rails FormHelper
JavaScript
1
star
21

spec_tracker

Spec tracker helps tracking tests that validate specification use cases
Ruby
1
star
22

clarke-slack

Ruby
1
star
23

gradle-dependencies-demo

1
star
24

adfastlane-gem

Fastlane wrapper to allow usage of distant Gemfile. Applidium internal usage
Ruby
1
star