AMapMarker.m
4.2 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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
#import <React/UIView+React.h>
#import "AMapMarker.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection"
#pragma clang diagnostic ignored "-Woverriding-method-mismatch"
@implementation AMapMarker {
MAPointAnnotation *_annotation;
MAAnnotationView *_annotationView;
MACustomCalloutView *_calloutView;
UIView *_customView;
__weak AMapView *_mapView;
MAPinAnnotationColor _pinColor;
UIImage *_image;
CGPoint _centerOffset;
BOOL _draggable;
BOOL _active;
BOOL _canShowCallout;
BOOL _enabled;
NSInteger _zIndex;
}
- (instancetype)init {
_annotation = [MAPointAnnotation new];
_enabled = YES;
_canShowCallout = YES;
self = [super init];
return self;
}
- (NSString *)title {
return _annotation.title;
}
- (NSString *)subtitle {
return _annotation.subtitle;
}
- (CLLocationCoordinate2D)coordinate {
return _annotation.coordinate;
}
- (void)setTitle:(NSString *)title {
_annotation.title = title;
}
- (void)setColor:(MAPinAnnotationColor)color {
_pinColor = color;
((MAPinAnnotationView *) _annotationView).pinColor = color;
}
- (void)setDraggable:(BOOL)draggable {
_draggable = draggable;
_annotationView.draggable = draggable;
}
- (void)setCenterOffset:(CGPoint)centerOffset {
_centerOffset = centerOffset;
_annotationView.centerOffset = centerOffset;
}
- (void)setImage:(NSString *)name {
_image = [UIImage imageNamed:name];
if (_image != nil) {
_annotationView.image = _image;
}
}
- (void)setDescription:(NSString *)description {
_annotation.subtitle = description;
}
- (void)setCoordinate:(CLLocationCoordinate2D)coordinate {
_annotation.coordinate = coordinate;
}
- (void)setActive:(BOOL)active {
_active = active;
dispatch_async(dispatch_get_main_queue(), ^{
if (active) {
[_mapView selectAnnotation:_annotation animated:YES];
} else {
[_mapView deselectAnnotation:_annotation animated:YES];
}
});
}
- (void)setInfoWindowDisabled:(BOOL)disabled {
_canShowCallout = !disabled;
_annotationView.canShowCallout = !disabled;
}
- (void)setClickDisabled:(BOOL)disabled {
_enabled = !disabled;
_annotationView.enabled = !disabled;
}
- (void)setZIndex:(NSInteger)zIndex {
_zIndex = zIndex;
_annotationView.zIndex = zIndex;
}
- (MAPointAnnotation *)annotation {
return _annotation;
}
- (void)setMapView:(AMapView *)mapView {
_mapView = mapView;
}
- (void)_handleTap:(UITapGestureRecognizer *)recognizer {
[_mapView selectAnnotation:_annotation animated:YES];
}
- (MAAnnotationView *)annotationView {
if (_annotationView == nil) {
if (_customView) {
_customView.hidden = NO;
_annotationView = [[MAAnnotationView alloc] initWithAnnotation:_annotation reuseIdentifier:nil];
_annotationView.bounds = _customView.bounds;
[_annotationView addSubview:_customView];
[_annotationView addGestureRecognizer:[
[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_handleTap:)]];
} else {
_annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:_annotation reuseIdentifier:nil];
((MAPinAnnotationView *) _annotationView).pinColor = _pinColor;
}
_annotationView.enabled = _enabled;
_annotationView.canShowCallout = _canShowCallout;
_annotationView.draggable = _draggable;
_annotationView.customCalloutView = _calloutView;
_annotationView.centerOffset = _centerOffset;
if (_zIndex) {
_annotationView.zIndex = _zIndex;
}
if (_image != nil) {
_annotationView.image = _image;
}
[self setActive:_active];
}
return _annotationView;
}
- (void)didAddSubview:(UIView *)subview {
if ([subview isKindOfClass:[AMapCallout class]]) {
_calloutView = [[MACustomCalloutView alloc] initWithCustomView:subview];
_annotationView.customCalloutView = _calloutView;
} else {
_customView = subview;
_customView.hidden = YES;
}
}
- (void)lockToScreen:(int)x y:(int)y {
_annotation.lockedToScreen = YES;
_annotation.lockedScreenPoint = CGPointMake(x, y);
}
@end