// // LinPullTopViewController.m // LINPullTableView // // Created by earnestLin on 2019/1/16. // Copyright © 2019年 earnestLin. All rights reserved. // #import "LinPullTopViewController.h" #import #import #import "PBProjectModel.h" #import "PBAnnotationView.h" #import "PBPointAnnotation.h" @interface LinPullTopViewController () @property (nonatomic, strong) UIButton *leftBackButton; @property (nonatomic, strong) MAMapView *mapView; @property (nonatomic, strong) NSArray *dataList; @end @implementation LinPullTopViewController - (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]; } }]; } #pragma mark - setupUI - (void)setupUI { // self.view.backgroundColor = [UIColor whiteColor]; // UIImageView *imgView = [[UIImageView alloc] initWithFrame:self.view.bounds]; // imgView.image = [UIImage imageNamed:@"topviewBg"]; // [self.view addSubview:imgView]; // // self.leftBackButton = [[UIButton alloc] init]; // self.leftBackButton.imageView.contentMode = UIViewContentModeScaleAspectFill; // [self.leftBackButton setImage:[UIImage imageNamed:@"icon_return"] // forState:UIControlStateNormal]; // // [self.view addSubview:self.leftBackButton]; // [self.leftBackButton mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(self.view).offset(0); // make.top.equalTo(self.view).offset(20); // make.height.width.mas_equalTo(60); // }]; // // [self.leftBackButton addTarget:self // action:@selector(leftBackButtonAction:) // forControlEvents:UIControlEventTouchUpInside]; // // [AMapServices sharedServices].enableHTTPS = YES; self.mapView = [[MAMapView alloc] initWithFrame:self.view.bounds]; self.mapView.delegate = self; self.mapView.zoomLevel = 3; //3 ~ 9 self.mapView.showsCompass = NO; self.mapView.centerCoordinate = CLLocationCoordinate2DMake(23.901512367, 106.631821404); [self.view addSubview:self.mapView]; UITapGestureRecognizer *mTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPress:)]; mTap.delegate = self; [self.mapView addGestureRecognizer:mTap]; } - (void)tapPress:(UIGestureRecognizer*)gestureRecognizer { // CGPoint touchPoint = [gestureRecognizer locationInView:_mapView];//这里touchPoint是点击的某点在地图控件中的位置 // CLLocationCoordinate2D secondLocation = [_mapView convertPoint:touchPoint toCoordinateFromView:_mapView];//这里touchMapCoordinate就是该点的经纬度了 // NSLog(@"%f=======%f",secondLocation.latitude,secondLocation.longitude); if (self.ShutDetailsBlock) { self.ShutDetailsBlock(); } } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; } #pragma mark - event response //- (void) leftBackButtonAction:(UIButton *)sender //{ // [self.navigationController popViewControllerAnimated:YES]; //} - (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.isFavorite) { annotationView.image = [UIImage imageNamed:@"red"]; }else { annotationView.image = [UIImage imageNamed:@"blue"]; } //设置中心点偏移,使得标注底部中间点成为经纬度对应点 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