You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

816 lines
29 KiB

//
// MapViewController.m
// watch
//
// Created by xTT on 2017/7/3.
// Copyright © 2017年 xTT. All rights reserved.
//
#import "MapViewController.h"
#import "UIViewExt.h"
#import "MyMQTT.h"
#import "CustomAnnotationView.h"
#import "CLLocation+YCLocation.h"
#import "UserAnnotationView.h"
#import "SwitchDeviceView.h"
#import "MarkViewController.h"
#import "MapReviseViewController.h"
#import "CommonTableView.h"
#import "MapBtnTableViewCell.h"
//高德SDK
#import <AMapFoundationKit/AMapFoundationKit.h>
#import <AMapSearchKit/AMapSearchKit.h>
#import <MAMapKit/MAMapKit.h>
#import "SLMarqueeControl.h"
//默认的定位位置 北京
#define DefineLocate CLLocationCoordinate2DMake(39.9086828351,116.3980865479)
@interface MapViewController ()<CLLocationManagerDelegate,MKMapViewDelegate,AMapSearchDelegate>
@property (strong, nonatomic) CLLocationManager *locationManager;
@property (strong, nonatomic) Locate *curLocate;// 设备当前的 位置
@property (strong, nonatomic) CLLocation *userLocate;// 用户当前的 位置
@property (strong, nonatomic) MKPointAnnotation *curPointAnnotation; //设备 View
@property (strong, nonatomic) MKPointAnnotation *userPointAnnotation; //用户 View
@property (strong, nonatomic) UITapGestureRecognizer *titleViewTap;
@property (strong, nonatomic) UIButton *downBtn;
@property (strong, nonatomic) UILabel *titleLabel;
@property (assign, nonatomic) BOOL isLocating; // 正在定位的标识
// 定位类型的显示Image
@property (weak, nonatomic) UIImageView *locationTypeImageView;
// 定位地址内容标题
@property (weak, nonatomic) SLMarqueeControl *marqueeControl;
@property (nonatomic ,weak) UIView *topView;
/**
定位超时的定时器
*/
@property (strong, nonatomic) NSTimer *OverTimer;
@property (nonatomic, strong) AMapSearchAPI *searchAPI;
//逆地理编码
@property (nonatomic, strong) AMapReGeocodeSearchRequest *regeo;
/// 地图模式切换View
@property (nonatomic ,strong) UIView *mapSwitchView;
@property (nonatomic ,strong) CommonTableView *btnTableView;
@property (nonatomic ,strong) NSMutableArray *titleArr;
@property (nonatomic ,strong) NSMutableArray *imageArr;
@property (nonatomic ,weak) UIButton *menuBtn;
@property (nonatomic ,strong) NSString *mapModeStr;
@end
@implementation MapViewController
-(void)setIsLocating:(BOOL)isLocating{
_isLocating = isLocating;
if(_isLocating == NO){
if (self.OverTimer) {
[self.OverTimer invalidate];// 使定时器 失效
self.OverTimer = nil;
}
}
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.zx_navLeftBtn setTitle:cUser.cDevice.name forState:0];
self.isSetTranslucent = NO;
[self loadData];
//进来定位一次
[cUser.cDevice getDeviceCurLocationSuccess:^(id responseObject) {
} failure:^(id faiObject) {
}];
[self.titleArr removeAllObjects];
[self.imageArr removeAllObjects];
[self.titleArr addObject:@"历史轨迹"];
[self.imageArr addObject:@"icon_baby_history"];
if (cUser.cDevice.support_safeArea.boolValue)
{
[self.titleArr addObject:@"电子围栏"];
[self.imageArr addObject:@"icon_baby_security_fence"];
}
[self.titleArr addObject:self.mapModeStr];
[self.imageArr addObject:@"icon_map_mode"];
[self.titleArr addObject:@"定位说明"];
[self.imageArr addObject:@"icon_positioning_g"];
[self.titleArr addObject:@"位置纠偏"];
[self.imageArr addObject:@"map_icon_correction"];
self.btnTableView.cellRow = self.titleArr.count;
[self.btnTableView reloadData];
}
- (void)rightBtnTouch
{
WeakSelf
[DeviceSwitchover.sharedManager showMenuViewWithAdd:NO Point:CGPointMake(ScreenWidth - 30, getRectNavAndStatusHight - 10)];
[DeviceSwitchover.sharedManager setSwitchDevice:^(NSInteger index) {
Device *device = cUser.myDevices[index];
cUser.cDevice = device;
[User saveDefaultImei:device.imei];
[weakSelf viewWillAppear:YES];
}];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapModeStr = @"标准模式";
self.zx_navLeftBtn.titleLabel.font = FontBold_(18);
[self.zx_navLeftBtn setTitleColor:KKWhiteColorColor forState:0];
[self zx_setRightBtnWithImg:ImageName_(@"icon_switch_devices") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
[self rightBtnTouch];
}];
[MAMapView updatePrivacyShow:AMapPrivacyShowStatusDidShow privacyInfo:AMapPrivacyInfoStatusDidContain];
[MAMapView updatePrivacyAgree:AMapPrivacyAgreeStatusDidAgree];
[AMapSearchAPI updatePrivacyShow:(AMapPrivacyShowStatusDidShow) privacyInfo:(AMapPrivacyInfoStatusDidContain)];
[self.mapView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.top.equalTo(self.view).offset(iPhoneX_NavHeight);
make.bottom.equalTo(self.view.mas_bottom);
}];
[self.view addSubview:self.topView];
[self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view).inset(20);
make.top.equalTo(self.view).offset(iPhoneX_NavHeight);
make.height.mas_equalTo(25);
}];
[self.view addSubview:self.btnTableView];
UIButton *menuBtn = [UICommon ui_buttonSimple:CGRectMake(25, ScreenHeight-TabBarHeight-55.5, 45, 45) font:Font_(0) normalColor:KKWhiteColorColor normalText:@"" click:^(UIButton *btn) {
btn.selected = !btn.selected;
if (btn.selected)
[self showView];
else
[self dismiss];
}];
[menuBtn setImage:ImageName_(@"button_list_close") forState:UIControlStateNormal];
[menuBtn setImage:ImageName_(@"button_list_open") forState:UIControlStateSelected];
self.menuBtn = menuBtn;
[self.view addSubview:menuBtn];
[self.btn_CurLocation mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view.mas_right).inset(20);
make.centerY.equalTo(menuBtn);
make.size.mas_equalTo(CGSizeMake(45, 45));
}];
self.mapView.delegate = self;
// [self setTitleView];
self.searchAPI = [[AMapSearchAPI alloc] init];
self.searchAPI.delegate = self;
[self initLocationManager];
// 广告的父View
self.adIconSuperView.layer.masksToBounds = YES;
self.adIconSuperView.layer.cornerRadius = self.adIconSuperView.frame.size.width / 2;
self.adIconSuperView.backgroundColor = [UIColor clearColor];
self.adIconSuperView.hidden = YES;
self.curPointAnnotation = [[MKPointAnnotation alloc] init];
self.userPointAnnotation = [[MKPointAnnotation alloc] init];
WEAKSELF
[[NSNotificationCenter defaultCenter] addObserverForName:PUSH_type_deviceNowLocation
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification * _Nonnull note)
{
//把定位超时的 标识复位
weakSelf.isLocating = NO;
[SVProgressHUD dismiss];
//定位的通知
if ([note.object[@"imei"] isEqualToString:cUser.cDevice.imei]) {
weakSelf.curLocate = [Locate mj_objectWithKeyValues:note.object];
cUser.cDevice.lastLocation = weakSelf.curLocate;
[weakSelf loadData];
}
}];
// self.locationAddressLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
[myHelper setBtnUpImageDownTitle:self.btn_CurLocation];//设置图片在按钮之上
// //设备按钮
// self.btn_UserLocation.layer.cornerRadius = 10;
// self.btn_UserLocation.layer.masksToBounds = YES;
//放大和缩小 VIew
self.zoomBtnView.layer.cornerRadius = 10;
self.zoomBtnView.layer.masksToBounds = YES;
self.zoomBtnView.hidden = YES;// add by lsz
UITapGestureRecognizer *tapPress = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(mapViewtapPressed:)];
[self.mapView addGestureRecognizer:tapPress];
[self.view addSubview:self.mapSwitchView];
[self.mapSwitchView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view).offset(82.5);
make.bottom.equalTo(self.menuBtn.mas_top).inset(135);
make.size.mas_equalTo(CGSizeMake(105, 90));
}];
}
- (void)loadData{
// [self.locationManager startUpdatingLocation];
if(cUser.cDevice.lastLocation)
{
self.curLocate = cUser.cDevice.lastLocation;
self.locationTypeImageView.image = ImageName_(@"home_icon_gps");
[self showCurPiont];
[self mapView:self.mapView didSelectAnnotationView:[CustomAnnotationView new]];
}
else
{
[self setMapZoom:DefineLocate];
self.marqueeControl.marqueeLabel.text = @"当前位置未知,请确保设备开机且能够联网,再点击定位按钮进行定位";
self.locationTypeImageView.image = ImageName_(@"home_icon_gps_inaccurate");
}
}
- (NSMutableArray *)getDeviceNameArr{
NSMutableArray *nameArr = [NSMutableArray array];
[cUser.myDevices enumerateObjectsUsingBlock:^(Device * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[nameArr addObject:obj.name];
}];
return nameArr;
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self.locationManager stopUpdatingHeading];
}
/**
//MARK:获取当前设备的定位信息
*/
- (IBAction)getCurLoactionClick:(UIButton *)sender{
if(self.isLocating){
return;
}
//先移动 到 设备的定位处
if([cUser.cDevice.lastLocation.lon doubleValue] == 0
&& [cUser.cDevice.lastLocation.lat doubleValue] == 0){
[self setMapZoom:DefineLocate];
}else{
[self setMapZoom:CLLocationCoordinate2DMake([cUser.cDevice.lastLocation.lat doubleValue], [cUser.cDevice.lastLocation.lon doubleValue])];
}
WEAKSELF
[cUser.cDevice getDeviceCurLocationSuccess:^(id responseObject) {
//请求成功 等待位置回传 显示 loading
[SVProgressHUD showWithStatus:@"定位中,请稍后..."];
weakSelf.isLocating = YES;
weakSelf.OverTimer = [NSTimer scheduledTimerWithTimeInterval:15 repeats:NO block:^(NSTimer * _Nonnull timer) {
if(weakSelf.isLocating){
weakSelf.isLocating = NO;
[SVProgressHUD dismiss];
}
}];
} failure:^(id faiObject) {
if([faiObject isKindOfClass:[NSDictionary class]]){
//5001
if([faiObject[@"code"] intValue] == HTTP_ERROR_5001){
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:nil message:@"定位失败,当前设备可能关机、欠费、或处于弱信号环境" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:nil destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
} cancelHandler:nil destructiveHandler:nil];
//获取当前的 VC
UIViewController *vc = weakSelf.navigationController.viewControllers.lastObject;
if([vc isKindOfClass:[MapViewController class]]){
[alertView showAnimated:YES completionHandler:nil];
}
}
}
}];
}
/**
获取当前用户的定位信息
*/
- (IBAction)getUserLocationAction:(UIButton *)sender
{
// [self.mapView setCenterCoordinate:self.mapView.userLocation.coordinate animated:YES];
//调整位置
//设置用户点 为当前地图范围的中心点
CLLocationCoordinate2D center = self.mapView.userLocation.coordinate;
if(center.latitude == 0 && center.longitude == 0){
center = DefineLocate;
}
[self setMapZoom:center];
// [self mapView:self.mapView didSelectAnnotationView:[UserAnnotationView new]];
}
/// 地图模式切换
- (IBAction)mapModeSwitch:(UIButton *)sender
{
sender.selected = !sender.selected;
self.mapSwitchView.hidden = !sender.selected;
}
//缩小地图
- (IBAction)subtractBtnAction:(id)sender {
//设置地图范围
//设置中心点为当前地图范围的中心点
CLLocationCoordinate2D center = self.mapView.region.center;
//设置跨度为当前地图范围的跨度 * 比例系数
MKCoordinateSpan span = MKCoordinateSpanMake(self.mapView.region.span.latitudeDelta * 2, self.mapView.region.span.longitudeDelta * 2);
//设置范围
@try {
MKCoordinateRegion region = MKCoordinateRegionMake(center, span);
xLog(@"span %@",[NSValue valueWithMKCoordinateSpan:span])
xLog(@"center %@",[NSValue valueWithMKCoordinate:center])
[self.mapView setRegion: region animated:YES];
} @catch (NSException *exception) {
xLog(@"error: %@",exception.description);
} @finally {
}
}
//放大地图
- (IBAction)addZoomBtnAction:(id)sender {
// 设置范围
// 设置中心点
CLLocationCoordinate2D center = self.mapView.region.center;
// 设置跨度 : 跨度变小,地图显示缩大 (地图的范围跨度 * 比例系数)
MKCoordinateSpan span = MKCoordinateSpanMake(self.mapView.region.span.latitudeDelta * 0.5, self.mapView.region.span.longitudeDelta * 0.5);
//设置地图范围
[self.mapView setRegion:MKCoordinateRegionMake(center, span) animated:YES];
}
/**
//MARK:点击地图触发的方法
*/
- (void)mapViewtapPressed:(id)sender{
[SVProgressHUD dismiss];
}
#pragma 定位
- (void)initLocationManager{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.delegate = self;
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
}
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
switch (status) {
case kCLAuthorizationStatusNotDetermined:
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
break;
default:
break;
}
}
//MARK : 初始化 用户位置
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
// CLLocation *userLocation = [locations lastObject];
// self.userLocate = userLocation;
// [User currentUser].curLocation = userLocation;
// [manager stopUpdatingLocation];
//
// [self showCurPiont];
// //直接 调一次
// if(self.curLocate){
// [self mapView:self.mapView didSelectAnnotationView:[CustomAnnotationView new]];
// }else{
// [self mapView:self.mapView didSelectAnnotationView:[UserAnnotationView new]];
// }
}
//- (NSMutableArray *)mapPoints{
// if (!_mapPoints) {
// _mapPoints = [[NSMutableArray alloc] init];
// }
// return _mapPoints;
//}
//MARK: 显示点
/**
显示点
*/
-(void)showCurPiont{
//要在地图上显示的点的数组
NSMutableArray *pointArr = [NSMutableArray array];
CLLocationCoordinate2D coordinate2D = DefineLocate;
if (self.curLocate) {
//设置新的地图信息
coordinate2D = CLLocationCoordinate2DMake([self.curLocate.lat doubleValue],
[self.curLocate.lon doubleValue]);
//删除原来的点
if ([self.mapView.annotations containsObject:self.curPointAnnotation]) {
// NSInteger index = [self.mapView.annotations indexOfObject:curPointAnnotation];
[self.mapView removeAnnotation:self.curPointAnnotation];
}
self.curPointAnnotation.coordinate = coordinate2D;
// 设备的 范围框
if (self.curLocate.radius) {
CLLocationDistance radius = [self.curLocate.radius doubleValue];
MKCircle *circle = [MKCircle circleWithCenterCoordinate:coordinate2D
radius:radius];
[self.mapView removeOverlays:self.mapView.overlays];
[self.mapView addOverlay:circle];
}
[pointArr addObject:self.curPointAnnotation];
}
if(pointArr.count > 0){
//如果 设备的位置存在则显示 设备的位置
[self.mapView addAnnotations:pointArr];
[self setMapZoom:coordinate2D];
}else{
//调整位置
//设置中心点为当前地图范围的中心点
CLLocationCoordinate2D center = DefineLocate;
//不存在 则 显示用户的位置
if(self.mapView.userLocation.isUpdating){
center = self.mapView.userLocation.coordinate;
}else if(self.userLocate){
center = self.userLocate.coordinate;
}
[self setMapZoom:center];
}
}
#pragma 缩小地图
- (void)setMapZoom:(CLLocationCoordinate2D)centerCoordinate{
// if (self.mapView.region.span.latitudeDelta > 20) {
// MARK: carh update by lsz 22-5-12 增加坐标合法性判断
@try {
if (CLLocationCoordinate2DIsValid(centerCoordinate)) {
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(centerCoordinate, 2000, 2000);
[self.mapView setRegion:region animated:YES];
}
} @catch (NSException *exception) {
} @finally {
}
//}
}
#pragma mark - 地图控件代理方法
#pragma mark 显示大头针时调用,注意方法中的annotation参数是即将显示的大头针对象
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
if([annotation isEqual:self.curPointAnnotation]){
//由于当前位置的标注也是一个大头针,所以此时需要判断,此代理方法返回nil使用默认大头针视图
static NSString *key1=@"CustomAnnotationView";
CustomAnnotationView *annotationView = (CustomAnnotationView*)[_mapView dequeueReusableAnnotationViewWithIdentifier:key1];
//如果缓存池中不存在则新建
if (!annotationView) {
annotationView =[[CustomAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:key1];
annotationView.canShowCallout=NO;//不允许交互点击
}else{
//重新设置此类大头针视图的大头针模型(因为有可能是从缓存池中取出来的,位置是放到缓存池时的位置)
annotationView.annotation = annotation;
}
//修改大头针视图 设置成头像
[annotationView setImageWithURLString:cUser.cDevice.avator];
//设置大小
annotationView.frame = CGRectMake(0, 0, 40.5, 60);
//设置中心偏移量
annotationView.centerOffset = CGPointMake(0, -26);
//定义详情视图偏移量
annotationView.calloutOffset=CGPointMake(0, 12);
return annotationView;
}else if([annotation isKindOfClass:[MKUserLocation class]]){
//由于当前位置的标注也是一个大头针,所以此时需要判断,此代理方法返回nil使用默认大头针视图
static NSString *key1=@"UserAnnotationView";
UserAnnotationView *annotationView = (UserAnnotationView*)[_mapView dequeueReusableAnnotationViewWithIdentifier:key1];
//如果缓存池中不存在则新建
if (!annotationView) {
annotationView =[[UserAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:key1];
annotationView.canShowCallout=NO;//不允许交互点击
}else{
//重新设置此类大头针视图的大头针模型(因为有可能是从缓存池中取出来的,位置是放到缓存池时的位置)
annotationView.annotation = annotation;
}
//修改大头针视图 设置成头像
[annotationView setImageWithURLString:cUser.avator];
//设置大小
annotationView.frame = CGRectMake(0, 0, 40.5, 60);
//设置中心偏移量
annotationView.centerOffset = CGPointMake(0, -26);
//定义详情视图偏移量
annotationView.calloutOffset=CGPointMake(0, 12);
return annotationView;
}
return nil;
}
//MARK: 点击地图 中的 标点 触发的方法
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
if([view isKindOfClass:[CustomAnnotationView class]])
{
self.locationTypeImageView.image = [UIImage imageNamed:@"home_icon_gps"];
if(self.curLocate)
self.marqueeControl.marqueeLabel.text = self.curLocate.address.length > 0 ? self.curLocate.address : @"位置解析中...";
self.regeo.location = [AMapGeoPoint locationWithLatitude:[self.curLocate.lat floatValue] longitude:[self.curLocate.lon floatValue]];
[self.searchAPI AMapReGoecodeSearch:self.regeo];
}
}
- (AMapReGeocodeSearchRequest *)regeo {
if (!_regeo) {
_regeo = [[AMapReGeocodeSearchRequest alloc]init];
_regeo.requireExtension = YES;
}
return _regeo;
}
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKCircle class]])
{
MKCircleRenderer *circle = [[MKCircleRenderer alloc] initWithOverlay:overlay];
circle.strokeColor = [UIColor clearColor];
circle.fillColor = [[UIColor blueColor] colorWithAlphaComponent:0.1];
// circle.lineWidth = 1;
return circle;
}
return nil;
}
#pragma mark ====高德地图位置解析回调====
-(void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response{
if (response.regeocode != nil)
{
NSString *name = response.regeocode.formattedAddress;
self.marqueeControl.marqueeLabel.text = name;
self.locationTypeImageView.image = ImageName_(@"home_icon_gps");
}
}
-(void)dealloc{
if(self.OverTimer){
[self.OverTimer invalidate];
self.OverTimer = nil;
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
switch (self.mapView.mapType) {
case MKMapTypeHybrid:
{
self.mapView.mapType = MKMapTypeStandard;
}
break;
case MKMapTypeStandard:
{
self.mapView.mapType = MKMapTypeHybrid;
}
break;
default:
break;
}
self.mapView.mapType = MKMapTypeStandard;
}
- (UIView *)mapSwitchView
{
if (!_mapSwitchView)
{
NSArray *arr = @[@"标准模式",@"卫星模式"];
_mapSwitchView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:10 borderWidth:0 borderColor:KKClearColor];
_mapSwitchView.hidden = YES;
for (int i = 0; i < arr.count; i++)
{
UIButton *btn = [UICommon ui_buttonSimple:CGRectZero font:Font_(14) normalColor:KKTextColor normalText:arr[i] click:^(UIButton *button) {
self.mapSwitchView.hidden = YES;
self.mapModeStr = button.currentTitle;
[self.titleArr replaceObjectAtIndex:self.titleArr.count == 5 ? 2 : 1 withObject:self.mapModeStr];
[self.btnTableView reloadData];
if([button.currentTitle isEqualToString:@"标准模式"])
self.mapView.mapType = MKMapTypeStandard;
else if([button.currentTitle isEqualToString:@"卫星模式"])
self.mapView.mapType = MKMapTypeSatellite;
else
{
}
}];
[_mapSwitchView addSubview:btn];
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(_mapSwitchView);
make.top.equalTo(_mapSwitchView).offset(i*45);
make.height.mas_equalTo(45);
}];
if (i < arr.count-1)
{
UILabel *line = [UILabel new];
line.backgroundColor = RGB(235, 235, 235);
[_mapSwitchView addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(_mapSwitchView);
make.bottom.equalTo(btn.mas_bottom);
make.height.mas_equalTo(0.5);
}];
}
}
}
return _mapSwitchView;
}
- (UIView *)topView
{
if (!_topView)
{
_topView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:12.5 borderWidth:0 borderColor:KKClearColor];
UIImageView *locationTypeImageView = [UIImageView new];
self.locationTypeImageView = locationTypeImageView;
[_topView addSubview:locationTypeImageView];
[locationTypeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_topView).offset(13);
make.centerY.equalTo(_topView);
make.size.mas_equalTo(CGSizeMake(15, 15));
}];
/// 位置跑马灯
SLMarqueeControl *control = [[SLMarqueeControl alloc] initWithFrame:CGRectMake(38, 5, ScreenWidth-40-38-15, 15)];
control.backgroundColor = KKClearColor;
control.marqueeLabel.text = @"当前位置未知,请确保设备开机且能够联网,再点击定位按钮进行定位";
self.marqueeControl = control;
[_topView addSubview:control];
}
return _topView;
}
- (CommonTableView *)btnTableView
{
if (!_btnTableView)
{
_btnTableView = [[CommonTableView alloc] initWithFrame:CGRectMake(22.5, ScreenHeight-TabBarHeight-55.5, 50, 0) style:UITableViewStylePlain cellHeight:71 cellRow:self.titleArr.count isAdaptive:NO isLine:YES commonCell:MapBtnTableViewCell.class createCell:^(ZZTableViewCell * _Nonnull cells, NSIndexPath * _Nonnull indexPath) {
MapBtnTableViewCell *cell = (MapBtnTableViewCell *)cells;
cell.imageName = self.imageArr[indexPath.row];
cell.titleName = self.titleArr[indexPath.row];
} selectedCell:^(UITableView * _Nonnull tableView, NSIndexPath * _Nonnull indexPath) {
NSString *title = self.titleArr[indexPath.row];
if ([title isEqualToString:@"历史轨迹"])
{
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"TrackViewController"];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"NewTrackVC"];
vc.title = @"历史轨迹";
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
}
else if ([title isEqualToString:@"电子围栏"])
{
[UICommon pusXibViewController:@"RailListViewController"];
}
else if ([title isEqualToString:@"标准模式"] || [title isEqualToString:@"卫星模式"] || [title isEqualToString:@"3D模式"])
{
BOOL ish = self.mapSwitchView.hidden;
self.mapSwitchView.hidden = !ish;
}
else if ([title isEqualToString:@"定位说明"])
{
MarkViewController *markVC = [[MarkViewController alloc] init];
markVC.hidesBottomBarWhenPushed = YES;
markVC.title = @"定位说明";
[self.navigationController pushViewController:markVC animated:YES];
}
else if ([title isEqualToString:@"位置纠偏"])
{
MapReviseViewController *vc = [[MapReviseViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
} DidscrollView:^(UIScrollView * _Nonnull scrollView) {}];
_btnTableView.layer.cornerRadius = 10;
_btnTableView.layer.masksToBounds = YES;
[UICommon setTavleViewlink:_btnTableView distance:0];
}
return _btnTableView;
}
- (void)showView
{
self.btnTableView.hidden = NO;
self.btnTableView.size = CGSizeMake(50, self.titleArr.count*71);
[UIView animateWithDuration:0.25f
delay:0.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^{
CGRect frame = self.btnTableView.frame;
frame.origin.y = frame.origin.y - frame.size.height-10;
self.btnTableView.frame = frame;
}completion:^(BOOL finished) {
}];
}
- (void)dismiss
{
self.mapSwitchView.hidden = YES;
[UIView animateWithDuration:0.25f
delay:0.0f
options:UIViewAnimationOptionCurveEaseIn
animations:^{
CGRect frame = self.btnTableView.frame;
frame.origin.y = frame.origin.y + frame.size.height+10;
self.btnTableView.frame = frame;
}completion:^(BOOL finished) {
self.btnTableView.hidden = YES;
}];
}
- (NSMutableArray *)titleArr
{
if (!_titleArr) _titleArr = [NSMutableArray new];
return _titleArr;
}
- (NSMutableArray *)imageArr
{
if (!_imageArr) _imageArr = [NSMutableArray new];
return _imageArr;
}
@end