ADClusterMapView 1.5.0

ADClusterMapView 1.5.0

测试测试
语言语言 Obj-CObjective C
许可证 BSD
发布上次发布2016年11月

Patrick NolletAntoine KuhnEdouard Siegel 维护。



  • Applidium

ADClusterMapView - 带有聚类的MKMapView

ADClusterMapView是MKMapView的一个子类,可以显示和动画注释的集群。这在您需要在地图上显示多个注释时非常有用。概念和实现已在Applidium的网站上进行了描述。

快速入门

  1. 将ADClusterMapView文件夹的内容添加到您的iOS项目中
  2. 如果您尚未链接MapKit和CoreLocation框架,请链接它们
  3. 将您的MKMapView实例转换为ADClusterMapView的子类
  4. 通过调用 setAnnotations: 设置您的注释。请不要使用 addAnnotation:addAnnotations: 因为它们目前不支持。

ARC

如果您项目中没有使用ARC,请在Xcode中“构建设置 > 编译源”部分将该库文件的“-fobjc-arc”标志添加到文件中。

显示自定义MKAnnotationView实例

在您地图视图代理的 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实例

- (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;

未来工作

可以做一些改进。如果您想做出贡献,请随意发送拉取请求!

  • 添加对注释添加和移除的支持。
  • 添加对多个独立树的支持。
  • 还有更多吗?