Rightpoint / BentoMap

Map Clustering for Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Associating a QuadTreeNode with it's parent

aodhol opened this issue · comments

Is there a way to associate a QuadTreeNode with an optional parent or 'parent' coordinate to allow that parent / coordinate to be retrieved later upon de-clustering?

i.e. associating a node with the cluster that it's contained in...

@aodhol Not in the current implementation of the library.

Assuming this is still on the subject of attempting to animate clusters breaking into individual units, it may be worth investigating creating the annotation on the cluster annotation view, with a flag for splitting on removal (like the flag on MKPinAnnotationView for animating drop) that causes the cluster to "split" into the child annotations on removal. The actual child annotations could fade in with a delay to make them appear to be animating alongside the cluster view.

@ateliercw Thanks for the response! The trouble is, there's no way of telling beforehand when an annotation view will be removed. Would you suggest getting the view for an annotation that is about to be removed and manually invoking such an animation?

@aodhol in the demo app, I would probably insert code somewhere around here:

    func updateAnnotations(inMapView mapView: MKMapView,
                                     forMapRect root: MKMapRect) {
        guard !mapView.frame.isEmpty && !MKMapRectIsEmpty(root) else {
            mapView.removeAnnotations(mapView.annotations)
            return
        }
        let zoomScale = Double(mapView.frame.width) / root.size.width
        let clusterResults = mapData.clusteredDataWithinMapRect(root,
                                                                zoomScale: zoomScale,
                                                                cellSize: Double(MapKitViewController.cellSize))
        let newAnnotations = clusterResults.map(BaseAnnotation.makeAnnotation)

        let oldAnnotations = mapView.annotations.flatMap({ $0 as? BaseAnnotation })

        let toRemove = oldAnnotations.filter { annotation in
            return !newAnnotations.contains { newAnnotation in
                return newAnnotation == annotation
            }
        }

        // TODO: insert code to trigger an animation on any clusters that are removed

        mapView.removeAnnotations(toRemove)

        let toAdd = newAnnotations.filter { annotation in
            return !oldAnnotations.contains { oldAnnotation in
                return oldAnnotation == annotation
            }
        }

        mapView.addAnnotations(toAdd)
    }

I'm not sure if that's the right solution / place to be doing it, but it's where I would start.