GithubHelp home page GithubHelp logo

iosxpert / clusterkit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hulab/clusterkit

0.0 1.0 0.0 69.03 MB

An iOS map clustering framework targeting MapKit and Google Maps.

License: MIT License

Ruby 1.82% Objective-C 98.18%

clusterkit's Introduction

CI Status Version License Platform Carthage


ClusterKit is an elegant and efficiant clustering controller for maps. Its flexible architecture make it very customizable, you can use your own algorithm and even your own map provider.

Features

  • Native supports of MapKit and GoogleMaps.
  • Comes with 2 clustering algorithms, a Grid Based Algorithm and a Non Hierarchical Distance Based Algorithm.
  • Annotations are stored in a QuadTree for efficient region queries.
  • Cluster center can be switched to Centroid, Nearest Centroid, Bottom.
  • Written in Objective-C with full Swift interop support.

Apple Plan Google Maps

Installation

CocoaPods

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

pod 'ClusterKit'

Carthage

With Carthage, add the following to your Cartfile:

github "hulab/ClusterKit"

Maps

If you want to use ClusterKit with Mapkit or GoogleMaps, please follow the Installation Guide.

Usage

If you want to try it, simply run:

pod try ClusterKit

Or clone the repo and run pod install from the Examples directory first.

Provide the Google API Key in the AppDelegate in order to try it with GoogleMaps.

MapKit

Configure the cluster manager
CKNonHierarchicalDistanceBasedAlgorithm *algorithm = [CKNonHierarchicalDistanceBasedAlgorithm new];
self.mapView.clusterManager.algorithm = algorithm;
self.mapView.clusterManager.annotations = annotations;
Handle interactions in the map view's delegate
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    [mapView.clusterManager updateClustersIfNeeded];
}

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
    
    if ([view.annotation isKindOfClass:[CKCluster class]]) {
        CKCluster *cluster = view.annotation;
        
        if (cluster.count > 1) {
            [mapView showCluster:cluster animated:YES];
        }
    }
}

GoogleMaps

Configure the cluster manager
CKGridBasedAlgorithm *algorithm = [CKGridBasedAlgorithm new];
self.mapView.clusterManager.algorithm = algorithm;
self.mapView.dataSource = self;
self.mapView.clusterManager.annotations = annotations;
Handle interactions in the map view's delegate
- (void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position {
    [mapView.clusterManager updateClustersIfNeeded];
}

- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
    if (marker.cluster.count > 1) {
        GMSCameraUpdate *cameraUpdate = [GMSCameraUpdate fitCluster:marker.cluster];
        [mapView animateWithCameraUpdate:cameraUpdate];
        return YES;
    }
    return NO;
}
Provide cluster marker in datasource
- (GMSMarker *)mapView:(GMSMapView *)mapView markerForCluster:(CKCluster *)cluster {
    GMSMarker *marker = [GMSMarker markerWithPosition:cluster.coordinate];
    
    if(cluster.count > 1) {
        marker.icon = <#Cluster icon#>;
    } else {
        marker.icon = <#Annotation icon#>;
    }
    
    return marker;
}

Credits

Assets by Hugo des Gayets.

License

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

clusterkit's People

Contributors

maxep avatar

Watchers

James Cloos 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.