123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
- //
- // OrbitVC.m
- // jiaPeiC
- //
- // Created by apple on 16/9/12.
- // Copyright © 2016年 JCZ. All rights reserved.
- //
- #import "OrbitVC.h"
- #import <WebKit/WebKit.h>
- //#import <BaiduMapAPI_Base/BMKBaseComponent.h>
- //#import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件
- //#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>//引入计算工具所有的头文件
- @interface OrbitVC ()<WKNavigationDelegate>
- //<BMKMapViewDelegate>
- //{
- // BMKMapView *_mapView;
- // BMKPointAnnotation *myAnnotation;
- // UIBarButtonItem *item;
- //
- //
- // NSArray *pointArray;
- // NSArray *railArray;
- // NSMutableArray *overlayArray;
- // NSMutableArray *annotationArray;
- //}
- @end
- @implementation OrbitVC
- -(void)creatWebViewWithUrlStr:(NSString *)urlStr
- {
- WKWebView *view = [[WKWebView alloc] initWithFrame:kFrame];
- view.height = kSize.height - kNavOffSet;
- view.navigationDelegate = self;
- [self.view addSubview: view];
-
- NSURLRequest *request = nil;
- if ([self.type isEqualToString: @"1"]) {
- request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@api/orderTrack?classId=%@&stuOutId=%@",urlStr,_orderId,defUser.userDict[@"outId"]]]];
- }else{
- request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@api/trainTrack?id=%@",urlStr,self.orderId]]];
-
- }
- NSLog(@"%@",request);
-
- [view loadRequest:request];
-
- }
- #pragma mark -
- // 页面加载失败时调用
- - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error{
-
- [MBProgressHUD hideHUDForView:self.view];
- }
- // 页面加载完毕时调用
- - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
-
- [MBProgressHUD hideHUDForView:self.view];
- }
- - (void)getStudentTrack {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
-
- NSString* method = @"getStudentTrack";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
-
- if (!root) {
- [MBProgressHUD hideHUDForView:self.view];
- ShowMsgFailed();
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- [MBProgressHUD hideHUDForView:self.view];
- ShowMsg(root[@"body"]);
- return;
- }
- NSString * str = root[@"body"];
- [self creatWebViewWithUrlStr:str];
- }];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.title = @"轨迹回放";
- self.view.backgroundColor = backGroundColor;
- [self configNavigationBar];
-
- [self getStudentTrack];
- }
- /*
-
- - (void)customView{
-
- self.view.backgroundColor = backGroundColor;
- self.title = @"移动轨迹";
- [self configNavigationBar];
-
- pointArray = [NSArray array];
- railArray = [NSArray array];
- overlayArray = [NSMutableArray array];
- annotationArray = [NSMutableArray array];
-
-
- _mapView = [[BMKMapView alloc]initWithFrame:[UIScreen mainScreen].bounds];
- _mapView.mapType = BMKMapTypeStandard;
- _mapView.delegate = self;
- _mapView.zoomLevel = 20;
-
- // 显示定位图层
- _mapView.showsUserLocation = YES;
-
- // 允许旋转地图
- _mapView.rotateEnabled = YES;
-
- // 显示比例尺
- _mapView.showMapScaleBar = YES;
- _mapView.mapScaleBarPosition = CGPointMake(self.view.frame.size.width - 50, self.view.frame.size.height - 50);
-
- [self.view addSubview:_mapView];
-
-
- item = [[UIBarButtonItem alloc] initWithTitle:@"刷新" style:UIBarButtonItemStyleDone target:self action:@selector(getGpsLocations)];
- [item setTintColor:defGreen];
- [self.navigationItem setRightBarButtonItem:item];
-
-
- [self getGpsLocations];
- }
-
-
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- _mapView.delegate = nil; // 不用时,置nil
- }
-
- -(void)initMap
- {
- if (overlayArray.count > 0) {
- [_mapView removeOverlays:overlayArray];
- }
-
- if (annotationArray.count > 0) {
- [_mapView removeAnnotations:annotationArray];
- }
-
- //设置中心点 起始点 轨迹点
- if (pointArray.count > 0) {
- NSDictionary *dic = [pointArray firstObject];
- CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([dic[@"LAT"] floatValue], [dic[@"LNG"] floatValue]);
- [_mapView setCenterCoordinate:coord animated:YES];
-
- //轨迹
- for (int i = 0; i < pointArray.count - 1; i ++) {
- NSDictionary *ddDic = pointArray[i];
- coord = CLLocationCoordinate2DMake([ddDic[@"LAT"] floatValue], [ddDic[@"LNG"] floatValue]);
- myAnnotation = [[BMKPointAnnotation alloc]init];
- myAnnotation.coordinate = coord;
- [_mapView addAnnotation:myAnnotation];
- [annotationArray addObject:myAnnotation];
- }
-
- //设置终点标注
- dic = [pointArray lastObject];
- coord = CLLocationCoordinate2DMake([dic[@"LAT"] floatValue], [dic[@"LNG"] floatValue]);
- myAnnotation = [[BMKPointAnnotation alloc]init];
- myAnnotation.coordinate = coord;
- myAnnotation.title = @"终点";
- [_mapView addAnnotation:myAnnotation];
- [annotationArray addObject:myAnnotation];
- }else{
- if (railArray.count > 0) {
- if ([[railArray firstObject] count] > 0) {
- NSDictionary *dic = [[railArray firstObject] firstObject];
- CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([dic[@"lat"] floatValue], [dic[@"lng"] floatValue]);
- [_mapView setCenterCoordinate:coord animated:YES];
- }
- }
- }
-
- //绘制围栏
- // NSLog(@"pointArray--->%@",pointArray);
- // NSLog(@"railArray--->%@",railArray);
- for (NSMutableArray *mArray in railArray) {
-
- if (mArray.count == 0) {
- continue;
- }
-
- BMKMapPoint *temppoints = new BMKMapPoint[mArray.count];
- for (int i = 0; i < mArray.count; i ++) {
-
- NSDictionary *dic = mArray[i];
- CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([dic[@"lat"] floatValue], [dic[@"lng"] floatValue]);
- BMKMapPoint mapPoint = BMKMapPointForCoordinate(coord);
- temppoints[i].x = mapPoint.x;
- temppoints[i].y = mapPoint.y;
- }
-
- BMKPolygon* polygon = [BMKPolygon polygonWithPoints:temppoints count:mArray.count];
- [_mapView addOverlay:polygon];
- [overlayArray addObject:polygon];
- }
-
-
- //dansonmark 我就想知道 为毛我画的线是这样的呀、、、、、、
- //绘制轨迹
- // BMKMapPoint *temppoints = new BMKMapPoint[pointArray.count];
- // for (int i = 0; i < pointArray.count; i ++) {
- // NSDictionary *dic = pointArray[i];
- // CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([dic[@"LAT"] floatValue], [dic[@"LNG"] floatValue]);
- // BMKMapPoint mapPoint = BMKMapPointForCoordinate(coord);
- // temppoints[i].x = mapPoint.x;
- // temppoints[i].y = mapPoint.y;
- // }
- // BMKPolyline *colorfulPolyline = [BMKPolyline polylineWithPoints:temppoints count:pointArray.count];
- // [_mapView addOverlay:colorfulPolyline];
-
-
- // for (int i = 0; i < pointArray.count - 1; i ++) {
- //
- // BMKMapPoint *temppoints = new BMKMapPoint[2];
- //
- // NSDictionary *dic = pointArray[i];
- // CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([dic[@"LAT"] floatValue], [dic[@"LNG"] floatValue]);
- // BMKMapPoint mapPoint = BMKMapPointForCoordinate(coord);
- // temppoints[0].x = mapPoint.x;
- // temppoints[0].y = mapPoint.y;
- //
- // dic = pointArray[i + 1];
- // coord = CLLocationCoordinate2DMake([dic[@"LAT"] floatValue], [dic[@"LNG"] floatValue]);
- // mapPoint = BMKMapPointForCoordinate(coord);
- // temppoints[1].x = mapPoint.x;
- // temppoints[1].y = mapPoint.y;
- //
- // BMKPolyline *colorfulPolyline = [BMKPolyline polylineWithPoints:temppoints count:2];
- // [_mapView addOverlay:colorfulPolyline];
- // free(temppoints);
- // [overlayArray addObject:colorfulPolyline];
- // }
- }
-
-
- //根据polyline设置地图范围
- - (void)mapViewFitPolyLine:(BMKPolyline *) polyLine {
- CGFloat ltX, ltY, rbX, rbY;
- if (polyLine.pointCount < 1) {
- return;
- }
- BMKMapPoint pt = polyLine.points[0];
- ltX = pt.x, ltY = pt.y;
- rbX = pt.x, rbY = pt.y;
- for (int i = 1; i < polyLine.pointCount; i++) {
- BMKMapPoint pt = polyLine.points[i];
- if (pt.x < ltX) {
- ltX = pt.x;
- }
- if (pt.x > rbX) {
- rbX = pt.x;
- }
- if (pt.y > ltY) {
- ltY = pt.y;
- }
- if (pt.y < rbY) {
- rbY = pt.y;
- }
- }
- BMKMapRect rect;
- rect.origin = BMKMapPointMake(ltX , ltY);
- rect.size = BMKMapSizeMake(rbX - ltX, rbY - ltY);
- [_mapView setVisibleMapRect:rect];
- _mapView.zoomLevel = _mapView.zoomLevel - 0.3;
- }
-
-
- #pragma mark 地图
- //标注
- -(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation
- {
- if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
- BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
- if (annotation.title.length > 0) {
- newAnnotationView.pinColor = BMKPinAnnotationColorRed;
- }else{
- newAnnotationView.pinColor = BMKPinAnnotationColorGreen;
- }
- // 设置该标注点动画显示
- newAnnotationView.animatesDrop = YES;
- return newAnnotationView;
- }
- return nil;
- }
-
-
-
- //- (BOOL)loadStrokeTextureImages:(NSArray *)textureImages
- //{
- // return YES;
- //}
- //根据overlay生成对应的View
- - (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id <BMKOverlay>)overlay
- {
- if ([overlay isKindOfClass:[BMKPolyline class]]) {
- BMKPolylineView *polylineView = [[BMKPolylineView alloc] initWithOverlay:overlay];
- polylineView.lineWidth = 3.0;
-
- polylineView.strokeColor = [UIColor redColor];
- return polylineView;
- }
-
- if ([overlay isKindOfClass:[BMKPolygon class]]){
- BMKPolygonView* polygonView = [[BMKPolygonView alloc] initWithOverlay:overlay];
- polygonView.strokeColor = [[UIColor greenColor] colorWithAlphaComponent:1];
- polygonView.fillColor = [[UIColor clearColor] colorWithAlphaComponent:0.2];
- polygonView.lineWidth = 4.0;
- return polygonView;
- }
- return nil;
- }
-
-
- #pragma mark 数据请求
- //获取学员详情
- - (void)getGpsLocations
- {
- item.enabled = NO;
- if (![Util connectedToNetWork]) {
- //showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"jxbh" Value:defUser.userDict[@"ciSchool"]];
- [arr addPro:@"orderId" Value:_orderId];
- [arr addPro:@"type" Value:_type];
-
- NSString* method = @"getGpsLocations";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- //NSLog(@"轨迹---->%@----->%@",arr,root);
- item.enabled = YES;
- if (!root) {
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- [LoadingView showMsg:root[@"body"]];
- return;
- }
-
- NSDictionary *dataDic = root[@"body"];
- if (![dataDic isKindOfClass:[NSDictionary class]]) {
- [LoadingView showMsg:@"暂无数据"];
- return;
- }
- pointArray = dataDic[@"gps"];
- railArray = dataDic[@"area"];
- [self initMap];
- }];
-
- }
-
-
- */
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- @end
|