OrbitVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. //
  2. // OrbitVC.m
  3. // jiaPeiC
  4. //
  5. // Created by apple on 16/9/12.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "OrbitVC.h"
  9. //#import <BaiduMapAPI_Base/BMKBaseComponent.h>
  10. //#import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件
  11. //#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>//引入计算工具所有的头文件
  12. @interface OrbitVC ()
  13. {
  14. // BMKMapView *_mapView;
  15. // BMKPointAnnotation *myAnnotation;
  16. // UIBarButtonItem *item;
  17. //
  18. //
  19. // NSArray *pointArray;
  20. // NSArray *railArray;
  21. // NSMutableArray *overlayArray;
  22. // NSMutableArray *annotationArray;
  23. }
  24. @end
  25. @implementation OrbitVC
  26. -(void)creatWebViewWithUrlStr:(NSString *)urlStr
  27. {
  28. UIWebView *view = [[UIWebView alloc] initWithFrame:kFrame];
  29. view.y += kNavOffSet;
  30. view.height = kSize.height - kNavOffSet;
  31. [self.view addSubview: view];
  32. NSURLRequest *request = nil;
  33. request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@api/orderTrack?classId=%@&stuOutId=%@",urlStr,_classId,_stuOutId]]];
  34. NSLog(@"%@",request);
  35. [view loadRequest:request];
  36. }
  37. - (void)getStudentTrack {
  38. [LoadingView showHUD];
  39. if (![Util connectedToNetWork]) {
  40. showMsgUnconnect();
  41. return;
  42. }
  43. NSMutableArray *arr=[NSMutableArray array];
  44. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  45. NSString* method = @"getStudentTrack";
  46. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  47. RemoveHUD();
  48. if (!root) {
  49. ShowMsgFailed();
  50. return;
  51. }
  52. if ([root[@"code"] isEqualToString:@"1"]) {
  53. ShowMsg(root[@"body"]);
  54. return;
  55. }
  56. NSString * str = root[@"body"];
  57. [self creatWebViewWithUrlStr:str];
  58. }];
  59. }
  60. - (void)viewDidLoad {
  61. [super viewDidLoad];
  62. self.title = @"轨迹回放";
  63. self.view.backgroundColor = backGroundColor;
  64. [self configNavBar];
  65. [self getStudentTrack];
  66. // self.view.backgroundColor = backGroundColor;
  67. // self.title = @"移动轨迹";
  68. // [self configNavBar];
  69. //
  70. // pointArray = [NSArray array];
  71. // railArray = [NSArray array];
  72. // overlayArray = [NSMutableArray array];
  73. // annotationArray = [NSMutableArray array];
  74. //
  75. // _mapView = [[BMKMapView alloc]initWithFrame:[UIScreen mainScreen].bounds];
  76. // _mapView.mapType = BMKMapTypeStandard;
  77. // _mapView.delegate = self;
  78. // _mapView.zoomLevel = 20;
  79. //
  80. // // 显示定位图层
  81. // _mapView.showsUserLocation = YES;
  82. //
  83. // // 允许旋转地图
  84. // _mapView.rotateEnabled = YES;
  85. //
  86. // // 显示比例尺
  87. // _mapView.showMapScaleBar = YES;
  88. // _mapView.mapScaleBarPosition = CGPointMake(self.view.frame.size.width - 50, self.view.frame.size.height - 50);
  89. //
  90. // [self.view addSubview:_mapView];
  91. //
  92. //
  93. // item = [[UIBarButtonItem alloc] initWithTitle:@"刷新" style:UIBarButtonItemStyleDone target:self action:@selector(getGpsLocations)];
  94. // [item setTintColor:defGreen];
  95. // [self.navigationItem setRightBarButtonItem:item];
  96. //
  97. //
  98. // [self getGpsLocations];
  99. }
  100. /*
  101. -(void)viewWillDisappear:(BOOL)animated
  102. {
  103. [super viewWillDisappear:animated];
  104. //RemoveHUD();
  105. _mapView.delegate = nil; // 不用时,置nil
  106. }
  107. -(void)initMap
  108. {
  109. if (overlayArray.count > 0) {
  110. [_mapView removeOverlays:overlayArray];
  111. }
  112. if (annotationArray.count > 0) {
  113. [_mapView removeAnnotations:annotationArray];
  114. }
  115. //设置中心点 起始点 轨迹点
  116. if (pointArray.count > 0) {
  117. NSDictionary *dic = [pointArray firstObject];
  118. CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([dic[@"LAT"] floatValue], [dic[@"LNG"] floatValue]);
  119. [_mapView setCenterCoordinate:coord animated:YES];
  120. //轨迹
  121. for (int i = 0; i < pointArray.count - 1; i ++) {
  122. NSDictionary *ddDic = pointArray[i];
  123. coord = CLLocationCoordinate2DMake([ddDic[@"LAT"] floatValue], [ddDic[@"LNG"] floatValue]);
  124. myAnnotation = [[BMKPointAnnotation alloc]init];
  125. myAnnotation.coordinate = coord;
  126. [_mapView addAnnotation:myAnnotation];
  127. [annotationArray addObject:myAnnotation];
  128. }
  129. //设置终点标注
  130. dic = [pointArray lastObject];
  131. coord = CLLocationCoordinate2DMake([dic[@"LAT"] floatValue], [dic[@"LNG"] floatValue]);
  132. myAnnotation = [[BMKPointAnnotation alloc]init];
  133. myAnnotation.coordinate = coord;
  134. myAnnotation.title = @"终点";
  135. [_mapView addAnnotation:myAnnotation];
  136. [annotationArray addObject:myAnnotation];
  137. }else{
  138. if (railArray.count > 0) {
  139. if ([[railArray firstObject] count] > 0) {
  140. NSDictionary *dic = [[railArray firstObject] firstObject];
  141. CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([dic[@"lat"] floatValue], [dic[@"lng"] floatValue]);
  142. [_mapView setCenterCoordinate:coord animated:YES];
  143. }
  144. }
  145. }
  146. //绘制围栏
  147. for (NSMutableArray *mArray in railArray) {
  148. //NSLog(@"--->%@",mArray);
  149. if (mArray.count == 0) {
  150. continue;
  151. }
  152. BMKMapPoint *temppoints = new BMKMapPoint[mArray.count];
  153. for (int i = 0; i < mArray.count; i ++) {
  154. NSDictionary *dic = mArray[i];
  155. CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([dic[@"lat"] floatValue], [dic[@"lng"] floatValue]);
  156. BMKMapPoint mapPoint = BMKMapPointForCoordinate(coord);
  157. temppoints[i].x = mapPoint.x;
  158. temppoints[i].y = mapPoint.y;
  159. }
  160. BMKPolygon* polygon = [BMKPolygon polygonWithPoints:temppoints count:mArray.count];
  161. [_mapView addOverlay:polygon];
  162. [overlayArray addObject:polygon];
  163. }
  164. //dansonmark 我就想知道 为毛我画的线是这样的呀、、、、、、
  165. // //绘制轨迹
  166. // BMKMapPoint *temppoints = new BMKMapPoint[pointArray.count];
  167. // for (int i = 0; i < pointArray.count; i ++) {
  168. // NSDictionary *dic = pointArray[i];
  169. // CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([dic[@"LAT"] floatValue], [dic[@"LNG"] floatValue]);
  170. // BMKMapPoint mapPoint = BMKMapPointForCoordinate(coord);
  171. // temppoints[i].x = mapPoint.x;
  172. // temppoints[i].y = mapPoint.y;
  173. // }
  174. // BMKPolyline *colorfulPolyline = [BMKPolyline polylineWithPoints:temppoints count:pointArray.count];
  175. // [_mapView addOverlay:colorfulPolyline];
  176. // for (int i = 0; i < pointArray.count - 1; i ++) {
  177. //
  178. // BMKMapPoint *temppoints = new BMKMapPoint[2];
  179. //
  180. // NSDictionary *dic = pointArray[i];
  181. // CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([dic[@"LAT"] floatValue], [dic[@"LNG"] floatValue]);
  182. // BMKMapPoint mapPoint = BMKMapPointForCoordinate(coord);
  183. // temppoints[0].x = mapPoint.x;
  184. // temppoints[0].y = mapPoint.y;
  185. //
  186. // dic = pointArray[i + 1];
  187. // coord = CLLocationCoordinate2DMake([dic[@"LAT"] floatValue], [dic[@"LNG"] floatValue]);
  188. // mapPoint = BMKMapPointForCoordinate(coord);
  189. // temppoints[1].x = mapPoint.x;
  190. // temppoints[1].y = mapPoint.y;
  191. //
  192. // BMKPolyline *colorfulPolyline = [BMKPolyline polylineWithPoints:temppoints count:2];
  193. // [_mapView addOverlay:colorfulPolyline];
  194. // free(temppoints);
  195. // [overlayArray addObject:colorfulPolyline];
  196. // }
  197. }
  198. //根据polyline设置地图范围
  199. - (void)mapViewFitPolyLine:(BMKPolyline *) polyLine {
  200. CGFloat ltX, ltY, rbX, rbY;
  201. if (polyLine.pointCount < 1) {
  202. return;
  203. }
  204. BMKMapPoint pt = polyLine.points[0];
  205. ltX = pt.x, ltY = pt.y;
  206. rbX = pt.x, rbY = pt.y;
  207. for (int i = 1; i < polyLine.pointCount; i++) {
  208. BMKMapPoint pt = polyLine.points[i];
  209. if (pt.x < ltX) {
  210. ltX = pt.x;
  211. }
  212. if (pt.x > rbX) {
  213. rbX = pt.x;
  214. }
  215. if (pt.y > ltY) {
  216. ltY = pt.y;
  217. }
  218. if (pt.y < rbY) {
  219. rbY = pt.y;
  220. }
  221. }
  222. BMKMapRect rect;
  223. rect.origin = BMKMapPointMake(ltX , ltY);
  224. rect.size = BMKMapSizeMake(rbX - ltX, rbY - ltY);
  225. [_mapView setVisibleMapRect:rect];
  226. _mapView.zoomLevel = _mapView.zoomLevel - 0.3;
  227. }
  228. #pragma mark 地图
  229. //标注
  230. -(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation
  231. {
  232. if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
  233. BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
  234. if (annotation.title.length > 0) {
  235. newAnnotationView.pinColor = BMKPinAnnotationColorRed;
  236. }else{
  237. newAnnotationView.pinColor = BMKPinAnnotationColorGreen;
  238. }
  239. // 设置该标注点动画显示
  240. newAnnotationView.animatesDrop = YES;
  241. return newAnnotationView;
  242. }
  243. return nil;
  244. }
  245. //- (BOOL)loadStrokeTextureImages:(NSArray *)textureImages
  246. //{
  247. // return YES;
  248. //}
  249. //根据overlay生成对应的View
  250. - (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id <BMKOverlay>)overlay
  251. {
  252. if ([overlay isKindOfClass:[BMKPolyline class]]) {
  253. BMKPolylineView *polylineView = [[BMKPolylineView alloc] initWithOverlay:overlay];
  254. polylineView.lineWidth = 1.50;
  255. polylineView.strokeColor = [UIColor redColor];
  256. return polylineView;
  257. }
  258. if ([overlay isKindOfClass:[BMKPolygon class]]){
  259. BMKPolygonView* polygonView = [[BMKPolygonView alloc] initWithOverlay:overlay];
  260. polygonView.strokeColor = [[UIColor greenColor] colorWithAlphaComponent:1];
  261. polygonView.fillColor = [[UIColor clearColor] colorWithAlphaComponent:0.2];
  262. polygonView.lineWidth = 4.0;
  263. return polygonView;
  264. }
  265. return nil;
  266. }
  267. #pragma mark 数据请求
  268. //获取学员成绩详情
  269. - (void)getGpsLocations
  270. {
  271. //[LoadingView showHUD];
  272. item.enabled = NO;
  273. if (![Util connectedToNetWork]) {
  274. //showMsgUnconnect();
  275. return;
  276. }
  277. NSMutableArray *arr=[NSMutableArray array];
  278. [arr addPro:@"jxbh" Value:defUser.userDict[@"ciSchool"]];
  279. // [arr addPro:@"orderId" Value:_orderId];
  280. // [arr addPro:@"type" Value:_type];
  281. NSString* method = @"getGpsLocations";
  282. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  283. //NSLog(@"轨迹---->%@----->%@",arr,root);
  284. item.enabled = YES;
  285. if (!root) {
  286. return;
  287. }
  288. if ([root[@"code"] isEqualToString:@"1"]) {
  289. [LoadingView showMsg:root[@"body"]];
  290. return;
  291. }
  292. NSDictionary *dataDic = root[@"body"];
  293. if (![dataDic isKindOfClass:[NSDictionary class]]) {
  294. [LoadingView showMsg:@"暂无数据"];
  295. return;
  296. }
  297. pointArray = dataDic[@"gps"];
  298. railArray = dataDic[@"area"];
  299. [self initMap];
  300. }];
  301. }
  302. */
  303. - (void)didReceiveMemoryWarning {
  304. [super didReceiveMemoryWarning];
  305. }
  306. @end