summaryrefslogtreecommitdiff
path: root/platform/ios/src/MGLMapView.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/ios/src/MGLMapView.mm')
-rw-r--r--platform/ios/src/MGLMapView.mm83
1 files changed, 5 insertions, 78 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index c0b7380607..ec3766c3a0 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -86,7 +86,6 @@ const MGLMapViewPreferredFramesPerSecond MGLMapViewPreferredFramesPerSecondMaxim
const MGLExceptionName MGLMissingLocationServicesUsageDescriptionException = @"MGLMissingLocationServicesUsageDescriptionException";
const MGLExceptionName MGLUserLocationAnnotationTypeException = @"MGLUserLocationAnnotationTypeException";
-const MGLExceptionName MGLResourceNotFoundException = @"MGLResourceNotFoundException";
const MGLExceptionName MGLUnderlyingMapUnavailableException = @"MGLUnderlyingMapUnavailableException";
const CGPoint MGLOrnamentDefaultPositionOffset = CGPointMake(8, 8);
@@ -197,7 +196,7 @@ public:
@property (nonatomic) NSMutableArray<NSLayoutConstraint *> *scaleBarConstraints;
@property (nonatomic, readwrite) MGLScaleBar *scaleBar;
-@property (nonatomic, readwrite) UIImageView *compassView;
+@property (nonatomic, readwrite) MGLCompassButton *compassView;
@property (nonatomic) NSMutableArray<NSLayoutConstraint *> *compassViewConstraints;
@property (nonatomic, readwrite) UIImageView *logoView;
@property (nonatomic) NSMutableArray<NSLayoutConstraint *> *logoViewConstraints;
@@ -308,7 +307,6 @@ public:
BOOL _delegateHasFillColorsForShapeAnnotations;
BOOL _delegateHasLineWidthsForShapeAnnotations;
- MGLCompassDirectionFormatter *_accessibilityCompassFormatter;
NSArray<id <MGLFeature>> *_visiblePlaceFeatures;
NSArray<id <MGLFeature>> *_visibleRoadFeatures;
NSMutableSet<MGLFeatureAccessibilityElement *> *_featureAccessibilityElements;
@@ -436,8 +434,6 @@ public:
// self.isAccessibilityElement = YES;
self.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"MAP_A11Y_LABEL", nil, nil, @"Map", @"Accessibility label");
self.accessibilityTraits = UIAccessibilityTraitAllowsDirectInteraction | UIAccessibilityTraitAdjustable;
- _accessibilityCompassFormatter = [[MGLCompassDirectionFormatter alloc] init];
- _accessibilityCompassFormatter.unitStyle = NSFormattingUnitStyleLong;
self.backgroundColor = [UIColor clearColor];
self.clipsToBounds = YES;
if (@available(iOS 11.0, *)) { self.accessibilityIgnoresInvertColors = YES; }
@@ -510,7 +506,7 @@ public:
// setup logo
//
- UIImage *logo = [MGLMapView resourceImageNamed:@"mapbox"];
+ UIImage *logo = [UIImage mgl_resourceImageNamed:@"mapbox"];
_logoView = [[UIImageView alloc] initWithImage:logo];
_logoView.accessibilityTraits = UIAccessibilityTraitStaticText;
_logoView.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"LOGO_A11Y_LABEL", nil, nil, @"Mapbox", @"Accessibility label");
@@ -538,14 +534,8 @@ public:
// setup compass
//
- _compassView = [[UIImageView alloc] initWithImage:self.compassImage];
- _compassView.alpha = 0;
- _compassView.userInteractionEnabled = YES;
+ _compassView = [MGLCompassButton compassButton];
[_compassView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleCompassTapGesture:)]];
- _compassView.accessibilityTraits = UIAccessibilityTraitButton;
- _compassView.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"COMPASS_A11Y_LABEL", nil, nil, @"Compass", @"Accessibility label");
- _compassView.accessibilityHint = NSLocalizedStringWithDefaultValue(@"COMPASS_A11Y_HINT", nil, nil, @"Rotates the map to face due north", @"Accessibility hint");
- _compassView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_compassView];
_compassViewConstraints = [NSMutableArray array];
_compassViewPosition = MGLOrnamentPositionTopRight;
@@ -664,26 +654,6 @@ public:
static_cast<uint32_t>(size.height) };
}
-- (UIImage *)compassImage
-{
- UIImage *scaleImage = [MGLMapView resourceImageNamed:@"Compass"];
- UIGraphicsBeginImageContextWithOptions(scaleImage.size, NO, [UIScreen mainScreen].scale);
- [scaleImage drawInRect:{ CGPointZero, scaleImage.size }];
-
- NSAttributedString *north = [[NSAttributedString alloc] initWithString:NSLocalizedStringWithDefaultValue(@"COMPASS_NORTH", nil, nil, @"N", @"Compass abbreviation for north") attributes:@{
- NSFontAttributeName: [UIFont systemFontOfSize:11 weight:UIFontWeightUltraLight],
- NSForegroundColorAttributeName: [UIColor whiteColor],
- }];
- CGRect stringRect = CGRectMake((scaleImage.size.width - north.size.width) / 2,
- scaleImage.size.height * 0.435,
- north.size.width, north.size.height);
- [north drawInRect:stringRect];
-
- UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- return image;
-}
-
- (void)reachabilityChanged:(NSNotification *)notification
{
MGLAssertIsMainThread();
@@ -4177,7 +4147,7 @@ public:
/// rect therefore excludes the bottom half.
- (MGLAnnotationImage *)defaultAnnotationImage
{
- UIImage *image = [MGLMapView resourceImageNamed:MGLDefaultStyleMarkerSymbolName];
+ UIImage *image = [UIImage mgl_resourceImageNamed:MGLDefaultStyleMarkerSymbolName];
image = [image imageWithAlignmentRectInsets:
UIEdgeInsetsMake(0, 0, image.size.height / 2, 0)];
MGLAnnotationImage *annotationImage = [MGLAnnotationImage annotationImageWithImage:image
@@ -6547,35 +6517,7 @@ public:
- (void)updateCompass
{
- CLLocationDirection direction = self.direction;
- CLLocationDirection plateDirection = mbgl::util::wrap(-direction, 0., 360.);
- self.compassView.transform = CGAffineTransformMakeRotation(MGLRadiansFromDegrees(plateDirection));
-
- self.compassView.isAccessibilityElement = direction > 0;
- self.compassView.accessibilityValue = [_accessibilityCompassFormatter stringFromDirection:direction];
-
- if (direction > 0 && self.compassView.alpha < 1)
- {
- [UIView animateWithDuration:MGLAnimationDuration
- delay:0
- options:UIViewAnimationOptionBeginFromCurrentState
- animations:^
- {
- self.compassView.alpha = 1;
- }
- completion:nil];
- }
- else if (direction == 0 && self.compassView.alpha > 0)
- {
- [UIView animateWithDuration:MGLAnimationDuration
- delay:0
- options:UIViewAnimationOptionBeginFromCurrentState
- animations:^
- {
- self.compassView.alpha = 0;
- }
- completion:nil];
- }
+ [self.compassView updateCompassWithDirection:self.direction];
}
- (void)updateScaleBar
@@ -6593,21 +6535,6 @@ public:
}
}
-+ (UIImage *)resourceImageNamed:(NSString *)imageName
-{
- UIImage *image = [UIImage imageNamed:imageName
- inBundle:[NSBundle mgl_frameworkBundle]
- compatibleWithTraitCollection:nil];
-
- if ( ! image)
- {
- [NSException raise:MGLResourceNotFoundException format:
- @"The resource named “%@” could not be found in the Mapbox framework bundle.", imageName];
- }
-
- return image;
-}
-
- (BOOL)isFullyLoaded
{
return self.mbglMap.isFullyLoaded();