Giter Club home page Giter Club logo

fbannotationclustering's Introduction

FBAnnotationClustering

Version Platform

FBAnnotationClustering is an iOS library for clustering map notifications in an easy and performant way. Check out the blog post about it.

FBAnnotationClustering example

Usage

Create your clustering manager (and initialize with annotations or add annotations later):

self.clusteringManager = [[FBClusteringManager alloc] initWithAnnotations:arrayOfAnnotations];

Implement MKMapView delegate method mapView:regionDidChangeAnimated: to display annotations grouped in clusters on the map. An example of implementation:

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    [[NSOperationQueue new] addOperationWithBlock:^{
        double scale = self.mapView.bounds.size.width / self.mapView.visibleMapRect.size.width;
        NSArray *annotations = [self.clusteringManager clusteredAnnotationsWithinMapRect:mapView.visibleMapRect withZoomScale:scale];
        
        [self.clusteringManager displayAnnotations:annotations onMapView:mapView];
    }];
}

Important: Call the method mapView:regionDidChangeAnimated: whenever you want to refresh currently visible map rectangle by yourself (for example, if you added annotations to clusteringManager)

All clusters will have FBAnnotationCluster class, so when MKMapView delegate methods are called, you can check if current annotation is cluster by checking its class. For example:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{   
    if ([annotation isKindOfClass:[FBAnnotationCluster class]]) {
        FBAnnotationCluster *cluster = (FBAnnotationCluster *)annotation;
        NSLog(@"Annotation is cluster. Number of annotations in cluster: %lu", (unsigned long)cluster.annotations.count);
    } else {
		NSLog(@"Normal annotation.")
    }	
        
    ...
} 

To run the example project; clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS SDK 6
  • ARC

Installation

FBAnnotationClustering is available through CocoaPods, to install it simply add the following line to your Podfile:

pod "FBAnnotationClustering"

If you don't like Cocapods, you can add all files from FBAnnotationClustering directory to your project.

TODO

  • replace NSRecursiveLock with GCD serial queue

  • removeAnnotations: method

      /**
       Remove array of annotations from current annotation collection.
    
       @param annotations Custom annotation objects.
       */
      - (void)removeAnnotations:(NSArray *)annotations;
    

Author

Filip Beć, [email protected]

Maintained by Infinum

Infinum

Credits

FBAnnotationClustering is based on a blog post written by thoughtbot.

License

FBAnnotationClustering is available under the MIT license. See the LICENSE file for more info.

fbannotationclustering's People

Contributors

filipbec avatar humblehacker avatar javery avatar streeter avatar waterskier2007 avatar

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.