GithubHelp home page GithubHelp logo

kenychen / adclustermapview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from applidium/adclustermapview

0.0 2.0 0.0 1.53 MB

MKMapView with clustering

Home Page: http://applidium.github.io/ADClusterMapView/

License: Other

Ruby 1.36% Objective-C 98.64%

adclustermapview's Introduction

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?

adclustermapview's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.