//
|
// PBMapViewController.m
|
// IphoneBIMe
|
//
|
// Created by zjf on 2020/5/12.
|
// Copyright © 2020 ProBIM. All rights reserved.
|
//
|
|
#import "PBMapViewController.h"
|
#import <MAMapKit/MAMapKit.h>
|
#import <AMapFoundationKit/AMapFoundationKit.h>
|
#import "PBProjectModel.h"
|
#import "PBAnnotationView.h"
|
#import "PBPointAnnotation.h"
|
#import "PBProjectInfoView.h"
|
|
@interface PBMapViewController ()<MAMapViewDelegate>
|
@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<MAAnnotation>)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<array.count; i++) {
|
PBPointAnnotation *pointAnnotation = array[i];
|
if (view.annotation.coordinate.latitude == pointAnnotation.coordinate.latitude) {
|
NSLog(@"%@",pointAnnotation.projectModel.fullname);
|
// [PBKeyWindow addSubview:self.projectInfoView];
|
// self.projectInfoView.projectModel = pointAnnotation.projectModel;
|
// [self.projectInfoView show];
|
[self show];
|
}
|
}
|
}
|
//- (PBProjectInfoView *)projectInfoView {
|
// if (_projectInfoView == nil) {
|
// _projectInfoView = [[PBProjectInfoView alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
// CGFloat height;
|
// if (IS_IPHONE_X) {
|
// height = 192.f + 34.f;
|
// }else {
|
// height = 192.f;
|
// }
|
// _projectInfoView.visualViewHeight = height;
|
// }
|
// return _projectInfoView;
|
//}
|
|
- (PBProjectInfoView *)projectInfoView {
|
if (_projectInfoView == nil) {
|
CGFloat height;
|
if (IS_IPHONE_X) {
|
height = 192.f + 34.f;
|
}else {
|
height = 192.f;
|
}
|
_projectInfoView = [[PBProjectInfoView alloc] initWithFrame:CGRectMake(0, PBScreenHeight, PBScreenWidth, height)];
|
}
|
return _projectInfoView;
|
}
|
- (void)hidden {
|
[UIView animateWithDuration:0.3 animations:^{
|
// self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0];
|
self.projectInfoView.y = PBScreenHeight;
|
}completion:^(BOOL finished) {
|
for (UIView *cover in PBKeyWindow.subviews) {
|
if ([cover isKindOfClass:[PBProjectInfoView class]]) {
|
[cover removeFromSuperview];
|
}
|
}
|
}];
|
}
|
- (void)show {
|
[UIView animateWithDuration:0.3 animations:^{
|
// self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
|
CGFloat height;
|
if (IS_IPHONE_X) {
|
height = 192.f + 34.f;
|
}else {
|
height = 192.f;
|
}
|
self.projectInfoView.y = PBScreenHeight - height;
|
}];
|
}
|
/*
|
#pragma mark - Navigation
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
// Get the new view controller using [segue destinationViewController].
|
// Pass the selected object to the new view controller.
|
}
|
*/
|
|
@end
|