-
Notifications
You must be signed in to change notification settings - Fork 86
Mapbox
Maxime edited this page Oct 18, 2017
·
1 revision
ClusterKit For Mapbox is available through CocoaPods. To install
it, simply add the following line to your Podfile
:
pod 'ClusterKit/Mapbox'
CKGridBasedAlgorithm *algorithm = [CKGridBasedAlgorithm new];
self.mapView.clusterManager.algorithm = algorithm;
self.mapView.dataSource = self;
self.mapView.clusterManager.annotations = annotations;
let algorithm = CKNonHierarchicalDistanceBasedAlgorithm()
mapView.clusterManager.algorithm = algorithm
mapView.clusterManager.annotations = annotations
- (void)mapView:(MGLMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
[mapView.clusterManager updateClustersIfNeeded];
}
- (void)mapView:(MGLMapView *)mapView didSelectAnnotation:(nonnull id<MGLAnnotation>)annotation {
CKCluster *cluster = (CKCluster *)annotation;
if (cluster.count > 1) {
UIEdgeInsets edgePadding = UIEdgeInsetsMake(40, 20, 44, 20);
MGLMapCamera *camera = [mapView cameraThatFitsCluster:cluster edgePadding:edgePadding];
[mapView setCamera:camera animated:YES];
}
}
func mapView(_ mapView: MGLMapView, regionDidChangeAnimated animated: Bool) {
mapView.clusterManager.updateClustersIfNeeded()
}
func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {
if let cluster = annotation as? CKCluster, cluster.count > 1 {
let edgePadding = UIEdgeInsetsMake(40, 20, 44, 20)
let camera = mapView.cameraThatFitsCluster(cluster, edgePadding: edgePadding)
mapView.setCamera(camera, animated: true)
}
}