OrbitVC.m 11 KB

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