Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
Z
ZhiJi-Overseas
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lmj
ZhiJi-Overseas
Commits
dd17385f
Commit
dd17385f
authored
Jul 31, 2020
by
lmj_521aiau@163.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
62d37206
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
526 additions
and
270 deletions
+526
-270
.DS_Store
.DS_Store
+0
-0
project.pbxproj
ZhiJi.xcodeproj/project.pbxproj
+6
-0
ZJBaseMapViewController.m
ZhiJi/Classes/Map/Controller/ZJBaseMapViewController.m
+36
-64
ZJCustomAnnotation.h
ZhiJi/Classes/Map/Controller/ZJCustomAnnotation.h
+22
-0
ZJCustomAnnotation.m
ZhiJi/Classes/Map/Controller/ZJCustomAnnotation.m
+13
-0
ZJFriendTrackMapViewController.m
...i/Classes/Map/Controller/ZJFriendTrackMapViewController.m
+373
-192
ZJMapPinchGestureRecognizer.h
ZhiJi/Classes/Map/Controller/ZJMapPinchGestureRecognizer.h
+20
-0
ZJMapPinchGestureRecognizer.m
ZhiJi/Classes/Map/Controller/ZJMapPinchGestureRecognizer.m
+48
-0
ZJUserTrackTimeView.m
ZhiJi/Classes/Map/View/ZJUserTrackTimeView.m
+8
-14
No files found.
.DS_Store
View file @
dd17385f
No preview for this file type
ZhiJi.xcodeproj/project.pbxproj
View file @
dd17385f
...
...
@@ -54,6 +54,7 @@
A948C4DA24977B3700C22D69
/* ZJFriendLocationRemindModel.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
A948C4D924977B3700C22D69
/* ZJFriendLocationRemindModel.m */
;
};
A948C4DF249A27FE00C22D69
/* ZJOauthLoginConfig.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
A948C4DE249A27FE00C22D69
/* ZJOauthLoginConfig.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 */
;
};
A95590942490AE3C00F3BB41
/* MBProgressHUD+MJ.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
A955908E2490AE3C00F3BB41
/* MBProgressHUD+MJ.m */
;
};
A95590952490AE3C00F3BB41
/* MBProgressHUD.bundle in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
A95590902490AE3C00F3BB41
/* MBProgressHUD.bundle */
;
};
...
...
@@ -281,6 +282,8 @@
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>"
;
};
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>"
;
};
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>"
;
};
...
...
@@ -1081,6 +1084,8 @@
A9619E7F24AAE2A8009A2012
/* ZJMapStyle2ViewController.m */
,
64F52440248F34DB0032BCA2
/* ZJFriendTrackMapViewController.h */
,
64F52441248F34DB0032BCA2
/* ZJFriendTrackMapViewController.m */
,
A94EE53224D401EB0046038D
/* ZJCustomAnnotation.h */
,
A94EE53124D401EB0046038D
/* ZJCustomAnnotation.m */
,
);
path
=
Controller
;
sourceTree
=
"<group>"
;
...
...
@@ -1552,6 +1557,7 @@
A95F5C62248DDE81001DB97E
/* UILabel+HExtension.m in Sources */
,
A95F5C61248DDE81001DB97E
/* UIView+HExtension.m in Sources */
,
A948C4782493578A00C22D69
/* ZJFriendModel.m in Sources */
,
A94EE53324D401EB0046038D
/* ZJCustomAnnotation.m in Sources */
,
A9619E8224AAE2A8009A2012
/* ZJBaseMapViewController.m in Sources */
,
D5271ED324907E6100F8B107
/* ZJLocationAttentionFooter.swift in Sources */
,
A95F5C98248DDE81001DB97E
/* ZJPhoneLoginViewController.m in Sources */
,
...
...
ZhiJi/Classes/Map/Controller/ZJBaseMapViewController.m
View file @
dd17385f
...
...
@@ -7,11 +7,12 @@
//
#import "ZJBaseMapViewController.h"
#import <MapKit/MapKit.h>
#import "ZJCustomAnnotation.h"
@interface
ZJBaseMapViewController
()
<
MAMapViewDelegate
,
XMPopupList
ViewDelegate
>
@interface
ZJBaseMapViewController
()
<
XMPopupListViewDelegate
,
MKMap
ViewDelegate
>
@property
(
nonatomic
,
strong
)
MAMapView
*
mapView
;
@property
(
nonatomic
,
strong
)
UIButton
*
gpsButton
;
@property
(
nonatomic
,
strong
)
MKMapView
*
mapView
;
@property
(
nonatomic
,
strong
)
ZJMapViewPersonCardView
*
cardView
;
...
...
@@ -25,12 +26,10 @@
-
(
void
)
viewDidLoad
{
[
super
viewDidLoad
];
// Do any additional setup after loading the view.
[
self
setupUI
];
self
.
friendDataSource
=
[
NSMutableArray
array
];
[
self
setupUI
];
[
self
getFriendList
];
}
...
...
@@ -49,26 +48,15 @@
-
(
void
)
setupUI
{
///初始化地图
self
.
mapView
=
[[
MAMapView
alloc
]
initWithFrame
:
self
.
view
.
bounds
];
_mapView
.
autoresizingMask
=
UIViewAutoresizingFlexibleWidth
|
UIViewAutoresizingFlexibleHeight
;
///把地图添加至view
[
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
)];
}
self
.
mapView
=
[[
MKMapView
alloc
]
initWithFrame
:
self
.
view
.
bounds
];
_mapView
.
showsUserLocation
=
YES
;
_mapView
.
userTrackingMode
=
MKUserTrackingModeFollow
;
_mapView
.
delegate
=
self
;
_mapView
.
zoomLevel
=
14
;
_mapView
.
showsScale
=
false
;
_mapView
.
showsCompass
=
false
;
_mapView
.
autoresizingMask
=
UIViewAutoresizingFlexibleWidth
|
UIViewAutoresizingFlexibleHeight
;
///把地图添加至view
[
self
.
view
addSubview
:
_mapView
];
// 添加 card view
self
.
cardView
=
[[[
NSBundle
mainBundle
]
loadNibNamed
:
@"ZJMapViewPersonCardView"
owner
:
self
options
:
nil
]
lastObject
];
...
...
@@ -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 好友列表
-
(
void
)
getFriendList
{
...
...
@@ -151,7 +115,7 @@
//未登录
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
_mapView
.
showsUserLocation
=
YES
;
_mapView
.
userTrackingMode
=
M
A
UserTrackingModeFollow
;
_mapView
.
userTrackingMode
=
M
K
UserTrackingModeFollow
;
return
;
}
[
self
.
friendDataSource
removeAllObjects
];
...
...
@@ -172,7 +136,7 @@
[
weakSelf
.
style2BgImV
setHidden
:
false
];
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
weakSelf
.
mapView
.
showsUserLocation
=
YES
;
weakSelf
.
mapView
.
userTrackingMode
=
M
A
UserTrackingModeFollow
;
weakSelf
.
mapView
.
userTrackingMode
=
M
K
UserTrackingModeFollow
;
}
else
{
[
weakSelf
.
cardView
setHidden
:
false
];
[
weakSelf
.
addCareButton
setHidden
:
true
];
...
...
@@ -198,7 +162,7 @@
}
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
weakSelf
.
mapView
.
showsUserLocation
=
YES
;
weakSelf
.
mapView
.
userTrackingMode
=
M
A
UserTrackingModeFollow
;
weakSelf
.
mapView
.
userTrackingMode
=
M
K
UserTrackingModeFollow
;
// [MBProgressHUD showError:[NSString stringWithFormat:@"获取好友列表失败\n%@", [response objectForKey:@"msg"]] toView:self.view];
}
...
...
@@ -206,13 +170,6 @@
// [MBProgressHUD showError:[NSString stringWithFormat:@"获取好友列表失败\n%@", error.description] toView:self.view];
}];
}
#pragma mark - Action Handlers
-
(
void
)
returnAction
{
[
self
.
navigationController
popViewControllerAnimated
:
YES
];
}
/**
选中cell后回调
@param indexPath 返回选中的indexPath
...
...
@@ -249,13 +206,15 @@
double
lat
=
[
response
[
@"result"
][
@"data"
][
@"lat"
]
doubleValue
];
double
lon
=
[
response
[
@"result"
][
@"data"
][
@"lon"
]
doubleValue
];
MAPointAnnotation
*
pointAnnotation
=
[[
MAPointAnnotation
alloc
]
init
];
ZJCustomAnnotation
*
pointAnnotation
=
[[
ZJCustomAnnotation
alloc
]
init
];
pointAnnotation
.
coordinate
=
CLLocationCoordinate2DMake
(
lat
,
lon
);
pointAnnotation
.
title
=
@"latestLocation"
;
[
_self
.
mapView
addAnnotation
:
pointAnnotation
];
[
_self
.
mapView
setCenterCoordinate
:
pointAnnotation
.
coordinate
animated
:
false
];
}
else
if
([[
response
objectForKey
:
@"status"
]
integerValue
]
==
105
)
{
}
else
{
[
MBProgressHUD
showError
:[
response
objectForKey
:
@"msg"
]
toView
:
self
.
view
];
}
...
...
@@ -266,13 +225,26 @@
}
#pragma mark - Map Delegate
-
(
MAAnnotationView
*
)
mapView
:
(
MAMapView
*
)
mapView
viewForAnnotation
:
(
id
<
MAAnnotation
>
)
annotation
{
-
(
nullable
MKAnnotationView
*
)
mapView
:
(
MKMapView
*
)
mapView
viewForAnnotation
:
(
id
<
MKAnnotation
>
)
annotation
{
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
]]){
if
([
annotation
isKindOfClass
:[
MAPointAnnotation
class
]])
{
NSString
*
pointReuseIndetifier
=
@"pointReuseIndetifier3"
;
M
AAnnotationView
*
annotationView
=
(
MAAnnotationView
*
)
[
mapView
dequeueReusableAnnotationViewWithIdentifier
:
pointReuseIndetifier
];
M
KAnnotationView
*
annotationView
=
[
mapView
dequeueReusableAnnotationViewWithIdentifier
:
pointReuseIndetifier
];
if
(
annotationView
==
nil
)
{
annotationView
=
[[
M
AAnnotationView
alloc
]
initWithAnnotation
:
annotation
reuseIdentifier
:
pointReuseIndetifier
];
annotationView
=
[[
M
KAnnotationView
alloc
]
initWithAnnotation
:(
id
<
MKAnnotation
>
)
annotation
reuseIdentifier
:
pointReuseIndetifier
];
annotationView
.
canShowCallout
=
YES
;
}
...
...
ZhiJi/Classes/Map/Controller/ZJCustomAnnotation.h
0 → 100644
View file @
dd17385f
//
// 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
ZhiJi/Classes/Map/Controller/ZJCustomAnnotation.m
0 → 100644
View file @
dd17385f
//
// ZJCustomAnnotation.m
// ZhiJi
//
// Created by 明津李 on 2020/7/27.
// Copyright © 2020 Company. All rights reserved.
//
#import "ZJCustomAnnotation.h"
@implementation
ZJCustomAnnotation
@end
ZhiJi/Classes/Map/Controller/ZJFriendTrackMapViewController.m
View file @
dd17385f
...
...
@@ -7,8 +7,6 @@
//
#import "ZJFriendTrackMapViewController.h"
#import <MAMapKit/MAMapKit.h>
#import <AMapFoundationKit/AMapFoundationKit.h>
#import "ZJUserTrackTimeView.h"
#import "ZhiJi-Swift.h"
#import "ZJUserInfoManager.h"
...
...
@@ -18,24 +16,43 @@
#import "AlertControllerTool.h"
#import <CoreLocation/CoreLocation.h>
#import "BaseWebViewController.h"
#import <MapKit/MapKit.h>
#import "ZJCustomAnnotation.h"
@interface
ZJFriendTrackMapViewController
()
<
MAMapViewDelegate
>
#define AnimationDuration 8
@property
(
nonatomic
,
strong
)
MAMapView
*
mapView
;
@property
(
nonatomic
,
strong
)
UIButton
*
gpsButton
;
@property
(
nonatomic
,
strong
)
ZJUserTrackTimeView
*
trackTimeView
;
@property
(
nonatomic
,
strong
)
NSMutableArray
<
ZJLocationModel
*>
*
locations
;
@interface
ZJFriendTrackMapViewController
()
<
MKMapViewDelegate
,
CAAnimationDelegate
>
{
float
*
hues
;
float
*
velocity
;
ZJCustomAnnotation
*
endAnnotation
;
BOOL
mapPaddle
;
}
@property
(
nonatomic
,
strong
)
ZJUserTrackTimeView
*
trackTimeView
;
@property
(
strong
,
nonatomic
)
NSDate
*
stratDate
;
@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
)
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
@implementation
ZJFriendTrackMapViewController
...
...
@@ -91,7 +108,6 @@
self
.
alertView
.
alertSubtitle
.
text
=
kLocalizedString
(
@"track_friend_authority_alert"
);
}
[
self
.
alertView
.
leftButton
addTapBlock
:
^
(
UITapGestureRecognizer
*
tap
)
{
NSLog
(
@"%@"
,
@"leftButton"
);
...
...
@@ -137,29 +153,20 @@
-
(
void
)
setupUI
{
///初始化地图
self
.
mapView
=
[[
MAMapView
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
];
self
.
mapView
=
[[
MKMapView
alloc
]
initWithFrame
:
self
.
view
.
bounds
];
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
_mapView
.
showsUserLocation
=
false
;
// _mapView.showsUserLocation = false;
_mapView
.
showsUserLocation
=
YES
;
_mapView
.
userTrackingMode
=
MKUserTrackingModeFollow
;
_mapView
.
delegate
=
self
;
_mapView
.
zoomLevel
=
14
;
_mapView
.
showsScale
=
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
self
.
trackTimeView
=
[[[
NSBundle
mainBundle
]
loadNibNamed
:
@"ZJUserTrackTimeView"
owner
:
self
options
:
nil
]
lastObject
];
...
...
@@ -187,47 +194,18 @@
weakSelf
.
stratDate
=
beginDate
;
weakSelf
.
endDate
=
endDate
;
};
self
.
track
=
[[
MAAnimatedAnnotation
alloc
]
init
];
self
.
track
.
title
=
@"pointReuseIndetifier1"
;
[
self
.
mapView
addAnnotation
:
self
.
track
];
mapPaddle
=
YES
;
}
-
(
void
)
drawLineAction
{
-
(
void
)
drawLineAction
{
if
(
self
.
isMyTrack
)
{
[
MobClick
event
:
@"mytrack_querybutton_click"
]
;
}
else
{
[
MobClick
event
:
@"friendtrack_querybutton_click"
];
}
//重制
// _endAnnotationView = nil
;
// _startAnnotationView = nil;
[
self
.
mapView
removeOverlays
:
self
.
mapView
.
overlays
];
[
self
.
mapView
removeAnnotations
:
self
.
mapView
.
annotations
];
[
self
.
trackTimeView
.
trackButton
setSelected
:
true
];
[
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
];
_trackAnimation
=
YES
;
//构造折线数据对象
CLLocationCoordinate2D
commonPolylineCoords
[
self
.
locations
.
count
];
...
...
@@ -237,141 +215,170 @@
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.boundingMapRect
//在地图上添加折线对象
[
self
.
mapView
addOverlay
:
commonPolyline
];
int
count
=
sizeof
(
commonPolylineCoords
)
/
sizeof
(
commonPolylineCoords
[
0
]);
self
.
mapView
.
centerCoordinate
=
commonPolylineCoords
[
count
/
2
];
double
sum
=
0
;
NSMutableArray
*
arr
=
[
NSMutableArray
arrayWithCapacity
:
count
];
for
(
int
i
=
0
;
i
<
count
-
1
;
++
i
)
{
CLLocation
*
begin
=
[[
CLLocation
alloc
]
initWithLatitude
:
commonPolylineCoords
[
i
].
latitude
longitude
:
commonPolylineCoords
[
i
].
longitude
];
CLLocation
*
end
=
[[
CLLocation
alloc
]
initWithLatitude
:
commonPolylineCoords
[
i
+
1
].
latitude
longitude
:
commonPolylineCoords
[
i
+
1
].
longitude
];
CLLocationDistance
distance
=
[
end
distanceFromLocation
:
begin
];
[
arr
addObject
:[
NSNumber
numberWithDouble
:
distance
]];
sum
+=
distance
;
}
self
.
distanceArray
=
arr
;
self
.
sumDistance
=
sum
;
double
speed_car1
=
self
.
sumDistance
/
12
;
//80 km/h
// int count1 = sizeof(commonPolylineCoords) / sizeof(commonPolylineCoords[0]);
[
self
.
track
setCoordinate
:
commonPolylineCoords
[
0
]];
__weak
typeof
(
self
)
weakSelf
=
self
;
[
self
.
track
addMoveAnimationWithKeyCoordinates
:
commonPolylineCoords
count
:
count
withDuration
:
self
.
sumDistance
/
speed_car1
withName
:
nil
completeCallback
:^
(
BOOL
isFinished
)
{
[
weakSelf
.
trackTimeView
.
trackButton
setEnabled
:
true
];
[
weakSelf
.
trackTimeView
.
trackButton
setSelected
:
false
];
}];
[
self
.
mapView
setVisibleMapRect
:
self
.
commonPolyline
.
boundingMapRect
edgePadding
:
UIEdgeInsetsMake
(
250
,
50
,
50
,
50
)
animated
:
true
];
[
self
.
mapView
addOverlay
:
self
.
commonPolyline
];
}
//动画行动点
endAnnotation
=
[[
ZJCustomAnnotation
alloc
]
init
];
endAnnotation
.
title
=
@"end"
;
[
_mapView
addAnnotation
:
endAnnotation
];
-
(
ZJAlertView
*
)
getAlertView
:
(
NSString
*
)
title
subtitle
:
(
NSString
*
)
subtitle
leftButtonTitle
:
(
NSString
*
)
leftButtonTitle
rightButtonTitle
:
(
NSString
*
)
rightButtonTitle
{
ZJAlertView
*
alertView
=
[[[
NSBundle
mainBundle
]
loadNibNamed
:
@"ZJAlertView"
owner
:
self
options
:
nil
]
lastObject
];
alertView
.
frame
=
CGRectMake
(
0
,
0
,
SCREEN_WIDTH
,
SCREEN_HEIGHT
);
alertView
.
alertTitle
.
text
=
title
;
alertView
.
alertSubtitle
.
text
=
subtitle
;
[
alertView
.
leftButton
setTitle
:
leftButtonTitle
forState
:
UIControlStateNormal
];
[
alertView
.
rightButton
setTitle
:
rightButtonTitle
forState
:
UIControlStateNormal
];
alertView
.
backgroundColor
=
[
UIColor
colorWithHex
:
000000
alpha
:
0
.
5
];
__weak
typeof
(
alertView
)
weakAlertView
=
alertView
;
[
alertView
addTapBlock
:
^
(
UITapGestureRecognizer
*
tap
)
{
[
weakAlertView
removeFromSuperview
];
}];
UIView
*
window
=
[
UIApplication
sharedApplication
].
keyWindow
.
rootViewController
.
view
;
[
window
addSubview
:
alertView
];
return
alertView
;
MKMapRect
rect
=
MKMapRectMake
(
self
.
commonPolyline
.
boundingMapRect
.
origin
.
x
,
self
.
commonPolyline
.
boundingMapRect
.
origin
.
y
,
self
.
commonPolyline
.
boundingMapRect
.
size
.
width
,
self
.
commonPolyline
.
boundingMapRect
.
size
.
height
);
[
self
.
mapView
setVisibleMapRect
:
rect
edgePadding
:
UIEdgeInsetsMake
(
40
,
40
,
40
,
40
)
animated
:
true
];
if
(
!
mapPaddle
)
{
[
self
addAnimation
];
}
}
#pragma mark - Map Delegate
//开始动画
-
(
void
)
addAnimation
{
-
(
MAAnnotationView
*
)
mapView
:
(
MAMapView
*
)
mapView
viewForAnnotation
:
(
id
<
MAAnnotation
>
)
annotation
{
_container
=
(
UIView
*
)[
self
.
mapView
.
subviews
firstObject
].
subviews
.
lastObject
;
if
(
annotation
==
self
.
track
)
{
NSString
*
pointReuseIndetifier
=
@"pointReuseIndetifier1"
;
//动画 路径 数据处理
_smoothTrackCount
=
_locations
.
count
;
_smoothTrackPoints
=
malloc
(
sizeof
(
CLLocationCoordinate2D
)
*
_smoothTrackCount
);
velocity
=
malloc
(
sizeof
(
float
)
*
_smoothTrackCount
);
MAAnnotationView
*
annotationView
=
(
MAAnnotationView
*
)[
mapView
dequeueReusableAnnotationViewWithIdentifier
:
pointReuseIndetifier
];
if
(
!
annotationView
)
{
annotationView
=
[[
MAAnnotationView
alloc
]
initWithAnnotation
:
annotation
reuseIdentifier
:
pointReuseIndetifier
];
for
(
int
i
=
0
;
i
<
_smoothTrackCount
;
i
++
){
@autoreleasepool
{
ZJLocationModel
*
model
=
[
self
.
locations
objectAtIndex
:
i
];
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
;
}
}
annotationView
.
canShowCallout
=
YES
;
CGPoint
*
points
=
[
self
pointsForCoordinates
:
_smoothTrackPoints
count
:
_smoothTrackCount
];
CGPathRef
path
=
[
self
pathForPoints
:
points
count
:
_smoothTrackCount
];
[
self
initShapeLayerWithPath
:
path
];
self
.
shapeLayer
.
frame
=
self
.
mapView
.
bounds
;
CAAnimation
*
shapeLayerAnimation
=
[
self
constructShapeLayerAnimation
];
shapeLayerAnimation
.
delegate
=
self
;
shapeLayerAnimation
.
removedOnCompletion
=
NO
;
shapeLayerAnimation
.
fillMode
=
kCAFillModeForwards
;
[
self
.
shapeLayer
addAnimation
:
shapeLayerAnimation
forKey
:
@"shape"
];
[
self
.
container
.
layer
addSublayer
:
self
.
shapeLayer
];
UIImage
*
imge
=
[
UIImage
imageNamed
:
@"map_track_move_icon"
];
annotationView
.
image
=
imge
;
[
self
initGradientLayerWithPoints
:
points
Count
:
_smoothTrackCount
];
ZJLocationModel
*
model
=
self
.
locations
[
0
];
[
endAnnotation
setCoordinate
:
CLLocationCoordinate2DMake
(
model
.
latitude
,
model
.
longitude
)];
_endAnnotationView
=
[
self
.
mapView
viewForAnnotation
:
endAnnotation
];
CAAnimation
*
annotationAnimation
=
[
self
constructAnnotationAnimationWithPath
:
path
];
_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
-
(
void
)
mapView
:
(
MKMapView
*
)
mapView
regionDidChangeAnimated
:
(
BOOL
)
animated
{
mapPaddle
=
YES
;
if
(
_trackAnimation
)
{
[
self
addAnimation
];
}
}
return
annotationView
;
}
else
if
([
annotation
isKindOfClass
:[
MAPointAnnotation
class
]])
{
-
(
MKAnnotationView
*
)
mapView
:
(
MKMapView
*
)
mapView
viewForAnnotation
:
(
id
<
MKAnnotation
>
)
annotation
{
NSString
*
pointReuseIndetifier
=
@"pointReuseIndetifier3"
;
MAAnnotationView
*
annotationView
=
(
MAAnnotationView
*
)[
mapView
dequeueReusableAnnotationViewWithIdentifier
:
pointReuseIndetifier
];
if
([
annotation
isKindOfClass
:[
ZJCustomAnnotation
class
]])
{
ZJCustomAnnotation
*
ann
=
(
ZJCustomAnnotation
*
)
annotation
;
if
([
ann
.
title
isEqualToString
:
@"start"
])
{
NSString
*
pointReuseIndetifier
=
@"startAnnotation"
;
MKAnnotationView
*
annotationView
=
(
MKAnnotationView
*
)[
mapView
dequeueReusableAnnotationViewWithIdentifier
:
pointReuseIndetifier
];
if
(
annotationView
==
nil
)
{
annotationView
=
[[
MAAnnotationView
alloc
]
initWithAnnotation
:
annotation
reuseIdentifier
:
pointReuseIndetifier
];
annotationView
=
[[
MKAnnotationView
alloc
]
initWithAnnotation
:(
id
<
MKAnnotation
>
)
annotation
reuseIdentifier
:
pointReuseIndetifier
];
annotationView
.
canShowCallout
=
YES
;
}
if
([
annotation
.
title
isEqualToString
:
@"start"
])
{
annotationView
.
enabled
=
NO
;
annotationView
.
image
=
[
UIImage
imageNamed
:
kLocalizedString
(
@"map_track_start_icon"
)];
}
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"
];
_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
]]){
NSString
*
pointReuseIndetifier
=
@"pointReuseIndetifier1"
;
MKAnnotationView
*
annotationView
=
(
MKAnnotationView
*
)[
mapView
dequeueReusableAnnotationViewWithIdentifier
:
pointReuseIndetifier
];
if
(
annotationView
==
nil
)
{
annotationView
=
[[
MKAnnotationView
alloc
]
initWithAnnotation
:(
id
<
MKAnnotation
>
)
annotation
reuseIdentifier
:
pointReuseIndetifier
];
annotationView
.
canShowCallout
=
YES
;
}
annotationView
.
enabled
=
NO
;
annotationView
.
image
=
[
UIImage
imageNamed
:
@"userPosition"
];
// [mapView viewForAnnotation:mapView.userLocation]
return
annotationView
;
}
return
nil
;
}
/// 设置折线的样式
-
(
MAOverlayRenderer
*
)
mapView
:
(
MAMapView
*
)
mapView
rendererForOverlay
:
(
id
<
MAOverlay
>
)
overlay
{
if
([
overlay
isKindOfClass
:[
MAPolyline
class
]])
{
MAPolylineRenderer
*
polylineRenderer
=
[[
MAPolylineRenderer
alloc
]
initWithPolyline
:
overlay
];
polylineRenderer
.
lineWidth
=
4
.
f
;
polylineRenderer
.
strokeColor
=
[
UIColor
colorWithHex
:
0x568EFC
];
polylineRenderer
.
lineJoinType
=
kMALineJoinRound
;
polylineRenderer
.
lineCapType
=
kMALineCapRound
;
-
(
MKOverlayRenderer
*
)
mapView
:
(
MKMapView
*
)
mapView
rendererForOverlay
:
(
id
<
MKOverlay
>
)
overlay
{
return
polylineRenderer
;
if
([
overlay
isKindOfClass
:[
MKPolyline
class
]]){
MKPolylineRenderer
*
render
=
[[
MKPolylineRenderer
alloc
]
initWithOverlay
:
overlay
];
render
.
lineWidth
=
4
.
f
;
render
.
strokeColor
=
[
UIColor
colorWithHex
:
0x568EFC
];
render
.
lineJoin
=
kCGLineJoinRound
;
render
.
lineCap
=
kCGLineJoinRound
;
return
render
;
}
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 查询轨迹
-
(
void
)
queryLocationList
:
(
ZJFriendModel
*
)
model
{
...
...
@@ -384,13 +391,13 @@
if
([
ZJUserInfoManager
shared
].
uid
.
length
<=
0
)
{
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
self
.
mapView
.
showsUserLocation
=
YES
;
self
.
mapView
.
userTrackingMode
=
M
A
UserTrackingModeFollow
;
self
.
mapView
.
userTrackingMode
=
M
K
UserTrackingModeFollow
;
return
;
}
if
([
ZJUserInfoManager
shared
].
token
.
length
<=
0
)
{
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
self
.
mapView
.
showsUserLocation
=
YES
;
self
.
mapView
.
userTrackingMode
=
M
A
UserTrackingModeFollow
;
self
.
mapView
.
userTrackingMode
=
M
K
UserTrackingModeFollow
;
return
;
}
...
...
@@ -426,14 +433,9 @@
}
}
}
// [self.locations sortUsingComparator:^NSComparisonResult(ZJLocationModel *obj1, ZJLocationModel *obj2) {
// return (obj1.latitude < obj2.latitude);
// }];
NSLog
(
@"%@"
,
self
.
locations
);
if
(
_self
.
locations
.
count
<
=
0
)
{
if
(
_self
.
locations
.
count
=
=
0
)
{
[
_self
showAlertView
];
// [MBProgressHUD showMessage:kLocalizedString(@"track_friend_timeWithin_no_location")];
return
;
}
[
_self
drawLineAction
];
...
...
@@ -454,7 +456,7 @@
if
([
ZJUserInfoManager
shared
].
uid
.
length
<=
0
||
!
[
ZJUserInfoManager
shared
].
isMember
)
{
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
self
.
mapView
.
showsUserLocation
=
YES
;
self
.
mapView
.
userTrackingMode
=
M
A
UserTrackingModeFollow
;
self
.
mapView
.
userTrackingMode
=
M
K
UserTrackingModeFollow
;
return
;
}
__weak
typeof
(
self
)
_self
=
self
;
...
...
@@ -463,7 +465,7 @@
if
(
uid
.
length
<=
0
)
{
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
self
.
mapView
.
showsUserLocation
=
YES
;
self
.
mapView
.
userTrackingMode
=
M
A
UserTrackingModeFollow
;
self
.
mapView
.
userTrackingMode
=
M
K
UserTrackingModeFollow
;
uid
=
[
ZJUserInfoManager
shared
].
uid
;
}
[[
TQNetworkTools
shared
]
getWithAction
:
getLocationDataLast
parameters
:@{
@"tid"
:
uid
}
success
:^
(
id
_Nonnull
response
)
{
...
...
@@ -478,7 +480,7 @@
double
lat
=
[
response
[
@"result"
][
@"data"
][
@"lat"
]
doubleValue
];
double
lon
=
[
response
[
@"result"
][
@"data"
][
@"lon"
]
doubleValue
];
M
APointAnnotation
*
pointAnnotation
=
[[
MA
PointAnnotation
alloc
]
init
];
M
KPointAnnotation
*
pointAnnotation
=
[[
MK
PointAnnotation
alloc
]
init
];
pointAnnotation
.
coordinate
=
CLLocationCoordinate2DMake
(
lat
,
lon
);
pointAnnotation
.
title
=
@"latestLocation"
;
[
_self
.
mapView
addAnnotation
:
pointAnnotation
];
...
...
@@ -491,7 +493,186 @@
}
failure
:^
(
NSError
*
_Nonnull
error
)
{
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
ZhiJi/Classes/Map/Controller/ZJMapPinchGestureRecognizer.h
0 → 100644
View file @
dd17385f
//
// 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
ZhiJi/Classes/Map/Controller/ZJMapPinchGestureRecognizer.m
0 → 100644
View file @
dd17385f
//
// 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
ZhiJi/Classes/Map/View/ZJUserTrackTimeView.m
View file @
dd17385f
...
...
@@ -38,12 +38,6 @@
}
-
(
IBAction
)
drawTrackAction
:
(
UIButton
*
)
sender
{
if
([
self
.
stratDate
compare
:
self
.
endDate
]
==
NSOrderedDescending
)
{
[
MBProgressHUD
showError
:
kLocalizedString
(
@"track_start_time_less_end"
)];
return
;
}
if
(
_drawTrackHandle
)
{
_drawTrackHandle
();
}
...
...
@@ -57,10 +51,10 @@
__weak
typeof
(
self
)
weakSelf
=
self
;
datePciker
.
commitTrackDateClosre
=
^
(
NSDate
*
date
)
{
NSLog
(
@"%@"
,
date
);
//
if ([date compare:weakSelf.endDate] == NSOrderedDescending) {
//
[MBProgressHUD showError:kLocalizedString(@"track_start_time_less_end")];
//
return;
//
}
if
([
date
compare
:
weakSelf
.
endDate
]
==
NSOrderedDescending
)
{
[
MBProgressHUD
showError
:
kLocalizedString
(
@"track_start_time_less_end"
)];
return
;
}
[
weakSelf
.
beginTimeButton
setTitle
:
[
weakSelf
getDateStringFromDate
:
date
]
forState
:
UIControlStateNormal
];
weakSelf
.
stratDate
=
date
;
if
(
weakSelf
.
dateSelectFinishedHandle
)
{
...
...
@@ -79,10 +73,10 @@
datePciker
.
commitTrackDateClosre
=
^
(
NSDate
*
date
)
{
NSLog
(
@"endTime %@"
,
date
);
//
if ([date compare:weakSelf.stratDate] == NSOrderedAscending) {
//
[MBProgressHUD showError:kLocalizedString(@"track_end_time_great_start")];
//
return;
//
}
if
([
date
compare
:
weakSelf
.
stratDate
]
==
NSOrderedAscending
)
{
[
MBProgressHUD
showError
:
kLocalizedString
(
@"track_end_time_great_start"
)];
return
;
}
weakSelf
.
endDate
=
date
;
[
weakSelf
.
endTimeButton
setTitle
:
[
weakSelf
getDateStringFromDate
:
date
]
forState
:
UIControlStateNormal
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment