root rect
aodhol opened this issue · comments
In the sample code, the min and max coords are set using the sample data. In a real world scenario, how would you determine a suitable min and max coord?
Thanks!
@aodhol That depends on how much you know about the data coming in. If there's a known min / max for your data when creating the quadtree then use that, if the min / max is unknown to you then use the world coordinates from MKMapRectWorld (https://developer.apple.com/reference/mapkit/mkmaprectworld) to make sure all of the points added will be within the tree
@ateliercw Thank you very much, that's exactly what I used, wasn't sure of the performance implications! One other thing I was wondering about was how should I animate the clustering / de-clustering of annotations?
@aodhol there isn't really one right answer to that. As a starting point I'd recommend just trying having the removed annotations fade out, and the added annotations fade in. After that, it's a matter of what looks right and how complex of an animation you'd like to implement. With the added / removed list you could calculate which added annotations were included in removed annotations, and use that to generate a "dividing" annotation.
@ateliercw Sounds exciting! When you say removed annotations, do you mean the cluster in this particular case? As in determining which annotations were part of the cluster then animating those from the centroid of the cluster..and would this happen for example, in the updateAnnotations
method of your sample code say, or would it be something in the annotation itself or in one of the MapKit didAdd/RemoveAnnotations
delegate methods?
I got something rough working this way, but it's likely sub-optimal:
func updateAnnotations(inMapView mapView: MKMapView,
forMapRect root: MKMapRect) {
// ...
// Add the clusterCentroid origin to each singleCluster so that the associated view
// can be animated from that centroid to it's actual (eventual) position in (didAddAnnotationViews).
toRemove.forEach {
if let clusterAnnotation = $0 as? ClusterAnnotation {
toAdd.forEach {
if let singleAnnotation = $0 as? SingleAnnotation {
if clusterAnnotation.root.containsCoordinate(singleAnnotation.originCoordinate) {
singleAnnotation.clusterCentroid = clusterAnnotation.originCoordinate
}
}
}
}
}
}
@aodhol that looks like the right place to get started