zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//
//  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