summaryrefslogtreecommitdiff
path: root/platform/ios/src
diff options
context:
space:
mode:
Diffstat (limited to 'platform/ios/src')
-rw-r--r--platform/ios/src/MGLAPIClient.m26
-rw-r--r--platform/ios/src/MGLAnnotationContainerView.h17
-rw-r--r--platform/ios/src/MGLAnnotationContainerView.m52
-rw-r--r--platform/ios/src/MGLAnnotationImage.h44
-rw-r--r--platform/ios/src/MGLAnnotationImage.m2
-rw-r--r--platform/ios/src/MGLAnnotationImage_Private.h3
-rw-r--r--platform/ios/src/MGLAnnotationView.h61
-rw-r--r--platform/ios/src/MGLAnnotationView.mm147
-rw-r--r--platform/ios/src/MGLAnnotationView_Private.h15
-rw-r--r--platform/ios/src/MGLCalloutView.h77
-rw-r--r--platform/ios/src/MGLLocationManager.m18
-rw-r--r--platform/ios/src/MGLMapView+IBAdditions.h49
-rw-r--r--platform/ios/src/MGLMapView+MGLCustomStyleLayerAdditions.h26
-rw-r--r--platform/ios/src/MGLMapView.h1187
-rw-r--r--platform/ios/src/MGLMapView.mm1334
-rw-r--r--platform/ios/src/MGLMapViewDelegate.h284
-rw-r--r--platform/ios/src/MGLMapView_Internal.h17
-rw-r--r--platform/ios/src/MGLMapboxEvents.m32
-rw-r--r--platform/ios/src/MGLUserLocation.h42
-rw-r--r--platform/ios/src/MGLUserLocation.m3
-rw-r--r--platform/ios/src/MGLUserLocationAnnotationView.m87
-rw-r--r--platform/ios/src/Mapbox.h38
22 files changed, 3281 insertions, 280 deletions
diff --git a/platform/ios/src/MGLAPIClient.m b/platform/ios/src/MGLAPIClient.m
index 63adb3c463..31fd39c83d 100644
--- a/platform/ios/src/MGLAPIClient.m
+++ b/platform/ios/src/MGLAPIClient.m
@@ -14,7 +14,7 @@ static NSString * const MGLAPIClientHTTPMethodPost = @"POST";
@interface MGLAPIClient ()
@property (nonatomic, copy) NSURLSession *session;
-@property (nonatomic, copy) NSString *baseURL;
+@property (nonatomic, copy) NSURL *baseURL;
@property (nonatomic, copy) NSData *digicertCert;
@property (nonatomic, copy) NSData *geoTrustCert;
@property (nonatomic, copy) NSData *testServerCert;
@@ -47,14 +47,14 @@ static NSString * const MGLAPIClientHTTPMethodPost = @"POST";
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSError *statusError = nil;
if (httpResponse.statusCode >= 400) {
- NSString *description = [NSString stringWithFormat:NSLocalizedString(@"The session data task failed. Original request was: %@", nil), dataTask.originalRequest];
- NSString *reason = [NSString stringWithFormat:NSLocalizedString(@"The status code was %ld", nil), (long)httpResponse.statusCode];
+ NSString *description = [NSString stringWithFormat:NSLocalizedStringWithDefaultValue(@"API_CLIENT_400_DESC", nil, nil, @"The session data task failed. Original request was: %@", nil), dataTask.originalRequest];
+ NSString *reason = [NSString stringWithFormat:NSLocalizedStringWithDefaultValue(@"API_CLIENT_400_REASON", nil, nil, @"The status code was %ld", nil), (long)httpResponse.statusCode];
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: description,
NSLocalizedFailureReasonErrorKey: reason};
statusError = [NSError errorWithDomain:MGLErrorDomain code:1 userInfo:userInfo];
}
if (completionHandler) {
- error = error ? error : statusError;
+ error = error ?: statusError;
completionHandler(error);
}
[self.dataTasks removeObject:dataTask];
@@ -76,8 +76,9 @@ static NSString * const MGLAPIClientHTTPMethodPost = @"POST";
#pragma mark Utilities
- (NSURLRequest *)requestForEvents:(NS_ARRAY_OF(MGLMapboxEventAttributes *) *)events {
- NSString *url = [NSString stringWithFormat:@"%@/%@?access_token=%@", self.baseURL, MGLAPIClientEventsPath, [MGLAccountManager accessToken]];
- NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
+ NSString *path = [NSString stringWithFormat:@"%@?access_token=%@", MGLAPIClientEventsPath, [MGLAccountManager accessToken]];
+ NSURL *url = [NSURL URLWithString:path relativeToURL:self.baseURL];
+ NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setValue:self.userAgent forHTTPHeaderField:MGLAPIClientHeaderFieldUserAgentKey];
[request setValue:MGLAPIClientHeaderFieldContentTypeValue forHTTPHeaderField:MGLAPIClientHeaderFieldContentTypeKey];
[request setHTTPMethod:MGLAPIClientHTTPMethodPost];
@@ -87,12 +88,13 @@ static NSString * const MGLAPIClientHTTPMethodPost = @"POST";
}
- (void)setupBaseURL {
- NSString *testServerURL = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLMetricsTestServerURL"];
- if (testServerURL) {
- _baseURL = testServerURL;
- _usesTestServer = YES;
+ NSString *testServerURLString = [[NSUserDefaults standardUserDefaults] stringForKey:@"MGLTelemetryTestServerURL"];
+ NSURL *testServerURL = [NSURL URLWithString:testServerURLString];
+ if (testServerURL && [testServerURL.scheme isEqualToString:@"https"]) {
+ self.baseURL = testServerURL;
+ self.usesTestServer = YES;
} else {
- _baseURL = MGLAPIClientBaseURL;
+ self.baseURL = [NSURL URLWithString:MGLAPIClientBaseURL];
}
}
@@ -120,7 +122,7 @@ static NSString * const MGLAPIClientHTTPMethodPost = @"POST";
NSString *appBuildNumber = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
NSString *semanticVersion = [NSBundle mgl_frameworkInfoDictionary][@"MGLSemanticVersionString"];
NSString *shortVersion = [NSBundle mgl_frameworkInfoDictionary][@"CFBundleShortVersionString"];
- NSString *sdkVersion = semanticVersion ? semanticVersion : shortVersion;
+ NSString *sdkVersion = semanticVersion ?: shortVersion;
_userAgent = [NSString stringWithFormat:@"%@/%@/%@ %@/%@", appName, appVersion, appBuildNumber, MGLAPIClientUserAgentBase, sdkVersion];
}
diff --git a/platform/ios/src/MGLAnnotationContainerView.h b/platform/ios/src/MGLAnnotationContainerView.h
new file mode 100644
index 0000000000..90d2964831
--- /dev/null
+++ b/platform/ios/src/MGLAnnotationContainerView.h
@@ -0,0 +1,17 @@
+#import <UIKit/UIKit.h>
+
+#import "MGLTypes.h"
+
+@class MGLAnnotationView;
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface MGLAnnotationContainerView : UIView
+
++ (instancetype)annotationContainerViewWithAnnotationContainerView:(MGLAnnotationContainerView *)annotationContainerView;
+
+- (void)addSubviews:(NS_ARRAY_OF(MGLAnnotationView *) *)subviews;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/src/MGLAnnotationContainerView.m b/platform/ios/src/MGLAnnotationContainerView.m
new file mode 100644
index 0000000000..9a823c839c
--- /dev/null
+++ b/platform/ios/src/MGLAnnotationContainerView.m
@@ -0,0 +1,52 @@
+#import "MGLAnnotationContainerView.h"
+#import "MGLAnnotationView.h"
+
+@interface MGLAnnotationContainerView ()
+
+@property (nonatomic) NS_MUTABLE_ARRAY_OF(MGLAnnotationView *) *annotationViews;
+
+@end
+
+@implementation MGLAnnotationContainerView
+
+- (instancetype)initWithFrame:(CGRect)frame
+{
+ self = [super initWithFrame:frame];
+ if (self)
+ {
+ _annotationViews = [NSMutableArray array];
+ }
+ return self;
+}
+
++ (instancetype)annotationContainerViewWithAnnotationContainerView:(nonnull MGLAnnotationContainerView *)annotationContainerView
+{
+ MGLAnnotationContainerView *newAnnotationContainerView = [[MGLAnnotationContainerView alloc] initWithFrame:annotationContainerView.frame];
+ [newAnnotationContainerView addSubviews:annotationContainerView.subviews];
+ return newAnnotationContainerView;
+}
+
+- (void)addSubviews:(NS_ARRAY_OF(MGLAnnotationView *) *)subviews
+{
+ for (MGLAnnotationView *view in subviews)
+ {
+ [self addSubview:view];
+ [self.annotationViews addObject:view];
+ }
+}
+
+#pragma mark UIAccessibility methods
+
+- (UIAccessibilityTraits)accessibilityTraits {
+ return UIAccessibilityTraitAdjustable;
+}
+
+- (void)accessibilityIncrement {
+ [self.superview.superview accessibilityIncrement];
+}
+
+- (void)accessibilityDecrement {
+ [self.superview.superview accessibilityDecrement];
+}
+
+@end
diff --git a/platform/ios/src/MGLAnnotationImage.h b/platform/ios/src/MGLAnnotationImage.h
new file mode 100644
index 0000000000..fa2adb3830
--- /dev/null
+++ b/platform/ios/src/MGLAnnotationImage.h
@@ -0,0 +1,44 @@
+#import <UIKit/UIKit.h>
+
+#import "MGLTypes.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+/** The MGLAnnotationImage class is responsible for presenting point-based annotations visually on a map view. Annotation image objects wrap `UIImage` objects and may be recycled later and put into a reuse queue that is maintained by the map view. */
+@interface MGLAnnotationImage : NSObject
+
+#pragma mark Initializing and Preparing the Image Object
+
+/**
+ Initializes and returns a new annotation image object.
+
+ @param image The image to be displayed for the annotation.
+ @param reuseIdentifier The string that identifies that this annotation image is reusable.
+ @return The initialized annotation image object or `nil` if there was a problem initializing the object.
+ */
++ (instancetype)annotationImageWithImage:(UIImage *)image reuseIdentifier:(NSString *)reuseIdentifier;
+
+#pragma mark Getting and Setting Attributes
+
+/** The image to be displayed for the annotation. */
+@property (nonatomic, strong, nullable) UIImage *image;
+
+/**
+ The string that identifies that this annotation image is reusable. (read-only)
+
+ You specify the reuse identifier when you create the image object. You use this type later to retrieve an annotation image object that was created previously but which is currently unused because its annotation is not on screen.
+
+ If you define distinctly different types of annotations (with distinctly different annotation images to go with them), you can differentiate between the annotation types by specifying different reuse identifiers for each one.
+ */
+@property (nonatomic, readonly) NSString *reuseIdentifier;
+
+/**
+ A Boolean value indicating whether the annotation is enabled.
+
+ The default value of this property is `YES`. If the value of this property is `NO`, the annotation image ignores touch events and cannot be selected.
+ */
+@property (nonatomic, getter=isEnabled) BOOL enabled;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/src/MGLAnnotationImage.m b/platform/ios/src/MGLAnnotationImage.m
index 374ed162fb..e1085be98d 100644
--- a/platform/ios/src/MGLAnnotationImage.m
+++ b/platform/ios/src/MGLAnnotationImage.m
@@ -3,6 +3,8 @@
@interface MGLAnnotationImage ()
@property (nonatomic, strong) NSString *reuseIdentifier;
+@property (nonatomic, strong, nullable) NSString *styleIconIdentifier;
+
@property (nonatomic, weak) id<MGLAnnotationImageDelegate> delegate;
@end
diff --git a/platform/ios/src/MGLAnnotationImage_Private.h b/platform/ios/src/MGLAnnotationImage_Private.h
index f22a9ac4e2..dcd8a49bf9 100644
--- a/platform/ios/src/MGLAnnotationImage_Private.h
+++ b/platform/ios/src/MGLAnnotationImage_Private.h
@@ -11,6 +11,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface MGLAnnotationImage (Private)
+/// Unique identifier of the sprite image used by the style to represent the receiver’s `image`.
+@property (nonatomic, strong, nullable) NSString *styleIconIdentifier;
+
@property (nonatomic, weak) id<MGLAnnotationImageDelegate> delegate;
@end
diff --git a/platform/ios/src/MGLAnnotationView.h b/platform/ios/src/MGLAnnotationView.h
new file mode 100644
index 0000000000..5b8091e7b4
--- /dev/null
+++ b/platform/ios/src/MGLAnnotationView.h
@@ -0,0 +1,61 @@
+#import <UIKit/UIKit.h>
+
+#import "MGLTypes.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+/** The MGLAnnotationView class is responsible for representing point-based annotation markers as a view. Annotation views represent an annotation object, which is an object that corresponds to the MGLAnnotation protocol. When an annotation’s coordinate point is visible on the map view, the map view delegate is asked to provide a corresponding annotation view. If an annotation view is created with a reuse identifier, the map view may recycle the view when it goes offscreen. */
+@interface MGLAnnotationView : UIView
+
+/**
+ Initializes and returns a new annotation view object.
+
+ @param reuseIdentifier The string that identifies that this annotation view is reusable.
+ @return The initialized annotation view object.
+ */
+- (instancetype)initWithReuseIdentifier:(nullable NSString *)reuseIdentifier;
+
+/**
+ The string that identifies that this annotation view is reusable. (read-only)
+
+ You specify the reuse identifier when you create the view. You use the identifier later to retrieve an annotation view that was
+ created previously but which is currently unused because its annotation is not on screen.
+
+ If you define distinctly different types of annotations (with distinctly different annotation views to go with them), you can
+ differentiate between the annotation types by specifying different reuse identifiers for each one.
+ */
+@property (nonatomic, readonly, nullable) NSString *reuseIdentifier;
+
+/**
+ Annotation view is centered at the coordinate point of the associated annotation.
+
+ By changing this property you can reposition the view as needed. The offset is measured in points.
+ Positive offset moves the annotation view towards the bottom right, while negative offset moves it towards the top left.
+ */
+@property (nonatomic) CGVector centerOffset;
+
+
+/**
+ Setting this property to YES will force the annotation view to tilt according to the associated map view.
+ */
+@property (nonatomic, assign, getter=isFlat) BOOL flat;
+
+/**
+ Setting this property to YES will cause the annotation view to shrink as it approaches the horizon and grow as it moves away from the
+ horizon when the associated map view is tilted. Conversely, setting this property to NO will ensure that the annotation view maintains
+ a constant size even when the map view is tilted. To maintain consistency with annotation representations that are not backed by an
+ MGLAnnotationView object, the default value of this property is YES.
+ */
+@property (nonatomic, assign, getter=isScaledWithViewingDistance) BOOL scalesWithViewingDistance;
+
+/**
+ Called when the view is removed from the reuse queue.
+
+ The default implementation of this method does nothing. You can override it in your custom annotation views and use it to put the view
+ in a known state before it is returned to your map view delegate.
+ */
+- (void)prepareForReuse;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/src/MGLAnnotationView.mm b/platform/ios/src/MGLAnnotationView.mm
new file mode 100644
index 0000000000..31657dbf4e
--- /dev/null
+++ b/platform/ios/src/MGLAnnotationView.mm
@@ -0,0 +1,147 @@
+#import "MGLAnnotationView.h"
+#import "MGLAnnotationView_Private.h"
+#import "MGLMapView_Internal.h"
+
+#import "NSBundle+MGLAdditions.h"
+
+#include <mbgl/util/constants.hpp>
+
+@interface MGLAnnotationView ()
+
+@property (nonatomic) id<MGLAnnotation> annotation;
+@property (nonatomic, readwrite, nullable) NSString *reuseIdentifier;
+
+@end
+
+@implementation MGLAnnotationView
+
+- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
+{
+ self = [self initWithFrame:CGRectZero];
+ if (self)
+ {
+ _reuseIdentifier = [reuseIdentifier copy];
+ _scalesWithViewingDistance = YES;
+ }
+ return self;
+}
+
+- (void)prepareForReuse
+{
+ // Intentionally left blank. The default implementation of this method does nothing.
+}
+
+- (void)setCenterOffset:(CGVector)centerOffset
+{
+ _centerOffset = centerOffset;
+ self.center = self.center;
+}
+
+- (void)setCenter:(CGPoint)center
+{
+ [self setCenter:center pitch:0];
+}
+
+- (void)setCenter:(CGPoint)center pitch:(CGFloat)pitch
+{
+ center.x += _centerOffset.dx;
+ center.y += _centerOffset.dy;
+
+ [super setCenter:center];
+
+ if (self.flat)
+ {
+ [self updatePitch:pitch];
+ }
+
+ if (self.scalesWithViewingDistance)
+ {
+ [self updateScaleForPitch:pitch];
+ }
+}
+
+- (void)updatePitch:(CGFloat)pitch
+{
+ CATransform3D t = CATransform3DRotate(CATransform3DIdentity, MGLRadiansFromDegrees(pitch), 1.0, 0, 0);
+ self.layer.transform = t;
+}
+
+- (void)updateScaleForPitch:(CGFloat)pitch
+{
+ CGFloat superviewHeight = CGRectGetHeight(self.superview.frame);
+ if (superviewHeight > 0.0) {
+ // Find the maximum amount of scale reduction to apply as the view's center moves from the top
+ // of the superview to the bottom. For example, if this view's center has moved 25% of the way
+ // from the top of the superview towards the bottom then the maximum scale reduction is 1 - .25
+ // or 75%. The range goes from a maximum of 100% to 0% as the view moves from the top to the bottom
+ // along the y axis of its superview.
+ CGFloat maxScaleReduction = 1.0 - self.center.y / superviewHeight;
+
+ // The pitch intensity represents how much the map view is actually pitched compared to
+ // what is possible. The value will range from 0% (not pitched at all) to 100% (pitched as much
+ // as the map view will allow). The map view's maximum pitch is defined in `mbgl::util::PITCH_MAX`.
+ // Since it is possible for the map view to report a pitch less than 0 due to the nature of
+ // how the gesture information is captured, the value is guarded with MAX.
+ CGFloat pitchIntensity = MAX(pitch, 0) / MGLDegreesFromRadians(mbgl::util::PITCH_MAX);
+
+ // The pitch adjusted scale is the inverse proportion of the maximum possible scale reduction
+ // multiplied by the pitch intensity. For example, if the maximum scale reduction is 75% and the
+ // map view is 50% pitched then the annotation view should be reduced by 37.5% (.75 * .5). The
+ // reduction is then normalized for a scale of 1.0.
+ CGFloat pitchAdjustedScale = 1.0 - maxScaleReduction * pitchIntensity;
+
+ CATransform3D transform = self.flat ? self.layer.transform : CATransform3DIdentity;
+ self.layer.transform = CATransform3DScale(transform, pitchAdjustedScale, pitchAdjustedScale, 1);
+ }
+}
+
+- (id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event
+{
+ // Allow mbgl to drive animation of this view’s bounds.
+ if ([event isEqualToString:@"bounds"])
+ {
+ return [NSNull null];
+ }
+ return [super actionForLayer:layer forKey:event];
+}
+
+#pragma mark UIAccessibility methods
+
+- (BOOL)isAccessibilityElement {
+ return !self.hidden;
+}
+
+- (UIAccessibilityTraits)accessibilityTraits {
+ return UIAccessibilityTraitButton | UIAccessibilityTraitAdjustable;
+}
+
+- (NSString *)accessibilityLabel {
+ return [self.annotation respondsToSelector:@selector(title)] ? self.annotation.title : super.accessibilityLabel;
+}
+
+- (NSString *)accessibilityValue {
+ return [self.annotation respondsToSelector:@selector(subtitle)] ? self.annotation.subtitle : super.accessibilityValue;
+}
+
+- (NSString *)accessibilityHint {
+ return NSLocalizedStringWithDefaultValue(@"ANNOTATION_A11Y_HINT", nil, nil, @"Shows more info", @"Accessibility hint");
+}
+
+- (CGRect)accessibilityFrame {
+ CGRect accessibilityFrame = self.frame;
+ CGRect minimumFrame = CGRectInset({ self.center, CGSizeZero },
+ -MGLAnnotationAccessibilityElementMinimumSize.width / 2,
+ -MGLAnnotationAccessibilityElementMinimumSize.height / 2);
+ accessibilityFrame = CGRectUnion(accessibilityFrame, minimumFrame);
+ return accessibilityFrame;
+}
+
+- (void)accessibilityIncrement {
+ [self.superview accessibilityIncrement];
+}
+
+- (void)accessibilityDecrement {
+ [self.superview accessibilityDecrement];
+}
+
+@end \ No newline at end of file
diff --git a/platform/ios/src/MGLAnnotationView_Private.h b/platform/ios/src/MGLAnnotationView_Private.h
new file mode 100644
index 0000000000..c5a65487a2
--- /dev/null
+++ b/platform/ios/src/MGLAnnotationView_Private.h
@@ -0,0 +1,15 @@
+#import "MGLAnnotationView.h"
+#import "MGLAnnotation.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface MGLAnnotationView (Private)
+
+@property (nonatomic) id<MGLAnnotation> annotation;
+@property (nonatomic, readwrite, nullable) NSString *reuseIdentifier;
+
+- (void)setCenter:(CGPoint)center pitch:(CGFloat)pitch;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/src/MGLCalloutView.h b/platform/ios/src/MGLCalloutView.h
new file mode 100644
index 0000000000..641976dfee
--- /dev/null
+++ b/platform/ios/src/MGLCalloutView.h
@@ -0,0 +1,77 @@
+#import <Foundation/Foundation.h>
+
+#import "MGLTypes.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@protocol MGLCalloutViewDelegate;
+@protocol MGLAnnotation;
+
+/**
+ A protocol for a `UIView` subclass that displays information about a selected annotation near that annotation.
+ */
+@protocol MGLCalloutView <NSObject>
+
+/**
+ An object conforming to the `MGLAnnotation` protocol whose details this callout view displays.
+ */
+@property (nonatomic, strong) id <MGLAnnotation> representedObject;
+
+/**
+ A view that the user may tap to perform an action. This view is conventionally positioned on the left side of the callout view.
+ */
+@property (nonatomic, strong) UIView *leftAccessoryView;
+
+/**
+ A view that the user may tap to perform an action. This view is conventionally positioned on the right side of the callout view.
+ */
+@property (nonatomic, strong) UIView *rightAccessoryView;
+
+/**
+ An object conforming to the `MGLCalloutViewDelegate` method that receives messages related to the callout view’s interactive subviews.
+ */
+@property (nonatomic, weak) id<MGLCalloutViewDelegate> delegate;
+
+/**
+ Presents a callout view by adding it to `inView` and pointing at the given rect of `inView`’s bounds. Constrains the callout to the bounds of the given view.
+ */
+- (void)presentCalloutFromRect:(CGRect)rect inView:(UIView *)view constrainedToView:(UIView *)constrainedView animated:(BOOL)animated;
+
+/**
+ Dismisses the callout view.
+ */
+- (void)dismissCalloutAnimated:(BOOL)animated;
+
+@end
+
+/**
+ The MGLCalloutViewDelegate protocol defines a set of optional methods that you can use to receive messages from an object that conforms to the MGLCalloutView protocol. The callout view uses these methods to inform the delegate that the user has interacted with the the callout view.
+ */
+@protocol MGLCalloutViewDelegate <NSObject>
+
+@optional
+/**
+ Returns a Boolean value indicating whether the entire callout view “highlights” when tapped. The default value is `YES`, which means the callout view highlights when tapped.
+
+ The return value of this method is ignored unless the delegate also responds to the `-calloutViewTapped` method.
+ */
+- (BOOL)calloutViewShouldHighlight:(UIView<MGLCalloutView> *)calloutView;
+
+/**
+ Tells the delegate that the callout view has been tapped.
+ */
+- (void)calloutViewTapped:(UIView<MGLCalloutView> *)calloutView;
+
+/**
+ Called before the callout view appears on screen, or before the appearance animation will start.
+ */
+- (void)calloutViewWillAppear:(UIView<MGLCalloutView> *)calloutView;
+
+/**
+ Called after the callout view appears on screen, or after the appearance animation is complete.
+ */
+- (void)calloutViewDidAppear:(UIView<MGLCalloutView> *)calloutView;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/src/MGLLocationManager.m b/platform/ios/src/MGLLocationManager.m
index b5740e3547..7a9faf5c8d 100644
--- a/platform/ios/src/MGLLocationManager.m
+++ b/platform/ios/src/MGLLocationManager.m
@@ -61,12 +61,16 @@ static NSString * const MGLLocationManagerRegionIdentifier = @"MGLLocationManage
}
- (void)startLocationServices {
- if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized ||
- [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse) {
-
+ CLAuthorizationStatus authorizationStatus = [CLLocationManager authorizationStatus];
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
+ BOOL authorizedAlways = authorizationStatus == kCLAuthorizationStatusAuthorizedAlways;
+#else
+ BOOL authorizedAlways = authorizationStatus == kCLAuthorizationStatusAuthorized;
+#endif
+ if (authorizedAlways || authorizationStatus == kCLAuthorizationStatusAuthorizedWhenInUse) {
// If the host app can run in the background with `always` location permissions then allow background
// updates and start the significant location change service and background timeout timer
- if (self.hostAppHasBackgroundCapability && [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized) {
+ if (self.hostAppHasBackgroundCapability && authorizedAlways) {
[self.standardLocationManager startMonitoringSignificantLocationChanges];
[self startBackgroundTimeoutTimer];
// On iOS 9 and above also allow background location updates
@@ -121,7 +125,11 @@ static NSString * const MGLLocationManagerRegionIdentifier = @"MGLLocationManage
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
switch (status) {
- case kCLAuthorizationStatusAuthorized: // Also handles kCLAuthorizationStatusAuthorizedAlways
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
+ case kCLAuthorizationStatusAuthorizedAlways:
+#else
+ case kCLAuthorizationStatusAuthorized:
+#endif
case kCLAuthorizationStatusAuthorizedWhenInUse:
[self startUpdatingLocation];
break;
diff --git a/platform/ios/src/MGLMapView+IBAdditions.h b/platform/ios/src/MGLMapView+IBAdditions.h
new file mode 100644
index 0000000000..f18df56e01
--- /dev/null
+++ b/platform/ios/src/MGLMapView+IBAdditions.h
@@ -0,0 +1,49 @@
+#import <Foundation/Foundation.h>
+
+#import "MGLTypes.h"
+
+@class MGLMapView;
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface MGLMapView (IBAdditions)
+
+// Core properties that can be manipulated in the Attributes inspector in
+// Interface Builder. These redeclarations merely add the IBInspectable keyword.
+// They appear here to ensure that they appear above the convenience properties;
+// inspectables declared in MGLMapView.h are always sorted before those in
+// MGLMapView+IBAdditions.h, due to ASCII sort order.
+
+#if TARGET_INTERFACE_BUILDER
+
+// HACK: We want this property to look like a URL bar in the Attributes
+// inspector, but just calling it styleURL would violate Cocoa naming
+// conventions and conflict with the existing NSURL property. Fortunately, IB
+// strips out the two underscores for display.
+@property (nonatomic, nullable) IBInspectable NSString *styleURL__;
+
+#endif // TARGET_INTERFACE_BUILDER
+
+// Convenience properties related to the initial viewport. These properties
+// are not meant to be used outside of Interface Builder. latitude and longitude
+// are backed by properties of type CLLocationDegrees, but these declarations
+// must use the type double because Interface Builder is unaware that
+// CLLocationDegrees is a typedef for double.
+
+@property (nonatomic) IBInspectable double latitude;
+@property (nonatomic) IBInspectable double longitude;
+@property (nonatomic) IBInspectable double zoomLevel;
+
+// Renamed properties. Interface Builder derives the display name of each
+// inspectable from the runtime name, but runtime names don’t always make sense
+// in UI.
+
+@property (nonatomic) IBInspectable BOOL allowsZooming;
+@property (nonatomic) IBInspectable BOOL allowsScrolling;
+@property (nonatomic) IBInspectable BOOL allowsRotating;
+@property (nonatomic) IBInspectable BOOL allowsTilting;
+@property (nonatomic) IBInspectable BOOL showsUserLocation;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/src/MGLMapView+MGLCustomStyleLayerAdditions.h b/platform/ios/src/MGLMapView+MGLCustomStyleLayerAdditions.h
new file mode 100644
index 0000000000..de4dc01f99
--- /dev/null
+++ b/platform/ios/src/MGLMapView+MGLCustomStyleLayerAdditions.h
@@ -0,0 +1,26 @@
+#import "MGLMapView.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+typedef void (^MGLCustomStyleLayerPreparationHandler)(void);
+
+typedef void (^MGLCustomStyleLayerDrawingHandler)(CGSize size,
+ CLLocationCoordinate2D centerCoordinate,
+ double zoomLevel,
+ CLLocationDirection direction,
+ CGFloat pitch,
+ CGFloat perspectiveSkew);
+
+typedef void (^MGLCustomStyleLayerCompletionHandler)(void);
+
+@interface MGLMapView (MGLCustomStyleLayerAdditions)
+
+- (void)insertCustomStyleLayerWithIdentifier:(NSString *)identifier preparationHandler:(MGLCustomStyleLayerPreparationHandler)preparation drawingHandler:(MGLCustomStyleLayerDrawingHandler)drawing completionHandler:(MGLCustomStyleLayerCompletionHandler)completion belowStyleLayerWithIdentifier:(nullable NSString *)otherIdentifier;
+
+- (void)removeCustomStyleLayerWithIdentifier:(NSString *)identifier;
+
+- (void)setCustomStyleLayersNeedDisplay;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h
new file mode 100644
index 0000000000..63d799bda9
--- /dev/null
+++ b/platform/ios/src/MGLMapView.h
@@ -0,0 +1,1187 @@
+#import "MGLGeometry.h"
+#import "MGLMapCamera.h"
+
+#import <UIKit/UIKit.h>
+#import <CoreLocation/CoreLocation.h>
+
+#import "MGLTypes.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@class MGLAnnotationView;
+@class MGLAnnotationImage;
+@class MGLUserLocation;
+@class MGLPolyline;
+@class MGLPolygon;
+@class MGLShape;
+
+@protocol MGLMapViewDelegate;
+@protocol MGLAnnotation;
+@protocol MGLOverlay;
+@protocol MGLCalloutView;
+@protocol MGLFeature;
+
+/** The vertical alignment of an annotation within a map view. */
+typedef NS_ENUM(NSUInteger, MGLAnnotationVerticalAlignment) {
+ /** Aligns the annotation vertically in the center of the map view. */
+ MGLAnnotationVerticalAlignmentCenter = 0,
+ /** Aligns the annotation vertically at the top of the map view. */
+ MGLAnnotationVerticalAlignmentTop,
+ /** Aligns the annotation vertically at the bottom of the map view. */
+ MGLAnnotationVerticalAlignmentBottom,
+};
+
+/** Options for enabling debugging features in an MGLMapView instance. */
+typedef NS_OPTIONS(NSUInteger, MGLMapDebugMaskOptions) {
+ /** Edges of tile boundaries are shown as thick, red lines to help diagnose
+ tile clipping issues. */
+ MGLMapDebugTileBoundariesMask = 1 << 1,
+ /** Each tile shows its tile coordinate (x/y/z) in the upper-left corner. */
+ MGLMapDebugTileInfoMask = 1 << 2,
+ /** Each tile shows a timestamp indicating when it was loaded. */
+ MGLMapDebugTimestampsMask = 1 << 3,
+ /** Edges of glyphs and symbols are shown as faint, green lines to help
+ diagnose collision and label placement issues. */
+ MGLMapDebugCollisionBoxesMask = 1 << 4,
+ /** Line widths, backgrounds, and fill colors are ignored to create a
+ wireframe effect. */
+ MGLMapDebugWireframesMask = 1 << 5,
+};
+
+/**
+ An interactive, customizable map view with an interface similar to the one
+ provided by Apple's MapKit.
+
+ Using `MGLMapView`, you can embed the map inside a view, allow users to
+ manipulate it with standard gestures, animate the map between different
+ viewpoints, and present information in the form of annotations and overlays.
+
+ The map view loads scalable vector tiles that conform to the
+ <a href="https://github.com/mapbox/vector-tile-spec">Mapbox Vector Tile Specification</a>.
+ It styles them with a style that conforms to the
+ <a href="https://www.mapbox.com/mapbox-gl-style-spec/">Mapbox GL style specification</a>.
+ Such styles can be designed in
+ <a href="https://www.mapbox.com/studio/">Mapbox Studio</a> and hosted on
+ mapbox.com.
+
+ A collection of Mapbox-hosted styles is available through the `MGLStyle`
+ class. These basic styles use
+ <a href="https://www.mapbox.com/developers/vector-tiles/mapbox-streets">Mapbox Streets</a>
+ or <a href="https://www.mapbox.com/satellite/">Mapbox Satellite</a> data
+ sources, but you can specify a custom style that makes use of your own data.
+
+ Mapbox-hosted vector tiles and styles require an API access token, which you
+ can obtain from the
+ <a href="https://www.mapbox.com/studio/account/tokens/">Mapbox account page</a>.
+ Access tokens associate requests to Mapbox's vector tile and style APIs with
+ your Mapbox account. They also deter other developers from using your styles
+ without your permission.
+
+ @note You are responsible for getting permission to use the map data and for
+ ensuring that your use adheres to the relevant terms of use.
+ */
+IB_DESIGNABLE
+@interface MGLMapView : UIView
+
+#pragma mark Creating Instances
+
+/**
+ Initializes and returns a newly allocated map view with the specified frame
+ and the default style.
+
+ @param frame The frame for the view, measured in points.
+ @return An initialized map view.
+ */
+- (instancetype)initWithFrame:(CGRect)frame;
+
+/**
+ Initializes and returns a newly allocated map view with the specified frame
+ and style URL.
+
+ @param frame The frame for the view, measured in points.
+ @param styleURL URL of the map style to display. The URL may be a full HTTP
+ or HTTPS URL, a Mapbox URL indicating the style's map ID
+ (`mapbox://styles/{user}/{style}`), or a path to a local file relative
+ to the application's resource path. Specify `nil` for the default style.
+ @return An initialized map view.
+ */
+- (instancetype)initWithFrame:(CGRect)frame styleURL:(nullable NSURL *)styleURL;
+
+#pragma mark Accessing the Delegate
+
+/**
+ The receiver's delegate.
+
+ A map view sends messages to its delegate to notify it of changes to its
+ contents or the viewpoint. The delegate also provides information about
+ annotations displayed on the map, such as the styles to apply to individual
+ annotations.
+ */
+@property(nonatomic, weak, nullable) IBOutlet id<MGLMapViewDelegate> delegate;
+
+#pragma mark Configuring the Map's Appearance
+
+/**
+ URLs of the styles bundled with the library.
+
+ @deprecated Call the relevant class method of `MGLStyle` for the URL of a
+ particular default style.
+ */
+@property (nonatomic, readonly) NS_ARRAY_OF(NSURL *) *bundledStyleURLs __attribute__((deprecated("Call the relevant class method of MGLStyle for the URL of a particular default style.")));
+
+/**
+ URL of the style currently displayed in the receiver.
+
+ The URL may be a full HTTP or HTTPS URL, a Mapbox URL indicating the style's
+ map ID (`mapbox://styles/{user}/{style}`), or a path to a local file
+ relative to the application's resource path.
+
+ If you set this property to `nil`, the receiver will use the default style
+ and this property will automatically be set to that style's URL.
+ */
+@property (nonatomic, null_resettable) NSURL *styleURL;
+
+/**
+ Reloads the style.
+
+ You do not normally need to call this method. The map view automatically
+ responds to changes in network connectivity by reloading the style. You may
+ need to call this method if you change the access token after a style has
+ loaded but before loading a style associated with a different Mapbox account.
+
+ This method does not bust the cache. Even if the style has recently changed on
+ the server, calling this method does not necessarily ensure that the map view
+ reflects those changes.
+ */
+- (IBAction)reloadStyle:(id)sender;
+
+/**
+ A control indicating the map's direction and allowing the user to manipulate
+ the direction, positioned in the upper-right corner.
+ */
+@property (nonatomic, readonly) UIImageView *compassView;
+
+/**
+ The Mapbox logo, positioned in the lower-left corner.
+
+ @note The Mapbox terms of service, which governs the use of Mapbox-hosted
+ vector tiles and styles,
+ <a href="https://www.mapbox.com/help/mapbox-logo/">requires</a> most Mapbox
+ customers to display the Mapbox logo. If this applies to you, do not
+ hide this view or change its contents.
+ */
+@property (nonatomic, readonly) UIImageView *logoView;
+
+/**
+ A view showing legally required copyright notices and telemetry settings,
+ positioned at the bottom-right of the map view.
+
+ @note The Mapbox terms of service, which governs the use of Mapbox-hosted
+ vector tiles and styles,
+ <a href="https://www.mapbox.com/help/attribution/">requires</a> these
+ copyright notices to accompany any map that features Mapbox-designed styles,
+ OpenStreetMap data, or other Mapbox data such as satellite or terrain
+ data. If that applies to this map view, do not hide this view or remove
+ any notices from it.
+
+ @note You are additionally
+ <a href="https://www.mapbox.com/help/telemetry-opt-out-for-users/">required</a>
+ to provide users with the option to disable anonymous usage and location
+ sharing (telemetry). If this view is hidden, you must implement this
+ setting elsewhere in your app or via `Settings.bundle`. See our
+ <a href="https://www.mapbox.com/ios-sdk/#telemetry_opt_out">website</a> for
+ implementation help.
+ */
+@property (nonatomic, readonly) UIButton *attributionButton;
+
+/**
+ Currently active style classes, represented as an array of string identifiers.
+ */
+@property (nonatomic) NS_ARRAY_OF(NSString *) *styleClasses;
+
+/**
+ Returns a Boolean value indicating whether the style class with the given
+ identifier is currently active.
+
+ @param styleClass The style class to query for.
+ @return Whether the style class is currently active.
+ */
+- (BOOL)hasStyleClass:(NSString *)styleClass;
+
+/**
+ Activates the style class with the given identifier.
+
+ @param styleClass The style class to activate.
+ */
+- (void)addStyleClass:(NSString *)styleClass;
+
+/**
+ Deactivates the style class with the given identifier.
+
+ @param styleClass The style class to deactivate.
+ */
+- (void)removeStyleClass:(NSString *)styleClass;
+
+#pragma mark Displaying the User's Location
+
+/**
+ A Boolean value indicating whether the map may display the user location.
+
+ Setting this property to `YES` causes the map view to use the Core Location
+ framework to find the current location. As long as this property is `YES`, the
+ map view continues to track the user's location and update it periodically.
+
+ This property does not indicate whether the user's position is actually visible
+ on the map, only whether the map view is allowed to display it. To determine
+ whether the user's position is visible, use the `userLocationVisible` property.
+ The default value of this property is `NO`.
+
+ On iOS 8 and above, your app must specify a value for
+ `NSLocationWhenInUseUsageDescription` or `NSLocationAlwaysUsageDescription` in
+ its `Info.plist` to satisfy the requirements of the underlying Core Location
+ framework when enabling this property.
+ */
+@property (nonatomic, assign) BOOL showsUserLocation;
+
+/**
+ A Boolean value indicating whether the device's current location is visible in
+ the map view.
+
+ Use `showsUserLocation` to control the visibility of the on-screen user
+ location annotation.
+ */
+@property (nonatomic, assign, readonly, getter=isUserLocationVisible) BOOL userLocationVisible;
+
+/**
+ Returns the annotation object indicating the user's current location.
+ */
+@property (nonatomic, readonly, nullable) MGLUserLocation *userLocation;
+
+/**
+ The mode used to track the user location. The default value is
+ `MGLUserTrackingModeNone`.
+
+ Changing the value of this property updates the map view with an animated
+ transition. If you don’t want to animate the change, use the
+ `-setUserTrackingMode:animated:` method instead.
+ */
+@property (nonatomic, assign) MGLUserTrackingMode userTrackingMode;
+
+/**
+ Sets the mode used to track the user location, with an optional transition.
+
+ @param mode The mode used to track the user location.
+ @param animated If `YES`, there is an animated transition from the current
+ viewport to a viewport that results from the change to `mode`. If `NO`, the
+ map view instantaneously changes to the new viewport. This parameter only
+ affects the initial transition; subsequent changes to the user location or
+ heading are always animated.
+ */
+- (void)setUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated;
+
+/**
+ The vertical alignment of the user location annotation within the receiver. The
+ default value is `MGLAnnotationVerticalAlignmentCenter`.
+
+ Changing the value of this property updates the map view with an animated
+ transition. If you don’t want to animate the change, use the
+ `-setUserLocationVerticalAlignment:animated:` method instead.
+ */
+@property (nonatomic, assign) MGLAnnotationVerticalAlignment userLocationVerticalAlignment;
+
+/**
+ Sets the vertical alignment of the user location annotation within the
+ receiver, with an optional transition.
+
+ @param alignment The vertical alignment of the user location annotation.
+ @param animated If `YES`, the user location annotation animates to its new
+ position within the map view. If `NO`, the user location annotation
+ instantaneously moves to its new position.
+ */
+- (void)setUserLocationVerticalAlignment:(MGLAnnotationVerticalAlignment)alignment animated:(BOOL)animated;
+
+/**
+ Whether the map view should display a heading calibration alert when necessary.
+ The default value is `YES`.
+ */
+@property (nonatomic, assign) BOOL displayHeadingCalibration;
+
+/**
+ The geographic coordinate that is the subject of observation as the user
+ location is being tracked.
+
+ By default, this property is set to an invalid coordinate, indicating that
+ there is no target. In course tracking mode, the target forms one of two foci
+ in the viewport, the other being the user location annotation. Typically, this
+ property is set to a destination or waypoint in a real-time navigation scene.
+ As the user annotation moves toward the target, the map automatically zooms in
+ to fit both foci optimally within the viewport.
+
+ This property has no effect if the `userTrackingMode` property is set to a
+ value other than `MGLUserTrackingModeFollowWithCourse`.
+
+ Changing the value of this property updates the map view with an animated
+ transition. If you don’t want to animate the change, use the
+ `-setTargetCoordinate:animated:` method instead.
+ */
+@property (nonatomic, assign) CLLocationCoordinate2D targetCoordinate;
+
+/**
+ Sets the geographic coordinate that is the subject of observation as the user
+ location is being tracked, with an optional transition animation.
+
+ By default, the target coordinate is set to an invalid coordinate, indicating
+ that there is no target. In course tracking mode, the target forms one of two
+ foci in the viewport, the other being the user location annotation. Typically,
+ the target is set to a destination or waypoint in a real-time navigation scene.
+ As the user annotation moves toward the target, the map automatically zooms in
+ to fit both foci optimally within the viewport.
+
+ This method has no effect if the `userTrackingMode` property is set to a value
+ other than `MGLUserTrackingModeFollowWithCourse`.
+
+ @param targetCoordinate The target coordinate to fit within the viewport.
+ @param animated If `YES`, the map animates to fit the target within the map
+ view. If `NO`, the map fits the target instantaneously.
+ */
+- (void)setTargetCoordinate:(CLLocationCoordinate2D)targetCoordinate animated:(BOOL)animated;
+
+#pragma mark Configuring How the User Interacts with the Map
+
+/**
+ A Boolean value that determines whether the user may zoom the map in and
+ out, changing the zoom level.
+
+ When this property is set to `YES`, the default, the user may zoom the map
+ in and out by pinching two fingers or by double tapping, holding, and moving
+ the finger up and down.
+
+ This property controls only user interactions with the map. If you set the
+ value of this property to `NO`, you may still change the map zoom
+ programmatically.
+ */
+@property(nonatomic, getter=isZoomEnabled) BOOL zoomEnabled;
+
+/**
+ A Boolean value that determines whether the user may scroll around the map,
+ changing the center coordinate.
+
+ When this property is set to `YES`, the default, the user may scroll the map
+ by dragging or swiping with one finger.
+
+ This property controls only user interactions with the map. If you set the
+ value of this property to `NO`, you may still change the map location
+ programmatically.
+ */
+@property(nonatomic, getter=isScrollEnabled) BOOL scrollEnabled;
+
+/**
+ A Boolean value that determines whether the user may rotate the map,
+ changing the direction.
+
+ When this property is set to `YES`, the default, the user may rotate the map
+ by moving two fingers in a circular motion.
+
+ This property controls only user interactions with the map. If you set the
+ value of this property to `NO`, you may still rotate the map
+ programmatically.
+ */
+@property(nonatomic, getter=isRotateEnabled) BOOL rotateEnabled;
+
+/**
+ A Boolean value that determines whether the user may change the pitch (tilt) of
+ the map.
+
+ When this property is set to `YES`, the default, the user may tilt the map by
+ vertically dragging two fingers.
+
+ This property controls only user interactions with the map. If you set the
+ value of this property to `NO`, you may still change the pitch of the map
+ programmatically.
+
+ The default value of this property is `YES`.
+ */
+@property(nonatomic, getter=isPitchEnabled) BOOL pitchEnabled;
+
+#pragma mark Manipulating the Viewpoint
+
+/**
+ The geographic coordinate at the center of the map view.
+
+ Changing the value of this property centers the map on the new coordinate
+ without changing the current zoom level.
+
+ Changing the value of this property updates the map view immediately. If you
+ want to animate the change, use the `-setCenterCoordinate:animated:` method
+ instead.
+ */
+@property (nonatomic) CLLocationCoordinate2D centerCoordinate;
+
+/**
+ Changes the center coordinate of the map and optionally animates the change.
+
+ Changing the center coordinate centers the map on the new coordinate without
+ changing the current zoom level.
+
+ @param coordinate The new center coordinate for the map.
+ @param animated Specify `YES` if you want the map view to scroll to the new
+ location or `NO` if you want the map to display the new location
+ immediately.
+ */
+- (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated;
+
+/**
+ Changes the center coordinate and zoom level of the map and optionally animates
+ the change.
+
+ @param centerCoordinate The new center coordinate for the map.
+ @param zoomLevel The new zoom level for the map.
+ @param animated Specify `YES` if you want the map view to animate scrolling and
+ zooming to the new location or `NO` if you want the map to display the new
+ location immediately.
+ */
+- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel animated:(BOOL)animated;
+
+/**
+ Changes the center coordinate, zoom level, and direction of the map and
+ optionally animates the change.
+
+ @param centerCoordinate The new center coordinate for the map.
+ @param zoomLevel The new zoom level for the map.
+ @param direction The new direction for the map, measured in degrees relative to
+ true north.
+ @param animated Specify `YES` if you want the map view to animate scrolling,
+ zooming, and rotating to the new location or `NO` if you want the map to
+ display the new location immediately.
+ */
+- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel direction:(CLLocationDirection)direction animated:(BOOL)animated;
+
+/**
+ Changes the center coordinate, zoom level, and direction of the map, calling a
+ completion handler at the end of an optional animation.
+
+ @param centerCoordinate The new center coordinate for the map.
+ @param zoomLevel The new zoom level for the map.
+ @param direction The new direction for the map, measured in degrees relative to
+ true north.
+ @param animated Specify `YES` if you want the map view to animate scrolling,
+ zooming, and rotating to the new location or `NO` if you want the map to
+ display the new location immediately.
+ @param completion The block executed after the animation finishes.
+ */
+- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel direction:(CLLocationDirection)direction animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion;
+
+/** The zoom level of the receiver.
+
+ In addition to affecting the visual size and detail of features on the map,
+ the zoom level affects the size of the vector tiles that are loaded. At zoom
+ level 0, each tile covers the entire world map; at zoom level 1, it covers ¼
+ of the world; at zoom level 2, <sup>1</sup>⁄<sub>16</sub> of the world, and
+ so on.
+
+ Changing the value of this property updates the map view immediately. If you
+ want to animate the change, use the `-setZoomLevel:animated:` method instead.
+ */
+@property (nonatomic) double zoomLevel;
+
+/**
+ Changes the zoom level of the map and optionally animates the change.
+
+ Changing the zoom level scales the map without changing the current center
+ coordinate.
+
+ @param zoomLevel The new zoom level for the map.
+ @param animated Specify `YES` if you want the map view to animate the change
+ to the new zoom level or `NO` if you want the map to display the new
+ zoom level immediately.
+ */
+- (void)setZoomLevel:(double)zoomLevel animated:(BOOL)animated;
+
+/**
+ * The minimum zoom level at which the map can be shown.
+ *
+ * Depending on the map view’s aspect ratio, the map view may be prevented
+ * from reaching the minimum zoom level, in order to keep the map from
+ * repeating within the current viewport.
+ *
+ * If the value of this property is greater than that of the
+ * maximumZoomLevel property, the behavior is undefined.
+ *
+ * The default minimumZoomLevel is 0.
+ */
+@property (nonatomic) double minimumZoomLevel;
+
+/**
+ * The maximum zoom level the map can be shown at.
+ *
+ * If the value of this property is smaller than that of the
+ * minimumZoomLevel property, the behavior is undefined.
+ *
+ * The default maximumZoomLevel is 20.
+ */
+@property (nonatomic) double maximumZoomLevel;
+
+/**
+ The heading of the map, measured in degrees clockwise from true north.
+
+ The value `0` means that the top edge of the map view corresponds to true
+ north. The value `90` means the top of the map is pointing due east. The
+ value `180` means the top of the map points due south, and so on.
+
+ Changing the value of this property updates the map view immediately. If you
+ want to animate the change, use the `-setDirection:animated:` method instead.
+ */
+@property (nonatomic) CLLocationDirection direction;
+
+/**
+ Changes the heading of the map and optionally animates the change.
+
+ @param direction The heading of the map, measured in degrees clockwise from
+ true north.
+ @param animated Specify `YES` if you want the map view to animate the change
+ to the new heading or `NO` if you want the map to display the new
+ heading immediately.
+
+ Changing the heading rotates the map without changing the current center
+ coordinate or zoom level.
+ */
+- (void)setDirection:(CLLocationDirection)direction animated:(BOOL)animated;
+
+/**
+ Resets the map rotation to a northern heading — a `direction` of `0` degrees.
+ */
+- (IBAction)resetNorth;
+
+/**
+ The coordinate bounds visible in the receiver's viewport.
+
+ Changing the value of this property updates the receiver immediately. If you
+ want to animate the change, call `-setVisibleCoordinateBounds:animated:`
+ instead.
+ */
+@property (nonatomic) MGLCoordinateBounds visibleCoordinateBounds;
+
+/**
+ Changes the receiver’s viewport to fit the given coordinate bounds,
+ optionally animating the change.
+
+ @param bounds The bounds that the viewport will show in its entirety.
+ @param animated Specify `YES` to animate the change by smoothly scrolling
+ and zooming or `NO` to immediately display the given bounds.
+ */
+- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds animated:(BOOL)animated;
+
+/**
+ Changes the receiver's viewport to fit the given coordinate bounds and
+ optionally some additional padding on each side.
+
+ @param bounds The bounds that the viewport will show in its entirety.
+ @param insets The minimum padding (in screen points) that will be visible
+ around the given coordinate bounds.
+ @param animated Specify `YES` to animate the change by smoothly scrolling and
+ zooming or `NO` to immediately display the given bounds.
+ */
+- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated;
+
+/**
+ Changes the receiver's viewport to fit all of the given coordinates and
+ optionally some additional padding on each side.
+
+ @param coordinates The coordinates that the viewport will show.
+ @param count The number of coordinates. This number must not be greater than
+ the number of elements in `coordinates`.
+ @param insets The minimum padding (in screen points) that will be visible
+ around the given coordinate bounds.
+ @param animated Specify `YES` to animate the change by smoothly scrolling and
+ zooming or `NO` to immediately display the given bounds.
+ */
+- (void)setVisibleCoordinates:(CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated;
+
+/**
+ Changes the receiver's viewport to fit all of the given coordinates and
+ optionally some additional padding on each side.
+
+ @param coordinates The coordinates that the viewport will show.
+ @param count The number of coordinates. This number must not be greater than
+ the number of elements in `coordinates`.
+ @param insets The minimum padding (in screen points) that will be visible
+ around the given coordinate bounds.
+ @param direction The direction to rotate the map to, measured in degrees
+ relative to true north.
+ @param duration The duration to animate the change in seconds.
+ @param function The timing function to animate the change.
+ @param completion The block executed after the animation finishes.
+ */
+- (void)setVisibleCoordinates:(CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction duration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion;
+
+/**
+ Sets the visible region so that the map displays the specified annotations.
+
+ Calling this method updates the value in the `visibleCoordinateBounds` property
+ and potentially other properties to reflect the new map region. A small amount
+ of padding is reserved around the edges of the map view. To specify a different
+ amount of padding, use the `-showAnnotations:edgePadding:animated:` method.
+
+ @param annotations The annotations that you want to be visible in the map.
+ @param animated `YES` if you want the map region change to be animated, or `NO`
+ if you want the map to display the new region immediately without animations.
+ */
+- (void)showAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations animated:(BOOL)animated;
+
+/**
+ Sets the visible region so that the map displays the specified annotations with
+ the specified amount of padding on each side.
+
+ Calling this method updates the value in the visibleCoordinateBounds property
+ and potentially other properties to reflect the new map region.
+
+ @param annotations The annotations that you want to be visible in the map.
+ @param insets The minimum padding (in screen points) around the edges of the
+ map view to keep clear of annotations.
+ @param animated `YES` if you want the map region change to be animated, or `NO`
+ if you want the map to display the new region immediately without animations.
+ */
+- (void)showAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated;
+
+/**
+ A camera representing the current viewpoint of the map.
+ */
+@property (nonatomic, copy) MGLMapCamera *camera;
+
+/**
+ Moves the viewpoint to a different location with respect to the map with an
+ optional transition animation.
+
+ @param camera The new viewpoint.
+ @param animated Specify `YES` if you want the map view to animate the change to
+ the new viewpoint or `NO` if you want the map to display the new viewpoint
+ immediately.
+ */
+- (void)setCamera:(MGLMapCamera *)camera animated:(BOOL)animated;
+
+/**
+ Moves the viewpoint to a different location with respect to the map with an
+ optional transition duration and timing function.
+
+ @param camera The new viewpoint.
+ @param duration The amount of time, measured in seconds, that the transition
+ animation should take. Specify `0` to jump to the new viewpoint
+ instantaneously.
+ @param function A timing function used for the animation. Set this parameter to
+ `nil` for a transition that matches most system animations. If the duration
+ is `0`, this parameter is ignored.
+ */
+- (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function;
+
+/**
+ Moves the viewpoint to a different location with respect to the map with an
+ optional transition duration and timing function.
+
+ @param camera The new viewpoint.
+ @param duration The amount of time, measured in seconds, that the transition
+ animation should take. Specify `0` to jump to the new viewpoint
+ instantaneously.
+ @param function A timing function used for the animation. Set this parameter to
+ `nil` for a transition that matches most system animations. If the duration
+ is `0`, this parameter is ignored.
+ @param completion The block to execute after the animation finishes.
+ */
+- (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion;
+
+/**
+ Moves the viewpoint to a different location using a transition animation that
+ evokes powered flight and a default duration based on the length of the flight
+ path.
+
+ The transition animation seamlessly incorporates zooming and panning to help
+ the user find his or her bearings even after traversing a great distance.
+
+ @param camera The new viewpoint.
+ @param completion The block to execute after the animation finishes.
+ */
+- (void)flyToCamera:(MGLMapCamera *)camera completionHandler:(nullable void (^)(void))completion;
+
+/**
+ Moves the viewpoint to a different location using a transition animation that
+ evokes powered flight and an optional transition duration.
+
+ The transition animation seamlessly incorporates zooming and panning to help
+ the user find his or her bearings even after traversing a great distance.
+
+ @param camera The new viewpoint.
+ @param duration The amount of time, measured in seconds, that the transition
+ animation should take. Specify `0` to jump to the new viewpoint
+ instantaneously. Specify a negative value to use the default duration, which
+ is based on the length of the flight path.
+ @param completion The block to execute after the animation finishes.
+ */
+- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion;
+
+/**
+ Moves the viewpoint to a different location using a transition animation that
+ evokes powered flight and an optional transition duration and peak altitude.
+
+ The transition animation seamlessly incorporates zooming and panning to help
+ the user find his or her bearings even after traversing a great distance.
+
+ @param camera The new viewpoint.
+ @param duration The amount of time, measured in seconds, that the transition
+ animation should take. Specify `0` to jump to the new viewpoint
+ instantaneously. Specify a negative value to use the default duration, which
+ is based on the length of the flight path.
+ @param peakAltitude The altitude, measured in meters, at the midpoint of the
+ animation. The value of this parameter is ignored if it is negative or if
+ the animation transition resulting from a similar call to
+ `-setCamera:animated:` would have a midpoint at a higher altitude.
+ @param completion The block to execute after the animation finishes.
+ */
+- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration peakAltitude:(CLLocationDistance)peakAltitude completionHandler:(nullable void (^)(void))completion;
+
+/**
+ Returns the camera that best fits the given coordinate bounds.
+
+ @param bounds The coordinate bounds to fit to the receiver’s viewport.
+ @return A camera object centered on the same location as the coordinate
+ bounds with zoom level as high (close to the ground) as possible while still
+ including the entire coordinate bounds. The camera object uses the current
+ direction and pitch.
+ */
+- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds;
+
+/**
+ Returns the camera that best fits the given coordinate bounds, optionally with
+ some additional padding on each side.
+
+ @param bounds The coordinate bounds to fit to the receiver’s viewport.
+ @param insets The minimum padding (in screen points) that would be visible
+ around the returned camera object if it were set as the receiver’s camera.
+ @return A camera object centered on the same location as the coordinate bounds
+ with zoom level as high (close to the ground) as possible while still
+ including the entire coordinate bounds. The camera object uses the current
+ direction and pitch.
+ */
+- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets;
+
+/**
+ The distance from the edges of the map view’s frame to the edges of the map
+ view’s logical viewport.
+
+ When the value of this property is equal to `UIEdgeInsetsZero`, viewport
+ properties such as `centerCoordinate` assume a viewport that matches the map
+ view’s frame. Otherwise, those properties are inset, excluding part of the
+ frame from the viewport. For instance, if the only the top edge is inset, the
+ map center is effectively shifted downward.
+
+ When the map view’s superview is an instance of `UIViewController` whose
+ `automaticallyAdjustsScrollViewInsets` property is `YES`, the value of this
+ property may be overridden at any time.
+
+ Changing the value of this property updates the map view immediately. If you
+ want to animate the change, use the `-setContentInset:animated:` method
+ instead.
+ */
+@property (nonatomic, assign) UIEdgeInsets contentInset;
+
+/**
+ Sets the distance from the edges of the map view’s frame to the edges of the
+ map view’s logical viewport with an optional transition animation.
+
+ When the value of this property is equal to `UIEdgeInsetsZero`, viewport
+ properties such as `centerCoordinate` assume a viewport that matches the map
+ view’s frame. Otherwise, those properties are inset, excluding part of the
+ frame from the viewport. For instance, if the only the top edge is inset, the
+ map center is effectively shifted downward.
+
+ When the map view’s superview is an instance of `UIViewController` whose
+ `automaticallyAdjustsScrollViewInsets` property is `YES`, the value of this
+ property may be overridden at any time.
+
+ @param contentInset The new values to inset the content by.
+ @param animated Specify `YES` if you want the map view to animate the change to
+ the content inset or `NO` if you want the map to inset the content
+ immediately.
+ */
+- (void)setContentInset:(UIEdgeInsets)contentInset animated:(BOOL)animated;
+
+#pragma mark Converting Geographic Coordinates
+
+/**
+ Converts a point in the given view's coordinate system to a geographic
+ coordinate.
+
+ @param point The point to convert.
+ @param view The view in whose coordinate system the point is expressed.
+ @return The geographic coordinate at the given point.
+ */
+- (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(nullable UIView *)view;
+
+/**
+ Converts a geographic coordinate to a point in the given view's coordinate
+ system.
+
+ @param coordinate The geographic coordinate to convert.
+ @param view The view in whose coordinate system the returned point should be
+ expressed. If this parameter is `nil`, the returned point is expressed
+ in the window's coordinate system. If `view` is not `nil`, it must
+ belong to the same window as the map view.
+ @return The point (in the appropriate view or window coordinate system)
+ corresponding to the given geographic coordinate.
+ */
+- (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(nullable UIView *)view;
+
+/**
+ Converts a rectangle in the given view’s coordinate system to a geographic
+ bounding box.
+
+ @param rect The rectangle to convert.
+ @param view The view in whose coordinate system the rectangle is expressed.
+ @return The geographic bounding box coextensive with the given rectangle.
+ */
+- (MGLCoordinateBounds)convertRect:(CGRect)rect toCoordinateBoundsFromView:(nullable UIView *)view;
+
+/**
+ Converts a geographic bounding box to a rectangle in the given view’s
+ coordinate system.
+
+ @param bounds The geographic bounding box to convert.
+ @param view The view in whose coordinate system the returned rectangle should
+ be expressed. If this parameter is `nil`, the returned rectangle is
+ expressed in the window’s coordinate system. If `view` is not `nil`, it must
+ belong to the same window as the map view.
+ */
+- (CGRect)convertCoordinateBounds:(MGLCoordinateBounds)bounds toRectToView:(nullable UIView *)view;
+
+/**
+ Returns the distance spanned by one point in the map view's coordinate system
+ at the given latitude and current zoom level.
+
+ The distance between points decreases as the latitude approaches the poles.
+ This relationship parallels the relationship between longitudinal coordinates
+ at different latitudes.
+
+ @param latitude The latitude of the geographic coordinate represented by the
+ point.
+ @return The distance in meters spanned by a single point.
+ */
+- (CLLocationDistance)metersPerPointAtLatitude:(CLLocationDegrees)latitude;
+
+- (CLLocationDistance)metersPerPixelAtLatitude:(CLLocationDegrees)latitude __attribute__((deprecated("Use -metersPerPointAtLatitude:.")));
+
+#pragma mark Annotating the Map
+
+/**
+ The complete list of annotations associated with the receiver. (read-only)
+
+ The objects in this array must adopt the `MGLAnnotation` protocol. If no
+ annotations are associated with the map view, the value of this property is
+ `nil`.
+ */
+@property (nonatomic, readonly, nullable) NS_ARRAY_OF(id <MGLAnnotation>) *annotations;
+
+/**
+ Adds an annotation to the map view.
+
+ @note `MGLMultiPolyline`, `MGLMultiPolygon`, and `MGLShapeCollection` objects
+ cannot be added to the map view at this time. Nor can `MGLMultiPoint`
+ objects that are not instances of `MGLPolyline` or `MGLPolygon`. Any
+ multipoint, multipolyline, multipolygon, or shape collection object that is
+ specified is silently ignored.
+
+ @param annotation The annotation object to add to the receiver. This object
+ must conform to the `MGLAnnotation` protocol. The map view retains the
+ annotation object. */
+- (void)addAnnotation:(id <MGLAnnotation>)annotation;
+
+/**
+ Adds an array of annotations to the map view.
+
+ @note `MGLMultiPolyline`, `MGLMultiPolygon`, and `MGLShapeCollection` objects
+ cannot be added to the map view at this time. Nor can `MGLMultiPoint`
+ objects that are not instances of `MGLPolyline` or `MGLPolygon`. Any
+ multipoint, multipolyline, multipolygon, or shape collection objects that
+ are specified are silently ignored.
+
+ @param annotations An array of annotation objects. Each object in the array
+ must conform to the `MGLAnnotation` protocol. The map view retains each
+ individual annotation object.
+ */
+- (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations;
+
+/**
+ Removes an annotation from the map view, deselecting it if it is selected.
+
+ Removing an annotation object dissociates it from the map view entirely,
+ preventing it from being displayed on the map. Thus you would typically call
+ this method only when you want to hide or delete a given annotation.
+
+ @param annotation The annotation object to remove. This object must conform
+ to the `MGLAnnotation` protocol
+ */
+- (void)removeAnnotation:(id <MGLAnnotation>)annotation;
+
+/**
+ Removes an array of annotations from the map view, deselecting any selected
+ annotations in the array.
+
+ Removing annotation objects dissociates them from the map view entirely,
+ preventing them from being displayed on the map. Thus you would typically
+ call this method only when you want to hide or delete the given annotations.
+
+ @param annotations The array of annotation objects to remove. Objects in the
+ array must conform to the `MGLAnnotation` protocol.
+ */
+- (void)removeAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations;
+
+/**
+ Returns a reusable annotation image object associated with its identifier.
+
+ For performance reasons, you should generally reuse `MGLAnnotationImage`
+ objects for identical-looking annotations in your map views. Dequeueing
+ saves time and memory during performance-critical operations such as
+ scrolling.
+
+ @param identifier A string identifying the annotation image to be reused.
+ This string is the same one you specify when initially returning the
+ annotation image object using the `-mapView:imageForAnnotation:` method.
+ @return An annotation image object with the given identifier, or `nil` if no
+ such object exists in the reuse queue.
+ */
+- (nullable MGLAnnotationImage *)dequeueReusableAnnotationImageWithIdentifier:(NSString *)identifier;
+
+/**
+ Returns a reusable annotation view object associated with its identifier.
+
+ For performance reasons, you should generally reuse `MGLAnnotationView`
+ objects for identical-looking annotations in your map views. Dequeueing
+ saves time and memory during performance-critical operations such as
+ scrolling.
+
+ @param identifier A string identifying the annotation view to be reused.
+ This string is the same one you specify when initially returning the
+ annotation view object using the `-mapView:viewForAnnotation:` method.
+ @return An annotation view object with the given identifier, or `nil` if no
+ such object exists in the reuse queue.
+ */
+- (nullable MGLAnnotationView *)dequeueReusableAnnotationViewWithIdentifier:(NSString *)identifier;
+
+#pragma mark Managing Annotation Selections
+
+/**
+ The currently selected annotations.
+
+ Assigning a new array to this property selects only the first annotation in
+ the array.
+ */
+@property (nonatomic, copy) NS_ARRAY_OF(id <MGLAnnotation>) *selectedAnnotations;
+
+/**
+ Selects an annotation and displays a callout view for it.
+
+ If the given annotation is not visible within the current viewport, this
+ method has no effect.
+
+ @param annotation The annotation object to select.
+ @param animated If `YES`, the callout view is animated into position.
+ */
+- (void)selectAnnotation:(id <MGLAnnotation>)annotation animated:(BOOL)animated;
+
+/**
+ Deselects an annotation and hides its callout view.
+
+ @param annotation The annotation object to deselect.
+ @param animated If `YES`, the callout view is animated offscreen.
+ */
+- (void)deselectAnnotation:(nullable id <MGLAnnotation>)annotation animated:(BOOL)animated;
+
+#pragma mark Overlaying the Map
+
+/**
+ Adds a single overlay object to the map.
+
+ To remove an overlay from a map, use the `-removeOverlay:` method.
+
+ @param overlay The overlay object to add. This object must conform to the
+ `MGLOverlay` protocol. */
+- (void)addOverlay:(id <MGLOverlay>)overlay;
+
+/**
+ Adds an array of overlay objects to the map.
+
+ To remove multiple overlays from a map, use the `-removeOverlays:` method.
+
+ @param overlays An array of objects, each of which must conform to the
+ `MGLOverlay` protocol.
+ */
+- (void)addOverlays:(NS_ARRAY_OF(id <MGLOverlay>) *)overlays;
+
+/**
+ Removes a single overlay object from the map.
+
+ If the specified overlay is not currently associated with the map view, this
+ method does nothing.
+
+ @param overlay The overlay object to remove.
+ */
+- (void)removeOverlay:(id <MGLOverlay>)overlay;
+
+/**
+ Removes one or more overlay objects from the map.
+
+ If a given overlay object is not associated with the map view, it is ignored.
+
+ @param overlays An array of objects, each of which conforms to the `MGLOverlay`
+ protocol.
+ */
+- (void)removeOverlays:(NS_ARRAY_OF(id <MGLOverlay>) *)overlays;
+
+#pragma mark Accessing the Underlying Map Data
+
+/**
+ Returns an array of rendered map features that intersect with a given point.
+
+ This method may return features from any of the map’s style layers. To restrict
+ the search to a particular layer or layers, use the
+ `-visibleFeaturesAtPoint:inStyleLayersWithIdentifiers:` method. For more
+ information about searching for map features, see that method’s documentation.
+
+ @param point A point expressed in the map view’s coordinate system.
+ @return An array of objects conforming to the `MGLFeature` protocol that
+ represent features in the sources used by the current style.
+ */
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(CGPoint)point NS_SWIFT_NAME(visibleFeatures(at:));
+
+/**
+ Returns an array of rendered map features that intersect with a given point,
+ restricted to the given style layers.
+
+ Each object in the returned array represents a feature rendered by the
+ current style and provides access to attributes specified by the relevant
+ <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile sources</a>.
+ The returned array includes features specified in vector and GeoJSON tile
+ sources but does not include anything from raster, image, or video sources.
+
+ Only visible features are returned. For example, suppose the current style uses
+ the
+ <a href="https://www.mapbox.com/vector-tiles/mapbox-streets/">Mapbox Streets source</a>,
+ but none of the specified style layers includes features that have the `maki`
+ property set to `bus`. If you pass a point corresponding to the location of a
+ bus stop into this method, the bus stop feature does not appear in the
+ resulting array. On the other hand, if the style does include bus stops, an
+ `MGLFeature` object representing that bus stop is returned and its
+ `featureAttributes` dictionary has the `maki` key set to `bus` (along with
+ other attributes). The dictionary contains only the attributes provided by the
+ tile source; it does not include computed attribute values or rules about how
+ the feature is rendered by the current style.
+
+ The returned array is sorted by z-order, starting with the topmost rendered
+ feature and ending with the bottommost rendered feature. A feature that is
+ rendered multiple times due to wrapping across the antimeridian at low zoom
+ levels is included only once, subject to the caveat that follows.
+
+ Features come from tiled vector data or GeoJSON data that is converted to tiles
+ internally, so feature geometries are clipped at tile boundaries and features
+ may appear duplicated across tiles. For example, suppose the specified point
+ lies along a road that spans the screen. The resulting array includes those
+ parts of the road that lie within the map tile that contain the specified
+ point, even if the road extends into other tiles.
+
+ To find out the layer names in a particular style, view the style in
+ <a href="https://www.mapbox.com/studio/">Mapbox Studio</a>.
+
+ @param point A point expressed in the map view’s coordinate system.
+ @param styleLayerIdentifiers A set of strings that correspond to the names of
+ layers defined in the current style. Only the features contained in these
+ layers are included in the returned array.
+ @return An array of objects conforming to the `MGLFeature` protocol that
+ represent features in the sources used by the current style.
+ */
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(CGPoint)point inStyleLayersWithIdentifiers:(nullable NS_SET_OF(NSString *) *)styleLayerIdentifiers NS_SWIFT_NAME(visibleFeatures(at:styleLayerIdentifiers:));
+
+/**
+ Returns an array of rendered map features that intersect with the given
+ rectangle.
+
+ This method may return features from any of the map’s style layers. To restrict
+ the search to a particular layer or layers, use the
+ `-visibleFeaturesAtPoint:inStyleLayersWithIdentifiers:` method. For more
+ information about searching for map features, see that method’s documentation.
+
+ @param rect A rectangle expressed in the map view’s coordinate system.
+ @return An array of objects conforming to the `MGLFeature` protocol that
+ represent features in the sources used by the current style.
+ */
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesInRect:(CGRect)rect NS_SWIFT_NAME(visibleFeatures(in:));
+
+/**
+ Returns an array of rendered map features that intersect with the given
+ rectangle, restricted to the given style layers.
+
+ Each object in the returned array represents a feature rendered by the
+ current style and provides access to attributes specified by the relevant
+ <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile sources</a>.
+ The returned array includes features specified in vector and GeoJSON tile
+ sources but does not include anything from raster, image, or video sources.
+
+ Only visible features are returned. For example, suppose the current style uses
+ the
+ <a href="https://www.mapbox.com/vector-tiles/mapbox-streets/">Mapbox Streets source</a>,
+ but none of the specified style layers includes features that have the `maki`
+ property set to `bus`. If you pass a rectangle containing the location of a bus
+ stop into this method, the bus stop feature does not appear in the resulting
+ array. On the other hand, if the style does include bus stops, an `MGLFeature`
+ object representing that bus stop is returned and its `featureAttributes`
+ dictionary has the `maki` key set to `bus` (along with other attributes). The
+ dictionary contains only the attributes provided by the tile source; it does
+ not include computed attribute values or rules about how the feature is
+ rendered by the current style.
+
+ The returned array is sorted by z-order, starting with the topmost rendered
+ feature and ending with the bottommost rendered feature. A feature that is
+ rendered multiple times due to wrapping across the antimeridian at low zoom
+ levels is included only once, subject to the caveat that follows.
+
+ Features come from tiled vector data or GeoJSON data that is converted to tiles
+ internally, so feature geometries are clipped at tile boundaries and features
+ may appear duplicated across tiles. For example, suppose the specified
+ rectangle intersects with a road that spans the screen. The resulting array
+ includes those parts of the road that lie within the map tiles covering the
+ specified rectangle, even if the road extends into other tiles. The portion of
+ the road within each map tile is included individually.
+
+ To find out the layer names in a particular style, view the style in
+ <a href="https://www.mapbox.com/studio/">Mapbox Studio</a>.
+
+ @param rect A rectangle expressed in the map view’s coordinate system.
+ @param styleLayerIdentifiers A set of strings that correspond to the names of
+ layers defined in the current style. Only the features contained in these
+ layers are included in the returned array.
+ @return An array of objects conforming to the `MGLFeature` protocol that
+ represent features in the sources used by the current style.
+ */
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesInRect:(CGRect)rect inStyleLayersWithIdentifiers:(nullable NS_SET_OF(NSString *) *)styleLayerIdentifiers NS_SWIFT_NAME(visibleFeatures(in:styleLayerIdentifiers:));
+
+#pragma mark Debugging the Map
+
+/**
+ The options that determine which debugging aids are shown on the map.
+
+ These options are all disabled by default and should remain disabled in
+ released software for performance and aesthetic reasons.
+ */
+@property (nonatomic) MGLMapDebugMaskOptions debugMask;
+
+@property (nonatomic, getter=isDebugActive) BOOL debugActive __attribute__((deprecated("Use -debugMask and -setDebugMask:.")));
+
+- (void)toggleDebug __attribute__((deprecated("Use -setDebugMask:.")));
+
+- (void)emptyMemoryCache __attribute__((deprecated));
+
+/**
+ Resets the map to the minimum zoom level, a center coordinate of (0, 0), and
+ a northern heading.
+ */
+- (void)resetPosition;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 57e59be10d..5d1bcb1109 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -1,6 +1,4 @@
-#import "MGLMapView.h"
-#import "MGLMapView+IBAdditions.h"
-#import "MGLMapView+MGLCustomStyleLayerAdditions.h"
+#import "MGLMapView_Internal.h"
#import <mbgl/platform/log.hpp>
#import <mbgl/gl/gl.hpp>
@@ -9,8 +7,7 @@
#import <OpenGLES/EAGL.h>
#include <mbgl/mbgl.hpp>
-#include <mbgl/annotation/point_annotation.hpp>
-#include <mbgl/annotation/shape_annotation.hpp>
+#include <mbgl/annotation/annotation.hpp>
#include <mbgl/sprite/sprite_image.hpp>
#include <mbgl/map/camera.hpp>
#include <mbgl/map/mode.hpp>
@@ -18,19 +15,21 @@
#include <mbgl/platform/darwin/reachability.h>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/network_status.hpp>
+#include <mbgl/style/transition_options.hpp>
+#include <mbgl/style/layers/custom_layer.hpp>
+#include <mbgl/math/wrap.hpp>
#include <mbgl/util/geo.hpp>
-#include <mbgl/util/math.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/projection.hpp>
-#include <mbgl/util/std.hpp>
#include <mbgl/util/default_styles.hpp>
#include <mbgl/util/chrono.hpp>
#import "Mapbox.h"
-#import "../../darwin/src/MGLGeometry_Private.h"
-#import "../../darwin/src/MGLMultiPoint_Private.h"
-#import "../../darwin/src/MGLOfflineStorage_Private.h"
+#import "MGLFeature_Private.h"
+#import "MGLGeometry_Private.h"
+#import "MGLMultiPoint_Private.h"
+#import "MGLOfflineStorage_Private.h"
#import "NSBundle+MGLAdditions.h"
#import "NSString+MGLAdditions.h"
@@ -39,8 +38,10 @@
#import "MGLUserLocationAnnotationView.h"
#import "MGLUserLocation_Private.h"
#import "MGLAnnotationImage_Private.h"
+#import "MGLAnnotationView_Private.h"
#import "MGLMapboxEvents.h"
#import "MGLCompactCalloutView.h"
+#import "MGLAnnotationContainerView.h"
#import <algorithm>
#import <cstdlib>
@@ -60,8 +61,6 @@ typedef NS_ENUM(NSUInteger, MGLUserTrackingState) {
MGLUserTrackingStateChanged,
};
-NSString *const MGLMapboxSetupDocumentationURLDisplayString = @"mapbox.com/help/first-steps-ios-sdk";
-
const NSTimeInterval MGLAnimationDuration = 0.3;
/// Duration of an animation due to a user location update, typically chosen to
@@ -99,6 +98,8 @@ const CGFloat MGLAnnotationImagePaddingForHitTest = 5;
/// Distance from the callout’s anchor point to the annotation it points to.
const CGFloat MGLAnnotationImagePaddingForCallout = 1;
+const CGSize MGLAnnotationAccessibilityElementMinimumSize = CGSizeMake(10, 10);
+
/// Unique identifier representing a single annotation in mbgl.
typedef uint32_t MGLAnnotationTag;
@@ -132,15 +133,69 @@ mbgl::Color MGLColorObjectFromUIColor(UIColor *color)
return {{ (float)r, (float)g, (float)b, (float)a }};
}
+@interface MGLAnnotationAccessibilityElement : UIAccessibilityElement
+
+@property (nonatomic) MGLAnnotationTag tag;
+
+- (instancetype)initWithAccessibilityContainer:(id)container tag:(MGLAnnotationTag)identifier NS_DESIGNATED_INITIALIZER;
+
+@end
+
+@implementation MGLAnnotationAccessibilityElement
+
+- (instancetype)initWithAccessibilityContainer:(id)container tag:(MGLAnnotationTag)tag
+{
+ if (self = [super initWithAccessibilityContainer:container])
+ {
+ _tag = tag;
+ self.accessibilityTraits = UIAccessibilityTraitButton | UIAccessibilityTraitAdjustable;
+ }
+ return self;
+}
+
+- (void)accessibilityIncrement
+{
+ [self.accessibilityContainer accessibilityIncrement];
+}
+
+- (void)accessibilityDecrement
+{
+ [self.accessibilityContainer accessibilityDecrement];
+}
+
+@end
+
/// Lightweight container for metadata about an annotation, including the annotation itself.
class MGLAnnotationContext {
public:
id <MGLAnnotation> annotation;
- /// mbgl-given identifier for the annotation image used by this annotation.
- /// Based on the annotation image’s reusable identifier.
- NSString *symbolIdentifier;
+ /// The annotation’s image’s reuse identifier.
+ NSString *imageReuseIdentifier;
+ MGLAnnotationAccessibilityElement *accessibilityElement;
+ MGLAnnotationView *annotationView;
+ NSString *viewReuseIdentifier;
};
+/** An accessibility element representing the MGLMapView at large. */
+@interface MGLMapViewProxyAccessibilityElement : UIAccessibilityElement
+
+@end
+
+@implementation MGLMapViewProxyAccessibilityElement
+
+- (instancetype)initWithAccessibilityContainer:(id)container
+{
+ if (self = [super initWithAccessibilityContainer:container])
+ {
+ self.accessibilityTraits = UIAccessibilityTraitButton;
+ self.accessibilityLabel = [self.accessibilityContainer accessibilityLabel];
+ self.accessibilityHint = @"Returns to the map";
+ }
+ return self;
+}
+
+@end
+
#pragma mark - Private -
@interface MGLMapView () <UIGestureRecognizerDelegate,
@@ -180,6 +235,8 @@ public:
@property (nonatomic) CGFloat quickZoomStart;
@property (nonatomic, getter=isDormant) BOOL dormant;
@property (nonatomic, readonly, getter=isRotationAllowed) BOOL rotationAllowed;
+@property (nonatomic) MGLMapViewProxyAccessibilityElement *mapViewProxyAccessibilityElement;
+@property (nonatomic) MGLAnnotationContainerView *annotationContainerView;
@end
@@ -191,14 +248,18 @@ public:
BOOL _opaque;
NS_MUTABLE_ARRAY_OF(NSURL *) *_bundledStyleURLs;
-
+
MGLAnnotationContextMap _annotationContextsByAnnotationTag;
/// Tag of the selected annotation. If the user location annotation is selected, this ivar is set to `MGLAnnotationTagNotFound`.
MGLAnnotationTag _selectedAnnotationTag;
+ NS_MUTABLE_DICTIONARY_OF(NSString *, NS_MUTABLE_ARRAY_OF(MGLAnnotationView *) *) *_annotationViewReuseQueueByIdentifier;
+
BOOL _userLocationAnnotationIsSelected;
/// Size of the rectangle formed by unioning the maximum slop area around every annotation image.
CGSize _unionedAnnotationImageSize;
std::vector<MGLAnnotationTag> _annotationsNearbyLastTap;
+ CGPoint _initialImplicitCalloutViewOffset;
+ NSDate *_userLocationAnimationCompletionDate;
BOOL _isWaitingForRedundantReachableNotification;
BOOL _isTargetingInterfaceBuilder;
@@ -219,6 +280,10 @@ public:
BOOL _delegateHasStrokeColorsForShapeAnnotations;
BOOL _delegateHasFillColorsForShapeAnnotations;
BOOL _delegateHasLineWidthsForShapeAnnotations;
+
+ MGLCompassDirectionFormatter *_accessibilityCompassFormatter;
+
+ CGSize _largestAnnotationViewSize;
}
#pragma mark - Setup & Teardown -
@@ -288,6 +353,12 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
_mbglMap->setStyleURL([[styleURL absoluteString] UTF8String]);
}
+- (IBAction)reloadStyle:(__unused id)sender {
+ NSURL *styleURL = self.styleURL;
+ _mbglMap->setStyleURL("");
+ self.styleURL = styleURL;
+}
+
- (void)commonInit
{
_isTargetingInterfaceBuilder = NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent;
@@ -299,7 +370,14 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
[self createGLView];
}
- self.accessibilityLabel = @"Map";
+ // setup accessibility
+ //
+// 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;
@@ -314,12 +392,12 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
// setup mbgl map
mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource;
- _mbglMap = new mbgl::Map(*_mbglView, *mbglFileSource, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None);
+ _mbglMap = new mbgl::Map(*_mbglView, *mbglFileSource, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default);
+ [self validateTileCacheSize];
// start paused if in IB
if (_isTargetingInterfaceBuilder || background) {
self.dormant = YES;
- _mbglMap->pause();
}
// Notify map object when network reachability status changes.
@@ -338,6 +416,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
// Set up annotation management and selection state.
_annotationImagesByIdentifier = [NSMutableDictionary dictionary];
_annotationContextsByAnnotationTag = {};
+ _annotationViewReuseQueueByIdentifier = [NSMutableDictionary dictionary];
_selectedAnnotationTag = MGLAnnotationTagNotFound;
_annotationsNearbyLastTap = {};
@@ -345,7 +424,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
//
UIImage *logo = [[MGLMapView resourceImageNamed:@"mapbox.png"] imageWithAlignmentRectInsets:UIEdgeInsetsMake(1.5, 4, 3.5, 2)];
_logoView = [[UIImageView alloc] initWithImage:logo];
- _logoView.accessibilityLabel = @"Mapbox logo";
+ _logoView.accessibilityTraits = UIAccessibilityTraitStaticText;
+ _logoView.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"LOGO_A11Y_LABEL", nil, nil, @"Mapbox", @"Accessibility label");
_logoView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_logoView];
_logoViewConstraints = [NSMutableArray array];
@@ -353,7 +433,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
// setup attribution
//
_attributionButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
- _attributionButton.accessibilityLabel = @"Attribution info";
+ _attributionButton.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"INFO_A11Y_LABEL", nil, nil, @"About this map", @"Accessibility label");
+ _attributionButton.accessibilityHint = NSLocalizedStringWithDefaultValue(@"INFO_A11Y_HINT", nil, nil, @"Shows credits, a feedback form, and more", @"Accessibility hint");
[_attributionButton addTarget:self action:@selector(showAttribution) forControlEvents:UIControlEventTouchUpInside];
_attributionButton.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_attributionButton];
@@ -362,12 +443,14 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
// setup compass
//
- _compassView = [[UIImageView alloc] initWithImage:[MGLMapView resourceImageNamed:@"Compass.png"]];
- _compassView.accessibilityLabel = @"Compass";
- _compassView.frame = CGRectMake(0, 0, _compassView.image.size.width, _compassView.image.size.height);
+ _compassView = [[UIImageView alloc] initWithImage:self.compassImage];
+ _compassView.frame = { CGPointZero, _compassView.image.size };
_compassView.alpha = 0;
_compassView.userInteractionEnabled = YES;
[_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");
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
[container addSubview:_compassView];
container.translatesAutoresizingMaskIntoConstraints = NO;
@@ -469,7 +552,6 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
_glView.delegate = self;
[_glView bindDrawable];
[self insertSubview:_glView atIndex:0];
-
_glView.contentMode = UIViewContentModeCenter;
// load extensions
@@ -488,6 +570,26 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
});
}
+- (UIImage *)compassImage
+{
+ UIImage *scaleImage = [MGLMapView resourceImageNamed:@"Compass.png"];
+ 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:9 weight:UIFontWeightUltraLight],
+ NSForegroundColorAttributeName: [UIColor whiteColor],
+ }];
+ CGRect stringRect = CGRectMake((scaleImage.size.width - north.size.width) / 2,
+ scaleImage.size.height * 0.45,
+ north.size.width, north.size.height);
+ [north drawInRect:stringRect];
+
+ UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+ return image;
+}
+
- (void)reachabilityChanged:(NSNotification *)notification
{
MGLReachability *reachability = [notification object];
@@ -503,6 +605,13 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_attributionButton removeObserver:self forKeyPath:@"hidden"];
+ // Removing the annotations unregisters any outstanding KVO observers.
+ NSArray *annotations = self.annotations;
+ if (annotations)
+ {
+ [self removeAnnotations:annotations];
+ }
+
[self validateDisplayLink];
if (_mbglMap)
@@ -533,14 +642,6 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
if (_delegate == delegate) return;
_delegate = delegate;
-
- if ([delegate respondsToSelector:@selector(mapView:symbolNameForAnnotation:)])
- {
- [NSException raise:@"Method unavailable" format:
- @"-mapView:symbolNameForAnnotation: has been removed from the MGLMapViewDelegate protocol, but %@ still implements it. "
- @"Implement -[%@ mapView:imageForAnnotation:] instead.",
- NSStringFromClass([delegate class]), NSStringFromClass([delegate class])];
- }
_delegateHasAlphasForShapeAnnotations = [_delegate respondsToSelector:@selector(mapView:alphaForShapeAnnotation:)];
_delegateHasStrokeColorsForShapeAnnotations = [_delegate respondsToSelector:@selector(mapView:strokeColorForShapeAnnotation:)];
@@ -558,15 +659,37 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (void)setFrame:(CGRect)frame
{
[super setFrame:frame];
-
- [self setNeedsLayout];
+ if ( ! CGRectEqualToRect(frame, self.frame))
+ {
+ [self validateTileCacheSize];
+ }
}
- (void)setBounds:(CGRect)bounds
{
[super setBounds:bounds];
+ if ( ! CGRectEqualToRect(bounds, self.bounds))
+ {
+ [self validateTileCacheSize];
+ }
+}
+
+- (void)validateTileCacheSize
+{
+ if ( ! _mbglMap)
+ {
+ return;
+ }
+
+ CGFloat zoomFactor = self.maximumZoomLevel - self.minimumZoomLevel + 1;
+ CGFloat cpuFactor = [NSProcessInfo processInfo].processorCount;
+ CGFloat memoryFactor = (CGFloat)[NSProcessInfo processInfo].physicalMemory / 1000 / 1000 / 1000;
+ CGFloat sizeFactor = (CGRectGetWidth(self.bounds) / mbgl::util::tileSize) *
+ (CGRectGetHeight(self.bounds) / mbgl::util::tileSize);
+
+ NSUInteger cacheSize = zoomFactor * cpuFactor * memoryFactor * sizeFactor * 0.5;
- [self setNeedsLayout];
+ _mbglMap->setSourceTileCacheSize(cacheSize);
}
+ (BOOL)requiresConstraintBasedLayout
@@ -636,6 +759,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
multiplier:1
constant:5]];
+ UIImage *compassImage = self.compassView.image;
[compassContainerConstraints addObject:
[NSLayoutConstraint constraintWithItem:compassContainer
attribute:NSLayoutAttributeWidth
@@ -643,7 +767,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
- constant:self.compassView.image.size.width]];
+ constant:compassImage.size.width]];
[compassContainerConstraints addObject:
[NSLayoutConstraint constraintWithItem:compassContainer
@@ -652,7 +776,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
- constant:self.compassView.image.size.height]];
+ constant:compassImage.size.height]];
[constraintParentView addConstraints:compassContainerConstraints];
// logo bug
@@ -741,17 +865,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
if ( ! self.dormant)
{
- CGFloat zoomFactor = _mbglMap->getMaxZoom() - _mbglMap->getMinZoom() + 1;
- CGFloat cpuFactor = (CGFloat)[[NSProcessInfo processInfo] processorCount];
- CGFloat memoryFactor = (CGFloat)[[NSProcessInfo processInfo] physicalMemory] / 1000 / 1000 / 1000;
- CGFloat sizeFactor = ((CGFloat)_mbglMap->getWidth() / mbgl::util::tileSize) *
- ((CGFloat)_mbglMap->getHeight() / mbgl::util::tileSize);
-
- NSUInteger cacheSize = zoomFactor * cpuFactor * memoryFactor * sizeFactor * 0.5;
-
- _mbglMap->setSourceTileCacheSize(cacheSize);
-
- _mbglMap->renderSync();
+ _mbglMap->render();
[self updateUserLocationAnnotationView];
}
@@ -894,7 +1008,6 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
[self validateDisplayLink];
self.dormant = YES;
- _mbglMap->pause();
[self.glView deleteDrawable];
}
}
@@ -967,8 +1080,6 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
[self.glSnapshotView addSubview:snapshotTint];
}
- _mbglMap->pause();
-
[self.glView deleteDrawable];
}
}
@@ -988,8 +1099,6 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
[self.glSnapshotView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
[self.glView bindDrawable];
-
- _mbglMap->resume();
_displayLink.paused = NO;
@@ -1017,6 +1126,10 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
for (UIView *subview in view.subviews) [self updateTintColorForView:subview];
}
+- (BOOL)canBecomeFirstResponder {
+ return YES;
+}
+
#pragma mark - Gestures -
- (void)handleCompassTapGesture:(__unused id)sender
@@ -1142,7 +1255,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
if (log2(newScale) < _mbglMap->getMinZoom()) return;
- _mbglMap->setScale(newScale, { centerPoint.x, centerPoint.y });
+ _mbglMap->setScale(newScale, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
// The gesture recognizer only reports the gesture’s current center
// point, so use the previous center point to anchor the transition.
@@ -1152,7 +1265,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
CLLocationCoordinate2D centerCoordinate = _previousPinchCenterCoordinate;
_mbglMap->setLatLng(MGLLatLngFromLocationCoordinate2D(centerCoordinate),
- { centerPoint.x, centerPoint.y });
+ mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
}
[self notifyMapChange:mbgl::MapChangeRegionIsChanging];
@@ -1190,7 +1303,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
if (velocity)
{
- _mbglMap->setScale(newScale, { centerPoint.x, centerPoint.y }, MGLDurationInSeconds(duration));
+ _mbglMap->setScale(newScale, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationInSeconds(duration));
}
[self notifyGestureDidEndWithDrift:velocity];
@@ -1239,7 +1352,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
newDegrees = fmaxf(newDegrees, -30);
}
- _mbglMap->setBearing(newDegrees, { centerPoint.x, centerPoint.y });
+ _mbglMap->setBearing(newDegrees, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
[self notifyMapChange:mbgl::MapChangeRegionIsChanging];
}
@@ -1254,7 +1367,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
CGFloat newRadians = radians + velocity * duration * 0.1;
CGFloat newDegrees = MGLDegreesFromRadians(newRadians) * -1;
- _mbglMap->setBearing(newDegrees, { centerPoint.x, centerPoint.y }, MGLDurationInSeconds(duration));
+ _mbglMap->setBearing(newDegrees, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationInSeconds(duration));
[self notifyGestureDidEndWithDrift:YES];
@@ -1280,24 +1393,40 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
return;
}
[self trackGestureEvent:MGLEventGestureSingleTap forRecognizer:singleTap];
+
+ if (self.mapViewProxyAccessibilityElement.accessibilityElementIsFocused)
+ {
+ id nextElement;
+ if (_userLocationAnnotationIsSelected)
+ {
+ nextElement = self.userLocationAnnotationView;
+ }
+ else
+ {
+ nextElement = _annotationContextsByAnnotationTag[_selectedAnnotationTag].accessibilityElement;
+ }
+ [self deselectAnnotation:self.selectedAnnotation animated:YES];
+ UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nextElement);
+ return;
+ }
CGPoint tapPoint = [singleTap locationInView:self];
- if (self.userLocationVisible)
+ if (self.userLocationVisible
+ && [self.userLocationAnnotationView.layer.presentationLayer hitTest:tapPoint])
{
- // Assume that the user is fat-fingering an annotation.
- CGRect hitRect = CGRectInset({ tapPoint, CGSizeZero },
- -MGLAnnotationImagePaddingForHitTest,
- -MGLAnnotationImagePaddingForHitTest);
-
- if (CGRectIntersectsRect(hitRect, self.userLocationAnnotationView.frame))
+ if ( ! _userLocationAnnotationIsSelected)
{
- if ( ! _userLocationAnnotationIsSelected)
- {
- [self selectAnnotation:self.userLocation animated:YES];
- }
- return;
+ [self selectAnnotation:self.userLocation animated:YES];
}
+ return;
+ }
+
+ MGLAnnotationView *hitAnnotationView = [self annotationViewAtPoint:tapPoint];
+ if (hitAnnotationView)
+ {
+ [self selectAnnotation:hitAnnotationView.annotation animated:YES];
+ return;
}
MGLAnnotationTag hitAnnotationTag = [self annotationTagAtPoint:tapPoint persistingResults:YES];
@@ -1405,7 +1534,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
centerPoint = self.userLocationAnnotationViewCenter;
}
_mbglMap->scaleBy(powf(2, newZoom) / _mbglMap->getScale(),
- { centerPoint.x, centerPoint.y });
+ mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
[self notifyMapChange:mbgl::MapChangeRegionIsChanging];
}
@@ -1440,7 +1569,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
centerPoint = self.userLocationAnnotationViewCenter;
}
- _mbglMap->setPitch(pitchNew, centerPoint);
+ _mbglMap->setPitch(pitchNew, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
[self notifyMapChange:mbgl::MapChangeRegionIsChanging];
}
@@ -1479,7 +1608,9 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
if ([self.delegate respondsToSelector:@selector(mapView:annotation:calloutAccessoryControlTapped:)])
{
NSAssert([tap.view isKindOfClass:[UIControl class]], @"Tapped view %@ is not a UIControl", tap.view);
- [self.delegate mapView:self annotation:self.selectedAnnotation
+ id <MGLAnnotation> selectedAnnotation = self.selectedAnnotation;
+ NSAssert(selectedAnnotation, @"Selected annotation should not be nil.");
+ [self.delegate mapView:self annotation:selectedAnnotation
calloutAccessoryControlTapped:(UIControl *)tap.view];
}
}
@@ -1493,7 +1624,9 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
if ([self.delegate respondsToSelector:@selector(mapView:tapOnCalloutForAnnotation:)])
{
- [self.delegate mapView:self tapOnCalloutForAnnotation:self.selectedAnnotation];
+ id <MGLAnnotation> selectedAnnotation = self.selectedAnnotation;
+ NSAssert(selectedAnnotation, @"Selected annotation should not be nil.");
+ [self.delegate mapView:self tapOnCalloutForAnnotation:selectedAnnotation];
}
}
@@ -1501,10 +1634,18 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
if ([self.delegate respondsToSelector:@selector(mapView:tapOnCalloutForAnnotation:)])
{
- [self.delegate mapView:self tapOnCalloutForAnnotation:self.selectedAnnotation];
+ id <MGLAnnotation> selectedAnnotation = self.selectedAnnotation;
+ NSAssert(selectedAnnotation, @"Selected annotation should not be nil.");
+ [self.delegate mapView:self tapOnCalloutForAnnotation:selectedAnnotation];
}
}
+- (void)calloutViewDidAppear:(UIView<MGLCalloutView> *)calloutView
+{
+ UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil);
+ UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, calloutView);
+}
+
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
NSArray *validSimultaneousGestures = @[ self.pan, self.pinch, self.rotate ];
@@ -1532,15 +1673,15 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
if ( ! self.attributionSheet)
{
- self.attributionSheet = [[UIActionSheet alloc] initWithTitle:@"Mapbox iOS SDK"
+ self.attributionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedStringWithDefaultValue(@"SDK_NAME", nil, nil, @"Mapbox iOS SDK", @"Action sheet title")
delegate:self
- cancelButtonTitle:@"Cancel"
+ cancelButtonTitle:NSLocalizedStringWithDefaultValue(@"CANCEL", nil, nil, @"Cancel", @"")
destructiveButtonTitle:nil
otherButtonTitles:
- @"© Mapbox",
- @"© OpenStreetMap",
- @"Improve This Map",
- @"Mapbox Telemetry",
+ NSLocalizedStringWithDefaultValue(@"COPY_MAPBOX", nil, nil, @"© Mapbox", @"Copyright notice in attribution sheet"),
+ NSLocalizedStringWithDefaultValue(@"COPY_OSM", nil, nil, @"© OpenStreetMap", @"Copyright notice in attribution sheet"),
+ NSLocalizedStringWithDefaultValue(@"MAP_FEEDBACK", nil, nil, @"Improve This Map", @"Action in attribution sheet"),
+ NSLocalizedStringWithDefaultValue(@"TELEMETRY_NAME", nil, nil, @"Mapbox Telemetry", @"Action in attribution sheet"),
nil];
}
@@ -1575,22 +1716,22 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsEnabled"])
{
- message = @"You are helping to make OpenStreetMap and Mapbox maps better by contributing anonymous usage data.";
- participate = @"Keep Participating";
- optOut = @"Stop Participating";
+ message = NSLocalizedStringWithDefaultValue(@"TELEMETRY_ENABLED_MSG", nil, nil, @"You are helping to make OpenStreetMap and Mapbox maps better by contributing anonymous usage data.", @"Telemetry prompt message");
+ participate = NSLocalizedStringWithDefaultValue(@"TELEMETRY_ENABLED_ON", nil, nil, @"Keep Participating", @"Telemetry prompt button");
+ optOut = NSLocalizedStringWithDefaultValue(@"TELEMETRY_ENABLED_OFF", nil, nil, @"Stop Participating", @"Telemetry prompt button");
}
else
{
- message = @"You can help make OpenStreetMap and Mapbox maps better by contributing anonymous usage data.";
- participate = @"Participate";
- optOut = @"Don’t Participate";
+ message = NSLocalizedStringWithDefaultValue(@"TELEMETRY_DISABLED_MSG", nil, nil, @"You can help make OpenStreetMap and Mapbox maps better by contributing anonymous usage data.", @"Telemetry prompt message");
+ participate = NSLocalizedStringWithDefaultValue(@"TELEMETRY_DISABLED_ON", nil, nil, @"Participate", @"Telemetry prompt button");
+ optOut = NSLocalizedStringWithDefaultValue(@"TELEMETRY_DISABLED_OFF", nil, nil, @"Don’t Participate", @"Telemetry prompt button");
}
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Make Mapbox Maps Better"
+ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedStringWithDefaultValue(@"TELEMETRY_TITLE", nil, nil, @"Make Mapbox Maps Better", @"Telemetry prompt title")
message:message
delegate:self
cancelButtonTitle:participate
- otherButtonTitles:@"Tell Me More", optOut, nil];
+ otherButtonTitles:NSLocalizedStringWithDefaultValue(@"TELEMETRY_MORE", nil, nil, @"Tell Me More", @"Telemetry prompt button"), optOut, nil];
[alert show];
}
}
@@ -1604,7 +1745,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
else if (buttonIndex == alertView.firstOtherButtonIndex)
{
[[UIApplication sharedApplication] openURL:
- [NSURL URLWithString:@"https://mapbox.com/telemetry/"]];
+ [NSURL URLWithString:@"https://www.mapbox.com/telemetry/"]];
}
else if (buttonIndex == alertView.firstOtherButtonIndex + 1)
{
@@ -1614,7 +1755,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
#pragma mark - Properties -
-- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(__unused void *)context
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"hidden"] && object == _attributionButton)
{
@@ -1625,6 +1766,35 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
[MGLMapboxEvents ensureMetricsOptoutExists];
}
}
+ else if ([keyPath isEqualToString:@"coordinate"] && [object conformsToProtocol:@protocol(MGLAnnotation)] && ![object isKindOfClass:[MGLMultiPoint class]])
+ {
+ id <MGLAnnotation> annotation = object;
+ MGLAnnotationTag annotationTag = (MGLAnnotationTag)(NSUInteger)context;
+ // We can get here because a subclass registered itself as an observer
+ // of the coordinate key path of a non-multipoint annotation but failed
+ // to handle the change. This check deters us from treating the
+ // subclass’s context as an annotation tag. If the context happens to
+ // match a valid annotation tag, the annotation will be unnecessarily
+ // but safely updated.
+ if (annotation == [self annotationWithTag:annotationTag])
+ {
+ const mbgl::Point<double> point = MGLPointFromLocationCoordinate2D(annotation.coordinate);
+
+ MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(annotationTag);
+ NSString *symbolName;
+ if (!annotationContext.annotationView)
+ {
+ MGLAnnotationImage *annotationImage = [self imageOfAnnotationWithTag:annotationTag];
+ symbolName = annotationImage.styleIconIdentifier;
+ }
+
+ _mbglMap->updateAnnotation(annotationTag, mbgl::SymbolAnnotation { point, symbolName.UTF8String ?: "" });
+ if (annotationTag == _selectedAnnotationTag)
+ {
+ [self deselectAnnotation:annotation animated:YES];
+ }
+ }
+ }
}
+ (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingZoomEnabled
@@ -1667,6 +1837,10 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
mask |= MGLMapDebugCollisionBoxesMask;
}
+ if (options & mbgl::MapDebugOptions::Wireframe)
+ {
+ mask |= MGLMapDebugWireframesMask;
+ }
return mask;
}
@@ -1689,6 +1863,10 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
options |= mbgl::MapDebugOptions::Collision;
}
+ if (debugMask & MGLMapDebugWireframesMask)
+ {
+ options |= mbgl::MapDebugOptions::Wireframe;
+ }
_mbglMap->setDebug(options);
}
@@ -1731,6 +1909,242 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
_mbglMap->onLowMemory();
}
+#pragma mark - Accessibility -
+
+- (NSString *)accessibilityValue
+{
+ double zoomLevel = round(self.zoomLevel + 1);
+ return [NSString stringWithFormat:NSLocalizedStringWithDefaultValue(@"MAP_A11Y_VALUE", nil, nil, @"Zoom %dx\n%ld annotation(s) visible", @"Map accessibility value"), (int)zoomLevel, (long)self.accessibilityAnnotationCount];
+}
+
+- (CGRect)accessibilityFrame
+{
+ CGRect frame = [super accessibilityFrame];
+ UIViewController *viewController = self.viewControllerForLayoutGuides;
+ if (viewController)
+ {
+ CGFloat topInset = viewController.topLayoutGuide.length;
+ frame.origin.y += topInset;
+ frame.size.height -= topInset + viewController.bottomLayoutGuide.length;
+ }
+ return frame;
+}
+
+- (UIBezierPath *)accessibilityPath
+{
+ UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.accessibilityFrame];
+
+ // Exclude any visible annotation callout view.
+ if (self.calloutViewForSelectedAnnotation)
+ {
+ UIBezierPath *calloutViewPath = [UIBezierPath bezierPathWithRect:self.calloutViewForSelectedAnnotation.frame];
+ [path appendPath:calloutViewPath];
+ }
+
+ return path;
+}
+
+- (NSInteger)accessibilityElementCount
+{
+ if (self.calloutViewForSelectedAnnotation)
+ {
+ return 2 /* selectedAnnotationCalloutView, mapViewProxyAccessibilityElement */;
+ }
+ NSInteger count = self.accessibilityAnnotationCount + 2 /* compass, attributionButton */;
+ if (self.userLocationAnnotationView)
+ {
+ count++;
+ }
+ return count;
+}
+
+- (NSInteger)accessibilityAnnotationCount
+{
+ std::vector<MGLAnnotationTag> visibleAnnotations = [self annotationTagsInRect:self.bounds];
+ return visibleAnnotations.size();
+}
+
+- (id)accessibilityElementAtIndex:(NSInteger)index
+{
+ if (self.calloutViewForSelectedAnnotation)
+ {
+ if (index == 0)
+ {
+ return self.calloutViewForSelectedAnnotation;
+ }
+ if (index == 1)
+ {
+ self.mapViewProxyAccessibilityElement.accessibilityFrame = self.accessibilityFrame;
+ self.mapViewProxyAccessibilityElement.accessibilityPath = self.accessibilityPath;
+ return self.mapViewProxyAccessibilityElement;
+ }
+ return nil;
+ }
+ std::vector<MGLAnnotationTag> visibleAnnotations = [self annotationTagsInRect:self.bounds];
+
+ // Ornaments
+ if (index == 0)
+ {
+ return self.compassView;
+ }
+ if ( ! self.userLocationAnnotationView)
+ {
+ index++;
+ }
+ else if (index == 1)
+ {
+ return self.userLocationAnnotationView;
+ }
+ if (index > 0 && (NSUInteger)index == visibleAnnotations.size() + 2 /* compass, userLocationAnnotationView */)
+ {
+ return self.attributionButton;
+ }
+
+ std::sort(visibleAnnotations.begin(), visibleAnnotations.end());
+ CGPoint centerPoint = self.contentCenter;
+ if (self.userTrackingMode != MGLUserTrackingModeNone)
+ {
+ centerPoint = self.userLocationAnnotationViewCenter;
+ }
+ CLLocationCoordinate2D currentCoordinate = [self convertPoint:centerPoint toCoordinateFromView:self];
+ std::sort(visibleAnnotations.begin(), visibleAnnotations.end(), [&](const MGLAnnotationTag tagA, const MGLAnnotationTag tagB) {
+ CLLocationCoordinate2D coordinateA = [[self annotationWithTag:tagA] coordinate];
+ CLLocationCoordinate2D coordinateB = [[self annotationWithTag:tagB] coordinate];
+ CLLocationDegrees deltaA = hypot(coordinateA.latitude - currentCoordinate.latitude,
+ coordinateA.longitude - currentCoordinate.longitude);
+ CLLocationDegrees deltaB = hypot(coordinateB.latitude - currentCoordinate.latitude,
+ coordinateB.longitude - currentCoordinate.longitude);
+ return deltaA < deltaB;
+ });
+
+ NSUInteger annotationIndex = MGLAnnotationTagNotFound;
+ if (index >= 0 && (NSUInteger)(index - 2) < visibleAnnotations.size())
+ {
+ annotationIndex = index - 2 /* compass, userLocationAnnotationView */;
+ }
+ MGLAnnotationTag annotationTag = visibleAnnotations[annotationIndex];
+ NSAssert(annotationTag != MGLAnnotationTagNotFound, @"Can’t get accessibility element for nonexistent or invisible annotation at index %li.", (long)index);
+ NSAssert(_annotationContextsByAnnotationTag.count(annotationTag), @"Missing annotation for tag %u.", annotationTag);
+ MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(annotationTag);
+ id <MGLAnnotation> annotation = annotationContext.annotation;
+
+ // Let the annotation view serve as its own accessibility element.
+ MGLAnnotationView *annotationView = annotationContext.annotationView;
+ if (annotationView && annotationView.superview)
+ {
+ return annotationView;
+ }
+
+ // Lazily create an accessibility element for the found annotation.
+ if ( ! annotationContext.accessibilityElement)
+ {
+ annotationContext.accessibilityElement = [[MGLAnnotationAccessibilityElement alloc] initWithAccessibilityContainer:self tag:annotationTag];
+ }
+
+ // Update the accessibility element.
+ MGLAnnotationImage *annotationImage = [self imageOfAnnotationWithTag:annotationTag];
+ CGRect annotationFrame = [self frameOfImage:annotationImage.image centeredAtCoordinate:annotation.coordinate];
+ CGPoint annotationFrameCenter = CGPointMake(CGRectGetMidX(annotationFrame), CGRectGetMidY(annotationFrame));
+ CGRect minimumFrame = CGRectInset({ annotationFrameCenter, CGSizeZero },
+ -MGLAnnotationAccessibilityElementMinimumSize.width / 2,
+ -MGLAnnotationAccessibilityElementMinimumSize.height / 2);
+ annotationFrame = CGRectUnion(annotationFrame, minimumFrame);
+ CGRect screenRect = UIAccessibilityConvertFrameToScreenCoordinates(annotationFrame, self);
+ annotationContext.accessibilityElement.accessibilityFrame = screenRect;
+ annotationContext.accessibilityElement.accessibilityHint = NSLocalizedStringWithDefaultValue(@"ANNOTATION_A11Y_HINT", nil, nil, @"Shows more info", @"Accessibility hint");
+
+ if ([annotation respondsToSelector:@selector(title)])
+ {
+ annotationContext.accessibilityElement.accessibilityLabel = annotation.title;
+ }
+ if ([annotation respondsToSelector:@selector(subtitle)])
+ {
+ annotationContext.accessibilityElement.accessibilityValue = annotation.subtitle;
+ }
+
+ return annotationContext.accessibilityElement;
+}
+
+- (NSInteger)indexOfAccessibilityElement:(id)element
+{
+ if (self.calloutViewForSelectedAnnotation)
+ {
+ return [@[self.calloutViewForSelectedAnnotation, self.mapViewProxyAccessibilityElement]
+ indexOfObject:element];
+ }
+ if (element == self.compassView)
+ {
+ return 0;
+ }
+ if (element == self.userLocationAnnotationView)
+ {
+ return 1;
+ }
+
+ std::vector<MGLAnnotationTag> visibleAnnotations = [self annotationTagsInRect:self.bounds];
+
+ MGLAnnotationTag tag = MGLAnnotationTagNotFound;
+ if ([element isKindOfClass:[MGLAnnotationView class]])
+ {
+ id <MGLAnnotation> annotation = [(MGLAnnotationView *)element annotation];
+ tag = [self annotationTagForAnnotation:annotation];
+ }
+ else if ([element isKindOfClass:[MGLAnnotationAccessibilityElement class]])
+ {
+ tag = [(MGLAnnotationAccessibilityElement *)element tag];
+ }
+ else if (element == self.attributionButton)
+ {
+ return !!self.userLocationAnnotationView + visibleAnnotations.size();
+ }
+ else
+ {
+ return NSNotFound;
+ }
+
+ std::sort(visibleAnnotations.begin(), visibleAnnotations.end());
+ auto foundElement = std::find(visibleAnnotations.begin(), visibleAnnotations.end(), tag);
+ if (foundElement == visibleAnnotations.end())
+ {
+ return NSNotFound;
+ }
+ return !!self.userLocationAnnotationView + std::distance(visibleAnnotations.begin(), foundElement) + 1 /* compass */;
+}
+
+- (MGLMapViewProxyAccessibilityElement *)mapViewProxyAccessibilityElement
+{
+ if ( ! _mapViewProxyAccessibilityElement)
+ {
+ _mapViewProxyAccessibilityElement = [[MGLMapViewProxyAccessibilityElement alloc] initWithAccessibilityContainer:self];
+ }
+ return _mapViewProxyAccessibilityElement;
+}
+
+- (void)accessibilityIncrement
+{
+ // Swipe up to zoom out.
+ [self accessibilityScaleBy:0.5];
+}
+
+- (void)accessibilityDecrement
+{
+ // Swipe down to zoom in.
+ [self accessibilityScaleBy:2];
+}
+
+- (void)accessibilityScaleBy:(double)scaleFactor
+{
+ CGPoint centerPoint = self.contentCenter;
+ if (self.userTrackingMode != MGLUserTrackingModeNone)
+ {
+ centerPoint = self.userLocationAnnotationViewCenter;
+ }
+ _mbglMap->scaleBy(scaleFactor, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
+ [self unrotateIfNeededForGesture];
+
+ UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, self.accessibilityValue);
+}
+
#pragma mark - Geography -
+ (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingCenterCoordinate
@@ -1837,6 +2251,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (void)setMinimumZoomLevel:(double)minimumZoomLevel
{
_mbglMap->setMinZoom(minimumZoomLevel);
+ [self validateTileCacheSize];
}
- (double)minimumZoomLevel
@@ -1847,6 +2262,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (void)setMaximumZoomLevel:(double)maximumZoomLevel
{
_mbglMap->setMaxZoom(maximumZoomLevel);
+ [self validateTileCacheSize];
}
- (double)maximumZoomLevel
@@ -1925,14 +2341,14 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
[self willChangeValueForKey:@"visibleCoordinateBounds"];
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets);
padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset);
- mbgl::AnnotationSegment segment;
- segment.reserve(count);
+ std::vector<mbgl::LatLng> latLngs;
+ latLngs.reserve(count);
for (NSUInteger i = 0; i < count; i++)
{
- segment.push_back({coordinates[i].latitude, coordinates[i].longitude});
+ latLngs.push_back({coordinates[i].latitude, coordinates[i].longitude});
}
- mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngs(segment, padding);
+ mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngs(latLngs, padding);
if (direction >= 0)
{
cameraOptions.angle = MGLRadiansFromDegrees(-direction);
@@ -1994,7 +2410,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
else
{
CGPoint centerPoint = self.userLocationAnnotationViewCenter;
- _mbglMap->setBearing(direction, { centerPoint.x, centerPoint.y },
+ _mbglMap->setBearing(direction, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y },
MGLDurationInSeconds(duration));
}
}
@@ -2016,14 +2432,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (MGLMapCamera *)camera
{
- CGFloat pitch = _mbglMap->getPitch();
- CLLocationDistance altitude = MGLAltitudeForZoomLevel(self.zoomLevel, pitch,
- self.centerCoordinate.latitude,
- self.frame.size);
- return [MGLMapCamera cameraLookingAtCenterCoordinate:self.centerCoordinate
- fromDistance:altitude
- pitch:pitch
- heading:self.direction];
+ mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInset);
+ return [self cameraForCameraOptions:_mbglMap->getCameraOptions(padding)];
}
- (void)setCamera:(MGLMapCamera *)camera
@@ -2123,6 +2533,29 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
[self didChangeValueForKey:@"camera"];
}
+- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds
+{
+ return [self cameraThatFitsCoordinateBounds:bounds edgePadding:UIEdgeInsetsZero];
+}
+
+- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets
+{
+ mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets);
+ padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset);
+ mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding);
+ return [self cameraForCameraOptions:cameraOptions];
+}
+
+- (MGLMapCamera *)cameraForCameraOptions:(const mbgl::CameraOptions &)cameraOptions
+{
+ CLLocationCoordinate2D centerCoordinate = MGLLocationCoordinate2DFromLatLng(cameraOptions.center ? *cameraOptions.center : _mbglMap->getLatLng());
+ double zoomLevel = cameraOptions.zoom ? *cameraOptions.zoom : self.zoomLevel;
+ CLLocationDirection direction = cameraOptions.angle ? -MGLDegreesFromRadians(*cameraOptions.angle) : self.direction;
+ CGFloat pitch = cameraOptions.pitch ? MGLDegreesFromRadians(*cameraOptions.pitch) : _mbglMap->getPitch();
+ CLLocationDistance altitude = MGLAltitudeForZoomLevel(zoomLevel, pitch, centerCoordinate.latitude, self.frame.size);
+ return [MGLMapCamera cameraLookingAtCenterCoordinate:centerCoordinate fromDistance:altitude pitch:pitch heading:direction];
+}
+
/// Returns a CameraOptions object that specifies parameters for animating to
/// the given camera.
- (mbgl::CameraOptions)cameraOptionsObjectForAnimatingToCamera:(MGLMapCamera *)camera edgePadding:(UIEdgeInsets)insets
@@ -2299,8 +2732,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
newAppliedClasses.insert(newAppliedClasses.end(), [appliedClass UTF8String]);
}
- _mbglMap->setDefaultTransitionDuration(MGLDurationInSeconds(transitionDuration));
- _mbglMap->setClasses(newAppliedClasses);
+ mbgl::style::TransitionOptions transition { { MGLDurationInSeconds(transitionDuration) } };
+ _mbglMap->setClasses(newAppliedClasses, transition);
}
- (BOOL)hasStyleClass:(NSString *)styleClass
@@ -2342,6 +2775,11 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
return pair.second.annotation;
});
+
+ annotations.erase(std::remove_if(annotations.begin(), annotations.end(),
+ [](const id <MGLAnnotation> annotation) { return annotation == nullptr; }),
+ annotations.end());
+
return [NSArray arrayWithObjects:&annotations[0] count:annotations.size()];
}
@@ -2390,10 +2828,13 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
if ( ! annotations) return;
[self willChangeValueForKey:@"annotations"];
- std::vector<mbgl::PointAnnotation> points;
- std::vector<mbgl::ShapeAnnotation> shapes;
+ NSMutableDictionary *annotationImagesForAnnotation = [NSMutableDictionary dictionary];
+ NSMutableDictionary *annotationViewsForAnnotation = [NSMutableDictionary dictionary];
+ BOOL delegateImplementsViewForAnnotation = [self.delegate respondsToSelector:@selector(mapView:viewForAnnotation:)];
BOOL delegateImplementsImageForPoint = [self.delegate respondsToSelector:@selector(mapView:imageForAnnotation:)];
+
+ NSMutableArray *newAnnotationViews = [[NSMutableArray alloc] initWithCapacity:annotations.count];
for (id <MGLAnnotation> annotation in annotations)
{
@@ -2401,66 +2842,153 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
if ([annotation isKindOfClass:[MGLMultiPoint class]])
{
- [(MGLMultiPoint *)annotation addShapeAnnotationObjectToCollection:shapes withDelegate:self];
- }
- else
- {
- MGLAnnotationImage *annotationImage = delegateImplementsImageForPoint ? [self.delegate mapView:self imageForAnnotation:annotation] : nil;
- if ( ! annotationImage)
+ // Actual multipoints aren’t supported as annotations.
+ if ([annotation isMemberOfClass:[MGLMultiPoint class]]
+ || [annotation isMemberOfClass:[MGLMultiPointFeature class]])
{
- annotationImage = [self dequeueReusableAnnotationImageWithIdentifier:MGLDefaultStyleMarkerSymbolName];
+ continue;
}
- if ( ! annotationImage)
- {
- // Create a default annotation image that depicts a round pin
- // rising from the center, with a shadow slightly below center.
- // The alignment rect therefore excludes the bottom half.
- UIImage *defaultAnnotationImage = [MGLMapView resourceImageNamed:MGLDefaultStyleMarkerSymbolName];
- defaultAnnotationImage = [defaultAnnotationImage imageWithAlignmentRectInsets:
- UIEdgeInsetsMake(0, 0, defaultAnnotationImage.size.height / 2, 0)];
- annotationImage = [MGLAnnotationImage annotationImageWithImage:defaultAnnotationImage
- reuseIdentifier:MGLDefaultStyleMarkerSymbolName];
+
+ // The polyline or polygon knows how to style itself (with the map view’s help).
+ MGLMultiPoint *multiPoint = (MGLMultiPoint *)annotation;
+ if (!multiPoint.pointCount) {
+ continue;
}
+
+ MGLAnnotationTag annotationTag = _mbglMap->addAnnotation([multiPoint annotationObjectWithDelegate:self]);
+ MGLAnnotationContext context;
+ context.annotation = annotation;
+ _annotationContextsByAnnotationTag[annotationTag] = context;
+ }
+ else if ( ! [annotation isKindOfClass:[MGLMultiPolyline class]]
+ || ![annotation isKindOfClass:[MGLMultiPolygon class]]
+ || ![annotation isKindOfClass:[MGLShapeCollection class]])
+ {
+ MGLAnnotationView *annotationView;
+ NSString *symbolName;
+ NSValue *annotationValue = [NSValue valueWithNonretainedObject:annotation];
- if ( ! self.annotationImagesByIdentifier[annotationImage.reuseIdentifier])
+ if (delegateImplementsViewForAnnotation)
{
- self.annotationImagesByIdentifier[annotationImage.reuseIdentifier] = annotationImage;
- [self installAnnotationImage:annotationImage];
- annotationImage.delegate = self;
+ annotationView = [self annotationViewForAnnotation:annotation];
+ if (annotationView)
+ {
+ annotationViewsForAnnotation[annotationValue] = annotationView;
+ annotationView.center = [self convertCoordinate:annotation.coordinate toPointToView:self];
+ [newAnnotationViews addObject:annotationView];
+ }
+ }
+
+ if ( ! annotationView) {
+ MGLAnnotationImage *annotationImage;
+
+ if (delegateImplementsImageForPoint)
+ {
+ annotationImage = [self.delegate mapView:self imageForAnnotation:annotation];
+ }
+ if ( ! annotationImage)
+ {
+ annotationImage = [self dequeueReusableAnnotationImageWithIdentifier:MGLDefaultStyleMarkerSymbolName];
+ }
+ if ( ! annotationImage)
+ {
+ annotationImage = self.defaultAnnotationImage;
+ }
+
+ symbolName = annotationImage.styleIconIdentifier;
+
+ if ( ! symbolName)
+ {
+ symbolName = [MGLAnnotationSpritePrefix stringByAppendingString:annotationImage.reuseIdentifier];
+ annotationImage.styleIconIdentifier = symbolName;
+ }
+ if ( ! self.annotationImagesByIdentifier[annotationImage.reuseIdentifier])
+ {
+ [self installAnnotationImage:annotationImage];
+ }
+
+ annotationImagesForAnnotation[annotationValue] = annotationImage;
}
- NSString *symbolName = [MGLAnnotationSpritePrefix stringByAppendingString:annotationImage.reuseIdentifier];
+ MGLAnnotationTag annotationTag = _mbglMap->addAnnotation(mbgl::SymbolAnnotation {
+ MGLPointFromLocationCoordinate2D(annotation.coordinate),
+ symbolName.UTF8String ?: ""
+ });
- points.emplace_back(MGLLatLngFromLocationCoordinate2D(annotation.coordinate), symbolName ? [symbolName UTF8String] : "");
+ MGLAnnotationContext context;
+ context.annotation = annotation;
+ MGLAnnotationImage *annotationImage = annotationImagesForAnnotation[annotationValue];
+
+ if (annotationImage) {
+ context.imageReuseIdentifier = annotationImage.reuseIdentifier;
+ }
+ if (annotationView) {
+ context.annotationView = annotationView;
+ context.viewReuseIdentifier = annotationView.reuseIdentifier;
+ }
+
+ _annotationContextsByAnnotationTag[annotationTag] = context;
+ if ([annotation isKindOfClass:[NSObject class]]) {
+ NSAssert(![annotation isKindOfClass:[MGLMultiPoint class]], @"Point annotation should not be MGLMultiPoint.");
+ [(NSObject *)annotation addObserver:self forKeyPath:@"coordinate" options:0 context:(void *)(NSUInteger)annotationTag];
+ }
}
}
- if (points.size())
+ [self updateAnnotationContainerViewWithAnnotationViews:newAnnotationViews];
+
+ [self didChangeValueForKey:@"annotations"];
+ UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);
+}
+
+- (void)updateAnnotationContainerViewWithAnnotationViews:(NS_ARRAY_OF(MGLAnnotationView *) *)annotationViews
+{
+ if (annotationViews.count == 0) return;
+
+ MGLAnnotationContainerView *newAnnotationContainerView;
+ if (self.annotationContainerView)
{
- std::vector<MGLAnnotationTag> pointAnnotationTags = _mbglMap->addPointAnnotations(points);
-
- for (size_t i = 0; i < pointAnnotationTags.size(); ++i)
- {
- MGLAnnotationContext context;
- context.annotation = annotations[i];
- context.symbolIdentifier = @(points[i].icon.c_str());
- _annotationContextsByAnnotationTag[pointAnnotationTags[i]] = context;
- }
+ // reload any previously added views
+ newAnnotationContainerView = [MGLAnnotationContainerView annotationContainerViewWithAnnotationContainerView:self.annotationContainerView];
+ [self.annotationContainerView removeFromSuperview];
+ }
+ else
+ {
+ newAnnotationContainerView = [[MGLAnnotationContainerView alloc] initWithFrame:self.bounds];
}
+ newAnnotationContainerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ newAnnotationContainerView.contentMode = UIViewContentModeCenter;
+ [newAnnotationContainerView addSubviews:annotationViews];
+ [_glView insertSubview:newAnnotationContainerView atIndex:0];
+ self.annotationContainerView = newAnnotationContainerView;
+}
+
+/// Initialize and return a default annotation image that depicts a round pin
+/// rising from the center, with a shadow slightly below center. The alignment
+/// rect therefore excludes the bottom half.
+- (MGLAnnotationImage *)defaultAnnotationImage
+{
+ UIImage *image = [MGLMapView resourceImageNamed:MGLDefaultStyleMarkerSymbolName];
+ image = [image imageWithAlignmentRectInsets:
+ UIEdgeInsetsMake(0, 0, image.size.height / 2, 0)];
+ MGLAnnotationImage *annotationImage = [MGLAnnotationImage annotationImageWithImage:image
+ reuseIdentifier:MGLDefaultStyleMarkerSymbolName];
+ annotationImage.styleIconIdentifier = [MGLAnnotationSpritePrefix stringByAppendingString:annotationImage.reuseIdentifier];
+ return annotationImage;
+}
- if (shapes.size())
+- (MGLAnnotationView *)annotationViewForAnnotation:(id<MGLAnnotation>)annotation
+{
+ MGLAnnotationView *annotationView = [self.delegate mapView:self viewForAnnotation:annotation];
+
+ if (annotationView)
{
- std::vector<MGLAnnotationTag> shapeAnnotationTags = _mbglMap->addShapeAnnotations(shapes);
-
- for (size_t i = 0; i < shapeAnnotationTags.size(); ++i)
- {
- MGLAnnotationContext context;
- context.annotation = annotations[i];
- _annotationContextsByAnnotationTag[shapeAnnotationTags[i]] = context;
- }
+ annotationView.annotation = annotation;
+ CGRect bounds = UIEdgeInsetsInsetRect({ CGPointZero, annotationView.frame.size }, annotationView.alignmentRectInsets);
+ _largestAnnotationViewSize = CGSizeMake(bounds.size.width / 2.0, bounds.size.height / 2.0);
}
- [self didChangeValueForKey:@"annotations"];
+ return annotationView;
}
- (double)alphaForShapeAnnotation:(MGLShape *)annotation
@@ -2499,6 +3027,10 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (void)installAnnotationImage:(MGLAnnotationImage *)annotationImage
{
+ NSString *iconIdentifier = annotationImage.styleIconIdentifier;
+ self.annotationImagesByIdentifier[annotationImage.reuseIdentifier] = annotationImage;
+ annotationImage.delegate = self;
+
// retrieve pixels
CGImageRef image = annotationImage.image.CGImage;
size_t width = CGImageGetWidth(image);
@@ -2519,8 +3051,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
float(annotationImage.image.scale));
// sprite upload
- NSString *symbolName = [MGLAnnotationSpritePrefix stringByAppendingString:annotationImage.reuseIdentifier];
- _mbglMap->addAnnotationIcon(symbolName.UTF8String, cSpriteImage);
+ _mbglMap->addAnnotationIcon(iconIdentifier.UTF8String, cSpriteImage);
// Create a slop area with a “radius” equal in size to the annotation
// image’s alignment rect, allowing the eventual tap to be on any point
@@ -2546,8 +3077,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
if ( ! annotations) return;
- std::vector<MGLAnnotationTag> annotationTagsToRemove;
- annotationTagsToRemove.reserve(annotations.count);
+ [self willChangeValueForKey:@"annotations"];
for (id <MGLAnnotation> annotation in annotations)
{
@@ -2558,7 +3088,10 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
continue;
}
- annotationTagsToRemove.push_back(annotationTag);
+
+ MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(annotationTag);
+ MGLAnnotationView *annotationView = annotationContext.annotationView;
+ [annotationView removeFromSuperview];
if (annotationTag == _selectedAnnotationTag)
{
@@ -2566,14 +3099,17 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
}
_annotationContextsByAnnotationTag.erase(annotationTag);
- }
+
+ if ([annotation isKindOfClass:[NSObject class]] && ![annotation isKindOfClass:[MGLMultiPoint class]])
+ {
+ [(NSObject *)annotation removeObserver:self forKeyPath:@"coordinate" context:(void *)(NSUInteger)annotationTag];
+ }
- if ( ! annotationTagsToRemove.empty())
- {
- [self willChangeValueForKey:@"annotations"];
- _mbglMap->removeAnnotations(annotationTagsToRemove);
- [self didChangeValueForKey:@"annotations"];
+ _mbglMap->removeAnnotation(annotationTag);
}
+
+ [self didChangeValueForKey:@"annotations"];
+ UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);
}
- (void)addOverlay:(id <MGLOverlay>)overlay
@@ -2583,10 +3119,12 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (void)addOverlays:(NS_ARRAY_OF(id <MGLOverlay>) *)overlays
{
+#if DEBUG
for (id <MGLOverlay> overlay in overlays)
{
NSAssert([overlay conformsToProtocol:@protocol(MGLOverlay)], @"overlay should conform to MGLOverlay");
}
+#endif
[self addAnnotations:overlays];
}
@@ -2598,23 +3136,48 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (void)removeOverlays:(NS_ARRAY_OF(id <MGLOverlay>) *)overlays
{
+#if DEBUG
for (id <MGLOverlay> overlay in overlays)
{
NSAssert([overlay conformsToProtocol:@protocol(MGLOverlay)], @"overlay should conform to MGLOverlay");
}
+#endif
[self removeAnnotations:overlays];
}
- (nullable MGLAnnotationImage *)dequeueReusableAnnotationImageWithIdentifier:(NSString *)identifier
{
- // This prefix is used to avoid collisions with style-defined sprites in
- // mbgl, but reusable identifiers are never prefixed.
- if ([identifier hasPrefix:MGLAnnotationSpritePrefix])
+ return self.annotationImagesByIdentifier[identifier];
+}
+
+- (nullable MGLAnnotationView *)dequeueReusableAnnotationViewWithIdentifier:(NSString *)identifier
+{
+ NSMutableArray *annotationViewReuseQueue = [self annotationViewReuseQueueForIdentifier:identifier];
+ MGLAnnotationView *reusableView = annotationViewReuseQueue.firstObject;
+ [reusableView prepareForReuse];
+ [annotationViewReuseQueue removeObject:reusableView];
+
+ return reusableView;
+}
+
+- (MGLAnnotationView *)annotationViewAtPoint:(CGPoint)point
+{
+ std::vector<MGLAnnotationTag> annotationTags = [self annotationTagsInRect:self.bounds];
+
+ for(auto const& annotationTag: annotationTags)
{
- identifier = [identifier substringFromIndex:MGLAnnotationSpritePrefix.length];
+ auto &annotationContext = _annotationContextsByAnnotationTag[annotationTag];
+ MGLAnnotationView *annotationView = annotationContext.annotationView;
+ CGPoint convertedPoint = [self convertPoint:point toView:annotationView];
+
+ if ([annotationView pointInside:convertedPoint withEvent:nil])
+ {
+ return annotationView;
+ }
}
- return self.annotationImagesByIdentifier[identifier];
+
+ return nil;
}
/**
@@ -2648,6 +3211,9 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
-MGLAnnotationImagePaddingForHitTest,
-MGLAnnotationImagePaddingForHitTest);
+ MGLAnnotationImage *fallbackAnnotationImage = [self dequeueReusableAnnotationImageWithIdentifier:MGLDefaultStyleMarkerSymbolName];
+ UIImage *fallbackImage = fallbackAnnotationImage.image;
+
// Filter out any annotation whose image is unselectable or for which
// hit testing fails.
auto end = std::remove_if(nearbyAnnotations.begin(), nearbyAnnotations.end(),
@@ -2656,6 +3222,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
id <MGLAnnotation> annotation = [self annotationWithTag:annotationTag];
NSAssert(annotation, @"Unknown annotation found nearby tap");
+ MGLAnnotationContext annotationContext = _annotationContextsByAnnotationTag[annotationTag];
+
MGLAnnotationImage *annotationImage = [self imageOfAnnotationWithTag:annotationTag];
if ( ! annotationImage.enabled)
{
@@ -2664,10 +3232,11 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
// Filter out the annotation if the fattened finger didn’t land
// within the image’s alignment rect.
- CGRect annotationRect = [self frameOfImage:annotationImage.image
- centeredAtCoordinate:annotation.coordinate];
+ CGRect annotationRect = [self frameOfImage:annotationImage.image ?: fallbackImage centeredAtCoordinate:annotation.coordinate];
+
return !!!CGRectIntersectsRect(annotationRect, hitRect);
});
+
nearbyAnnotations.resize(std::distance(nearbyAnnotations.begin(), end));
}
@@ -2732,9 +3301,9 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
}
// Choose the first nearby annotation.
- if (_annotationsNearbyLastTap.size())
+ if (nearbyAnnotations.size())
{
- hitAnnotationTag = _annotationsNearbyLastTap.front();
+ hitAnnotationTag = nearbyAnnotations.front();
}
}
}
@@ -2773,7 +3342,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (NS_ARRAY_OF(id <MGLAnnotation>) *)selectedAnnotations
{
- return (self.selectedAnnotation ? @[ self.selectedAnnotation ] : @[]);
+ id <MGLAnnotation> selectedAnnotation = self.selectedAnnotation;
+ return (selectedAnnotation ? @[ selectedAnnotation ] : @[]);
}
- (void)setSelectedAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)selectedAnnotations
@@ -2813,10 +3383,29 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
if (annotationTag == MGLAnnotationTagNotFound && annotation != self.userLocation)
{
[self addAnnotation:annotation];
+ annotationTag = [self annotationTagForAnnotation:annotation];
+ if (annotationTag == MGLAnnotationTagNotFound) return;
}
- // The annotation can’t be selected if no part of it is hittable.
+ // By default attempt to use the GL annotation image frame as the positioning rect.
CGRect positioningRect = [self positioningRectForCalloutForAnnotationWithTag:annotationTag];
+
+ if (annotation != self.userLocation)
+ {
+ MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(annotationTag);
+
+ MGLAnnotationView *annotationView = annotationContext.annotationView;
+ if (annotationView)
+ {
+ // Annotations represented by views use the view frame as the positioning rect.
+ positioningRect = annotationView.frame;
+
+ [annotationView.superview bringSubviewToFront:annotationView];
+ }
+ }
+
+ // The client can request that any annotation be selected (even ones that are offscreen).
+ // The annotation can’t be selected if no part of it is hittable.
if ( ! CGRectIntersectsRect(positioningRect, self.bounds) && annotation != self.userLocation)
{
return;
@@ -2830,59 +3419,62 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
[self.delegate mapView:self annotationCanShowCallout:annotation])
{
// build the callout
+ UIView <MGLCalloutView> *calloutView;
if ([self.delegate respondsToSelector:@selector(mapView:calloutViewForAnnotation:)])
{
- self.calloutViewForSelectedAnnotation = [self.delegate mapView:self calloutViewForAnnotation:annotation];
+ calloutView = [self.delegate mapView:self calloutViewForAnnotation:annotation];
}
- if (!self.calloutViewForSelectedAnnotation)
+ if (!calloutView)
{
- self.calloutViewForSelectedAnnotation = [self calloutViewForAnnotation:annotation];
+ calloutView = [self calloutViewForAnnotation:annotation];
}
+ self.calloutViewForSelectedAnnotation = calloutView;
if (_userLocationAnnotationIsSelected)
{
- positioningRect = CGRectInset(self.userLocationAnnotationView.frame,
- -MGLAnnotationImagePaddingForCallout,
- -MGLAnnotationImagePaddingForCallout);
+ positioningRect = [self.userLocationAnnotationView.layer.presentationLayer frame];
+
+ CGRect implicitAnnotationFrame = [self.userLocationAnnotationView.layer.presentationLayer frame];
+ CGRect explicitAnnotationFrame = self.userLocationAnnotationView.frame;
+ _initialImplicitCalloutViewOffset = CGPointMake(CGRectGetMinX(explicitAnnotationFrame) - CGRectGetMinX(implicitAnnotationFrame),
+ CGRectGetMinY(explicitAnnotationFrame) - CGRectGetMinY(implicitAnnotationFrame));
}
// consult delegate for left and/or right accessory views
if ([self.delegate respondsToSelector:@selector(mapView:leftCalloutAccessoryViewForAnnotation:)])
{
- self.calloutViewForSelectedAnnotation.leftAccessoryView =
- [self.delegate mapView:self leftCalloutAccessoryViewForAnnotation:annotation];
+ calloutView.leftAccessoryView = [self.delegate mapView:self leftCalloutAccessoryViewForAnnotation:annotation];
- if ([self.calloutViewForSelectedAnnotation.leftAccessoryView isKindOfClass:[UIControl class]])
+ if ([calloutView.leftAccessoryView isKindOfClass:[UIControl class]])
{
UITapGestureRecognizer *calloutAccessoryTap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleCalloutAccessoryTapGesture:)];
- [self.calloutViewForSelectedAnnotation.leftAccessoryView addGestureRecognizer:calloutAccessoryTap];
+ [calloutView.leftAccessoryView addGestureRecognizer:calloutAccessoryTap];
}
}
if ([self.delegate respondsToSelector:@selector(mapView:rightCalloutAccessoryViewForAnnotation:)])
{
- self.calloutViewForSelectedAnnotation.rightAccessoryView =
- [self.delegate mapView:self rightCalloutAccessoryViewForAnnotation:annotation];
+ calloutView.rightAccessoryView = [self.delegate mapView:self rightCalloutAccessoryViewForAnnotation:annotation];
- if ([self.calloutViewForSelectedAnnotation.rightAccessoryView isKindOfClass:[UIControl class]])
+ if ([calloutView.rightAccessoryView isKindOfClass:[UIControl class]])
{
UITapGestureRecognizer *calloutAccessoryTap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleCalloutAccessoryTapGesture:)];
- [self.calloutViewForSelectedAnnotation.rightAccessoryView addGestureRecognizer:calloutAccessoryTap];
+ [calloutView.rightAccessoryView addGestureRecognizer:calloutAccessoryTap];
}
}
// set annotation delegate to handle taps on the callout view
- self.calloutViewForSelectedAnnotation.delegate = self;
+ calloutView.delegate = self;
// present popup
- [self.calloutViewForSelectedAnnotation presentCalloutFromRect:positioningRect
- inView:self.glView
- constrainedToView:self.glView
- animated:animated];
+ [calloutView presentCalloutFromRect:positioningRect
+ inView:self.glView
+ constrainedToView:self.glView
+ animated:animated];
}
// notify delegate
@@ -2906,6 +3498,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
/// and is appropriate for positioning a popover.
- (CGRect)positioningRectForCalloutForAnnotationWithTag:(MGLAnnotationTag)annotationTag
{
+ MGLAnnotationContext annotationContext = _annotationContextsByAnnotationTag[annotationTag];
+
id <MGLAnnotation> annotation = [self annotationWithTag:annotationTag];
if ( ! annotation)
{
@@ -2914,11 +3508,16 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
UIImage *image = [self imageOfAnnotationWithTag:annotationTag].image;
if ( ! image)
{
+ image = [self dequeueReusableAnnotationImageWithIdentifier:MGLDefaultStyleMarkerSymbolName].image;
+ }
+ if ( ! image)
+ {
return CGRectZero;
}
CGRect positioningRect = [self frameOfImage:image centeredAtCoordinate:annotation.coordinate];
positioningRect.origin.x -= 0.5;
+
return CGRectInset(positioningRect, -MGLAnnotationImagePaddingForCallout,
-MGLAnnotationImagePaddingForCallout);
}
@@ -2941,7 +3540,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
return nil;
}
- NSString *customSymbol = _annotationContextsByAnnotationTag.at(annotationTag).symbolIdentifier;
+ NSString *customSymbol = _annotationContextsByAnnotationTag.at(annotationTag).imageReuseIdentifier;
NSString *symbolName = customSymbol.length ? customSymbol : MGLDefaultStyleMarkerSymbolName;
return [self dequeueReusableAnnotationImageWithIdentifier:symbolName];
@@ -2951,7 +3550,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
if ( ! annotation) return;
- if ([self.selectedAnnotation isEqual:annotation])
+ if (self.selectedAnnotation == annotation)
{
// dismiss popup
[self.calloutViewForSelectedAnnotation dismissCalloutAnimated:animated];
@@ -2968,6 +3567,35 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
}
}
+- (void)calloutViewWillAppear:(UIView <MGLCalloutView> *)calloutView
+{
+ if (_userLocationAnnotationIsSelected ||
+ CGPointEqualToPoint(_initialImplicitCalloutViewOffset, CGPointZero))
+ {
+ return;
+ }
+
+ // The user location callout view initially points to the user location
+ // annotation’s implicit (visual) frame, which is offset from the
+ // annotation’s explicit frame. Now the callout view needs to rendezvous
+ // with the explicit frame. Then,
+ // -updateUserLocationAnnotationViewAnimatedWithDuration: will take over the
+ // next time an updated location arrives.
+ [UIView animateWithDuration:_userLocationAnimationCompletionDate.timeIntervalSinceNow
+ delay:0
+ options:(UIViewAnimationOptionCurveLinear |
+ UIViewAnimationOptionAllowUserInteraction |
+ UIViewAnimationOptionBeginFromCurrentState)
+ animations:^
+ {
+ calloutView.frame = CGRectOffset(calloutView.frame,
+ _initialImplicitCalloutViewOffset.x,
+ _initialImplicitCalloutViewOffset.y);
+ _initialImplicitCalloutViewOffset = CGPointZero;
+ }
+ completion:NULL];
+}
+
- (void)showAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations animated:(BOOL)animated
{
CGFloat maximumPadding = 100;
@@ -3006,11 +3634,53 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (void)annotationImageNeedsRedisplay:(MGLAnnotationImage *)annotationImage
{
- // remove sprite
- NSString *symbolName = [MGLAnnotationSpritePrefix stringByAppendingString:annotationImage.reuseIdentifier];
- _mbglMap->removeAnnotationIcon(symbolName.UTF8String);
- [self installAnnotationImage:annotationImage];
- _mbglMap->update(mbgl::Update::Annotations);
+ NSString *reuseIdentifier = annotationImage.reuseIdentifier;
+ NSString *iconIdentifier = annotationImage.styleIconIdentifier;
+ NSString *fallbackReuseIdentifier = MGLDefaultStyleMarkerSymbolName;
+ NSString *fallbackIconIdentifier = [MGLAnnotationSpritePrefix stringByAppendingString:fallbackReuseIdentifier];
+
+ // Remove the old icon from the style.
+ if ( ! [iconIdentifier isEqualToString:fallbackIconIdentifier]) {
+ _mbglMap->removeAnnotationIcon(iconIdentifier.UTF8String);
+ }
+
+ if (annotationImage.image)
+ {
+ // Add the new icon to the style.
+ NSString *updatedIconIdentifier = [MGLAnnotationSpritePrefix stringByAppendingString:annotationImage.reuseIdentifier];
+ annotationImage.styleIconIdentifier = updatedIconIdentifier;
+ [self installAnnotationImage:annotationImage];
+
+ if ([iconIdentifier isEqualToString:fallbackIconIdentifier])
+ {
+ // Update any annotations associated with the annotation image.
+ [self applyIconIdentifier:updatedIconIdentifier toAnnotationsWithImageReuseIdentifier:reuseIdentifier];
+ }
+ }
+ else
+ {
+ // Add the default icon to the style if necessary.
+ annotationImage.styleIconIdentifier = fallbackIconIdentifier;
+ if ( ! [self dequeueReusableAnnotationImageWithIdentifier:MGLDefaultStyleMarkerSymbolName])
+ {
+ [self installAnnotationImage:self.defaultAnnotationImage];
+ }
+
+ // Update any annotations associated with the annotation image.
+ [self applyIconIdentifier:fallbackIconIdentifier toAnnotationsWithImageReuseIdentifier:reuseIdentifier];
+ }
+}
+
+- (void)applyIconIdentifier:(NSString *)iconIdentifier toAnnotationsWithImageReuseIdentifier:(NSString *)reuseIdentifier
+{
+ for (auto &pair : _annotationContextsByAnnotationTag)
+ {
+ if ([pair.second.imageReuseIdentifier isEqualToString:reuseIdentifier])
+ {
+ const mbgl::Point<double> point = MGLPointFromLocationCoordinate2D(pair.second.annotation.coordinate);
+ _mbglMap->updateAnnotation(pair.first, mbgl::SymbolAnnotation { point, iconIdentifier.UTF8String ?: "" });
+ }
+ }
}
#pragma mark - User Location -
@@ -3149,7 +3819,9 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
}
MGLUserTrackingMode oldMode = _userTrackingMode;
+ [self willChangeValueForKey:@"userTrackingMode"];
_userTrackingMode = mode;
+ [self didChangeValueForKey:@"userTrackingMode"];
switch (_userTrackingMode)
{
@@ -3173,9 +3845,10 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
[self.locationManager stopUpdatingHeading];
- if (self.userLocationAnnotationView)
+ CLLocation *location = self.userLocation.location;
+ if (location && self.userLocationAnnotationView)
{
- [self locationManager:self.locationManager didUpdateLocations:@[self.userLocation.location] animated:animated];
+ [self locationManager:self.locationManager didUpdateLocations:@[location] animated:animated];
}
break;
@@ -3223,7 +3896,11 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
_userLocationVerticalAlignment = alignment;
if (self.userTrackingMode != MGLUserTrackingModeNone)
{
- [self locationManager:self.locationManager didUpdateLocations:@[self.userLocation.location] animated:animated];
+ CLLocation *location = self.userLocation.location;
+ if (location)
+ {
+ [self locationManager:self.locationManager didUpdateLocations:@[location] animated:animated];
+ }
}
}
@@ -3280,7 +3957,19 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
self.userLocationAnnotationView.haloLayer.hidden = ! CLLocationCoordinate2DIsValid(self.userLocation.coordinate) ||
newLocation.horizontalAccuracy > 10;
- [self updateUserLocationAnnotationView];
+ NSTimeInterval duration = MGLAnimationDuration;
+ if (oldLocation && ! CGPointEqualToPoint(self.userLocationAnnotationView.center, CGPointZero))
+ {
+ duration = MIN([newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp], MGLUserLocationAnimationDuration);
+ }
+ [self updateUserLocationAnnotationViewAnimatedWithDuration:duration];
+
+ if (self.userTrackingMode == MGLUserTrackingModeNone &&
+ self.userLocationAnnotationView.accessibilityElementIsFocused &&
+ [UIApplication sharedApplication].applicationState == UIApplicationStateActive)
+ {
+ UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self.userLocationAnnotationView);
+ }
}
- (void)didUpdateLocationWithUserTrackingAnimated:(BOOL)animated
@@ -3541,6 +4230,57 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
}
}
+#pragma mark Data
+
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(CGPoint)point
+{
+ return [self visibleFeaturesAtPoint:point inStyleLayersWithIdentifiers:nil];
+}
+
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(CGPoint)point inStyleLayersWithIdentifiers:(NS_SET_OF(NSString *) *)styleLayerIdentifiers
+{
+ mbgl::ScreenCoordinate screenCoordinate = { point.x, point.y };
+
+ mbgl::optional<std::vector<std::string>> optionalLayerIDs;
+ if (styleLayerIdentifiers)
+ {
+ __block std::vector<std::string> layerIDs;
+ layerIDs.reserve(styleLayerIdentifiers.count);
+ [styleLayerIdentifiers enumerateObjectsUsingBlock:^(NSString * _Nonnull identifier, BOOL * _Nonnull stop)
+ {
+ layerIDs.push_back(identifier.UTF8String);
+ }];
+ optionalLayerIDs = layerIDs;
+ }
+
+ std::vector<mbgl::Feature> features = _mbglMap->queryRenderedFeatures(screenCoordinate, optionalLayerIDs);
+ return MGLFeaturesFromMBGLFeatures(features);
+}
+
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesInRect:(CGRect)rect {
+ return [self visibleFeaturesInRect:rect inStyleLayersWithIdentifiers:nil];
+}
+
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesInRect:(CGRect)rect inStyleLayersWithIdentifiers:(NS_SET_OF(NSString *) *)styleLayerIdentifiers {
+ mbgl::ScreenBox screenBox = {
+ { CGRectGetMinX(rect), CGRectGetMinY(rect) },
+ { CGRectGetMaxX(rect), CGRectGetMaxY(rect) },
+ };
+
+ mbgl::optional<std::vector<std::string>> optionalLayerIDs;
+ if (styleLayerIdentifiers) {
+ __block std::vector<std::string> layerIDs;
+ layerIDs.reserve(styleLayerIdentifiers.count);
+ [styleLayerIdentifiers enumerateObjectsUsingBlock:^(NSString * _Nonnull identifier, BOOL * _Nonnull stop) {
+ layerIDs.push_back(identifier.UTF8String);
+ }];
+ optionalLayerIDs = layerIDs;
+ }
+
+ std::vector<mbgl::Feature> features = _mbglMap->queryRenderedFeatures(screenBox, optionalLayerIDs);
+ return MGLFeaturesFromMBGLFeatures(features);
+}
+
#pragma mark - Utility -
- (void)animateWithDelay:(NSTimeInterval)delay animations:(void (^)(void))animations
@@ -3652,6 +4392,10 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
if ( ! [self isSuppressingChangeDelimiters] && [self.delegate respondsToSelector:@selector(mapView:regionDidChangeAnimated:)])
{
+ if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive)
+ {
+ UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);
+ }
BOOL animated = change == mbgl::MapChangeRegionDidChangeAnimated;
[self.delegate mapView:self regionDidChangeAnimated:animated];
}
@@ -3714,6 +4458,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
[self.delegate mapViewDidFinishRenderingFrame:self fullyRendered:(change == mbgl::MapChangeDidFinishRenderingFrameFullyRendered)];
}
+ [self updateAnnotationViews];
break;
}
}
@@ -3721,14 +4466,81 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (void)updateUserLocationAnnotationView
{
+ [self updateUserLocationAnnotationViewAnimatedWithDuration:0];
+}
+
+- (void)updateAnnotationViews
+{
+ BOOL delegateImplementsViewForAnnotation = [self.delegate respondsToSelector:@selector(mapView:viewForAnnotation:)];
+
+ if (!delegateImplementsViewForAnnotation)
+ {
+ return;
+ }
+
+ for (auto &pair : _annotationContextsByAnnotationTag)
+ {
+ CGRect viewPort = CGRectInset(self.bounds, -_largestAnnotationViewSize.width - MGLAnnotationUpdateViewportOutset.width, -_largestAnnotationViewSize.height - MGLAnnotationUpdateViewportOutset.width);
+
+ MGLAnnotationContext &annotationContext = pair.second;
+ MGLAnnotationView *annotationView = annotationContext.annotationView;
+
+ if (!annotationView)
+ {
+ MGLAnnotationView *annotationView = [self annotationViewForAnnotation:annotationContext.annotation];
+ if (annotationView)
+ {
+ // If the annotation view has no superview it means it was never used before so add it
+ if (!annotationView.superview)
+ {
+ [self.glView addSubview:annotationView];
+ }
+
+ CGPoint center = [self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self];
+ [annotationView setCenter:center pitch:self.camera.pitch];
+
+ annotationContext.annotationView = annotationView;
+ }
+ }
+
+ bool annotationViewIsVisible = CGRectContainsRect(viewPort, annotationView.frame);
+ if (!annotationViewIsVisible)
+ {
+ [self enqueueAnnotationViewForAnnotationContext:annotationContext];
+ }
+ else
+ {
+ CGPoint center = [self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self];
+ [annotationView setCenter:center pitch:self.camera.pitch];
+ }
+ }
+}
+
+- (void)enqueueAnnotationViewForAnnotationContext:(MGLAnnotationContext &)annotationContext
+{
+ MGLAnnotationView *annotationView = annotationContext.annotationView;
+
+ if (!annotationView) return;
+
+ if (annotationContext.viewReuseIdentifier)
+ {
+ NSMutableArray *annotationViewReuseQueue = [self annotationViewReuseQueueForIdentifier:annotationContext.viewReuseIdentifier];
+ if (![annotationViewReuseQueue containsObject:annotationView])
+ {
+ [annotationViewReuseQueue addObject:annotationView];
+ annotationContext.annotationView = nil;
+ }
+ }
+}
+
+- (void)updateUserLocationAnnotationViewAnimatedWithDuration:(NSTimeInterval)duration
+{
MGLUserLocationAnnotationView *annotationView = self.userLocationAnnotationView;
if ( ! CLLocationCoordinate2DIsValid(self.userLocation.coordinate)) {
annotationView.hidden = YES;
return;
}
- if ( ! annotationView.superview) [self.glView addSubview:annotationView];
-
CGPoint userPoint;
if (self.userTrackingMode != MGLUserTrackingModeNone
&& self.userTrackingState == MGLUserTrackingStateChanged)
@@ -3739,11 +4551,36 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
userPoint = [self convertCoordinate:self.userLocation.coordinate toPointToView:self];
}
+
+ if ( ! annotationView.superview)
+ {
+ [self.glView addSubview:annotationView];
+ // Prevents the view from sliding in from the origin.
+ annotationView.center = userPoint;
+ }
if (CGRectContainsPoint(CGRectInset(self.bounds, -MGLAnnotationUpdateViewportOutset.width,
-MGLAnnotationUpdateViewportOutset.height), userPoint))
{
- annotationView.center = userPoint;
+ // Smoothly move the user location annotation view and callout view to
+ // the new location.
+ [UIView animateWithDuration:duration
+ delay:0
+ options:(UIViewAnimationOptionCurveLinear |
+ UIViewAnimationOptionAllowUserInteraction |
+ UIViewAnimationOptionBeginFromCurrentState)
+ animations:^{
+ if (self.selectedAnnotation == self.userLocation)
+ {
+ UIView <MGLCalloutView> *calloutView = self.calloutViewForSelectedAnnotation;
+ calloutView.frame = CGRectOffset(calloutView.frame,
+ userPoint.x - annotationView.center.x,
+ userPoint.y - annotationView.center.y);
+ }
+ annotationView.center = userPoint;
+ } completion:NULL];
+ _userLocationAnimationCompletionDate = [NSDate dateWithTimeIntervalSinceNow:duration];
+
annotationView.hidden = NO;
[annotationView setupLayers];
@@ -3802,11 +4639,14 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (void)updateCompass
{
- CLLocationDirection degrees = mbgl::util::wrap(-self.direction, 0., 360.);
-
- self.compassView.transform = CGAffineTransformMakeRotation(MGLRadiansFromDegrees(degrees));
+ 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 (_mbglMap->getBearing() && self.compassView.alpha < 1)
+ if (direction > 0 && self.compassView.alpha < 1)
{
[UIView animateWithDuration:MGLAnimationDuration
delay:0
@@ -3817,7 +4657,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
}
completion:nil];
}
- else if (_mbglMap->getBearing() == 0 && self.compassView.alpha > 0)
+ else if (direction == 0 && self.compassView.alpha > 0)
{
[UIView animateWithDuration:MGLAnimationDuration
delay:0
@@ -3868,7 +4708,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
// Headline
UILabel *headlineLabel = [[UILabel alloc] init];
- headlineLabel.text = @"MGLMapView";
+ headlineLabel.text = NSStringFromClass([self class]);
headlineLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
headlineLabel.textAlignment = NSTextAlignmentCenter;
headlineLabel.numberOfLines = 1;
@@ -3879,8 +4719,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
// Explanation
UILabel *explanationLabel = [[UILabel alloc] init];
- explanationLabel.text = (@"To display a Mapbox-hosted map here, set MGLMapboxAccessToken to your access token in Info.plist\n\n"
- @"For detailed instructions, see:");
+ explanationLabel.text = [NSString stringWithFormat:NSLocalizedStringWithDefaultValue(@"DESIGNABLE", nil, nil, @"To display a Mapbox-hosted map here, set %@ to your access token in %@\n\nFor detailed instructions, see:", @"Instructions in Interface Builder designable; {key}, {plist file name}"), @"MGLMapboxAccessToken", @"Info.plist"];
explanationLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
explanationLabel.numberOfLines = 0;
explanationLabel.translatesAutoresizingMaskIntoConstraints = NO;
@@ -3890,7 +4729,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
// Link
UIButton *linkButton = [UIButton buttonWithType:UIButtonTypeSystem];
- [linkButton setTitle:MGLMapboxSetupDocumentationURLDisplayString forState:UIControlStateNormal];
+ [linkButton setTitle:NSLocalizedStringWithDefaultValue(@"FIRST_STEPS_URL", nil, nil, @"mapbox.com/help/first-steps-ios-sdk", @"Setup documentation URL display string; keep as short as possible") forState:UIControlStateNormal];
linkButton.translatesAutoresizingMaskIntoConstraints = NO;
linkButton.titleLabel.numberOfLines = 0;
[linkButton setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
@@ -3955,14 +4794,21 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
views:views]];
}
+- (NS_MUTABLE_ARRAY_OF(MGLAnnotationView *) *)annotationViewReuseQueueForIdentifier:(NSString *)identifier {
+ if (!_annotationViewReuseQueueByIdentifier[identifier])
+ {
+ _annotationViewReuseQueueByIdentifier[identifier] = [NSMutableArray array];
+ }
+
+ return _annotationViewReuseQueueByIdentifier[identifier];
+}
+
class MBGLView : public mbgl::View
{
- public:
- MBGLView(MGLMapView* nativeView_, const float scaleFactor_)
- : nativeView(nativeView_), scaleFactor(scaleFactor_) {
- }
- virtual ~MBGLView() {}
-
+public:
+ MBGLView(MGLMapView* nativeView_, const float scaleFactor_)
+ : nativeView(nativeView_), scaleFactor(scaleFactor_) {
+ }
float getPixelRatio() const override {
return scaleFactor;
@@ -3970,7 +4816,7 @@ class MBGLView : public mbgl::View
std::array<uint16_t, 2> getSize() const override {
return {{ static_cast<uint16_t>([nativeView bounds].size.width),
- static_cast<uint16_t>([nativeView bounds].size.height) }};
+ static_cast<uint16_t>([nativeView bounds].size.height) }};
}
std::array<uint16_t, 2> getFramebufferSize() const override {
@@ -3978,15 +4824,14 @@ class MBGLView : public mbgl::View
static_cast<uint16_t>([[nativeView glView] drawableHeight]) }};
}
- void notify() override
+ void notifyMapChange(mbgl::MapChange change) override
{
- // no-op
+ [nativeView notifyMapChange:change];
}
- void notifyMapChange(mbgl::MapChange change) override
+ void invalidate() override
{
- assert([[NSThread currentThread] isMainThread]);
- [nativeView notifyMapChange:change];
+ [nativeView setNeedsGLDisplay];
}
void activate() override
@@ -3999,26 +4844,9 @@ class MBGLView : public mbgl::View
[EAGLContext setCurrentContext:nil];
}
- void invalidate() override
- {
- [nativeView performSelectorOnMainThread:@selector(setNeedsGLDisplay)
- withObject:nil
- waitUntilDone:NO];
- }
-
- void beforeRender() override
- {
- // no-op
- }
-
- void afterRender() override
- {
- // no-op
- }
-
- private:
- __weak MGLMapView *nativeView = nullptr;
- const float scaleFactor;
+private:
+ __weak MGLMapView *nativeView = nullptr;
+ const float scaleFactor;
};
@end
@@ -4188,7 +5016,7 @@ void MGLPrepareCustomStyleLayer(void *context)
}
}
-void MGLDrawCustomStyleLayer(void *context, const mbgl::CustomLayerRenderParameters &params)
+void MGLDrawCustomStyleLayer(void *context, const mbgl::style::CustomLayerRenderParameters &params)
{
CGSize size = CGSizeMake(params.width, params.height);
CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(params.latitude, params.longitude);
@@ -4220,14 +5048,14 @@ void MGLFinishCustomStyleLayer(void *context)
{
NSAssert(identifier, @"Style layer needs an identifier");
MGLCustomStyleLayerHandlers *context = new MGLCustomStyleLayerHandlers(preparation, drawing, completion);
- _mbglMap->addCustomLayer(identifier.UTF8String, MGLPrepareCustomStyleLayer,
- MGLDrawCustomStyleLayer, MGLFinishCustomStyleLayer,
- context, otherIdentifier.UTF8String);
+ _mbglMap->addLayer(std::make_unique<mbgl::style::CustomLayer>(identifier.UTF8String, MGLPrepareCustomStyleLayer,
+ MGLDrawCustomStyleLayer, MGLFinishCustomStyleLayer, context),
+ otherIdentifier ? mbgl::optional<std::string>(otherIdentifier.UTF8String) : mbgl::optional<std::string>());
}
- (void)removeCustomStyleLayerWithIdentifier:(NSString *)identifier
{
- _mbglMap->removeCustomLayer(identifier.UTF8String);
+ _mbglMap->removeLayer(identifier.UTF8String);
}
- (void)setCustomStyleLayersNeedDisplay
diff --git a/platform/ios/src/MGLMapViewDelegate.h b/platform/ios/src/MGLMapViewDelegate.h
new file mode 100644
index 0000000000..39eb43d4ca
--- /dev/null
+++ b/platform/ios/src/MGLMapViewDelegate.h
@@ -0,0 +1,284 @@
+#import <UIKit/UIKit.h>
+
+#import "MGLTypes.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@class MGLMapView;
+
+/** The MGLMapViewDelegate protocol defines a set of optional methods that you can use to receive map-related update messages. Because many map operations require the `MGLMapView` class to load data asynchronously, the map view calls these methods to notify your application when specific operations complete. The map view also uses these methods to request annotation marker symbology and to manage interactions with those markers. */
+@protocol MGLMapViewDelegate <NSObject>
+
+@optional
+
+#pragma mark Responding to Map Position Changes
+
+/**
+ Tells the delegate that the region displayed by the map view is about to change.
+
+ This method is called whenever the currently displayed map region will start changing.
+
+ @param mapView The map view whose visible region will change.
+ @param animated Whether the change will cause an animated effect on the map.
+ */
+- (void)mapView:(MGLMapView *)mapView regionWillChangeAnimated:(BOOL)animated;
+
+/**
+ Tells the delegate that the region displayed by the map view is changing.
+
+ This method is called whenever the currently displayed map region changes. During movement, this method may be called many times to report updates to the map position. Therefore, your implementation of this method should be as lightweight as possible to avoid affecting performance.
+
+ @param mapView The map view whose visible region is changing.
+ */
+- (void)mapViewRegionIsChanging:(MGLMapView *)mapView;
+
+/**
+ Tells the delegate that the region displayed by the map view just changed.
+
+ This method is called whenever the currently displayed map region has finished changing.
+
+ @param mapView The map view whose visible region changed.
+ @param animated Whether the change caused an animated effect on the map.
+ */
+- (void)mapView:(MGLMapView *)mapView regionDidChangeAnimated:(BOOL)animated;
+
+#pragma mark Loading the Map
+
+/**
+ Tells the delegate that the map view will begin to load.
+
+ This method is called whenever the map view starts loading, including when a new style has been set and the map must reload.
+
+ @param mapView The map view that is starting to load.
+ */
+- (void)mapViewWillStartLoadingMap:(MGLMapView *)mapView;
+
+/**
+ Tells the delegate that the map view has finished loading.
+
+ This method is called whenever the map view finishes loading, either after the initial load or after a style change has forced a reload.
+
+ @param mapView The map view that has finished loading.
+ */
+- (void)mapViewDidFinishLoadingMap:(MGLMapView *)mapView;
+
+// TODO
+- (void)mapViewDidFailLoadingMap:(MGLMapView *)mapView withError:(NSError *)error;
+
+// TODO
+- (void)mapViewWillStartRenderingMap:(MGLMapView *)mapView;
+
+// TODO
+- (void)mapViewDidFinishRenderingMap:(MGLMapView *)mapView fullyRendered:(BOOL)fullyRendered;
+
+// TODO
+- (void)mapViewWillStartRenderingFrame:(MGLMapView *)mapView;
+
+// TODO
+- (void)mapViewDidFinishRenderingFrame:(MGLMapView *)mapView fullyRendered:(BOOL)fullyRendered;
+
+#pragma mark Tracking User Location
+
+/**
+ Tells the delegate that the map view will begin tracking the user's location.
+
+ This method is called when the value of the `showsUserLocation` property changes to `YES`.
+
+ @param mapView The map view that is tracking the user's location.
+ */
+- (void)mapViewWillStartLocatingUser:(MGLMapView *)mapView;
+
+/**
+ Tells the delegate that the map view has stopped tracking the user's location.
+
+ This method is called when the value of the `showsUserLocation` property changes to `NO`.
+
+ @param mapView The map view that is tracking the user's location.
+ */
+- (void)mapViewDidStopLocatingUser:(MGLMapView *)mapView;
+
+/**
+ Tells the delegate that the location of the user was updated.
+
+ While the `showsUserLocation` property is set to `YES`, this method is called whenever a new location update is received by the map view. This method is also called if the map view's user tracking mode is set to `MGLUserTrackingModeFollowWithHeading` and the heading changes, or if it is set to `MGLUserTrackingModeFollowWithCourse` and the course changes.
+
+ This method is not called if the application is currently running in the background. If you want to receive location updates while running in the background, you must use the Core Location framework.
+
+ @param mapView The map view that is tracking the user's location.
+ @param userLocation The location object representing the user's latest location. This property may be `nil`.
+ */
+- (void)mapView:(MGLMapView *)mapView didUpdateUserLocation:(nullable MGLUserLocation *)userLocation;
+
+/**
+ Tells the delegate that an attempt to locate the user's position failed.
+
+ @param mapView The map view that is tracking the user's location.
+ @param error An error object containing the reason why location tracking failed.
+ */
+- (void)mapView:(MGLMapView *)mapView didFailToLocateUserWithError:(NSError *)error;
+
+/**
+ Tells the delegate that the map view's user tracking mode has changed.
+
+ This method is called after the map view asynchronously changes to reflect the new user tracking mode, for example by beginning to zoom or rotate.
+
+ @param mapView The map view that changed its tracking mode.
+ @param mode The new tracking mode.
+ @param animated Whether the change caused an animated effect on the map.
+ */
+- (void)mapView:(MGLMapView *)mapView didChangeUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated;
+
+#pragma mark Managing the Display of Annotations
+
+/**
+ Returns a view object to use for the marker for the specified point annotation object.
+
+ @param mapView The map view that requested the annotation view.
+ @param annotation The object representing the annotation that is about to be displayed.
+ @return The view object to display for the specified annotation or `nil` if you want to display the default marker image.
+ */
+- (nullable MGLAnnotationView *)mapView:(MGLMapView *)mapView viewForAnnotation:(id <MGLAnnotation>)annotation;
+
+/**
+ Returns an image object to use for the marker for the specified point annotation object.
+
+ @param mapView The map view that requested the annotation image.
+ @param annotation The object representing the annotation that is about to be displayed.
+ @return The image object to display for the specified annotation or `nil` if you want to display the default marker image.
+ */
+- (nullable MGLAnnotationImage *)mapView:(MGLMapView *)mapView imageForAnnotation:(id <MGLAnnotation>)annotation;
+
+/**
+ Returns the alpha value to use when rendering a shape annotation. Defaults to `1.0`.
+
+ @param mapView The map view rendering the shape annotation.
+ @param annotation The annotation being rendered.
+ @return An alpha value between `0` and `1.0`.
+ */
+- (CGFloat)mapView:(MGLMapView *)mapView alphaForShapeAnnotation:(MGLShape *)annotation;
+
+/**
+ Returns the stroke color to use when rendering a shape annotation. Defaults to the map view’s tint color.
+
+ @param mapView The map view rendering the shape annotation.
+ @param annotation The annotation being rendered.
+ @return A color to use for the shape outline.
+ */
+- (UIColor *)mapView:(MGLMapView *)mapView strokeColorForShapeAnnotation:(MGLShape *)annotation;
+
+/**
+ Returns the fill color to use when rendering a polygon annotation. Defaults to the map view’s tint color.
+
+ @param mapView The map view rendering the polygon annotation.
+ @param annotation The annotation being rendered.
+ @return A color to use for the polygon interior.
+ */
+- (UIColor *)mapView:(MGLMapView *)mapView fillColorForPolygonAnnotation:(MGLPolygon *)annotation;
+
+/**
+ Returns the line width to use when rendering a polyline annotation. Defaults to `3.0`.
+
+ @param mapView The map view rendering the polygon annotation.
+ @param annotation The annotation being rendered.
+ @return A line width for the polyline.
+ */
+- (CGFloat)mapView:(MGLMapView *)mapView lineWidthForPolylineAnnotation:(MGLPolyline *)annotation;
+
+/**
+ Returns a Boolean value indicating whether the annotation is able to display extra information in a callout bubble.
+
+ If the value returned is `YES`, a standard callout bubble is shown when the user taps a selected annotation. The callout uses the title and subtitle text from the associated annotation object. If there is no title text, though, the annotation will not show a callout. The callout also displays any custom callout views returned by the delegate for the left and right callout accessory views.
+
+ If the value returned is `NO`, the value of the title and subtitle strings are ignored.
+
+ @param mapView The map view that requested the annotation callout ability.
+ @param annotation The object representing the annotation.
+ @return A Boolean indicating whether the annotation should show a callout.
+ */
+- (BOOL)mapView:(MGLMapView *)mapView annotationCanShowCallout:(id <MGLAnnotation>)annotation;
+
+/**
+ Returns a callout view to display for the specified annotation.
+
+ If this method is present in the delegate, it must return a new instance of a view dedicated to display the callout bubble. It will be configured by the map view. If this method is not present, or if it returns `nil`, a standard, two-line, bubble-like callout view is displayed by default.
+
+ @param mapView The map view that requested the callout view.
+ @param annotation The object representing the annotation.
+ @return A view conforming to the `MGLCalloutView` protocol, or `nil` to use the default callout view.
+ */
+- (nullable UIView <MGLCalloutView> *)mapView:(MGLMapView *)mapView calloutViewForAnnotation:(id <MGLAnnotation>)annotation;
+
+/**
+ Returns the view to display on the left side of the standard callout bubble.
+
+ The default value is treated as if `nil`. The left callout view is typically used to display information about the annotation or to link to custom information provided by your application.
+
+ If the view you specify is also a descendant of the `UIControl` class, you can use the map view's delegate to receive notifications when your control is tapped. If it does not descend from `UIControl`, your view is responsible for handling any touch events within its bounds.
+
+ @param mapView The map view presenting the annotation callout.
+ @param annotation The object representing the annotation with the callout.
+ @return The accessory view to display.
+ */
+- (nullable UIView *)mapView:(MGLMapView *)mapView leftCalloutAccessoryViewForAnnotation:(id <MGLAnnotation>)annotation;
+
+/**
+ Returns the view to display on the right side of the standard callout bubble.
+
+ The default value is treated is if `nil`. The right callout view is typically used to link to more detailed information about the annotation. A common view to specify for this property is `UIButton` object whose type is set to `UIButtonTypeDetailDisclosure`.
+
+ If the view you specify is also a descendant of the `UIControl` class, you can use the map view's delegate to receive notifications when your control is tapped. If it does not descend from `UIControl`, your view is responsible for handling any touch events within its bounds.
+
+ @param mapView The map view presenting the annotation callout.
+ @param annotation The object representing the annotation with the callout.
+ @return The accessory view to display.
+ */
+- (nullable UIView *)mapView:(MGLMapView *)mapView rightCalloutAccessoryViewForAnnotation:(id <MGLAnnotation>)annotation;
+
+#pragma mark Managing Annotations
+
+/**
+ Tells the delegate that the user tapped one of the annotation's accessory buttons.
+
+ Accessory views contain custom content and are positioned on either side of the annotation title text. If a view you specify is a descendant of the `UIControl` class, the map view calls this method as a convenience whenever the user taps your view. You can use this method to respond to taps and perform any actions associated with that control. For example, if your control displayed additional information about the annotation, you could use this method to present a modal panel with that information.
+
+ If your custom accessory views are not descendants of the `UIControl` class, the map view does not call this method.
+
+ @param mapView The map view containing the specified annotation.
+ @param annotation The annotation whose button was tapped.
+ @param control The control that was tapped.
+ */
+- (void)mapView:(MGLMapView *)mapView annotation:(id <MGLAnnotation>)annotation calloutAccessoryControlTapped:(UIControl *)control;
+
+/**
+ Tells the delegate that the user tapped on an annotation's callout view.
+
+ @param mapView The map view containing the specified annotation.
+ @param annotation The annotation whose callout was tapped.
+ */
+- (void)mapView:(MGLMapView *)mapView tapOnCalloutForAnnotation:(id <MGLAnnotation>)annotation;
+
+#pragma mark Selecting Annotations
+
+/**
+ Tells the delegate that one of its annotations was selected.
+
+ You can use this method to track changes in the selection state of annotations.
+
+ @param mapView The map view containing the annotation.
+ @param annotation The annotation that was selected.
+ */
+- (void)mapView:(MGLMapView *)mapView didSelectAnnotation:(id <MGLAnnotation>)annotation;
+
+/**
+ Tells the delegate that one of its annotations was deselected.
+
+ You can use this method to track changes in the selection state of annotations.
+
+ @param mapView The map view containing the annotation.
+ @param annotation The annotation that was deselected.
+ */
+- (void)mapView:(MGLMapView *)mapView didDeselectAnnotation:(id <MGLAnnotation>)annotation;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/src/MGLMapView_Internal.h b/platform/ios/src/MGLMapView_Internal.h
new file mode 100644
index 0000000000..6225e11749
--- /dev/null
+++ b/platform/ios/src/MGLMapView_Internal.h
@@ -0,0 +1,17 @@
+#import <Mapbox/Mapbox.h>
+
+/// Minimum size of an annotation’s accessibility element.
+extern const CGSize MGLAnnotationAccessibilityElementMinimumSize;
+
+@interface MGLMapView (Internal)
+
+/** Triggers another render pass even when it is not necessary. */
+- (void)setNeedsGLDisplay;
+
+/** Returns whether the map view is currently loading or processing any assets required to render the map */
+- (BOOL)isFullyLoaded;
+
+/** Empties the in-memory tile cache. */
+- (void)didReceiveMemoryWarning;
+
+@end
diff --git a/platform/ios/src/MGLMapboxEvents.m b/platform/ios/src/MGLMapboxEvents.m
index 2dc7fee280..5ddf4e2b57 100644
--- a/platform/ios/src/MGLMapboxEvents.m
+++ b/platform/ios/src/MGLMapboxEvents.m
@@ -123,7 +123,7 @@ const NSTimeInterval MGLFlushInterval = 180;
@property (nonatomic) MGLLocationManager *locationManager;
@property (nonatomic) NSTimer *timer;
@property (nonatomic) NSDate *instanceIDRotationDate;
-@property (nonatomic) NSDate *turnstileSendDate;
+@property (nonatomic) NSDate *nextTurnstileSendDate;
@end
@@ -136,7 +136,7 @@ const NSTimeInterval MGLFlushInterval = 180;
NSBundle *bundle = [NSBundle mainBundle];
NSNumber *accountTypeNumber = [bundle objectForInfoDictionaryKey:@"MGLMapboxAccountType"];
[[NSUserDefaults standardUserDefaults] registerDefaults:@{
- @"MGLMapboxAccountType": accountTypeNumber ? accountTypeNumber : @0,
+ @"MGLMapboxAccountType": accountTypeNumber ?: @0,
@"MGLMapboxMetricsEnabled": @YES,
@"MGLMapboxMetricsDebugLoggingEnabled": @NO,
}];
@@ -144,8 +144,12 @@ const NSTimeInterval MGLFlushInterval = 180;
}
+ (BOOL)isEnabled {
+#if TARGET_OS_SIMULATOR
+ return NO;
+#else
return ([[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsEnabled"] &&
[[NSUserDefaults standardUserDefaults] integerForKey:@"MGLMapboxAccountType"] == 0);
+#endif
}
- (BOOL)debugLoggingEnabled {
@@ -311,7 +315,7 @@ const NSTimeInterval MGLFlushInterval = 180;
}
- (void)pushTurnstileEvent {
- if (self.turnstileSendDate && [[NSDate date] timeIntervalSinceDate:self.turnstileSendDate] < 0) {
+ if (self.nextTurnstileSendDate && [[NSDate date] timeIntervalSinceDate:self.nextTurnstileSendDate] < 0) {
return;
}
@@ -338,11 +342,25 @@ const NSTimeInterval MGLFlushInterval = 180;
return;
}
[strongSelf writeEventToLocalDebugLog:turnstileEventAttributes];
- NSTimeInterval twentyFourHourTimeInterval = 24 * 3600;
- strongSelf.turnstileSendDate = [[NSDate date] dateByAddingTimeInterval:twentyFourHourTimeInterval];
+ [strongSelf updateNextTurnstileSendDate];
}];
}
+- (void)updateNextTurnstileSendDate {
+ // Find the time a day from now (sometime tomorrow)
+ NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
+ NSDateComponents *dayComponent = [[NSDateComponents alloc] init];
+ dayComponent.day = 1;
+ NSDate *sometimeTomorrow = [calendar dateByAddingComponents:dayComponent toDate:[NSDate date] options:0];
+
+ // Find the start of tomorrow and use that as the next turnstile send date. The effect of this is that
+ // turnstile events can be sent as much as once per calendar day and always at the start of a session
+ // when a map load happens.
+ NSDate *startOfTomorrow = nil;
+ [calendar rangeOfUnit:NSCalendarUnitDay startDate:&startOfTomorrow interval:nil forDate:sometimeTomorrow];
+ self.nextTurnstileSendDate = startOfTomorrow;
+}
+
+ (void)pushEvent:(NSString *)event withAttributes:(MGLMapboxEventAttributes *)attributeDictionary {
[[MGLMapboxEvents sharedManager] pushEvent:event withAttributes:attributeDictionary];
}
@@ -356,7 +374,7 @@ const NSTimeInterval MGLFlushInterval = 180;
[self pushTurnstileEvent];
}
- if ([self isPaused]) {
+ if (self.paused) {
return;
}
@@ -446,7 +464,7 @@ const NSTimeInterval MGLFlushInterval = 180;
// Called implicitly from public use of +flush.
//
- (void)postEvents:(NS_ARRAY_OF(MGLMapboxEventAttributes *) *)events {
- if ([self isPaused]) {
+ if (self.paused) {
return;
}
diff --git a/platform/ios/src/MGLUserLocation.h b/platform/ios/src/MGLUserLocation.h
new file mode 100644
index 0000000000..6160413510
--- /dev/null
+++ b/platform/ios/src/MGLUserLocation.h
@@ -0,0 +1,42 @@
+#import <Foundation/Foundation.h>
+#import <CoreLocation/CoreLocation.h>
+
+#import "MGLAnnotation.h"
+
+#import "MGLTypes.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+/** The MGLUserLocation class defines a specific type of annotation that identifies the user’s current location. You do not create instances of this class directly. Instead, you retrieve an existing MGLUserLocation object from the userLocation property of the map view displayed in your application. */
+@interface MGLUserLocation : NSObject <MGLAnnotation>
+
+#pragma mark Determining the User’s Position
+
+/**
+ The current location of the device. (read-only)
+
+ This property contains `nil` if the map view is not currently showing the user location or if the user’s location has not yet been determined.
+ */
+@property (nonatomic, readonly, nullable) CLLocation *location;
+
+/** A Boolean value indicating whether the user’s location is currently being updated. (read-only) */
+@property (nonatomic, readonly, getter=isUpdating) BOOL updating;
+
+/**
+ The heading of the user location. (read-only)
+
+ This property is `nil` if the user location tracking mode is not `MGLUserTrackingModeFollowWithHeading`.
+ */
+@property (nonatomic, readonly, nullable) CLHeading *heading;
+
+#pragma mark Accessing the User Annotation Text
+
+/** The title to display for the user location annotation. */
+@property (nonatomic, copy) NSString *title;
+
+/** The subtitle to display for the user location annotation. */
+@property (nonatomic, copy, nullable) NSString *subtitle;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/src/MGLUserLocation.m b/platform/ios/src/MGLUserLocation.m
index 0ee90a3c2c..a568ec8be1 100644
--- a/platform/ios/src/MGLUserLocation.m
+++ b/platform/ios/src/MGLUserLocation.m
@@ -1,6 +1,7 @@
#import "MGLUserLocation_Private.h"
#import "MGLMapView.h"
+#import "NSBundle+MGLAdditions.h"
NS_ASSUME_NONNULL_BEGIN
@@ -68,7 +69,7 @@ NS_ASSUME_NONNULL_END
- (NSString *)title
{
- return (_title ? _title : @"You Are Here");
+ return _title ?: NSLocalizedStringWithDefaultValue(@"USER_DOT_TITLE", nil, nil, @"You Are Here", @"Default user location annotation title");
}
- (NSString *)description
diff --git a/platform/ios/src/MGLUserLocationAnnotationView.m b/platform/ios/src/MGLUserLocationAnnotationView.m
index a7ca352bc0..c514026e42 100644
--- a/platform/ios/src/MGLUserLocationAnnotationView.m
+++ b/platform/ios/src/MGLUserLocationAnnotationView.m
@@ -4,6 +4,8 @@
#import "MGLUserLocation_Private.h"
#import "MGLAnnotation.h"
#import "MGLMapView.h"
+#import "MGLCoordinateFormatter.h"
+#import "NSBundle+MGLAdditions.h"
const CGFloat MGLUserLocationAnnotationDotSize = 22.0;
const CGFloat MGLUserLocationAnnotationHaloSize = 115.0;
@@ -36,6 +38,8 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck
CLLocationAccuracy _oldHorizontalAccuracy;
double _oldZoom;
double _oldPitch;
+
+ MGLCoordinateFormatter *_accessibilityCoordinateFormatter;
}
- (instancetype)initWithFrame:(CGRect)frame
@@ -53,7 +57,10 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck
self.annotation = [[MGLUserLocation alloc] initWithMapView:mapView];
_mapView = mapView;
[self setupLayers];
- self.accessibilityLabel = @"User location";
+ self.accessibilityTraits = UIAccessibilityTraitButton | UIAccessibilityTraitAdjustable | UIAccessibilityTraitUpdatesFrequently;
+
+ _accessibilityCoordinateFormatter = [[MGLCoordinateFormatter alloc] init];
+ _accessibilityCoordinateFormatter.unitStyle = NSFormattingUnitStyleLong;
}
return self;
}
@@ -64,6 +71,62 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck
return [self initInMapView:mapView];
}
+- (BOOL)isAccessibilityElement
+{
+ return !self.hidden;
+}
+
+- (NSString *)accessibilityLabel
+{
+ return self.annotation.title;
+}
+
+- (NSString *)accessibilityValue
+{
+ if (self.annotation.subtitle)
+ {
+ return self.annotation.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);
+ }
+}
+
- (void)setTintColor:(UIColor *)tintColor
{
if (_puckModeActivated)
@@ -128,6 +191,22 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck
}
}
+- (void)updateFrameWithSize:(CGFloat)size
+{
+ CGSize newSize = CGSizeMake(size, size);
+ if (CGSizeEqualToSize(self.frame.size, newSize))
+ {
+ return;
+ }
+
+ // Update frame size, keeping the existing center point.
+ CGPoint oldCenter = self.center;
+ CGRect newFrame = self.frame;
+ newFrame.size = newSize;
+ [self setFrame:newFrame];
+ [self setCenter:oldCenter];
+}
+
- (void)drawPuck
{
if ( ! _puckModeActivated)
@@ -140,6 +219,8 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck
_haloLayer = nil;
_dotBorderLayer = nil;
_dotLayer = nil;
+
+ [self updateFrameWithSize:MGLUserLocationAnnotationPuckSize];
}
// background dot (white with black shadow)
@@ -215,6 +296,8 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck
_puckDot = nil;
_puckArrow = nil;
+
+ [self updateFrameWithSize:MGLUserLocationAnnotationDotSize];
}
BOOL showHeadingIndicator = _mapView.userTrackingMode == MGLUserTrackingModeFollowWithHeading;
@@ -471,7 +554,7 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck
CGContextDrawRadialGradient(context, gradient,
centerPoint, 0.0,
centerPoint, haloRadius,
- nil);
+ kNilOptions);
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
diff --git a/platform/ios/src/Mapbox.h b/platform/ios/src/Mapbox.h
new file mode 100644
index 0000000000..bc22a5f955
--- /dev/null
+++ b/platform/ios/src/Mapbox.h
@@ -0,0 +1,38 @@
+#import <Foundation/Foundation.h>
+
+/// Project version number for Mapbox.
+FOUNDATION_EXPORT double MapboxVersionNumber;
+
+/// Project version string for Mapbox.
+FOUNDATION_EXPORT const unsigned char MapboxVersionString[];
+
+#import "MGLAnnotationView.h"
+#import "MGLAccountManager.h"
+#import "MGLAnnotation.h"
+#import "MGLAnnotationImage.h"
+#import "MGLCalloutView.h"
+#import "MGLClockDirectionFormatter.h"
+#import "MGLCompassDirectionFormatter.h"
+#import "MGLCoordinateFormatter.h"
+#import "MGLFeature.h"
+#import "MGLGeometry.h"
+#import "MGLMapCamera.h"
+#import "MGLMapView.h"
+#import "MGLMapView+IBAdditions.h"
+#import "MGLMapView+MGLCustomStyleLayerAdditions.h"
+#import "MGLMapViewDelegate.h"
+#import "MGLMultiPoint.h"
+#import "MGLOfflinePack.h"
+#import "MGLOfflineRegion.h"
+#import "MGLOfflineStorage.h"
+#import "MGLOverlay.h"
+#import "MGLPointAnnotation.h"
+#import "MGLPolygon.h"
+#import "MGLPolyline.h"
+#import "MGLShape.h"
+#import "MGLShapeCollection.h"
+#import "MGLStyle.h"
+#import "MGLTilePyramidOfflineRegion.h"
+#import "MGLTypes.h"
+#import "MGLUserLocation.h"
+#import "NSValue+MGLAdditions.h"