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
4c5ea2b7
Commit
4c5ea2b7
authored
Jul 27, 2020
by
lmj_521aiau@163.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
e3d8716d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
96 deletions
+103
-96
AppDelegate.m
ZhiJi/AppDelegate.m
+13
-9
ZJFriendTrackMapViewController.m
...i/Classes/Map/Controller/ZJFriendTrackMapViewController.m
+90
-87
No files found.
ZhiJi/AppDelegate.m
View file @
4c5ea2b7
...
...
@@ -47,16 +47,20 @@
[
self
logCollection
];
self
.
window
=
[[
UIWindow
alloc
]
init
];
self
.
window
.
frame
=
[
UIScreen
mainScreen
].
bounds
;
self
.
window
.
backgroundColor
=
[
UIColor
whiteColor
];
self
.
window
.
rootViewController
=
[
UIViewController
new
];
// self.window.rootViewController = [[GuideViewController alloc] init];
//guide setting
[
ZJGuideConfig
configWithWindow
:
self
.
window
finishMainVC
:[
BaseTabBarViewController
new
]];
[
self
.
window
makeKeyAndVisible
];
// @available(iOS 13.0,*)表示iOS 13.0及以上的系统,后面的*表示所有平台
if
(
@available
(
iOS
13
.
0
,
*
))
{
}
else
{
self
.
window
=
[[
UIWindow
alloc
]
init
];
self
.
window
.
frame
=
[
UIScreen
mainScreen
].
bounds
;
self
.
window
.
backgroundColor
=
[
UIColor
whiteColor
];
[
self
.
window
makeKeyAndVisible
];
self
.
window
.
rootViewController
=
[[
BaseViewController
alloc
]
init
];
// guide setting
[
ZJGuideConfig
configWithWindow
:
self
.
window
finishMainVC
:[
BaseTabBarViewController
new
]];
}
return
YES
;
}
...
...
ZhiJi/Classes/Map/Controller/ZJFriendTrackMapViewController.m
View file @
4c5ea2b7
...
...
@@ -21,24 +21,30 @@
#import <MapKit/MapKit.h>
#import "ZJCustomAnnotation.h"
#define AnimationDuration 8
@interface
ZJFriendTrackMapViewController
()
<
MAMapViewDelegate
,
MKMapViewDelegate
,
CAAnimationDelegate
>
{
float
*
hues
;
float
*
velocity
;
ZJCustomAnnotation
*
start
Annotation
;
UIView
*
container
;
ZJCustomAnnotation
*
end
Annotation
;
BOOL
mapPaddle
;
}
@property
(
nonatomic
,
strong
)
ZJUserTrackTimeView
*
trackTimeView
;
@property
(
strong
,
nonatomic
)
NSDate
*
stratDate
;
@property
(
strong
,
nonatomic
)
NSDate
*
endDate
;
@property
(
nonatomic
,
strong
)
MKMapView
*
map
View
;
@property
(
nonatomic
,
strong
)
ZJAlertView
*
alert
View
;
@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
)
ZJAlertView
*
alertView
;
@property
(
nonatomic
,
strong
)
MAPointAnnotation
*
startAnnotation
;
@property
(
nonatomic
,
strong
)
MKAnnotationView
*
startAnnotationView
;
@property
(
nonatomic
,
strong
)
MKAnnotationView
*
endAnnotationView
;
@property
(
nonatomic
,
strong
)
CAShapeLayer
*
shapeLayer
;
...
...
@@ -49,11 +55,6 @@
@property
(
nonatomic
,
strong
)
CALayer
*
gradientLayer
;
@property
(
nonatomic
,
strong
)
NSMutableArray
*
gradientColors
;
/**
大头针 - 移动的大头针视图
*/
@property
(
nonatomic
,
weak
)
MKAnnotationView
*
annotationView
;
@end
@implementation
ZJFriendTrackMapViewController
...
...
@@ -138,7 +139,7 @@
///初始化地图
self
.
mapView
=
[[
MKMapView
alloc
]
initWithFrame
:
self
.
view
.
bounds
];
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
_mapView
.
showsUserLocation
=
YES
;
_mapView
.
showsUserLocation
=
false
;
_mapView
.
delegate
=
self
;
_mapView
.
showsScale
=
false
;
_mapView
.
showsCompass
=
false
;
...
...
@@ -175,12 +176,20 @@
weakSelf
.
stratDate
=
beginDate
;
weakSelf
.
endDate
=
endDate
;
};
startAnnotation
=
[[
ZJCustomAnnotation
alloc
]
init
];
[
_mapView
addAnnotation
:
startAnnotation
];
mapPaddle
=
YES
;
}
-
(
void
)
drawLineAction1
{
-
(
void
)
drawLineAction1
{
// _endAnnotationView = nil;
// _startAnnotationView = nil;
[
self
.
mapView
removeAnnotations
:
self
.
mapView
.
annotations
];
_trackAnimation
=
YES
;
endAnnotation
=
[[
ZJCustomAnnotation
alloc
]
init
];
[
_mapView
addAnnotation
:
endAnnotation
];
_smoothTrackCount
=
_locations
.
count
;
_smoothTrackPoints
=
malloc
(
sizeof
(
CLLocationCoordinate2D
)
*
_smoothTrackCount
);
...
...
@@ -197,19 +206,64 @@
_smoothTrackPoints
[
i
]
=
coordinate
;
}
}
_trackAnimation
=
YES
;
}
-
(
void
)
drawLineAction
{
-
(
void
)
addAnimation
{
_container
=
(
UIView
*
)[
self
.
mapView
.
subviews
firstObject
].
subviews
.
lastObject
;
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
];
[
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
removeOverlay
:
self
.
commonPolyline
];
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
=
[[
MAPointAnnotation
alloc
]
init
];
_startAnnotation
.
coordinate
=
CLLocationCoordinate2DMake
(
self
.
locations
.
firstObject
.
latitude
,
self
.
locations
.
firstObject
.
longitude
);
_startAnnotation
.
title
=
@"start"
;
[
self
.
mapView
addAnnotation
:(
id
<
MKAnnotation
>
)
_startAnnotation
];
}
-
(
void
)
drawLineAction
{
// MAPointAnnotation *pointAnnotation1 = [[MAPointAnnotation alloc] init];
// pointAnnotation1.coordinate = CLLocationCoordinate2DMake(self.locations.firstObject.latitude, self.locations.firstObject.longitude);
// pointAnnotation1.title = @"start";
// [self.mapView addAnnotation:(id<MKAnnotation>)pointAnnotation1];
[
self
.
mapView
removeOverlays
:
self
.
mapView
.
overlays
];
//构造折线数据对象
CLLocationCoordinate2D
commonPolylineCoords
[
self
.
locations
.
count
];
...
...
@@ -219,82 +273,30 @@
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:(id<MKAnnotation>)pointAnnotation2];
//构造折线对象
MKPolyline
*
commonPolyline
=
[
MKPolyline
polylineWithCoordinates
:
commonPolylineCoords
count
:
self
.
locations
.
count
];
self
.
commonPolyline
=
commonPolyline
;
//在地图上添加折线对象
[
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
.
mapView
addOverlay
:
self
.
commonPolyline
];
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
(
250
,
50
,
50
,
50
)
animated
:
true
];
if
(
!
mapPaddle
)
{
[
self
addAnimation
];
}
}
#pragma mark - Map Delegate
-
(
void
)
mapView
:
(
MKMapView
*
)
mapView
regionDidChangeAnimated
:
(
BOOL
)
animated
{
mapPaddle
=
YES
;
}
-
(
void
)
mapViewDidFinishRenderingMap
:
(
MKMapView
*
)
mapView
fullyRendered
:
(
BOOL
)
fullyRendered
{
if
(
_trackAnimation
)
{
container
=
(
UIView
*
)[
mapView
.
subviews
firstObject
].
subviews
.
lastObject
;
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
.
mapView
.
layer
addSublayer
:
self
.
shapeLayer
];
[
self
initGradientLayerWithPoints
:
points
Count
:
_smoothTrackCount
];
ZJLocationModel
*
model
=
self
.
locations
[
0
];
[
startAnnotation
setCoordinate
:
CLLocationCoordinate2DMake
(
model
.
latitude
,
model
.
longitude
)];
MKAnnotationView
*
annotationView
=
[
self
.
mapView
viewForAnnotation
:
startAnnotation
];
CAAnimation
*
annotationAnimation
=
[
self
constructAnnotationAnimationWithPath
:
path
];
annotationView
.
image
=
[
UIImage
imageNamed
:
@"map_track_start_icon"
];
[
annotationView
.
layer
addAnimation
:
annotationAnimation
forKey
:
@"annotation"
];
[
annotationView
.
annotation
setCoordinate
:
_smoothTrackPoints
[
_smoothTrackCount
-
1
]];
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
3
.
3
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
// [self.gradientLayer removeFromSuperlayer];
// [self.shapeLayer removeFromSuperlayer];
// MAPointAnnotation *pointAnnotation2 = [[MAPointAnnotation alloc] init];
// pointAnnotation2.coordinate = CLLocationCoordinate2DMake(self.locations.lastObject.latitude, self.locations.lastObject.longitude);
// pointAnnotation2.title = @"end";
// [self.mapView addAnnotation:(id<MKAnnotation>)pointAnnotation2];
});
(
void
)(
free
(
points
)),
points
=
NULL
;
(
void
)(
CGPathRelease
(
path
)),
path
=
NULL
;
_trackAnimation
=
NO
;
[
self
addAnimation
];
}
}
...
...
@@ -323,6 +325,7 @@
if
([
annotation
.
title
isEqualToString
:
@"start"
])
{
annotationView
.
enabled
=
NO
;
annotationView
.
image
=
[
UIImage
imageNamed
:
kLocalizedString
(
@"map_track_start_icon"
)];
_startAnnotationView
=
(
MKAnnotationView
*
)
annotationView
;
}
else
if
([
annotation
.
title
isEqualToString
:
@"end"
])
{
annotationView
.
enabled
=
NO
;
annotationView
.
image
=
[
UIImage
imageNamed
:
kLocalizedString
(
@"map_track_end_icon"
)];
...
...
@@ -339,7 +342,7 @@
}
annotationView
.
enabled
=
NO
;
//
annotationView.image = [UIImage imageNamed:@"userPosition"];
annotationView
.
image
=
[
UIImage
imageNamed
:
@"userPosition"
];
return
annotationView
;
}
...
...
@@ -523,7 +526,7 @@
#pragma mark - 构建shapeLayer的basicAnimation
-
(
CAAnimation
*
)
constructShapeLayerAnimation
{
CABasicAnimation
*
theStrokeAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
theStrokeAnimation
.
duration
=
3
;
theStrokeAnimation
.
duration
=
AnimationDuration
;
theStrokeAnimation
.
fromValue
=
@0.f
;
theStrokeAnimation
.
toValue
=
@1.f
;
theStrokeAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
...
...
@@ -537,7 +540,7 @@
}
CAKeyframeAnimation
*
keyFrameAnimation
=
[
CAKeyframeAnimation
animationWithKeyPath
:
@"position"
];
keyFrameAnimation
.
duration
=
3
;
keyFrameAnimation
.
duration
=
AnimationDuration
;
keyFrameAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
keyFrameAnimation
.
path
=
path
;
keyFrameAnimation
.
calculationMode
=
kCAAnimationPaced
;
...
...
@@ -623,7 +626,7 @@
}
}
[
self
.
gradientLayer
setMask
:
self
.
shapeLayer
];
[
self
.
mapView
.
layer
addSublayer
:
self
.
gradientLayer
];
[
self
.
container
.
layer
addSublayer
:
self
.
gradientLayer
];
}
#define V_MAX 4.5
...
...
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