Giter VIP home page Giter VIP logo

Comments (3)

jacogasp avatar jacogasp commented on June 19, 2024

I think that a possible solution could be to initialize a QuadTree object that can be used as datasource for the mapView and that can provide, in another viewcontroller, the annotations near to the user location.
But I don't know how to implement this, the QuadTree class is not accessible and I think there's no way tell the mapView.clusterManager which tree its should use.

from clusterkit.

maxep avatar maxep commented on June 19, 2024

Hi @jacogasp

We need to balance the pros and cons of setting a tree to the cluster manager instead of an array of annotations.

CKQuadTree is private but you can access by importing it:

#import <ClusterKit/CKQuadTree.h>
import ClusterKit.CKQuadTree

from clusterkit.

jacogasp avatar jacogasp commented on June 19, 2024

I changed the target membership of CKQuadTree.h from Private to Public and added the following method to CKClusterManager.m

- (void)setQuadTree:(id<CKAnnotationTree>)quadTree {
    _tree = quadTree;
    _tree.delegate = self;
    [self updateClusters];
}

Then I can simply create a general purpose quadTree object as

var quadTree = CKQuadTree()
quadTree = CKQuadTree(annotations: annotationsArray)

and set the clusterManager of the mapView as

let algorithm = CKNonHierarchicalDistanceBasedAlgorithm()
algorithm.cellSize = 300
mapView.clusterManager.algorithm = algorithm
mapView.clusterManager.marginFactor = 1
mapView.clusterManager.setQuadTree(quadTree)

At this point it is possible to get the annotations within a certain MKMapRegion from any viewController as

 let annotationsInRect = quadTree.annotations(in: rect)

I think it's a very convenient way to access very quickly to the annotations stored into the quadTree object and reuse them for other purposes, preserving the benefits of the quadTree algorithm.
The performance seems to be pretty good.

from clusterkit.

Related Issues (20)

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.