/
JogView.m
66 lines (44 loc) · 1.67 KB
/
JogView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// JogView.m
// JogBuddy
//
// Created by Mohammad Azam on 7/12/11.
// Copyright 2011 HighOnCoding. All rights reserved.
//
#import "JogView.h"
#import "JogPoint.h"
@implementation JogView
@synthesize pointsToPlot;
-(id) initWithOverlayAndPoints:(id<MKOverlay>)overlay pts:(NSMutableArray *)points
{
if((self = [super initWithOverlay:overlay]))
{
self.pointsToPlot = points;
}
return self;
}
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
{
if(self.pointsToPlot.count < 5) return;
CGMutablePathRef path = NULL;
CGFloat lineWidth = MKRoadWidthAtZoomScale(zoomScale);
path = CGPathCreateMutable();
for(int i=0;i<([self.pointsToPlot count] -1 );i++)
{
MKMapPoint *firstPoint = ((JogPoint *) [self.pointsToPlot objectAtIndex:i]).points;
MKMapPoint *secondPoint = ((JogPoint *) [self.pointsToPlot objectAtIndex:i+1]).points;
CGPoint lastCGPoint = [self pointForMapPoint:firstPoint[0]];
CGPathMoveToPoint(path, NULL, lastCGPoint.x, lastCGPoint.y);
CGPoint cgPoint = [self pointForMapPoint:secondPoint[0]];
CGPathAddLineToPoint(path, NULL, cgPoint.x, cgPoint.y);
}
CGContextAddPath(context, path);
CGContextSetRGBStrokeColor(context, 0.0f, 0.0f, 1.0f, 0.5f);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, lineWidth);
CGContextStrokePath(context);
CGPathRelease(path);
[self setNeedsDisplay];
}
@end