Commit dd17385f authored by lmj_521aiau@163.com's avatar lmj_521aiau@163.com

no message

parent 62d37206
No preview for this file type
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
A948C4DA24977B3700C22D69 /* ZJFriendLocationRemindModel.m in Sources */ = {isa = PBXBuildFile; fileRef = A948C4D924977B3700C22D69 /* ZJFriendLocationRemindModel.m */; }; A948C4DA24977B3700C22D69 /* ZJFriendLocationRemindModel.m in Sources */ = {isa = PBXBuildFile; fileRef = A948C4D924977B3700C22D69 /* ZJFriendLocationRemindModel.m */; };
A948C4DF249A27FE00C22D69 /* ZJOauthLoginConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = A948C4DE249A27FE00C22D69 /* ZJOauthLoginConfig.m */; }; A948C4DF249A27FE00C22D69 /* ZJOauthLoginConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = A948C4DE249A27FE00C22D69 /* ZJOauthLoginConfig.m */; };
A948C504249B887B00C22D69 /* ZJGoodsModel.m in Sources */ = {isa = PBXBuildFile; fileRef = A948C503249B887B00C22D69 /* ZJGoodsModel.m */; }; A948C504249B887B00C22D69 /* ZJGoodsModel.m in Sources */ = {isa = PBXBuildFile; fileRef = A948C503249B887B00C22D69 /* ZJGoodsModel.m */; };
A94EE53324D401EB0046038D /* ZJCustomAnnotation.m in Sources */ = {isa = PBXBuildFile; fileRef = A94EE53124D401EB0046038D /* ZJCustomAnnotation.m */; };
A95590932490AE3C00F3BB41 /* QJGIFView.m in Sources */ = {isa = PBXBuildFile; fileRef = A955908D2490AE3C00F3BB41 /* QJGIFView.m */; }; A95590932490AE3C00F3BB41 /* QJGIFView.m in Sources */ = {isa = PBXBuildFile; fileRef = A955908D2490AE3C00F3BB41 /* QJGIFView.m */; };
A95590942490AE3C00F3BB41 /* MBProgressHUD+MJ.m in Sources */ = {isa = PBXBuildFile; fileRef = A955908E2490AE3C00F3BB41 /* MBProgressHUD+MJ.m */; }; A95590942490AE3C00F3BB41 /* MBProgressHUD+MJ.m in Sources */ = {isa = PBXBuildFile; fileRef = A955908E2490AE3C00F3BB41 /* MBProgressHUD+MJ.m */; };
A95590952490AE3C00F3BB41 /* MBProgressHUD.bundle in Resources */ = {isa = PBXBuildFile; fileRef = A95590902490AE3C00F3BB41 /* MBProgressHUD.bundle */; }; A95590952490AE3C00F3BB41 /* MBProgressHUD.bundle in Resources */ = {isa = PBXBuildFile; fileRef = A95590902490AE3C00F3BB41 /* MBProgressHUD.bundle */; };
...@@ -281,6 +282,8 @@ ...@@ -281,6 +282,8 @@
A948C4DE249A27FE00C22D69 /* ZJOauthLoginConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ZJOauthLoginConfig.m; sourceTree = "<group>"; }; A948C4DE249A27FE00C22D69 /* ZJOauthLoginConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ZJOauthLoginConfig.m; sourceTree = "<group>"; };
A948C502249B887B00C22D69 /* ZJGoodsModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ZJGoodsModel.h; sourceTree = "<group>"; }; A948C502249B887B00C22D69 /* ZJGoodsModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ZJGoodsModel.h; sourceTree = "<group>"; };
A948C503249B887B00C22D69 /* ZJGoodsModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ZJGoodsModel.m; sourceTree = "<group>"; }; A948C503249B887B00C22D69 /* ZJGoodsModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ZJGoodsModel.m; sourceTree = "<group>"; };
A94EE53124D401EB0046038D /* ZJCustomAnnotation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZJCustomAnnotation.m; sourceTree = "<group>"; };
A94EE53224D401EB0046038D /* ZJCustomAnnotation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZJCustomAnnotation.h; sourceTree = "<group>"; };
A955908B2490AE3C00F3BB41 /* MBProgressHUD+MJ.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MBProgressHUD+MJ.h"; sourceTree = "<group>"; }; A955908B2490AE3C00F3BB41 /* MBProgressHUD+MJ.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MBProgressHUD+MJ.h"; sourceTree = "<group>"; };
A955908D2490AE3C00F3BB41 /* QJGIFView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QJGIFView.m; sourceTree = "<group>"; }; A955908D2490AE3C00F3BB41 /* QJGIFView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QJGIFView.m; sourceTree = "<group>"; };
A955908E2490AE3C00F3BB41 /* MBProgressHUD+MJ.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MBProgressHUD+MJ.m"; sourceTree = "<group>"; }; A955908E2490AE3C00F3BB41 /* MBProgressHUD+MJ.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MBProgressHUD+MJ.m"; sourceTree = "<group>"; };
...@@ -1081,6 +1084,8 @@ ...@@ -1081,6 +1084,8 @@
A9619E7F24AAE2A8009A2012 /* ZJMapStyle2ViewController.m */, A9619E7F24AAE2A8009A2012 /* ZJMapStyle2ViewController.m */,
64F52440248F34DB0032BCA2 /* ZJFriendTrackMapViewController.h */, 64F52440248F34DB0032BCA2 /* ZJFriendTrackMapViewController.h */,
64F52441248F34DB0032BCA2 /* ZJFriendTrackMapViewController.m */, 64F52441248F34DB0032BCA2 /* ZJFriendTrackMapViewController.m */,
A94EE53224D401EB0046038D /* ZJCustomAnnotation.h */,
A94EE53124D401EB0046038D /* ZJCustomAnnotation.m */,
); );
path = Controller; path = Controller;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -1552,6 +1557,7 @@ ...@@ -1552,6 +1557,7 @@
A95F5C62248DDE81001DB97E /* UILabel+HExtension.m in Sources */, A95F5C62248DDE81001DB97E /* UILabel+HExtension.m in Sources */,
A95F5C61248DDE81001DB97E /* UIView+HExtension.m in Sources */, A95F5C61248DDE81001DB97E /* UIView+HExtension.m in Sources */,
A948C4782493578A00C22D69 /* ZJFriendModel.m in Sources */, A948C4782493578A00C22D69 /* ZJFriendModel.m in Sources */,
A94EE53324D401EB0046038D /* ZJCustomAnnotation.m in Sources */,
A9619E8224AAE2A8009A2012 /* ZJBaseMapViewController.m in Sources */, A9619E8224AAE2A8009A2012 /* ZJBaseMapViewController.m in Sources */,
D5271ED324907E6100F8B107 /* ZJLocationAttentionFooter.swift in Sources */, D5271ED324907E6100F8B107 /* ZJLocationAttentionFooter.swift in Sources */,
A95F5C98248DDE81001DB97E /* ZJPhoneLoginViewController.m in Sources */, A95F5C98248DDE81001DB97E /* ZJPhoneLoginViewController.m in Sources */,
......
...@@ -7,11 +7,12 @@ ...@@ -7,11 +7,12 @@
// //
#import "ZJBaseMapViewController.h" #import "ZJBaseMapViewController.h"
#import <MapKit/MapKit.h>
#import "ZJCustomAnnotation.h"
@interface ZJBaseMapViewController ()<MAMapViewDelegate, XMPopupListViewDelegate> @interface ZJBaseMapViewController ()<XMPopupListViewDelegate, MKMapViewDelegate>
@property (nonatomic, strong) MAMapView *mapView; @property (nonatomic, strong) MKMapView *mapView;
@property (nonatomic, strong) UIButton *gpsButton;
@property (nonatomic, strong) ZJMapViewPersonCardView *cardView; @property (nonatomic, strong) ZJMapViewPersonCardView *cardView;
...@@ -25,12 +26,10 @@ ...@@ -25,12 +26,10 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
// Do any additional setup after loading the view.
[self setupUI];
self.friendDataSource = [NSMutableArray array]; self.friendDataSource = [NSMutableArray array];
[self setupUI];
[self getFriendList]; [self getFriendList];
} }
...@@ -49,26 +48,15 @@ ...@@ -49,26 +48,15 @@
- (void)setupUI{ - (void)setupUI{
///初始化地图 ///初始化地图
self.mapView = [[MAMapView alloc] initWithFrame:self.view.bounds]; self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
_mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; _mapView.showsUserLocation = YES;
///把地图添加至view _mapView.userTrackingMode = MKUserTrackingModeFollow;
[self.view addSubview: _mapView];
self.mapView.mapType = 0;
_mapView.showsWorldMap = @YES;
[self.mapView performSelector:@selector(setShowsWorldMap:) withObject:@(YES)];
if ([ZJUserInfoManager CNLanguage]) {
self.mapView.mapLanguage = @0;
[self.mapView performSelector:NSSelectorFromString(@"setMapLanguage:") withObject:@(0)];
}else{
self.mapView.mapLanguage = @1;
[self.mapView performSelector:NSSelectorFromString(@"setMapLanguage:") withObject:@(1)];
}
_mapView.delegate = self; _mapView.delegate = self;
_mapView.zoomLevel = 14;
_mapView.showsScale = false; _mapView.showsScale = false;
_mapView.showsCompass = false; _mapView.showsCompass = false;
_mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
///把地图添加至view
[self.view addSubview: _mapView];
// 添加 card view // 添加 card view
self.cardView = [[[NSBundle mainBundle] loadNibNamed:@"ZJMapViewPersonCardView" owner:self options:nil] lastObject]; self.cardView = [[[NSBundle mainBundle] loadNibNamed:@"ZJMapViewPersonCardView" owner:self options:nil] lastObject];
...@@ -120,30 +108,6 @@ ...@@ -120,30 +108,6 @@
}; };
} }
- (void)mapView:(UIView *)mapView regionDidChangeAnimated:(BOOL)animated {
// if(mapView.isHidden) {
// return;
// }
//
// if(self.isSwitching) {
// self.isSwitching = NO;
// return;
// }
// [self.mapView performSelector:NSSelectorFromString(@"setMapLanguage:") withObject:@(1)];
// [self.mapView performSelector:NSSelectorFromString(@"setMapLanguage:") withObject:@(0)];
if([mapView isKindOfClass:[MAMapView class]]) {
if(!AMapDataAvailableForCoordinate(self.mapView.centerCoordinate)) {
}
} else {
if(AMapDataAvailableForCoordinate(self.mapView.centerCoordinate)) {
}
}
}
#pragma mark 好友列表 #pragma mark 好友列表
- (void)getFriendList{ - (void)getFriendList{
...@@ -151,7 +115,7 @@ ...@@ -151,7 +115,7 @@
//未登录 //未登录
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
_mapView.showsUserLocation = YES; _mapView.showsUserLocation = YES;
_mapView.userTrackingMode = MAUserTrackingModeFollow; _mapView.userTrackingMode = MKUserTrackingModeFollow;
return; return;
} }
[self.friendDataSource removeAllObjects]; [self.friendDataSource removeAllObjects];
...@@ -172,7 +136,7 @@ ...@@ -172,7 +136,7 @@
[weakSelf.style2BgImV setHidden:false]; [weakSelf.style2BgImV setHidden:false];
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
weakSelf.mapView.showsUserLocation = YES; weakSelf.mapView.showsUserLocation = YES;
weakSelf.mapView.userTrackingMode = MAUserTrackingModeFollow; weakSelf.mapView.userTrackingMode = MKUserTrackingModeFollow;
} else { } else {
[weakSelf.cardView setHidden:false]; [weakSelf.cardView setHidden:false];
[weakSelf.addCareButton setHidden:true]; [weakSelf.addCareButton setHidden:true];
...@@ -198,7 +162,7 @@ ...@@ -198,7 +162,7 @@
} }
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
weakSelf.mapView.showsUserLocation = YES; weakSelf.mapView.showsUserLocation = YES;
weakSelf.mapView.userTrackingMode = MAUserTrackingModeFollow; weakSelf.mapView.userTrackingMode = MKUserTrackingModeFollow;
// [MBProgressHUD showError:[NSString stringWithFormat:@"获取好友列表失败\n%@", [response objectForKey:@"msg"]] toView:self.view]; // [MBProgressHUD showError:[NSString stringWithFormat:@"获取好友列表失败\n%@", [response objectForKey:@"msg"]] toView:self.view];
} }
...@@ -206,13 +170,6 @@ ...@@ -206,13 +170,6 @@
// [MBProgressHUD showError:[NSString stringWithFormat:@"获取好友列表失败\n%@", error.description] toView:self.view]; // [MBProgressHUD showError:[NSString stringWithFormat:@"获取好友列表失败\n%@", error.description] toView:self.view];
}]; }];
} }
#pragma mark - Action Handlers
- (void)returnAction
{
[self.navigationController popViewControllerAnimated:YES];
}
/** /**
选中cell后回调 选中cell后回调
@param indexPath 返回选中的indexPath @param indexPath 返回选中的indexPath
...@@ -249,13 +206,15 @@ ...@@ -249,13 +206,15 @@
double lat = [response[@"result"][@"data"][@"lat"] doubleValue]; double lat = [response[@"result"][@"data"][@"lat"] doubleValue];
double lon = [response[@"result"][@"data"][@"lon"] doubleValue]; double lon = [response[@"result"][@"data"][@"lon"] doubleValue];
MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
ZJCustomAnnotation *pointAnnotation = [[ZJCustomAnnotation alloc] init];
pointAnnotation.coordinate = CLLocationCoordinate2DMake(lat, lon); pointAnnotation.coordinate = CLLocationCoordinate2DMake(lat, lon);
pointAnnotation.title = @"latestLocation"; pointAnnotation.title = @"latestLocation";
[_self.mapView addAnnotation:pointAnnotation]; [_self.mapView addAnnotation:pointAnnotation];
[_self.mapView setCenterCoordinate:pointAnnotation.coordinate animated:false]; [_self.mapView setCenterCoordinate:pointAnnotation.coordinate animated:false];
}else if ([[response objectForKey:@"status"] integerValue] == 105) { }else{
[MBProgressHUD showError:[response objectForKey:@"msg"] toView:self.view]; [MBProgressHUD showError:[response objectForKey:@"msg"] toView:self.view];
} }
...@@ -266,13 +225,26 @@ ...@@ -266,13 +225,26 @@
} }
#pragma mark - Map Delegate #pragma mark - Map Delegate
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation { - (nullable MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
if([annotation isKindOfClass:[MAPointAnnotation class]]) { if([annotation isKindOfClass:[ZJCustomAnnotation class]]) {
NSString *pointReuseIndetifier = @"pointReuseIndetifier3";
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
if (annotationView == nil) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndetifier];
annotationView.canShowCallout = YES;
}
annotationView.image = [UIImage imageNamed:@"userPosition"];
annotationView.enabled = NO;
return annotationView;
}
else if([annotation isKindOfClass:[MKUserLocation class]]){
NSString *pointReuseIndetifier = @"pointReuseIndetifier3"; NSString *pointReuseIndetifier = @"pointReuseIndetifier3";
MAAnnotationView *annotationView = (MAAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier]; MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
if (annotationView == nil) { if (annotationView == nil) {
annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndetifier]; annotationView = [[MKAnnotationView alloc] initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:pointReuseIndetifier];
annotationView.canShowCallout = YES; annotationView.canShowCallout = YES;
} }
......
//
// ZJCustomAnnotation.h
// ZhiJi
//
// Created by 明津李 on 2020/7/27.
// Copyright © 2020 Company. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface ZJCustomAnnotation : NSObject<MKAnnotation>
@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic,copy) NSString * title;
@property (nonatomic,copy) NSString * subtitle;
@end
NS_ASSUME_NONNULL_END
//
// ZJCustomAnnotation.m
// ZhiJi
//
// Created by 明津李 on 2020/7/27.
// Copyright © 2020 Company. All rights reserved.
//
#import "ZJCustomAnnotation.h"
@implementation ZJCustomAnnotation
@end
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
// //
#import "ZJFriendTrackMapViewController.h" #import "ZJFriendTrackMapViewController.h"
#import <MAMapKit/MAMapKit.h>
#import <AMapFoundationKit/AMapFoundationKit.h>
#import "ZJUserTrackTimeView.h" #import "ZJUserTrackTimeView.h"
#import "ZhiJi-Swift.h" #import "ZhiJi-Swift.h"
#import "ZJUserInfoManager.h" #import "ZJUserInfoManager.h"
...@@ -18,24 +16,43 @@ ...@@ -18,24 +16,43 @@
#import "AlertControllerTool.h" #import "AlertControllerTool.h"
#import <CoreLocation/CoreLocation.h> #import <CoreLocation/CoreLocation.h>
#import "BaseWebViewController.h" #import "BaseWebViewController.h"
#import <MapKit/MapKit.h>
#import "ZJCustomAnnotation.h"
@interface ZJFriendTrackMapViewController () <MAMapViewDelegate> #define AnimationDuration 8
@property (nonatomic, strong) MAMapView *mapView; @interface ZJFriendTrackMapViewController () <MKMapViewDelegate, CAAnimationDelegate>{
@property (nonatomic, strong) UIButton *gpsButton; float* hues;
@property (nonatomic, strong) ZJUserTrackTimeView *trackTimeView; float *velocity;
@property (nonatomic, strong) NSMutableArray<ZJLocationModel *> *locations; ZJCustomAnnotation * endAnnotation;
BOOL mapPaddle;
}
@property (nonatomic, strong) ZJUserTrackTimeView *trackTimeView;
@property (strong, nonatomic) NSDate *stratDate; @property (strong, nonatomic) NSDate *stratDate;
@property (strong, nonatomic) NSDate *endDate; @property (strong, nonatomic) NSDate *endDate;
///全轨迹overlay
@property (strong, nonatomic) MAPolyline *commonPolyline;
///车头方向跟随转动
@property (nonatomic, strong) MAAnimatedAnnotation *track;
@property (nonatomic, strong) NSArray *distanceArray;
@property (nonatomic, assign) double sumDistance;
@property (nonatomic, strong) ZJAlertView *alertView; @property (nonatomic, strong) ZJAlertView *alertView;
@property (nonatomic, strong) MKMapView *mapView;
@property (nonatomic, strong) UIView * container;
@property (nonatomic, strong) NSMutableArray<ZJLocationModel *> *locations;
///全轨迹overlay
@property (strong, nonatomic) MKPolyline *commonPolyline;
@property (nonatomic, strong) ZJCustomAnnotation * startAnnotation;
@property (nonatomic, strong) MKAnnotationView * startAnnotationView;
@property (nonatomic, strong) MKAnnotationView * endAnnotationView;
@property (nonatomic, strong) CAShapeLayer * shapeLayer;
@property (nonatomic, assign) NSInteger smoothTrackCount;
@property (nonatomic, assign) BOOL trackAnimation;
@property (nonatomic, assign) CLLocationCoordinate2D * smoothTrackPoints;
@property (nonatomic, strong) CALayer * gradientLayer;
@property (nonatomic, strong) NSMutableArray * gradientColors;
@end @end
@implementation ZJFriendTrackMapViewController @implementation ZJFriendTrackMapViewController
...@@ -91,7 +108,6 @@ ...@@ -91,7 +108,6 @@
self.alertView.alertSubtitle.text = kLocalizedString(@"track_friend_authority_alert"); self.alertView.alertSubtitle.text = kLocalizedString(@"track_friend_authority_alert");
} }
[self.alertView.leftButton addTapBlock:^(UITapGestureRecognizer *tap) { [self.alertView.leftButton addTapBlock:^(UITapGestureRecognizer *tap) {
NSLog(@"%@", @"leftButton"); NSLog(@"%@", @"leftButton");
...@@ -137,30 +153,21 @@ ...@@ -137,30 +153,21 @@
- (void)setupUI { - (void)setupUI {
///初始化地图 ///初始化地图
self.mapView = [[MAMapView alloc] initWithFrame:self.view.bounds]; self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
_mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.mapView.mapType = 0;
_mapView.showsWorldMap = @YES;
[self.mapView performSelector:@selector(setShowsWorldMap:) withObject:@(YES)];
if ([ZJUserInfoManager CNLanguage]) {
self.mapView.mapLanguage = @0;
[self.mapView performSelector:NSSelectorFromString(@"setMapLanguage:") withObject:@(0)];
}else{
self.mapView.mapLanguage = @1;
[self.mapView performSelector:NSSelectorFromString(@"setMapLanguage:") withObject:@(1)];
}
///把地图添加至view
[self.view addSubview: _mapView];
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
_mapView.showsUserLocation = false; // _mapView.showsUserLocation = false;
_mapView.showsUserLocation = YES;
_mapView.userTrackingMode = MKUserTrackingModeFollow;
_mapView.delegate = self; _mapView.delegate = self;
_mapView.zoomLevel = 14;
_mapView.showsScale = false; _mapView.showsScale = false;
_mapView.showsCompass = false; _mapView.showsCompass = false;
_mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
///把地图添加至view
[self.view addSubview: _mapView];
MKCircle * transparentCircle = [MKCircle circleWithCenterCoordinate:CLLocationCoordinate2DMake(39.905, 116.398) radius:100000000];
[self.mapView addOverlay:transparentCircle level:1];
// 添加 card view // 添加 card view
self.trackTimeView = [[[NSBundle mainBundle] loadNibNamed:@"ZJUserTrackTimeView" owner:self options:nil] lastObject]; self.trackTimeView = [[[NSBundle mainBundle] loadNibNamed:@"ZJUserTrackTimeView" owner:self options:nil] lastObject];
[self.view addSubview: _trackTimeView]; [self.view addSubview: _trackTimeView];
...@@ -187,191 +194,191 @@ ...@@ -187,191 +194,191 @@
weakSelf.stratDate = beginDate; weakSelf.stratDate = beginDate;
weakSelf.endDate = endDate; weakSelf.endDate = endDate;
}; };
mapPaddle = YES;
self.track = [[MAAnimatedAnnotation alloc] init];
self.track.title = @"pointReuseIndetifier1";
[self.mapView addAnnotation:self.track];
} }
- (void) drawLineAction { - (void)drawLineAction{
if (self.isMyTrack) { //重制
[MobClick event:@"mytrack_querybutton_click"]; // _endAnnotationView = nil;
}else{ // _startAnnotationView = nil;
[MobClick event:@"friendtrack_querybutton_click"]; [self.mapView removeOverlays:self.mapView.overlays];
} [self.mapView removeAnnotations:self.mapView.annotations];
[self.trackTimeView.trackButton setSelected:true]; _trackAnimation = YES;
[self.trackTimeView.trackButton setEnabled:false];
//移除
[self.mapView removeOverlay:self.commonPolyline];
// need get user location info
if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)) {
// do nothing
} else if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) {
//定位不能用
[AlertControllerTool alertControllerWithTitle:kLocalizedString(@"alert_location_switch") message:kLocalizedString(@"alert_location_service") cancelTitle:kLocalizedString(@"alert_cancel") cancelBlock:^{
} confirm:kLocalizedString(@"alert_setting") confirmBlock:^(id s) {
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if([[UIApplication sharedApplication] canOpenURL:url]) {
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}else{
[[UIApplication sharedApplication] openURL:url];
}
}
} finishBlock:nil];
return;
}
MAPointAnnotation *pointAnnotation1 = [[MAPointAnnotation alloc] init];
pointAnnotation1.coordinate = CLLocationCoordinate2DMake(self.locations.firstObject.latitude, self.locations.firstObject.longitude);
pointAnnotation1.title = @"start";
[self.mapView addAnnotation:pointAnnotation1];
//构造折线数据对象 //构造折线数据对象
CLLocationCoordinate2D commonPolylineCoords[self.locations.count]; CLLocationCoordinate2D commonPolylineCoords[self.locations.count];
for (int i = 0 ; i < self.locations.count; i++) { for (int i = 0 ; i < self.locations.count; i++) {
commonPolylineCoords[i].latitude = self.locations[i].latitude; commonPolylineCoords[i].latitude = self.locations[i].latitude;
commonPolylineCoords[i].longitude = self.locations[i].longitude; commonPolylineCoords[i].longitude = self.locations[i].longitude;
} }
MAPointAnnotation *pointAnnotation2 = [[MAPointAnnotation alloc] init];
pointAnnotation2.coordinate = CLLocationCoordinate2DMake(self.locations.lastObject.latitude, self.locations.lastObject.longitude);
pointAnnotation2.title = @"end";
[self.mapView addAnnotation:pointAnnotation2];
//构造折线对象 //构造折线对象
MAPolyline *commonPolyline = [MAPolyline polylineWithCoordinates:commonPolylineCoords count:self.locations.count]; MKPolyline *commonPolyline = [MKPolyline polylineWithCoordinates:commonPolylineCoords count:self.locations.count];
if (self.commonPolyline.boundingMapRect.origin.x != commonPolyline.boundingMapRect.origin.x ||
self.commonPolyline.boundingMapRect.origin.y != commonPolyline.boundingMapRect.origin.y ||
self.commonPolyline.boundingMapRect.size.width != commonPolyline.boundingMapRect.size.width ||
self.commonPolyline.boundingMapRect.size.height != commonPolyline.boundingMapRect.size.height) {
mapPaddle = YES;
}
self.commonPolyline = commonPolyline; self.commonPolyline = commonPolyline;
// self.commonPolyline.boundingMapRect
//在地图上添加折线对象 //在地图上添加折线对象
[self.mapView addOverlay: commonPolyline]; [self.mapView addOverlay: self.commonPolyline];
int count = sizeof(commonPolylineCoords) / sizeof(commonPolylineCoords[0]); //动画行动点
self.mapView.centerCoordinate = commonPolylineCoords[count/2]; endAnnotation = [[ZJCustomAnnotation alloc] init];
double sum = 0; endAnnotation.title = @"end";
NSMutableArray *arr = [NSMutableArray arrayWithCapacity:count]; [_mapView addAnnotation:endAnnotation];
for(int i = 0; i < count - 1; ++i) {
CLLocation *begin = [[CLLocation alloc] initWithLatitude:commonPolylineCoords[i].latitude longitude:commonPolylineCoords[i].longitude]; MKMapRect rect = MKMapRectMake(self.commonPolyline.boundingMapRect.origin.x, self.commonPolyline.boundingMapRect.origin.y, self.commonPolyline.boundingMapRect.size.width, self.commonPolyline.boundingMapRect.size.height);
CLLocation *end = [[CLLocation alloc] initWithLatitude:commonPolylineCoords[i+1].latitude longitude:commonPolylineCoords[i+1].longitude];
CLLocationDistance distance = [end distanceFromLocation:begin]; [self.mapView setVisibleMapRect:rect edgePadding:UIEdgeInsetsMake(40, 40, 40, 40) animated:true];
[arr addObject:[NSNumber numberWithDouble:distance]]; if (!mapPaddle) {
sum += distance; [self addAnimation];
} }
}
//开始动画
- (void)addAnimation{
self.distanceArray = arr; _container = (UIView *)[self.mapView.subviews firstObject].subviews.lastObject;
self.sumDistance = sum;
double speed_car1 = self.sumDistance / 12; //80 km/h //动画 路径 数据处理
// int count1 = sizeof(commonPolylineCoords) / sizeof(commonPolylineCoords[0]); _smoothTrackCount = _locations.count;
[self.track setCoordinate:commonPolylineCoords[0]]; _smoothTrackPoints = malloc(sizeof(CLLocationCoordinate2D)*_smoothTrackCount);
__weak typeof(self) weakSelf = self; velocity = malloc(sizeof(float)*_smoothTrackCount);
[self.track addMoveAnimationWithKeyCoordinates:commonPolylineCoords count:count withDuration:self.sumDistance / speed_car1 withName:nil completeCallback:^(BOOL isFinished) {
[weakSelf.trackTimeView.trackButton setEnabled:true]; for(int i=0;i<_smoothTrackCount;i++){
[weakSelf.trackTimeView.trackButton setSelected:false]; @autoreleasepool {
}]; ZJLocationModel *model = [self.locations objectAtIndex:i];
[self.mapView setVisibleMapRect:self.commonPolyline.boundingMapRect edgePadding:UIEdgeInsetsMake(250, 50, 50, 50) animated:true]; CLLocationDegrees latitude = model.latitude;
CLLocationDegrees longitude = model.longitude;
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
// velocity[i] = [dic[@"speed"] doubleValue];
velocity[i] = 0.1;
_smoothTrackPoints[i] = coordinate;
}
}
} CGPoint *points = [self pointsForCoordinates:_smoothTrackPoints count:_smoothTrackCount];
CGPathRef path = [self pathForPoints:points count:_smoothTrackCount];
[self initShapeLayerWithPath:path];
self.shapeLayer.frame = self.mapView.bounds;
- (ZJAlertView *)getAlertView:(NSString *)title subtitle:(NSString *)subtitle leftButtonTitle:(NSString *)leftButtonTitle rightButtonTitle:(NSString *)rightButtonTitle { CAAnimation *shapeLayerAnimation = [self constructShapeLayerAnimation];
ZJAlertView* alertView = [[[NSBundle mainBundle]loadNibNamed:@"ZJAlertView" owner:self options:nil]lastObject]; shapeLayerAnimation.delegate = self;
alertView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); shapeLayerAnimation.removedOnCompletion = NO;
alertView.alertTitle.text = title; shapeLayerAnimation.fillMode = kCAFillModeForwards;
alertView.alertSubtitle.text = subtitle; [self.shapeLayer addAnimation:shapeLayerAnimation forKey:@"shape"];
[alertView.leftButton setTitle:leftButtonTitle forState:UIControlStateNormal]; [self.container.layer addSublayer:self.shapeLayer];
[alertView.rightButton setTitle:rightButtonTitle forState:UIControlStateNormal];
alertView.backgroundColor = [UIColor colorWithHex:000000 alpha:0.5]; [self initGradientLayerWithPoints:points Count:_smoothTrackCount];
__weak typeof(alertView) weakAlertView = alertView;
[alertView addTapBlock:^(UITapGestureRecognizer *tap) { ZJLocationModel * model = self.locations[0];
[weakAlertView removeFromSuperview]; [endAnnotation setCoordinate:CLLocationCoordinate2DMake(model.latitude, model.longitude)];
}];
UIView *window = [UIApplication sharedApplication].keyWindow.rootViewController.view; _endAnnotationView = [self.mapView viewForAnnotation:endAnnotation];
[window addSubview:alertView]; CAAnimation *annotationAnimation = [self constructAnnotationAnimationWithPath:path];
return alertView; _endAnnotationView.image = [UIImage imageNamed:kLocalizedString(@"map_track_end_icon")];
[_endAnnotationView.layer addAnimation:annotationAnimation forKey:@"annotation"];
[_endAnnotationView.annotation setCoordinate:_smoothTrackPoints[_smoothTrackCount - 1]];
[self.trackTimeView.trackButton setSelected:true];
[self.trackTimeView.trackButton setEnabled:false];
self.mapView.userInteractionEnabled = NO;
[self performSelector:@selector(removeLayer) withObject:nil afterDelay:AnimationDuration + 0.33];
(void)(free(points)), points = NULL;
(void)(CGPathRelease(path)), path = NULL;
_trackAnimation = NO;
mapPaddle = NO;
}
//动画结束
- (void)removeLayer{
_mapView.userInteractionEnabled = YES;
[self.trackTimeView.trackButton setSelected:false];
[self.trackTimeView.trackButton setEnabled:true];
[self.gradientLayer removeFromSuperlayer];
[self.shapeLayer removeFromSuperlayer];
_startAnnotation = [[ZJCustomAnnotation alloc] init];
_startAnnotation.coordinate = CLLocationCoordinate2DMake(self.locations.firstObject.latitude, self.locations.firstObject.longitude);
_startAnnotation.title = @"start";
[self.mapView addAnnotation:(id<MKAnnotation>)_startAnnotation];
} }
#pragma mark - Map Delegate #pragma mark - Map Delegate
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
mapPaddle = YES;
if (_trackAnimation) {
[self addAnimation];
}
}
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation { - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if (annotation == self.track) { if ([annotation isKindOfClass:[ZJCustomAnnotation class]]) {
NSString *pointReuseIndetifier = @"pointReuseIndetifier1"; ZJCustomAnnotation * ann = (ZJCustomAnnotation *)annotation;
if ([ann.title isEqualToString:@"start"]) {
MAAnnotationView *annotationView = (MAAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier]; NSString *pointReuseIndetifier = @"startAnnotation";
if(!annotationView) { MKAnnotationView *annotationView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndetifier]; if (annotationView == nil) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:pointReuseIndetifier];
annotationView.canShowCallout = YES; annotationView.canShowCallout = YES;
}
UIImage *imge = [UIImage imageNamed:@"map_track_move_icon"];
annotationView.image = imge; annotationView.enabled = NO;
annotationView.image = [UIImage imageNamed:kLocalizedString(@"map_track_start_icon")];
_startAnnotationView = (MKAnnotationView *)annotationView;
return annotationView;
}else{
static NSString * key = @"endAnnotation";
MKAnnotationView * annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:key];
if (!annotationView) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:key];
annotationView.canShowCallout = true; //允许交互点击
annotationView.calloutOffset = CGPointMake(0, 0); //定义详情视图偏移量
}
annotationView.annotation = annotation;
return annotationView;
} }
}else if([annotation isKindOfClass:[MKUserLocation class]]){
return annotationView;
} else if([annotation isKindOfClass:[MAPointAnnotation class]]) { NSString *pointReuseIndetifier = @"pointReuseIndetifier1";
MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
NSString *pointReuseIndetifier = @"pointReuseIndetifier3";
MAAnnotationView *annotationView = (MAAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
if (annotationView == nil) { if (annotationView == nil) {
annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndetifier]; annotationView = [[MKAnnotationView alloc] initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:pointReuseIndetifier];
annotationView.canShowCallout = YES; annotationView.canShowCallout = YES;
} }
if ([annotation.title isEqualToString:@"start"]) { annotationView.enabled = NO;
annotationView.enabled = NO; annotationView.image = [UIImage imageNamed:@"userPosition"];
annotationView.image = [UIImage imageNamed:kLocalizedString(@"map_track_start_icon")]; // [mapView viewForAnnotation:mapView.userLocation]
} else if ([annotation.title isEqualToString:@"end"]) {
annotationView.enabled = NO;
annotationView.image = [UIImage imageNamed:kLocalizedString(@"map_track_end_icon")];
} else {
annotationView.enabled = NO;
annotationView.image = [UIImage imageNamed:@"userPosition"];
}
return annotationView; return annotationView;
} }
return nil; return nil;
} }
/// 设置折线的样式 /// 设置折线的样式
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay{
{
if ([overlay isKindOfClass:[MAPolyline class]]) { if([overlay isKindOfClass:[MKPolyline class]]){
MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:overlay]; MKPolylineRenderer *render = [[MKPolylineRenderer alloc] initWithOverlay:overlay];
render.lineWidth = 4.f;
polylineRenderer.lineWidth = 4.f; render.strokeColor = [UIColor colorWithHex:0x568EFC];
polylineRenderer.strokeColor = [UIColor colorWithHex:0x568EFC]; render.lineJoin = kCGLineJoinRound;
polylineRenderer.lineJoinType = kMALineJoinRound; render.lineCap = kCGLineJoinRound;
polylineRenderer.lineCapType = kMALineCapRound; return render;
return polylineRenderer;
} }
return nil; return nil;
} }
//- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
//{
// 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];
// }
//// annotationView.image = [UIImage imageNamed:@"gpsStat2"];
// //设置中心点偏移,使得标注底部中间点成为经纬度对应点
//// annotationView.centerOffset = CGPointMake(0, -18);
// return annotationView;
// }
// return nil;
//}
#pragma mark 查询轨迹 #pragma mark 查询轨迹
- (void)queryLocationList:(ZJFriendModel *)model{ - (void)queryLocationList:(ZJFriendModel *)model{
...@@ -384,13 +391,13 @@ ...@@ -384,13 +391,13 @@
if ([ZJUserInfoManager shared].uid.length <= 0) { if ([ZJUserInfoManager shared].uid.length <= 0) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
self.mapView.showsUserLocation = YES; self.mapView.showsUserLocation = YES;
self.mapView.userTrackingMode = MAUserTrackingModeFollow; self.mapView.userTrackingMode = MKUserTrackingModeFollow;
return; return;
} }
if ([ZJUserInfoManager shared].token.length <= 0) { if ([ZJUserInfoManager shared].token.length <= 0) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
self.mapView.showsUserLocation = YES; self.mapView.showsUserLocation = YES;
self.mapView.userTrackingMode = MAUserTrackingModeFollow; self.mapView.userTrackingMode = MKUserTrackingModeFollow;
return; return;
} }
...@@ -426,14 +433,9 @@ ...@@ -426,14 +433,9 @@
} }
} }
} }
// [self.locations sortUsingComparator:^NSComparisonResult(ZJLocationModel *obj1, ZJLocationModel *obj2) {
// return (obj1.latitude < obj2.latitude);
// }];
NSLog(@"%@", self.locations); NSLog(@"%@", self.locations);
if (_self.locations.count <= 0) { if (_self.locations.count == 0) {
[_self showAlertView]; [_self showAlertView];
// [MBProgressHUD showMessage:kLocalizedString(@"track_friend_timeWithin_no_location")];
return; return;
} }
[_self drawLineAction]; [_self drawLineAction];
...@@ -454,7 +456,7 @@ ...@@ -454,7 +456,7 @@
if ([ZJUserInfoManager shared].uid.length <= 0 || ![ZJUserInfoManager shared].isMember) { if ([ZJUserInfoManager shared].uid.length <= 0 || ![ZJUserInfoManager shared].isMember) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
self.mapView.showsUserLocation = YES; self.mapView.showsUserLocation = YES;
self.mapView.userTrackingMode = MAUserTrackingModeFollow; self.mapView.userTrackingMode = MKUserTrackingModeFollow;
return; return;
} }
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
...@@ -463,7 +465,7 @@ ...@@ -463,7 +465,7 @@
if (uid.length <= 0) { if (uid.length <= 0) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
self.mapView.showsUserLocation = YES; self.mapView.showsUserLocation = YES;
self.mapView.userTrackingMode = MAUserTrackingModeFollow; self.mapView.userTrackingMode = MKUserTrackingModeFollow;
uid = [ZJUserInfoManager shared].uid; uid = [ZJUserInfoManager shared].uid;
} }
[[TQNetworkTools shared] getWithAction:getLocationDataLast parameters:@{@"tid": uid} success:^(id _Nonnull response) { [[TQNetworkTools shared] getWithAction:getLocationDataLast parameters:@{@"tid": uid} success:^(id _Nonnull response) {
...@@ -478,7 +480,7 @@ ...@@ -478,7 +480,7 @@
double lat = [response[@"result"][@"data"][@"lat"] doubleValue]; double lat = [response[@"result"][@"data"][@"lat"] doubleValue];
double lon = [response[@"result"][@"data"][@"lon"] doubleValue]; double lon = [response[@"result"][@"data"][@"lon"] doubleValue];
MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init]; MKPointAnnotation *pointAnnotation = [[MKPointAnnotation alloc] init];
pointAnnotation.coordinate = CLLocationCoordinate2DMake(lat, lon); pointAnnotation.coordinate = CLLocationCoordinate2DMake(lat, lon);
pointAnnotation.title = @"latestLocation"; pointAnnotation.title = @"latestLocation";
[_self.mapView addAnnotation:pointAnnotation]; [_self.mapView addAnnotation:pointAnnotation];
...@@ -491,7 +493,186 @@ ...@@ -491,7 +493,186 @@
} failure:^(NSError * _Nonnull error) { } failure:^(NSError * _Nonnull error) {
NSLog(@"失败"); NSLog(@"失败");
}]; }];
}
#pragma mark - 构造shapeLayer
- (void)initShapeLayerWithPath:(CGPathRef)path{
self.shapeLayer = [[CAShapeLayer alloc] init];
self.shapeLayer.strokeColor = [UIColor greenColor].CGColor;
self.shapeLayer.fillColor = [UIColor clearColor].CGColor;
self.shapeLayer.lineJoin = kCALineCapRound;
self.shapeLayer.lineWidth = 3;
self.shapeLayer.path = path;
}
#pragma mark - 经纬度转屏幕坐标, 调用者负责释放内存!
- (CGPoint *)pointsForCoordinates:(CLLocationCoordinate2D *)coordinates count:(NSUInteger)count{
if (coordinates == NULL || count <= 1){
return NULL;
}
/* 申请屏幕坐标存储空间. */
CGPoint *points = (CGPoint *)malloc(count * sizeof(CGPoint));
/* 经纬度转换为屏幕坐标. */
for (int i = 0; i < count; i++)
{
CGPoint point = CGPointMake([self.mapView convertCoordinate:coordinates[i] toPointToView:self.mapView].x, [self.mapView convertCoordinate:coordinates[i] toPointToView:self.mapView].y);
points[i] = point;
}
return points;
}
#pragma mark - 构建path, 调用者负责释放内存!
- (CGMutablePathRef)pathForPoints:(CGPoint *)points count:(NSUInteger)count{
if (points == NULL || count <= 1){
return NULL;
}
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddLines(path, NULL, points, count);
return path;
}
#pragma mark - 构建shapeLayer的basicAnimation
- (CAAnimation *)constructShapeLayerAnimation{
CABasicAnimation *theStrokeAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
theStrokeAnimation.duration = AnimationDuration;
theStrokeAnimation.fromValue = @0.f;
theStrokeAnimation.toValue = @1.f;
theStrokeAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
return theStrokeAnimation;
}
#pragma mark - 构建Annotation动画
- (CAAnimation *)constructAnnotationAnimationWithPath:(CGPathRef)path{
if (path == NULL){
return nil;
}
CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
keyFrameAnimation.duration = AnimationDuration;
keyFrameAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
keyFrameAnimation.path = path;
keyFrameAnimation.calculationMode = kCAAnimationPaced;
return keyFrameAnimation;
}
#pragma mark - 构造gradientLayer
- (void)initGradientLayerWithPoints:(CGPoint *)points Count:(NSUInteger)count{
if(count<1){
return;
}
self.gradientLayer = [[CALayer alloc] init];
[self velocity:velocity ToHue:&hues count:(int)count];
for(int i=0;i<count-1;i++){
@autoreleasepool {
CGPoint point1 = points[i];
CGPoint point2 = points[i+1];
double xDiff = point2.x-point1.x;
double yDiff = point2.y-point1.y;
CGPoint startPoint,endPoint;
double offset = 0.;
CAGradientLayer *gradientLayer = [[CAGradientLayer alloc] init];
//相邻两个最标点 构造一个渐变图层
[gradientLayer setFrame:CGRectMake(MIN(point1.x, point2.x)-3, MIN(point1.y, point2.y)-3, fabs(xDiff)+6, fabs(yDiff)+6)];
//渐变方向
if(xDiff>0.){
if(yDiff>0.){
if(xDiff>yDiff){
offset = yDiff/xDiff;
startPoint = CGPointMake(0, 0);
endPoint = CGPointMake(offset, 1);
}else{
offset = xDiff/yDiff;
startPoint = CGPointMake(0, 0);
endPoint = CGPointMake(1, offset);
}
}else{
if(xDiff>fabs(yDiff)){
offset = fabs(yDiff)/xDiff;
startPoint = CGPointMake(1, 0);
endPoint = CGPointMake(1, offset);
}else{
offset = xDiff/fabs(yDiff);
startPoint = CGPointMake(1, 0);
endPoint = CGPointMake(0, offset);
}
}
}else{
if(yDiff>0.){
if(fabs(xDiff)>yDiff){
offset = yDiff/fabs(xDiff);
startPoint = CGPointMake(0, 1);
endPoint = CGPointMake(offset, 0);
}else{
offset = fabs(xDiff)/yDiff;
startPoint = CGPointMake(1, 0);
endPoint = CGPointMake(1-offset, 1);
}
}else{
if(fabs(xDiff)>fabs(yDiff)){
offset = fabs(yDiff)/fabs(xDiff);
startPoint = CGPointMake(1, 1);
endPoint = CGPointMake(1-offset, 0);
}else{
offset = fabs(xDiff)/fabs(yDiff);
startPoint = CGPointMake(1, 1);
endPoint = CGPointMake(0, 1-offset);
}
}
}
gradientLayer.cornerRadius = 6;
gradientLayer.startPoint = startPoint;
gradientLayer.endPoint = endPoint;
gradientLayer.colors = @[[_gradientColors objectAtIndex:i],
[_gradientColors objectAtIndex:i+1]];
// gradientLayer.colors = @[(__bridge id)[UIColor redColor].CGColor,
// (__bridge id)[UIColor blueColor].CGColor,
// (__bridge id)[UIColor greenColor].CGColor];
[self.gradientLayer addSublayer:gradientLayer];
}
}
[self.gradientLayer setMask:self.shapeLayer];
[self.container.layer addSublayer:self.gradientLayer];
}
#define V_MAX 4.5
#define V_MIN 1.0
#define H_MAX 0.33
#define H_MIN 0.03
- (void) velocity:(float*)velocity ToHue:(float**)_hue count:(int)count{
_gradientColors = [NSMutableArray new];
*_hue = malloc(sizeof(float)*count);
for (int i=0;i<count;i++){
float curVelo = velocity[i];
if(curVelo>0.){
curVelo = ((curVelo < V_MIN) ? V_MIN : (curVelo > V_MAX) ? V_MAX : curVelo);
(*_hue)[i] = H_MIN + ((curVelo-V_MIN)*(H_MAX-H_MIN))/(V_MAX-V_MIN);
}else if(curVelo==0){
//暂停颜色
(*_hue)[i] = 0.5;
}else{
//超速颜色
(*_hue)[i] = 0.;
}
//填充轨迹渐变数组
UIColor *color;
if(curVelo>0.){
// color = [UIColor colorWithHue:(*_hue)[i] saturation:1.0f brightness:1.0f alpha:1.0f];
color = [UIColor greenColor];
}else{
// color = [UIColor colorWithHue:(*_hue)[i] saturation:1.0f brightness:1.0f alpha:0.0f];
color = [UIColor greenColor];
}
[_gradientColors addObject:(__bridge id)color.CGColor];
}
} }
@end @end
//
// ZJMapPinchGestureRecognizer.h
// ZhiJi
//
// Created by 明津李 on 2020/7/28.
// Copyright © 2020 Company. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface ZJMapPinchGestureRecognizer : UIPinchGestureRecognizer
- (id)initWithMapView:(MKMapView *)mapView;
@end
NS_ASSUME_NONNULL_END
//
// ZJMapPinchGestureRecognizer.m
// ZhiJi
//
// Created by 明津李 on 2020/7/28.
// Copyright © 2020 Company. All rights reserved.
//
#import "ZJMapPinchGestureRecognizer.h"
@interface ZJMapPinchGestureRecognizer ()
- (void)handlePinchGesture;
@property (nonatomic, assign) MKMapView *mapView;
@end
@implementation ZJMapPinchGestureRecognizer
- (id)initWithMapView:(MKMapView *)mapView {
if (mapView == nil) {
[NSException raise:NSInvalidArgumentException format:@"mapView cannot be nil."];
}
if ((self = [super initWithTarget:self action:@selector(handlePinchGesture)])) {
self.mapView = mapView;
}
return self;
}
- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer {
return NO;
}
- (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer {
return NO;
}
- (void)handlePinchGesture {
CLLocation *location = self.mapView.userLocation.location;
if (location != nil) {
[self.mapView setCenterCoordinate:location.coordinate];
}
}
@end
...@@ -38,12 +38,6 @@ ...@@ -38,12 +38,6 @@
} }
- (IBAction)drawTrackAction:(UIButton *)sender { - (IBAction)drawTrackAction:(UIButton *)sender {
if ([self.stratDate compare:self.endDate] == NSOrderedDescending) {
[MBProgressHUD showError:kLocalizedString(@"track_start_time_less_end")];
return;
}
if (_drawTrackHandle) { if (_drawTrackHandle) {
_drawTrackHandle(); _drawTrackHandle();
} }
...@@ -57,10 +51,10 @@ ...@@ -57,10 +51,10 @@
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
datePciker.commitTrackDateClosre = ^(NSDate *date) { datePciker.commitTrackDateClosre = ^(NSDate *date) {
NSLog(@"%@", date); NSLog(@"%@", date);
// if ([date compare:weakSelf.endDate] == NSOrderedDescending) { if ([date compare:weakSelf.endDate] == NSOrderedDescending) {
// [MBProgressHUD showError:kLocalizedString(@"track_start_time_less_end")]; [MBProgressHUD showError:kLocalizedString(@"track_start_time_less_end")];
// return; return;
// } }
[weakSelf.beginTimeButton setTitle: [weakSelf getDateStringFromDate:date] forState:UIControlStateNormal]; [weakSelf.beginTimeButton setTitle: [weakSelf getDateStringFromDate:date] forState:UIControlStateNormal];
weakSelf.stratDate = date; weakSelf.stratDate = date;
if (weakSelf.dateSelectFinishedHandle) { if (weakSelf.dateSelectFinishedHandle) {
...@@ -79,10 +73,10 @@ ...@@ -79,10 +73,10 @@
datePciker.commitTrackDateClosre = ^(NSDate *date) { datePciker.commitTrackDateClosre = ^(NSDate *date) {
NSLog(@"endTime %@", date); NSLog(@"endTime %@", date);
// if ([date compare:weakSelf.stratDate] == NSOrderedAscending) { if ([date compare:weakSelf.stratDate] == NSOrderedAscending) {
// [MBProgressHUD showError:kLocalizedString(@"track_end_time_great_start")]; [MBProgressHUD showError:kLocalizedString(@"track_end_time_great_start")];
// return; return;
// } }
weakSelf.endDate = date; weakSelf.endDate = date;
[weakSelf.endTimeButton setTitle: [weakSelf getDateStringFromDate:date] forState:UIControlStateNormal]; [weakSelf.endTimeButton setTitle: [weakSelf getDateStringFromDate:date] forState:UIControlStateNormal];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment