OrbitVC.m 12 KB

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