测试测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | BSD |
发布上次发布 | 2016年11月 |
由 Patrick Nollet、Antoine Kuhn、Edouard Siegel 维护。
ADClusterMapView是MKMapView的一个子类,可以显示和动画注释的集群。这在您需要在地图上显示多个注释时非常有用。概念和实现已在Applidium的网站上进行了描述。
setAnnotations:
设置您的注释。请不要使用 addAnnotation:
或 addAnnotations:
因为它们目前不支持。如果您项目中没有使用ARC,请在Xcode中“构建设置 > 编译源”部分将该库文件的“-fobjc-arc”标志添加到文件中。
在您地图视图代理的 mapView:viewForAnnotation:
和 mapView:viewForClusterAnnotation:
实现中,您将获得一个ADClusterAnnotation实例。您可以通过调用 [annotation originalAnnotations]
来检索您的原始 id<MKAnnotation>
实例,并自定义您的 MKAnnotationView
实例,就像您使用MapKit那样。这在处理具有明显只包含单个对象的 leaf 注释时,特别有用。
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
MyAnnotationView * pinView = (MyAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"ADClusterableAnnotation"];
if (!pinView) {
pinView = [[[MyAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"ADClusterableAnnotation"]
autorelease];
}
MyModel * model = [annotation originalAnnotations][0];
pinView.image = model.image;
return pinView;
}
我们为您提供了几个可选方法,您可以将它们添加到您的 ADClusterMapViewDelegate
实现中
- (NSInteger)numberOfClustersInMapView:(ADClusterMapView *)mapView; // default: 32
- (MKAnnotationView *)mapView:(ADClusterMapView *)mapView viewForClusterAnnotation:(id <MKAnnotation>)annotation; // default: same as returned by mapView:viewForAnnotation:
- (NSString *)clusterTitleForMapView:(ADClusterMapView *)mapView; // default : @"%d elements"
- (BOOL)shouldShowSubtitleForClusterAnnotationsInMapView:(ADClusterMapView *)mapView; // default: YES
- (double)clusterDiscriminationPowerForMapView:(ADClusterMapView *)mapView; // This parameter emphasize the discrimination of annotations which are far away from the center of mass. default: 1.0 (no discrimination applied)
- (void)clusterAnimationDidStopForMapView:(ADClusterMapView *)mapView;
可以做一些改进。如果您想做出贡献,请随意发送拉取请求!