blob: 9795565050c0f56cdb1a783a6b0b66f605b3b843 (
plain)
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
|
#import "MGLUserLocationAnnotationView.h"
#import "MGLUserLocation.h"
#import "MGLUserLocation_Private.h"
#import "MGLAnnotationView_Private.h"
#import "MGLAnnotation.h"
#import "MGLMapView.h"
#import "MGLCoordinateFormatter.h"
#import "NSBundle+MGLAdditions.h"
@interface MGLUserLocationAnnotationView()
@property (nonatomic, weak, nullable) MGLMapView *mapView;
@property (nonatomic, weak, nullable) MGLUserLocation *userLocation;
@property (nonatomic, weak) CALayer *hitTestLayer;
@end
@implementation MGLUserLocationAnnotationView {
MGLCoordinateFormatter *_accessibilityCoordinateFormatter;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self == nil) return nil;
self.accessibilityTraits = UIAccessibilityTraitButton | UIAccessibilityTraitAdjustable | UIAccessibilityTraitUpdatesFrequently;
_accessibilityCoordinateFormatter = [[MGLCoordinateFormatter alloc] init];
_accessibilityCoordinateFormatter.unitStyle = NSFormattingUnitStyleLong;
return self;
}
- (CALayer *)hitTestLayer
{
return self.layer.presentationLayer;
}
- (void)update
{
// Left blank intentionally. Subclasses should usually override this in order to update the annotation’s appearance.
}
- (BOOL)isAccessibilityElement
{
return !self.hidden;
}
- (NSString *)accessibilityLabel
{
return self.userLocation.title;
}
- (NSString *)accessibilityValue
{
if (self.userLocation.subtitle)
{
return self.userLocation.subtitle;
}
// Each arcminute of longitude is at most about 1 nmi, too small for low zoom levels.
// Each arcsecond of longitude is at most about 30 m, too small for all but the very highest of zoom levels.
double zoomLevel = self.mapView.zoomLevel;
_accessibilityCoordinateFormatter.allowsMinutes = zoomLevel > 8;
_accessibilityCoordinateFormatter.allowsSeconds = zoomLevel > 20;
return [_accessibilityCoordinateFormatter stringFromCoordinate:self.mapView.centerCoordinate];
}
- (CGRect)accessibilityFrame
{
return CGRectInset(self.frame, -15, -15);
}
- (UIBezierPath *)accessibilityPath
{
return [UIBezierPath bezierPathWithOvalInRect:self.frame];
}
- (void)accessibilityIncrement
{
[self.mapView accessibilityIncrement];
}
- (void)accessibilityDecrement
{
[self.mapView accessibilityDecrement];
}
- (void)setHidden:(BOOL)hidden
{
BOOL oldValue = super.hidden;
[super setHidden:hidden];
if (oldValue != hidden)
{
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);
}
}
@end
|