Giter Club home page Giter Club logo

clustermapview's Introduction

ClusterMapView

An MKMapView subclass with clustering. Inspired by ADClusterMapView.

Features

  • Swift implementation
  • Principal Components Analysis algorithm
  • Full tree's depth on the map view
  • Animations

Tradeoffs

  • Annotation encapsulation: for performance reasons, each annotation is encapsulated in a Node to keep track of its children and parent. The original annotation can be retrieved in the node's annotation property.
  • Since the goal is to display all the tree (current depth) on the map, performance is slightly reduced, but sufficient for most use cases.

Requirements

  • iOS 8.0+
  • Swift 3.0+

Installation

CocoaPods

platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'ClusterMapView'
end

Usage

  1. Replace your MKMapView instance by a ClusterMapView instance.

  2. Add annotations using setAnnotations.

Annotation Views

As annotations are now encapsulated in nodes, you can observe each Node's type property to adjust annotation views accordingly.

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    if let node = annotation as? Node {
        var pin: MKPinAnnotationView!
        if let dequeued = mapView.dequeueReusableAnnotationView(withIdentifier: "pin") as? MKPinAnnotationView {
            pin = dequeued
            pin.annotation = node
        } else {
            pin = MKPinAnnotationView(annotation: node, reuseIdentifier: "pin")
        }
        switch node.type {
        case .leaf:
            pin.pinTintColor = .green
        case .node:
            pin.pinTintColor = .blue
        case .root:
            pin.pinTintColor = .red
        }
        return pin
    }
    return nil
}

MKMapViewDelegate

ClusterMapView adds additional methods on MKMapViewDelegate.

Customize the maximum number of nodes that you want to see on your map:

var numberOfVisibleNodes: Int { get } // default 32

Customize the animation duration:

var animationDuration: Double { get } // default 0.4

Events:

func mapViewDidFinishClustering(_ mapView: MKMapView)
    
func mapViewDidFinishAnimating(_ mapView: MKMapView)

clustermapview's People

Watchers

James Cloos avatar Antoine Dauguet 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.