1//
2// Created by Leland Richardson on 12/27/15.
3// Copyright (c) 2015 Facebook. All rights reserved.
4//
5
6#import "AIRMapCircle.h"
7#import <React/UIView+React.h>
8
9
10@implementation AIRMapCircle {
11    BOOL _radiusSet;
12    BOOL _centerSet;
13}
14
15- (void)setFillColor:(UIColor *)fillColor {
16    _fillColor = fillColor;
17    [self update];
18}
19
20- (void)setStrokeColor:(UIColor *)strokeColor {
21    _strokeColor = strokeColor;
22    [self update];
23}
24
25- (void)setStrokeWidth:(CGFloat)strokeWidth {
26    _strokeWidth = strokeWidth;
27    [self update];
28}
29
30- (void)setLineJoin:(CGLineJoin)lineJoin {
31    _lineJoin = lineJoin;
32    [self update];
33}
34
35- (void)setLineCap:(CGLineCap)lineCap {
36    _lineCap = lineCap;
37    [self update];
38}
39
40- (void)setMiterLimit:(CGFloat)miterLimit {
41    _miterLimit = miterLimit;
42    [self update];
43}
44
45- (void)setLineDashPhase:(CGFloat)lineDashPhase {
46    _lineDashPhase = lineDashPhase;
47    [self update];
48}
49
50- (void)setLineDashPattern:(NSArray <NSNumber *> *)lineDashPattern {
51    _lineDashPattern = lineDashPattern;
52    [self update];
53}
54
55- (void)setRadius:(CLLocationDistance)radius {
56    _radius = radius;
57    _radiusSet = YES;
58    [self createCircleAndRendererIfPossible];
59    [self update];
60}
61
62- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate{
63    _centerCoordinate = centerCoordinate;
64    _centerSet = YES;
65    [self createCircleAndRendererIfPossible];
66    [self update];
67}
68
69- (void) createCircleAndRendererIfPossible
70{
71    if (!_centerSet || !_radiusSet) return;
72    self.circle = [MKCircle circleWithCenterCoordinate:_centerCoordinate radius:_radius];
73    self.renderer = [[MKCircleRenderer alloc] initWithCircle:self.circle];
74}
75
76- (void) update
77{
78    if (!_renderer) return;
79    _renderer.fillColor = _fillColor;
80    _renderer.strokeColor = _strokeColor;
81    _renderer.lineWidth = _strokeWidth;
82    _renderer.lineCap = _lineCap;
83    _renderer.lineJoin = _lineJoin;
84    _renderer.miterLimit = _miterLimit;
85    _renderer.lineDashPhase = _lineDashPhase;
86    _renderer.lineDashPattern = _lineDashPattern;
87
88    if (_map == nil) return;
89    [_map removeOverlay:self];
90    [_map addOverlay:self];
91}
92
93
94#pragma mark MKOverlay implementation
95
96- (CLLocationCoordinate2D) coordinate
97{
98    return self.circle.coordinate;
99}
100
101- (MKMapRect) boundingMapRect
102{
103    return self.circle.boundingMapRect;
104}
105
106- (BOOL)intersectsMapRect:(MKMapRect)mapRect
107{
108    BOOL answer = [self.circle intersectsMapRect:mapRect];
109    return answer;
110}
111
112- (BOOL)canReplaceMapContent
113{
114    return NO;
115}
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169@end