// // PBMapViewController.m // IphoneBIMe // // Created by zjf on 2020/5/12. // Copyright © 2020 ProBIM. All rights reserved. // #import "PBMapViewController.h" #import #import #import "PBProjectModel.h" #import "PBAnnotationView.h" #import "PBPointAnnotation.h" #import "PBProjectInfoView.h" @interface PBMapViewController () @property (nonatomic, strong) MAMapView *mapView; @property (nonatomic, strong) NSArray *dataList; @property (nonatomic, strong) PBProjectInfoView *projectInfoView; @end @implementation PBMapViewController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES animated:animated]; } - (void)viewDidLoad { [super viewDidLoad]; [self setupUI]; [self loadProjectList]; } - (void)addProjectAnnotation { for (PBProjectModel *obj in self.dataList) { PBPointAnnotation *pointAnnotation = [[PBPointAnnotation alloc] init]; pointAnnotation.coordinate = CLLocationCoordinate2DMake(obj.bog_latitude, obj.bog_longitude); pointAnnotation.projectModel = obj; [_mapView addAnnotation:pointAnnotation]; }; } - (void)loadProjectList { [YJProgressHUD showProgress:@"正在加载项目数据" inView:self.view]; [[PBNetworkTools sharedTools] getProjectListWithKeyword:@"" andIsPublic:@"" andSort:@"CreateDate desc" andSkip:@"0" andtake:@"999" andOnlyFavorite:@"" andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) { if(error) { NSLog(@"%@",error); [YJProgressHUD showMessage:@"加载项目列表失败" inView:self.view]; return; } NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str]; if (networkModel.Ret == 1) { [YJProgressHUD hide]; self.dataList = [NSArray yy_modelArrayWithClass:[PBProjectModel class] json:[networkModel.Data valueForKey:@"rows"]]; [self addProjectAnnotation]; }else { [YJProgressHUD showMessage:networkModel.Msg inView:self.view]; } }]; } - (void)setupUI { self.view.backgroundColor = [UIColor whiteColor]; [AMapServices sharedServices].enableHTTPS = YES; self.mapView = [[MAMapView alloc] initWithFrame:self.view.bounds]; [self.view addSubview:self.mapView]; self.mapView.delegate = self; self.mapView.zoomLevel = 3; [self.view addSubview:self.projectInfoView]; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.projectInfoView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = self.projectInfoView.bounds; maskLayer.path = maskPath.CGPath; self.projectInfoView.layer.mask = maskLayer; } - (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id)annotation { if ([annotation isKindOfClass:[MAPointAnnotation class]]) { static NSString *reuseIndetifier = @"annotationReuseIndetifier"; PBPointAnnotation *point = annotation; MAAnnotationView *annotationView = (MAAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier]; if (annotationView == nil) { annotationView = [[PBAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIndetifier]; } if (point.projectModel.bimcomposerid == nil) { annotationView.image = [UIImage imageNamed:@"blue"]; }else { annotationView.image = [UIImage imageNamed:@"red"]; } //设置中心点偏移,使得标注底部中间点成为经纬度对应点 annotationView.centerOffset = CGPointMake(0, -18); return annotationView; } return nil; } - (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view { NSArray * array = [NSArray arrayWithArray:_mapView.annotations]; for (int i=0; i