HACClusterMapViewController 2.7

HACClusterMapViewController 2.7

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最后发布2017年4月

“litoarias”维护。




HACClusterMapViewController 类是用 Objective-C 编写的,便于在地图上有许多标记点时使用。这需要我们为任务构建一个超快速的数据结构。我们需要用 C 语言构建它以达到高性能。这个 2.2 版本是从原始作者的 2.0 版本派生而来的,增加了对代理和注释显示的更多灵活性,以及纠正了一些问题。

Preview

##需求和依赖项

  • iOS >= 7.0
  • 启用 ARC
  • CoreLocation 框架
  • MKMapKit 框架

##安装

####CocoaPods

pod 'HACClusterMapViewController'

####手动安装

  • HACQuadTree.hHACQuadTree.mHACManagerQuadTree.hHACManagerQuadTree.mHAClusterAnnotation.hHAClusterAnnotation.mHAClusterAnnotationView.hHAClusterAnnotationView.mHACMKMapView.hHACMKMapView.m 复制到您的项目中
  • 手动安装 HACClusterMapViewController

##用法

在您的 .h 文件中导入 HACMKMapView

#import "HACMKMapView.h"

地图 IBOutlet

为了使用 Interface Builder,请将您的 MKMapView 类设置为 HACMKMapView,并将您的地图设置为 IBOutlet,例如将名称设置给 IBOutlet 为 mapView

使用方法的代理

@interface MapViewController () <HACMKMapViewDelegate>
- (void)viewDidLoad {
    [super viewDidLoad];
    self.mapView.mapDelegate = self;
}

创建树结构

使用很简单,您必须在循环中创建以下结构。

 NSArray *data = @[
                      @{kLatitude:@48.47352, kLongitude:@3.87426,  kTitle : @"Title 1", kSubtitle : @"",            kIndex : @0},
                      @{kLatitude:@52.59758, kLongitude:@-1.93061, kTitle : @"Title 2", kSubtitle : @"Subtitle 2",  kIndex : @1},
                      @{kLatitude:@48.41370, kLongitude:@3.43531,  kTitle : @"Title 3", kSubtitle : @"Subtitle 3",  kIndex : @2},
                      @{kLatitude:@48.31921, kLongitude:@18.10184, kTitle : @"Title 4", kSubtitle : @"Subtitle 4",  kIndex : @3},
                      @{kLatitude:@47.84302, kLongitude:@22.81101, kTitle : @"Title 5", kSubtitle : @"Subtitle 5",  kIndex : @4},
                      @{kLatitude:@60.88622, kLongitude:@26.83792, kTitle : @"Title 6", kSubtitle : @""          ,  kIndex : @5}
                      ];
                      

发送构建

最后一步是将驱动程序的父级调用并传递数组作为参数以启动该过程。

 [self.mapView.coordinateQuadTree buildTreeWithArray:data];

代理方法

使用代理方法,我们可以设置注释的自定义图像或知道要引用的对象的索引。

-(void)viewForAnnotationView:(HAClusterAnnotationView *)annotationView annotation:(HAClusterAnnotation *)annotation{
    if (annotation.index % 2 == 0) {
        annotationView.image = [UIImage imageNamed:@"pin_museum"];
    }else{
        annotationView.image = [UIImage imageNamed:@"pin_coffee"];
    }
}

-(void)didSelectAnnotationView:(HAClusterAnnotation *)annotation{
    NSLog(@"You ara select annotation index %ld", (long)annotation.index);
}

自定义

编程方式

    self.mapView.backgroundAnnotation = [UIColor redColor];
    self.mapView.borderAnnotation = [UIColor whiteColor];
    self.mapView.textAnnotation = [UIColor whiteColor];
    self.mapView.compassFrame = CGRectMake(10, 10, 25, 25);
    self.mapView.legalFrame = CGRectMake(CGRectGetWidth([UIScreen mainScreen].bounds)-50, CGRectGetHeight([UIScreen mainScreen].bounds)-50, 50, 50);

界面构建器

Preview

享受 :D

贡献

  1. 分叉它( https://github.com/[my-github-username]/HACClusterMapViewController/fork
  2. 创建您的功能分支(git checkout -b my-new-feature
  3. 提交您的更改(git commit -am '添加某些功能'
  4. 推送至分支(git push origin my-new-feature
  5. 创建新的拉取请求