-
Notifications
You must be signed in to change notification settings - Fork 86
/
IndoorMapPathView.m
87 lines (70 loc) · 2.06 KB
/
IndoorMapPathView.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// IndoorMapPathView.m
// WisdomMallAPP
//
// Created by apple on 14-4-15.
// Copyright (c) 2014年 apple. All rights reserved.
//
#import "IndoorMapPathView.h"
#import "Constants.h"
#import "AStarItem.h"
@interface IndoorMapPathView ()
{
CGFloat offset_y;
NSMutableArray *newPaths;
}
@end
@implementation IndoorMapPathView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setBackgroundColor:[UIColor clearColor]];
//iPhone 5
offset_y = OFFSET_Y;
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
//抗锯齿
CGContextSetAllowsAntialiasing(context, TRUE);
CGContextSetShouldAntialias(context, true);
//图片大小458*404
//转化成可绘制坐标
CGFloat x_ratio = 320 / 458.0f;
CGFloat h_ratio = 0.63;
if (IS_IPHONE_5) {
h_ratio = 0.52f;
offset_y += 46.0f;
}
CGFloat y_ratio = MRScreenHeight / 404.f * h_ratio;
if (newPaths) {
int j = 0;
for (AStarItem *item in newPaths) {
if (j == 0)
{
CGContextMoveToPoint(context, item.id_col * x_ratio, item.id_row * y_ratio + offset_y); // 开始坐标右边开始
j++;
continue;
}
CGContextAddLineToPoint(context, item.id_col * x_ratio, item.id_row * y_ratio + offset_y);
}
CGContextSetLineWidth(context, 1.0f);
CGFloat lengths[] = {4, 4};
CGContextSetLineDash(context, 0, lengths, 2);
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);//线框颜色
CGContextStrokePath(context);
}
}
- (void)drawPathWithPoints:(NSMutableArray *const)paths
{
newPaths = paths;
[self setNeedsDisplay];
}
@end