Files
xj-ios/XinjiangProject/XinjiangProject/Project/SOS/Controller/XJSosCenterViewController.m
T

840 lines
30 KiB
Objective-C

//
// XJSosCenterViewController.m
// XinjiangProject
//
// Created by 仁康信息 on 2023/4/13.
//
#import "XJSosCenterViewController.h"
#import "POIAnnotation.h"
#import "CustomAnnotationView.h"
#import "XMButton.h"
#import <WebKit/WebKit.h>
#import "LXSegmentTitleView.h"
#import "XJSOSCenterModel.h"
#import <AMapFoundationKit/AMapFoundationKit.h>
#import <AMapSearchKit/AMapSearchKit.h>
#import <AMapLocationKit/AMapLocationKit.h>
#import "XJSOSAddressView.h"
#import "SOSGroupIMModel.h"
#import "TYMapNavSheet.h"
#import "XJHealthInterveneHomeModel.h"
#import "XJAEDNetWrokModel.h"
@interface XJSosCenterViewController ()<MAMapViewDelegate, LXSegmentTitleViewDelegate, LXSegmentTitleViewDataSource,AMapLocationManagerDelegate,SoSBottomProtocol,UIActionSheetDelegate>
{
TYMapNavSheet * TYNavSheet;
}
@property (nonatomic, strong) MAMapView * mapView ;
@property (nonatomic, strong) UIView * grapView ;
@property (nonatomic, strong) AMapSearchAPI *search;
@property (nonatomic, strong) AMapLocationManager *locationManager;
@property (nonatomic, copy) AMapLocatingCompletionBlock completionBlock;
@property (nonatomic, strong) LXSegmentTitleView *titleView;
@property(strong, nonatomic) NSArray *titles;
@property(strong, nonatomic) NSMutableArray * titlesArray;
@property(strong, nonatomic) NSMutableArray * ponisArray;
@property (strong, nonatomic) XJSOSCenterModel * model;
//经纬度
@property (assign, nonatomic) CGFloat Longitude;
@property (assign, nonatomic) CGFloat latitude;
@property (copy, nonatomic) NSString * type;
//
@property (nonatomic, strong) XJSOSAddressView * addressView;
@property (nonatomic, strong) XJSOSResourcesModel * resourceModel;
@property (assign, nonatomic) NSInteger selecetIndex;
@property (nonatomic, strong) UIButton *gpsButton;
//@property (strong, nonatomic) NSMutableArray * hospitalArray;
//
//@property (strong, nonatomic) NSMutableArray * AedArray;
//
//@property (strong, nonatomic) NSMutableArray * carArray;
@end
@implementation XJSosCenterViewController
//- (NSMutableArray *)carArray {
//
// if (!_carArray) {
//
// _carArray = [[NSMutableArray alloc] init];
// }
// return _carArray;
//}
//
//- (NSMutableArray *)hospitalArray {
//
// if (!_hospitalArray) {
//
// _hospitalArray = [[NSMutableArray alloc] init];
// }
// return _hospitalArray;
//}
//
//- (NSMutableArray *)AedArray {
//
// if (!_AedArray) {
//
// _AedArray = [[NSMutableArray alloc] init];
// }
// return _AedArray;
//
//
//}
- (NSMutableArray *)titlesArray {
if (!_titlesArray) {
_titlesArray = [[NSMutableArray alloc] init];
}
return _titlesArray;
}
- (NSMutableArray *)ponisArray {
if (!_ponisArray) {
_ponisArray = [[NSMutableArray alloc] init];
}
return _ponisArray;
}
- (XJSOSAddressView *)addressView {
if (!_addressView) {
_addressView = [[XJSOSAddressView alloc] initWithFrame:CGRectZero];
_addressView.addressDelegate = self;
_addressView.backgroundColor = KWhiteColor;
}
return _addressView;
}
- (void)showBottomBtn {
self.grapView.hidden = false;
}
- (void)configLocationManager
{
self.locationManager = [[AMapLocationManager alloc] init];
[self.locationManager setDelegate:self];
//设置期望定位精度
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
//设置不允许系统暂停定位
[self.locationManager setPausesLocationUpdatesAutomatically:NO];
//设置允许在后台定位
[self.locationManager setAllowsBackgroundLocationUpdates:NO];
//设置定位超时时间
[self.locationManager setLocationTimeout:10];
//设置逆地理超时时间
[self.locationManager setReGeocodeTimeout:3];
//设置开启虚拟定位风险监测,可以根据需要开启
[self.locationManager setDetectRiskOfFakeLocation:NO];
}
- (void)cleanUpAction
{
//停止定位
[self.locationManager stopUpdatingLocation];
[self.locationManager setDelegate:nil];
}
- (void)reGeocodeAction
{
[self.mapView removeAnnotations:self.mapView.annotations];
//进行单次带逆地理定位请求
[self.locationManager requestLocationWithReGeocode:YES completionBlock:self.completionBlock];
}
- (void)initCompleteBlock
{
__weak XJSosCenterViewController *weakSelf = self;
self.completionBlock = ^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error)
{
if (error != nil && error.code == AMapLocationErrorLocateFailed)
{
//定位错误:此时location和regeocode没有返回值,不进行annotation的添加
return;
}
else if (error != nil
&& (error.code == AMapLocationErrorReGeocodeFailed
|| error.code == AMapLocationErrorTimeOut
|| error.code == AMapLocationErrorCannotFindHost
|| error.code == AMapLocationErrorBadURL
|| error.code == AMapLocationErrorNotConnectedToInternet
|| error.code == AMapLocationErrorCannotConnectToHost))
{
//逆地理错误:在带逆地理的单次定位中,逆地理过程可能发生错误,此时location有返回值,regeocode无返回值,进行annotation的添加
}
else if (error != nil && error.code == AMapLocationErrorRiskOfFakeLocation)
{
//存在虚拟定位的风险:此时location和regeocode没有返回值,不进行annotation的添加
//存在虚拟定位的风险的定位结果
__unused CLLocation *riskyLocateResult = [error.userInfo objectForKey:@"AMapLocationRiskyLocateResult"];
//存在外接的辅助定位设备
__unused NSDictionary *externalAccressory = [error.userInfo objectForKey:@"AMapLocationAccessoryInfo"];
return;
}
else
{
//没有错误:location有返回值,regeocode是否有返回值取决于是否进行逆地理操作,进行annotation的添加
}
//根据定位信息,添加annotation
MAPointAnnotation *annotation = [[MAPointAnnotation alloc] init];
[annotation setCoordinate:location.coordinate];
//有无逆地理信息,annotationView的标题显示的字段不一样
if (regeocode)
{
[annotation setTitle:[NSString stringWithFormat:@"%@", regeocode.formattedAddress]];
[annotation setSubtitle:[NSString stringWithFormat:@"%@-%@-%.2fm", regeocode.citycode, regeocode.adcode, location.horizontalAccuracy]];
}
else
{
[annotation setTitle:[NSString stringWithFormat:@"lat:%f;lon:%f;", location.coordinate.latitude, location.coordinate.longitude]];
[annotation setSubtitle:[NSString stringWithFormat:@"accuracy:%.2fm", location.horizontalAccuracy]];
}
self.Longitude = location.coordinate.longitude;
self.latitude = location.coordinate.latitude;
[self getResourceDataWithType:@"1" Longitude:self.Longitude withLatitude:self.latitude];
// XJSosCenterViewController *strongSelf = weakSelf;
// [strongSelf addAnnotationToMapView:annotation];
};
}
- (void)addAnnotationToMapView:(id<MAAnnotation>)annotation
{
[self.mapView addAnnotation:annotation];
[self.mapView showAnnotations:self.mapView.annotations edgePadding:UIEdgeInsetsMake(100, 100, 100, 100) animated:YES];
[self.mapView setCenterCoordinate:annotation.coordinate animated:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.isHidenNaviBar = false;
self.type = @"0";
self.selecetIndex = 0;
self.navigationItem.title = @"应急就医";
self.view.backgroundColor = KWhiteColor;
TYNavSheet = [[TYMapNavSheet alloc]init];
[self initMapView];
UIButton *locationBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, 80, 40, 40)];
[locationBtn setImage:[UIImage imageNamed:@"location_icon"] forState:UIControlStateNormal];
[locationBtn addTarget:self action:@selector(onLocationBtnPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:locationBtn];
self.titleView = [[LXSegmentTitleView alloc] initWithFrame:CGRectMake(0 , 0 , kScreenWidth , kRealValue(35))];
self.titleView.itemMinMargin = 15.f;
self.titleView.delegate = self;
self.titleView.titleNormalColor = CFontColor1;
self.titleView.titleSelectedColor = KWhiteColor;
self.titleView.btnNormalColor = KClearColor;
self.titleView.btnSelectedColor = UIColorHex(#21BEBD);
self.titleView.backgroundColor = KWhiteColor;
self.titleView.indicatorColor = KWhiteColor;
[self.view addSubview:self.titleView];
UIView * grapView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight - kTopHeight - kRealValue(170) - kTabBarHeight, kScreenWidth,kRealValue(170))];
grapView.backgroundColor = RGBA(0, 0, 0, 0.2); //
self.grapView = grapView;
self.grapView.hidden = false;
[self.view addSubview:grapView];
[self addWhiteToBlackTransparentGradientToView:self.grapView];
XMButton * callBtn = [[XMButton alloc] initWithFrame:CGRectMake(kScreenWidth/2 - 70 - kRealValue(33), grapView.height - 17 - 70 , 70, 70)];
callBtn.style = SDButtonStyleTop;
callBtn.backgroundColor = KWhiteColor;
callBtn.layer.cornerRadius = 35.0f;
callBtn.layer.masksToBounds = true;
[callBtn setTitle:@"120" forState:UIControlStateNormal];
callBtn.titleLabel.font = SYSTEMFONT(12);
[callBtn setTitleColor:UIColorHex(#FF422F) forState:UIControlStateNormal];
[callBtn setImage:[UIImage imageNamed:@"callHospation"] forState:UIControlStateNormal];
[callBtn addTarget:self action:@selector(callHospationAction) forControlEvents:UIControlEventTouchUpInside];
callBtn.imageW = 22;
callBtn.imageH = 20;
callBtn.imageY = 19;
callBtn.imageX = 24;
callBtn.interval = 5;
[grapView addSubview:callBtn];
XMButton * sosBtn = [[XMButton alloc] initWithFrame:CGRectMake(kScreenWidth/2 + kRealValue(33), callBtn.top , 70,70)];
sosBtn.style = SDButtonStyleTop;
sosBtn.backgroundColor = KWhiteColor;
sosBtn.layer.cornerRadius = 35.0f;
sosBtn.layer.masksToBounds = true;
[sosBtn setTitle:@"应急就医" forState:UIControlStateNormal];
sosBtn.titleLabel.font = SYSTEMFONT(11);
[sosBtn setTitleColor:UIColorHex(#FF422F) forState:UIControlStateNormal];
[sosBtn setImage:[UIImage imageNamed:@"callSoSIcon"] forState:UIControlStateNormal];
[sosBtn addTarget:self action:@selector(callSoSAction) forControlEvents:UIControlEventTouchUpInside];
sosBtn.imageW = 22;
sosBtn.imageH = 21;
sosBtn.imageY = 19;
sosBtn.imageX = 24;
sosBtn.interval = 5;
[grapView addSubview:sosBtn];
self.titles = @[@"油田医院",@"合作医院",@"健康小屋",@"AED",@"救护车"];
self.titleView.segmentTitles = self.titles;
[self.titleView reloadData];
self.gpsButton = [self makeGPSButtonView];
self.gpsButton.frame = CGRectMake(kScreenWidth - 40, kRealValue(150), 40, 40);
[self.mapView addSubview:self.gpsButton];
UIView *zoomPannelView = [self makeZoomPannelView];
zoomPannelView.center = CGPointMake(self.grapView.bounds.size.width - CGRectGetMidX(zoomPannelView.bounds) - 10,
self.grapView.bounds.size.height - CGRectGetMidY(zoomPannelView.bounds) - 10);
zoomPannelView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
[self.grapView addSubview:zoomPannelView];
}
- (void)addWhiteToBlackTransparentGradientToView:(UIView *)view {
// 让 view 本身透明
view.backgroundColor = [UIColor clearColor];
// 移除已有的渐变层,避免重复叠加
for (CALayer *layer in view.layer.sublayers.copy) {
if ([layer isKindOfClass:[CAGradientLayer class]]) {
[layer removeFromSuperlayer];
}
}
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = view.bounds;
gradient.colors = @[
(__bridge id)[[UIColor colorWithWhite:1.0 alpha:0.15] CGColor], // 顶部白色半透明
(__bridge id)[[UIColor colorWithWhite:0.0 alpha:0.25] CGColor] // 底部黑色半透明
];
gradient.startPoint = CGPointMake(0.5, 0.0);
gradient.endPoint = CGPointMake(0.5, 1.0);
[view.layer insertSublayer:gradient atIndex:0];
}
- (void)initMapView {
if (self.mapView == nil) {
[AMapServices sharedServices].enableHTTPS = YES;
// ///初始化地图
self.mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.mapView.showsCompass = YES; //设置成NO表示关闭指南针;YES表示显示指南针
self.mapView.compassOrigin = CGPointMake(self.mapView.compassOrigin.x, 222);
self.mapView.showsScale = YES; //设置成NO表示不显示比例尺;YES表示显示比例尺
self.mapView.delegate = self;
// ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
// _mapView.scaleOrigin= CGPointMake(_mapView.scaleOrigin.x, kRealValue(45)); //设置比例尺位置
[self.view addSubview:self.mapView];
//
//
self.mapView.showsUserLocation = YES;
// self.mapView.userTrackingMode = MAUserTrackingModeFollow;
//1.2、新增点A
// //将目标经纬度设置为地图中心店
MAUserLocationRepresentation *r = [[MAUserLocationRepresentation alloc] init];
r.showsAccuracyRing = YES;///精度圈是否显示,默认YES
r.showsHeadingIndicator = YES;///是否显示方向指示(MAUserTrackingModeFollowWithHeading模式开启)。默认为YES
r.enablePulseAnnimation = YES;///内部蓝色圆点是否使用律动效果, 默认YES
r.image = [UIImage imageNamed:@"myLocationIcon"]; ///定位图标, 与蓝色原点互斥
[self.mapView updateUserLocationRepresentation:r];
}
}
- (UIButton *)makeGPSButtonView {
UIButton *ret = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
ret.backgroundColor = [UIColor whiteColor];
ret.layer.cornerRadius = 4;
[ret setImage:[UIImage imageNamed:@"gpsStat1"] forState:UIControlStateNormal];
[ret addTarget:self action:@selector(gpsAction) forControlEvents:UIControlEventTouchUpInside];
return ret;
}
- (void)gpsAction {
self.mapView.showsUserLocation = YES;
self.mapView.userTrackingMode = MAUserTrackingModeFollow;
self.mapView.zoomLevel = 13;
[self.mapView setCenterCoordinate:self.mapView.userLocation.location.coordinate animated:YES];
[self.gpsButton setSelected:YES];
}
- (UIView *)makeZoomPannelView
{
UIView *ret = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 53, 98)];
UIButton *incBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 53, 49)];
[incBtn setImage:[UIImage imageNamed:@"increase"] forState:UIControlStateNormal];
[incBtn sizeToFit];
[incBtn addTarget:self action:@selector(zoomPlusAction) forControlEvents:UIControlEventTouchUpInside];
UIButton *decBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 49, 53, 49)];
[decBtn setImage:[UIImage imageNamed:@"decrease"] forState:UIControlStateNormal];
[decBtn sizeToFit];
[decBtn addTarget:self action:@selector(zoomMinusAction) forControlEvents:UIControlEventTouchUpInside];
[ret addSubview:incBtn];
[ret addSubview:decBtn];
return ret;
}
- (void)zoomPlusAction
{
CGFloat oldZoom = self.mapView.zoomLevel;
[self.mapView setZoomLevel:(oldZoom + 1) animated:YES];
self.mapView.showsScale = YES;
}
- (void)zoomMinusAction
{
CGFloat oldZoom = self.mapView.zoomLevel;
[self.mapView setZoomLevel:(oldZoom - 1) animated:YES];
self.mapView.showsScale = NO;
}
- (void)onLocationBtnPressed {
self.mapView.zoomLevel = 13;
self.mapView.userTrackingMode = MAUserTrackingModeFollow;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
CGFloat longitude = [[user objectForKey:USERDEFAULLONG] floatValue];
CGFloat latitude = [[user objectForKey:USERDEFAULLATITUDE] floatValue];
[self getResourceDataWithType:@"1" Longitude:longitude withLatitude:latitude];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// 开启定位
// self.mapView.showsUserLocation = YES;
// self.mapView.userTrackingMode = MAUserTrackingModeFollow;
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
#pragma mark: 拨打120
- (void)callHospationAction {
NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
CGFloat longitude = [[user objectForKey:USERDEFAULLONG] floatValue];
CGFloat latitude = [[user objectForKey:USERDEFAULLATITUDE] floatValue];
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:@(longitude) forKey:@"longitude"];
[parmDic setObject:@(latitude) forKey:@"latitude"];
[parmDic setObject:@"0" forKey:@"callType"];
[parmDic setObject:self.type forKey:@"resourceId"];
JKCQAPI * sosApi = [[JKCQAPI alloc] init:self tag:@"CALLAPI" NeedToken:@""];
[sosApi PostSoSPhoneEmergency:parmDic];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://120"] options:nil completionHandler:^(BOOL success) {
}];
}
#pragma mark:应急点击
- (void)callSoSAction {
[self showMBProgressHUDWithString:@"应急发起中,请稍候..." autoHidden:false];
NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
CGFloat longitude = [[user objectForKey:USERDEFAULLONG] floatValue];
CGFloat latitude = [[user objectForKey:USERDEFAULLATITUDE] floatValue];
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:@(longitude) forKey:@"longitude"];
[parmDic setObject:@(latitude) forKey:@"latitude"];
[parmDic setObject:@"0" forKey:@"name"];
JKCQAPI * sosApi = [[JKCQAPI alloc] init:self tag:@"GroupAPI" NeedToken:@""];
[sosApi getSoSCreateGroupChat:parmDic];
}
#pragma mark - AMapLocationManager Delegate
- (void)amapLocationManager:(AMapLocationManager *)manager doRequireLocationAuth:(CLLocationManager *)locationManager
{
[locationManager requestAlwaysAuthorization];
}
#pragma mark - MAMapViewDelegate
- (void)mapViewRequireLocationAuth:(CLLocationManager *)locationManager
{
[locationManager requestAlwaysAuthorization];
}
- (void)mapView:(MAMapView *)mapView didChangeUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated
{
}
#pragma mark:定位失败
- (void)mapView:(MAMapView *)mapView didFailToLocateUserWithError:(NSError *)error {
}
#pragma mark:更新位置
- (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation
{
if (updatingLocation)
{
DLog(@"userlocation :%f", userLocation.location.coordinate.latitude);
self.Longitude = userLocation.location.coordinate.longitude;
self.latitude = userLocation.location.coordinate.latitude;
NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
[user setObject:@(userLocation.location.coordinate.longitude) forKey:USERDEFAULLONG];
[user setObject:@(userLocation.location.coordinate.latitude) forKey:USERDEFAULLATITUDE];
[user synchronize];
}
}
#pragma mark - LXSegmentTitleViewDataSource
- (NSArray *)segmentTitlesOfSegmentTitleView:(LXSegmentTitleView *)segmentView {
return self.titles;
}
- (void)segmentTitleView:(LXSegmentTitleView *)segmentView selectedIndex:(NSInteger)selectedIndex lastSelectedIndex:(NSInteger)lastSelectedIndex {
// self.mapView.showsUserLocation = YES;
// self.mapView.userTrackingMode = MAUserTrackingModeFollow;
self.addressView.hidden = true;
self.grapView.hidden = false;
self.selecetIndex = selectedIndex + 1;
[self getResourceDataWithType:[NSString stringWithFormat:@"%ld",self.selecetIndex] Longitude:self.Longitude withLatitude:self.latitude];
[self.addressView removeFromSuperview];
}
- (void)getResourceDataWithType:(NSString *)type
Longitude:(CGFloat)longitude
withLatitude:(CGFloat)latitude{
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:type forKey:@"type"];
[parmDic setObject:@(longitude) forKey:@"longitude"];
[parmDic setObject:@(latitude) forKey:@"latitude"];
JKCQAPI * api = [[JKCQAPI alloc] init:self tag:@"RESOURCES" NeedToken:@""];
[api GetSoSHomePageResources:parmDic];
}
#pragma mark:网络请求
- (void)Failed:(NSString*)message tag:(NSString*)tag
{
[EasyTextView showErrorText:message];
[self hiddenAllMBProgressHUD];
}
- (void)Sucess:(id)response tag:(NSString*)tag
{
if ([tag isEqualToString:@"RESOURCES"])
{
NSDictionary * parmDic = response;
XJSOSCenterModel * model = [XJSOSCenterModel modelWithDictionary:parmDic];
self.model = model;
NSMutableArray * poiAnnotations = [[NSMutableArray alloc] init];
[self.mapView removeAnnotations:self.mapView.annotations];
[self.ponisArray removeAllObjects];
for (XJSOSResourcesModel * resourceModel in model.resources) {
MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
pointAnnotation.coordinate = CLLocationCoordinate2DMake(resourceModel.latitude, resourceModel.longitude);
pointAnnotation.title = resourceModel.name;
pointAnnotation.subtitle = resourceModel.address;
[poiAnnotations addObject:pointAnnotation];
[self addAnnotationToMapView:pointAnnotation];
[self.ponisArray addObject:pointAnnotation];
}
if (self.ponisArray.count == 1) {
self.mapView.zoomLevel = 11;
}
if (self.ponisArray.count == 0) {
self.mapView.showsUserLocation = YES;
self.mapView.userTrackingMode = MAUserTrackingModeFollow;
self.mapView.zoomLevel = 13;
} else {
UIEdgeInsets insets = UIEdgeInsetsMake(80, 50, 80, 50); // 增加边距让视野更广
[self.mapView showAnnotations:self.ponisArray edgePadding:insets animated:YES];
}
}
if ([tag isEqualToString:@"CALLAPI"]) {
NSDictionary * dic = response;
}
if ([tag isEqualToString:@"GroupAPI"]) {
NSDictionary * dic = response;
[self hiddenAllMBProgressHUD];
if ([ESCTUIManager TUIUserStatus] == false) {
[self loginImAccount];
return;
}
SOSGroupIMModel * model = [SOSGroupIMModel modelWithDictionary:dic];
ChatViewController * chatVC = [[ChatViewController alloc] init];
chatVC.isGroupID = YES;
chatVC.isVideo = YES;
chatVC.eableSendReport = true;
chatVC.eablehaveHelathData = true ;
chatVC.chatID = model.groupId;
chatVC.tfNew = model.tfNew;
chatVC.member = model.member;
chatVC.sosEnd_id = model.sosEnd_id;
chatVC.navTitle = @"应急中心";
chatVC.questionType = 1;
[self.navigationController pushViewController:chatVC animated:YES];
}
if ([tag isEqualToString:@"loginIMAPI"]) {
NSDictionary * pamrDic = response;
IMUserInfoModel * model = [IMUserInfoModel modelWithDictionary:pamrDic];
IMUserInfoModel * iminfoModel = [[IMUserInfoModel alloc] init];
iminfoModel.IMInfo = pamrDic;
[HQCommonUtils keyedArchiverWithData:iminfoModel key:IMLoginUserInfo];
[ESCTUIManager loginInitTUISDKAppidWith:[model.sdkAppId intValue] UserID:model.userId userSig:model.userSig];
[self callSoSAction];
}
}
- (void)loginImAccount {
JKCQAPI * proctocolApi = [[JKCQAPI alloc] init:self tag:@"loginIMAPI" NeedToken:nil];
[proctocolApi GetIMLoginAccount:nil];
}
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
{
//用户当前位置大头针
if ([annotation isKindOfClass:[MAUserLocation class]])
{
static NSString *userLocationStyleReuseIndetifier = @"userLocationStyleReuseIndetifier";
MAAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:userLocationStyleReuseIndetifier];
if (annotationView == nil)
{
annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:userLocationStyleReuseIndetifier];
}
annotationView.canShowCallout = true;
annotationView.image = [UIImage imageNamed:@"myLocationIcon"];
annotationView.frame = CGRectMake(0, 0, 50, 50);
return annotationView;
}
if ([annotation isKindOfClass:[MAPointAnnotation class]])
{
static NSString *reuseIndetifier = @"annotationReuseIndetifier";
MAAnnotationView *annotationView = (MAAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
if (annotationView == nil)
{
annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:reuseIndetifier];
}
for (XJSOSResourcesModel * resourceModel in self.model.resources) {
if (annotation.coordinate.longitude == resourceModel.longitude && annotation.coordinate.latitude == resourceModel.latitude) {
if ([resourceModel.type integerValue]== 1) {
annotationView.image = [UIImage imageNamed:@"youtianHosoital"];
}
if ([resourceModel.type integerValue]== 2) {
annotationView.image = [UIImage imageNamed:@"hezuoHospital"];
}
if ([resourceModel.type integerValue]== 3) {
annotationView.image = [UIImage imageNamed:@"medicalAnnitation"];
}
if ([resourceModel.type integerValue]== 4) {
annotationView.image = [UIImage imageNamed:@"AEDIcon"];
}
if ([resourceModel.type integerValue]== 5) {
annotationView.image = [UIImage imageNamed:@"sosCard"];
}
if ([resourceModel.type integerValue]== 6) {
annotationView.image = [UIImage imageNamed:@"sosPeople"];
}
}
}
// 使用动画效果将点显示在屏幕内
[annotationView setSelected:false animated:YES];
//设置中心点偏移,使得标注底部中间点成为经纬度对应点
annotationView.centerOffset = CGPointMake(0, -10);
[self.mapView showAnnotations:self.mapView.annotations edgePadding:UIEdgeInsetsMake(100, 100, 100, 100) animated:YES];
return annotationView;
}
return nil;
}
- (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view
{
self.grapView.hidden = true;
for (XJSOSResourcesModel * resourceModel in self.model.resources) {
if (view.annotation.coordinate.longitude == resourceModel.longitude && view.annotation.coordinate.latitude == resourceModel.latitude) {
self.addressView.resourceModel = resourceModel;
self.resourceModel = resourceModel;
self.addressView.hidden = false;
[self.mapView addSubview:self.addressView];
[ self.addressView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view).insets(UIEdgeInsetsMake(0, 20, 0, 20));
make.bottom.mas_offset(- 20);
}];
}
}
// }
}
- (void)addressNavLocataion {
NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
CGFloat longitude = [[user objectForKey:USERDEFAULLONG] floatValue];
CGFloat latitude = [[user objectForKey:USERDEFAULLATITUDE] floatValue];
NSMutableDictionary * Dic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"我的位置",@"startName",self.resourceModel.address,@"endName", nil];
[TYNavSheet ShowMapNavSheetSuperView:self withLocationDic:Dic withstartCoor:CLLocationCoordinate2DMake(latitude, longitude) withendCoor:CLLocationCoordinate2DMake(self.resourceModel.latitude, self.resourceModel.longitude)];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
[TYNavSheet actionSheetBtnClick:buttonIndex];
}
- (void)resourcePhoneOnclick:(NSString *)phoneNumber {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: [NSString stringWithFormat:@"tel://%@",phoneNumber]] options:nil completionHandler:^(BOOL success) {
}];
}
//在线时票据过期:此时您需要生成新的 userSig,并再次重新调用初始化。
- (void)onKickedOffline {
[HQCommonUtils keyedArchiverWithData:nil key:LoginUserInfo];
[ESCTUIManager outLoginTUISDK];
KPostNotification(KNotificationLoginStateChange, @NO);
}
/*
#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