From 83b9d5c682b21d88133f24da0f94dd56bd79e687 Mon Sep 17 00:00:00 2001 From: 单军华 Date: Thu, 19 Jul 2018 13:38:55 +0800 Subject: [PATCH] change --- screendisplay/screendisplay/Classes/检测/Controller/MonitoringMapViewController.m | 647 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 647 insertions(+), 0 deletions(-) diff --git "a/screendisplay/screendisplay/Classes/\346\243\200\346\265\213/Controller/MonitoringMapViewController.m" "b/screendisplay/screendisplay/Classes/\346\243\200\346\265\213/Controller/MonitoringMapViewController.m" new file mode 100644 index 0000000..d3e97bc --- /dev/null +++ "b/screendisplay/screendisplay/Classes/\346\243\200\346\265\213/Controller/MonitoringMapViewController.m" @@ -0,0 +1,647 @@ +// +// MonitoringMapViewController.m +// screendisplay +// +// Created by ��������� on 2018/7/5. +// Copyright �� 2018��� ���������. All rights reserved. +// + +#import "MonitoringMapViewController.h" +#import "MyAnimatedAnnotationView.h" +#import "DevicesService.h" +#import "DeviceModel.h" +#import "NSObject+CustomIndex.h" +#import "DetailDataViewController.h" +#import "AppDelegate.h" + +@interface MonitoringMapViewController () +{ + BMKPointAnnotation* pointAnnotation; + BMKPointAnnotation* animatedAnnotation; + BMKPointAnnotation* lockedScreenAnnotation; + UIView * popView; + BMKPinAnnotationView *annotationView; + BMKActionPaopaoView * pPaopaoView; + UILabel * titleLabel; + UILabel * addressLabel; + NSTimer * myTimer; // ������������������ + int hCurrentIndex; +} + +/** digest */ +@property (nonatomic, strong) DevicesService *deviceSevice; + +@end + +@implementation MonitoringMapViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view. + + // ������������������ + self.fd_interactivePopDisabled = YES; + + //[self setNavBarImg:@"map_top_bar_bk"]; + [self initMap]; + + [self getDevicesList:FALSE]; + + //���1���������������function��������� + myTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(updateDevices) userInfo:nil repeats:YES]; + hCurrentIndex = 0; + //[self addMapMark]; +} + +-(void) initMap +{ +#pragma mark baidumap init begin + //������ios7 + if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0)) + { + // self.edgesForExtendedLayout=UIRectEdgeNone; + self.navigationController.navigationBar.translucent = NO; + } + + self.view.backgroundColor = kUIColorFromRGB(0x0b2f76); + + UIImageView * viewBackground = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-AdaptedWidth(355))/2, NavBar_Height+AdaptedHeight(13), AdaptedWidth(355), AdaptedHeight(576))]; + viewBackground.image = [UIImage imageNamed:@"map_background"]; + [self.view addSubview:viewBackground]; + + //��������������� + _mapView = [[BMKMapView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-AdaptedWidth(350))/2, NavBar_Height+AdaptedHeight(16), AdaptedWidth(350), AdaptedHeight(570))]; + _mapView.showsUserLocation = YES;//������������������ + _mapView.showMapScaleBar=YES; + _mapView.mapType = BMKMapTypeStandard; + [self.view addSubview:_mapView]; + + _mapView.delegate = self; // ������������������������������������nil������������������������������ + + _geocodesearch = [[BMKGeoCodeSearch alloc]init]; + _coordinateXText = @"121.1379"; + _coordinateYText= @"31.466325"; + _cityText = @"������"; + _addrText = @"���������������������10���"; + [_mapView setZoomLevel:18]; //������������������ +#pragma mark baidumap init end +} + + +#pragma mark baidumap function begin + +-(void)viewWillAppear:(BOOL)animated { + [_mapView viewWillAppear]; + _mapView.delegate = self; // ������������������������������������nil������������������������������ + _geocodesearch.delegate = self; // ������������������������������������nil������������������������������ + if (myTimer == nil) + myTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(updateDevices) userInfo:nil repeats:YES]; + else + //��������������� + [myTimer setFireDate:[NSDate distantPast]]; +} + + +-(void)viewWillDisappear:(BOOL)animated { + [_mapView viewWillDisappear]; + _mapView.delegate = nil; // ���������������nil + _geocodesearch.delegate = nil; // ���������������nil + +} + +-(void)viewDidDisappear:(BOOL)animated +{ + [super viewDidDisappear:YES]; + + //��������������� + if(myTimer) + [myTimer setFireDate:[NSDate distantFuture]]; +} + +- (void)viewDidUnload { + [super viewDidUnload]; + // Release any retained subviews of the main view. + + +} + +- (void)dealloc { + if (_geocodesearch != nil) { + _geocodesearch = nil; + } + if (_mapView) { + _mapView = nil; + } +} + +- (void)onGetGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKGeoCodeSearchResult *)result errorCode:(BMKSearchErrorCode)error +{ + NSArray* array = [NSArray arrayWithArray:_mapView.annotations]; + [_mapView removeAnnotations:array]; + array = [NSArray arrayWithArray:_mapView.overlays]; + [_mapView removeOverlays:array]; + if (error == 0) { + BMKPointAnnotation* item = [[BMKPointAnnotation alloc]init]; + item.coordinate = result.location; + item.title = _addrText; + [_mapView addAnnotation:item]; + _mapView.centerCoordinate = result.location; + NSString* titleStr; + NSString* showmeg; + + titleStr = @"������������������"; + showmeg = [NSString stringWithFormat:@"������:%f,������:%f",item.coordinate.latitude,item.coordinate.longitude]; + + UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:titleStr message:showmeg delegate:self cancelButtonTitle:nil otherButtonTitles:@"������",nil]; + [myAlertView show]; + } +} + +-(void) onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeSearchResult *)result errorCode:(BMKSearchErrorCode)error +{ + NSArray* array = [NSArray arrayWithArray:_mapView.annotations]; + [_mapView removeAnnotations:array]; + array = [NSArray arrayWithArray:_mapView.overlays]; + [_mapView removeOverlays:array]; + if (error == 0) + { + BMKPointAnnotation* item = [[BMKPointAnnotation alloc]init]; + item.coordinate = result.location; + item.title = @"���������������������������"; + item.subtitle = [NSString stringWithFormat:@"������:%@",result.address]; + + [_mapView addAnnotation:item]; + _mapView.centerCoordinate = result.location; + //LOG_INFO(@"������������������"); + } +} + +// ������������������������������������ +-(void)onClickGeocode +{ + BMKGeoCodeSearchOption *geocodeSearchOption = [[BMKGeoCodeSearchOption alloc]init]; + geocodeSearchOption.city= _cityText; + geocodeSearchOption.address = _addrText; + BOOL flag = [_geocodesearch geoCode:geocodeSearchOption]; + if(flag) + { + NSLog(@"geo������������������"); + } + else + { + NSLog(@"geo������������������"); + } +} + +// ��������������������������������� +-(void)onClickReverseGeocode +{ + CLLocationCoordinate2D pt = (CLLocationCoordinate2D){0, 0}; + if (_coordinateXText != nil && _coordinateYText != nil) + { + pt = (CLLocationCoordinate2D){[_coordinateYText floatValue], [_coordinateXText floatValue]}; + } + + BMKReverseGeoCodeSearchOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeSearchOption alloc]init]; + reverseGeocodeSearchOption.location = pt; + reverseGeocodeSearchOption.isLatestAdmin = YES; + BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption]; + if(flag) + { + //[self addMapMark]; + NSLog(@"���geo������������������"); + } + else + { + NSLog(@"���geo������������������"); + } +} + +#pragma mark baidumap function end + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} +#pragma mark Annotation function + //������������ +-(void)addMapMark +{ + //[_mapView removeOverlays:_mapView.overlays]; + [_mapView removeAnnotations:_mapView.annotations]; + [self addPointAnnotation]; + //[self addAnimatedAnnotation]; + //[self addLockScreenAnnotation]; +} + +//������������ +-(void)addPointAnnotation +{ + for (int index = 0; index < self.deviceSevice.deviceViewModels.count; index++) + { + DeviceModel *pModel = [self.deviceSevice.deviceViewModels objectAtIndex:index]; + if(TWIsEmpty(pModel)) continue; + + BMKPointAnnotation * pPointAnno = [[BMKPointAnnotation alloc]init]; + CLLocationCoordinate2D coor; + coor.latitude = [pModel.latitude doubleValue]; + coor.longitude = [pModel.longitude doubleValue]; + pPointAnno.coordinate = coor; + pPointAnno.title = pModel.device_name; + pPointAnno.subtitle = pModel.address; + pPointAnno.customIndex = [NSNumber numberWithInt:index]; + [_mapView addAnnotation:pPointAnno]; + } +} + +//��������������������������������� +-(void)addLockScreenAnnotation +{ + if (lockedScreenAnnotation == nil) { + lockedScreenAnnotation = [[BMKPointAnnotation alloc]init]; + lockedScreenAnnotation.isLockedToScreen = YES; + lockedScreenAnnotation.screenPointToLock = CGPointMake(100, 100); + lockedScreenAnnotation.title = @"���������������������������"; + } + [_mapView addAnnotation:lockedScreenAnnotation]; +} + +// ������������Annotation +- (void)addAnimatedAnnotation { + if (animatedAnnotation == nil) { + animatedAnnotation = [[BMKPointAnnotation alloc]init]; + CLLocationCoordinate2D coor; + coor.latitude = 31.496381; + coor.longitude = 121.190792; + animatedAnnotation.coordinate = coor; + animatedAnnotation.title = @"������������Annotation"; + } + [_mapView addAnnotation:animatedAnnotation]; +} + +// ������anntation���������������View +- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation +{ + //������annotation + if (annotation == animatedAnnotation) + { + NSString *AnnotationViewID = @"AnimatedAnnotation"; + MyAnimatedAnnotationView *annotationView = nil; + if (annotationView == nil) { + annotationView = [[MyAnimatedAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID]; + } + NSMutableArray *images = [NSMutableArray array]; + for (int i = 1; i < 4; i++) { + UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"poi_%d.png", i]]; + [images addObject:image]; + } + annotationView.annotationImages = images; + return annotationView; + } + + //������annotation + if ([annotation isKindOfClass:[BMKPointAnnotation class]]) + { + NSString *AnnotationViewID = @"renameMark"; + BMKPinAnnotationView *annotationView = (BMKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID]; + if (annotationView == nil) + { + annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID]; + } + + if (annotation == lockedScreenAnnotation) + { + // ������������ + annotationView.pinColor = BMKPinAnnotationColorGreen; + // ��������������� + annotationView.draggable = NO; + } + else + { + NSString * imageName = @""; + DeviceModel *pModel = [self.deviceSevice.deviceViewModels objectAtIndex:[((BMKPointAnnotation*)annotation).customIndex intValue]]; + // 0 ������ 1 ������������ 2 ������������ 3 ������������ 4 ������ + switch ([pModel.state intValue]) { + case 0: + { + imageName = @"map_segment_normal"; + } + break; + case 1: + { + imageName = @"map_segment_one"; + } + break; + case 2: + { + imageName = @"map_segment_two"; + } + break; + case 3: + { + imageName = @"map_segment_three"; + } + break; + case 4: + { + imageName = @"map_segment_four"; + } + break; + default: + imageName = @"map_segment_four"; + break; + } + + + //������������������������ + annotationView.image = [UIImage imageNamed:imageName]; + annotationView.size = CGSizeMake(32, 32); + // ��������������� + annotationView.draggable = YES; + //[annotationView setSelected:YES]; + annotationView.annotation = annotation; + + // ������popView��������� + CGFloat hWidth = 180; + CGFloat hHight = 80; + if(popView == nil) + { + popView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, AdaptedWidth(hWidth), AdaptedHeight(hHight))]; + + // ���������������������button + UIButton * popViewBk = [[UIButton alloc] initWithFrame:CGRectMake(5, 0, AdaptedWidth(hWidth), AdaptedHeight(hHight))]; + [popViewBk setBackgroundImage:[UIImage imageNamed:@"map_Airbubbles"] forState:UIControlStateNormal]; + [popViewBk addTarget:self action:@selector(clickPopView) forControlEvents:UIControlEventTouchUpInside]; + [popView addSubview:popViewBk]; + + // ������������ + UIButton * coloseBtn = [[UIButton alloc]initWithFrame:CGRectMake(AdaptedWidth(hWidth-10-10), AdaptedHeight(10), AdaptedWidth(10), AdaptedHeight(10))]; + [coloseBtn setBackgroundImage:[UIImage imageNamed:@"map_close"] forState:UIControlStateNormal]; + [coloseBtn addTarget:self action:@selector(closePopView) forControlEvents:UIControlEventTouchUpInside]; + [popViewBk addSubview:coloseBtn]; + + // title + if(titleLabel==nil) + { + titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(AdaptedWidth(10), AdaptedHeight(10), AdaptedWidth(hWidth-20-10), AdaptedHeight(20))]; + + titleLabel.font = AdaptedFontSize(10); + titleLabel.textColor = kUIColorFromRGB(0xff7800); + titleLabel.textAlignment = NSTextAlignmentLeft; + [popViewBk addSubview:titleLabel]; + } + + // ������ + if(addressLabel==nil) + { + addressLabel = [[UILabel alloc]initWithFrame:CGRectMake(AdaptedWidth(10), AdaptedHeight(10+20+2), AdaptedWidth(hWidth-20-10), AdaptedHeight(20))]; + + addressLabel.textColor = kUIColorFromRGB(0x595959); + addressLabel.textAlignment = NSTextAlignmentLeft; + addressLabel.font = AdaptedFontSize(10); + [popViewBk addSubview:addressLabel]; + } + + pPaopaoView = [[BMKActionPaopaoView alloc]initWithCustomView:popView]; + pPaopaoView.frame = CGRectMake(0, 0, AdaptedWidth(hWidth), AdaptedHeight(hHight)); + } + + titleLabel.text = pModel.device_name; + addressLabel.text = pModel.address; + + ((BMKPinAnnotationView *)annotationView).paopaoView = pPaopaoView; + popView = ((BMKPinAnnotationView *)annotationView).paopaoView ; + } + + // ��������������������� + annotationView.animatesDrop = NO; + + return annotationView; + } + return nil; +} + +-(void)clickPopView +{ + DeviceModel* model = [self.deviceSevice.deviceViewModels objectAtIndex:hCurrentIndex]; + + if([model.state intValue] == 4) + { + // Make toast with a title + [self.navigationController.view makeToast:@"���������������������������������������������!" + duration:3.0 + position:CSToastPositionBottom + title:@"������������" + image:nil + style:nil + completion:nil]; + + //[MBProgressHUD showWarn:@"���������������������������������������������!" ToView:self.view]; + //[Global alertMessageEx:@"���������������������������������������������!" title:@"������������" okTtitle:nil cancelTitle:@"������" delegate:self]; + } + else + { + DetailDataViewController * page = [[DetailDataViewController alloc] init]; + //[self presentViewController:page animated:YES completion:nil]; + page.deviceModel = [self.deviceSevice.deviceViewModels objectAtIndex:hCurrentIndex]; + [UserDefault setObject:page.deviceModel.mac forKey:@"mac"]; + [UserDefault setObject:page.deviceModel.state forKey:@"state"]; + [UserDefault synchronize];//������synchronize���������������������������������,���������������NSUserDefaults������������������������������������ + [self.navigationController pushViewController:page animated:YES]; + NSLog(@"clickPopView"); + } +} + +-(void)closePopView +{ + [annotationView setSelected:NO]; + [popView setHidden:YES]; + NSLog(@"closePopView"); +} + +// ���������annotation view������������������������������������ +- (void)mapView:(BMKMapView *)mapView annotationViewForBubble:(BMKAnnotationView *)view; +{ + NSLog(@"paopaoclick"); +} +/** + *���������������annotation views��������������������� + *@param mapView ������View + *@param view ���������annotation views + */ +- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view; +{ + DeviceModel *pModel = [self.deviceSevice.deviceViewModels objectAtIndex:[((BMKPointAnnotation*)view.annotation).customIndex intValue]]; + titleLabel.text = pModel.device_name; + addressLabel.text = pModel.address; + hCurrentIndex = [((BMKPointAnnotation*)view.annotation).customIndex intValue]; + [popView setHidden:NO]; + NSLog(@"didSelectAnnotationView"); +} + + +#pragma mark custom function +- (DevicesService *)deviceSevice +{ + if(_deviceSevice == nil) { + _deviceSevice = [DevicesService new]; + } + return _deviceSevice; +} + +-(void)updateDevices +{ + [self getDevicesList:YES]; +} + +-(void)getDevicesList:(BOOL)bIsUpdate +{ + NSMutableDictionary *param = [[NSMutableDictionary alloc] init]; + [param setObject:[UserDefault stringForKey:@"organizationId"] forKey:@"organizationId"]; + + MBProgressHUD *HUD = nil; + if(!bIsUpdate) + { + // ������������������ + HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; + HUD.labelText = @"���������������..."; + // ��������������������������������� + HUD.removeFromSuperViewOnHide = YES; + // YES������������������������ + HUD.dimBackground = YES; + } + + TWWeak(self); + [self.deviceSevice getDeviceListWithParameters:param completion:^(NSString *desc, int code) { + if(!bIsUpdate) + HUD.hidden = YES; + + if(code == 1) + { + if(weakself.deviceSevice.deviceViewModels.count > 0) + { + if(!bIsUpdate) + { + DeviceModel * model = [weakself.deviceSevice.deviceViewModels objectAtIndex:0]; + if(!TWIsEmpty(model)) + { + _coordinateXText = model.longitude; + _coordinateYText = model.latitude; + [self onClickReverseGeocode]; + } + + dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0/*������������������*/ * NSEC_PER_SEC)); + dispatch_after(delayTime, dispatch_get_main_queue(), ^{ + [weakself addMapMark]; + }); + } + else + { + [weakself addMapMark]; + } + } + } + else + { + // Make toast with a title + if(!bIsUpdate) + { + [Global alertMessageEx:desc title:@"������������������" okTtitle:nil cancelTitle:@"OK" delegate:self]; + } +// [self.navigationController.view makeToast:@"���������������������������������������������!" +// duration:3.0 +// position:CSToastPositionBottom +// title:@"������������" +// image:nil +// style:nil +// completion:nil]; + } + }]; +} + +/* +#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. +} +*/ + +#pragma mark - LMJNavUIBaseViewControllerDataSource + +- (UIStatusBarStyle)navUIBaseViewControllerPreferStatusBarStyle:(LMJNavUIBaseViewController *)navUIBaseViewController +{ + return UIStatusBarStyleDefault; +} + +/**������������*/ +- (NSMutableAttributedString*)lmjNavigationBarTitle:(LMJNavigationBar *)navigationBar +{ + return [self changeTitle:@"������������" changeColor:[UIColor whiteColor]]; +} + +//������������ +//- (UIImage *)lmjNavigationBarBackgroundImage:(LMJNavigationBar *)navigationBar +//{ +// return [UIImage imageNamed:@"map_top_bar_bk"]; +//} + +/** ��������� */ +- (UIColor *)lmjNavigationBackgroundColor:(LMJNavigationBar *)navigationBar +{ + return kUIColorFromRGB(0x0b2f76); +} + +/** ������������������������ */ +- (BOOL)lmjNavigationIsHideBottomLine:(LMJNavigationBar *)navigationBar +{ + return YES; +} + +/** ������������������������ */ +- (UIImage *)lmjNavigationBarLeftButtonImage:(UIButton *)leftButton navigationBar:(LMJNavigationBar *)navigationBar +{ + return nil; + //return [UIImage imageNamed:@"map_back"]; +} +/** ������������������������ */ +- (UIImage *)lmjNavigationBarRightButtonImage:(UIButton *)rightButton navigationBar:(LMJNavigationBar *)navigationBar +{ + [rightButton setTitle:@"������������" forState: UIControlStateNormal]; + [rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + [rightButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted]; + rightButton.titleLabel.font = [UIFont systemFontOfSize:15]; + + rightButton.lmj_width = 80; + + return nil; +} + + + +#pragma mark - LMJNavUIBaseViewControllerDelegate +/** ������������������������ */ +-(void)leftButtonEvent:(UIButton *)sender navigationBar:(LMJNavigationBar *)navigationBar +{ + //[self onClickReverseGeocode]; + + //[self dismissViewControllerAnimated:YES completion:nil]; +} + + +/** ������������������������ */ +-(void)rightButtonEvent:(UIButton *)sender navigationBar:(LMJNavigationBar *)navigationBar +{ + [UserDefault setObject:@"0" forKey:@"isLogin"]; + [UserDefault setObject:nil forKey:@"user_id"]; + + [GetAppDelegate showLoginPage]; + + //[self addMapMark]; +} + + + +@end -- Gitblit v1.8.0