Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Replace styleID property with styleURL__ inspectable #2632

Merged
merged 2 commits into from
Oct 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## iOS master

- The `styleID` property has been removed from MGLMapView. Instead, set the `styleURL` property to an NSURL in the form `mapbox://styles/STYLE_ID`. If you previously set the style ID in Interface Builder’s Attributes inspector, delete the `styleID` entry from the User Defined Runtime Attributes section of the Identity inspector, then set the new “Style URL” inspectable to a value in the form `mapbox://styles/STYLE_ID`. ([#2632](https://github.com/mapbox/mapbox-gl-native/pull/2632)
- The SDK now builds with Bitcode enabled. ([#2332](https://github.com/mapbox/mapbox-gl-native/issues/2332))
- The double-tap-drag gesture for zooming in and out is now consistent with the Google Maps SDK. ([#2153](https://github.com/mapbox/mapbox-gl-native/pull/2153))
- A new `MGLAnnotationImage.enabled` property allows you to disable touch events on individual annotations. ([#2501](https://github.com/mapbox/mapbox-gl-native/pull/2501))
Expand Down
2 changes: 0 additions & 2 deletions include/mbgl/ios/MGLAccountManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ NS_ASSUME_NONNULL_BEGIN

/** @name Providing User Metrics Opt-Out */

+ (void)setMapboxMetricsEnabledSettingShownInApp:(BOOL)showsOptOut __attribute__((unavailable("Set MGLMapboxMetricsEnabledSettingShownInApp in Info.plist.")));

/** Whether in-app user metrics opt-out is configured. If set to the default value of `NO`, a user opt-out preference is expected in a `Settings.bundle` that shows in the application's section within the system Settings app. */
+ (BOOL)mapboxMetricsEnabledSettingShownInApp;

Expand Down
6 changes: 5 additions & 1 deletion include/mbgl/ios/MGLMapView+IBAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ NS_ASSUME_NONNULL_BEGIN
// inspectables declared in MGLMapView.h are always sorted before those in
// MGLMapView+IBAdditions.h, due to ASCII sort order.

@property (nonatomic, nullable) IBInspectable NSString *styleID;
// 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__;

// Convenience properties related to the initial viewport. These properties
// are not meant to be used outside of Interface Builder. latitude and longitude
Expand Down
20 changes: 1 addition & 19 deletions include/mbgl/ios/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,12 @@ IB_DESIGNABLE
* @param frame The frame for the view, measured in points.
* @return An initialized map view. */
- (instancetype)initWithFrame:(CGRect)frame;
- (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken __attribute__((unavailable("Use -initWithFrame:. Set MGLMapboxAccessToken in the Info.plist or call +[MGLAccountManager setAccessToken:].")));

/** 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 The map style URL to use. Can be either an HTTP/HTTPS URL or a Mapbox map ID style URL (`mapbox://styles/<user>/<style>`). Specify `nil` for the default style.
* @return An initialized map view. */
- (instancetype)initWithFrame:(CGRect)frame styleURL:(nullable NSURL *)styleURL;
- (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken styleURL:(nullable NSURL *)styleURL __attribute__((unavailable("Use -initWithFrame:styleURL:. Set MGLMapboxAccessToken in the Info.plist or call +[MGLAccountManager setAccessToken:].")));

#pragma mark - Authorizing Access

/** @name Authorizing Access */

@property (nonatomic, nullable) NSString *accessToken __attribute__((unavailable("Use +[MGLAccountManager accessToken] and +[MGLAccountManager setAccessToken:].")));

#pragma mark - Managing Constraints

/** @name Managing Constraints */

#pragma mark - Accessing Map Properties

Expand Down Expand Up @@ -227,13 +215,7 @@ IB_DESIGNABLE

/** @name Styling the Map */

/** Mapbox ID of the style currently displayed in the receiver, or `nil` if the style does not have an ID.
*
* The style may lack an ID if it is located at an HTTP, HTTPS, or local file URL. Use `styleURL` to get the URL in these cases.
*
* To display the default style, set this property to `nil`. */
@property (nonatomic, nullable) NSString *styleID;
@property (nonatomic, nullable) NSString *mapID __attribute__((unavailable("Use styleID.")));
@property (nonatomic, nullable) NSString *styleID __attribute__((unavailable("Set styleURL to an NSURL of the form <mapbox://styles/STYLE_ID>, where STYLE_ID would have been the value of this property.")));

/** URLs of the styles bundled with the library. */
@property (nonatomic, readonly) NS_ARRAY_OF(NSURL *) *bundledStyleURLs;
Expand Down
69 changes: 28 additions & 41 deletions platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,9 @@ - (instancetype)initWithCoder:(nonnull NSCoder *)decoder
return self;
}

- (nullable NSString *)accessToken
{
[NSException raise:@"Method unavailable" format:
@"%s has been removed. "
@"Use +[MGLAccountManager accessToken] or get MGLMapboxAccessToken from the Info.plist.",
__PRETTY_FUNCTION__];
return nil;
}

- (void)setAccessToken:(nullable NSString *)accessToken
{
[NSException raise:@"Method unavailable" format:
@"%s has been replaced by +[MGLAccountManager setAccessToken:].\n\n"
@"If you previously set this access token in a storyboard inspectable, select the MGLMapView in Interface Builder and delete the “accessToken” entry from the User Defined Runtime Attributes section of the Identity inspector. "
@"Then go to the Info.plist file and set MGLMapboxAccessToken to “%@”.",
__PRETTY_FUNCTION__, accessToken];
}

+ (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingStyleURL
{
return [NSSet setWithObject:@"styleID"];
return [NSSet setWithObjects:@"styleURL__", nil];
}

- (nonnull NSURL *)styleURL
Expand Down Expand Up @@ -2012,37 +1994,21 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
return [NSArray arrayWithArray:_bundledStyleURLs];
}

+ (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingStyleID
{
return [NSSet setWithObject:@"styleURL"];
}

- (nullable NSString *)styleID
{
NSURL *styleURL = self.styleURL;
return [styleURL.scheme isEqualToString:@"mapbox"] ? styleURL.host.mgl_stringOrNilIfEmpty : nil;
}

- (void)setStyleID:(nullable NSString *)styleID
{
self.styleURL = styleID ? [NSURL URLWithString:[NSString stringWithFormat:@"mapbox://%@", styleID]] : nil;
}

- (nullable NSString *)mapID
{
[NSException raise:@"Method unavailable" format:
@"%s has been renamed -[MGLMapView styleID].",
@"%s has been replaced by -[MGLMapView styleURL].",
__PRETTY_FUNCTION__];
return nil;
}

- (void)setMapID:(nullable NSString *)mapID
- (void)setStyleID:(nullable NSString *)styleID
{
[NSException raise:@"Method unavailable" format:
@"%s has been renamed -[MGLMapView setStyleID:].\n\n"
@"If you previously set this map ID in a storyboard inspectable, select the MGLMapView in Interface Builder and delete the “mapID” entry from the User Defined Runtime Attributes section of the Identity inspector. "
@"Then go to the Attributes inspector and enter “%@” into the “Style ID” field.",
__PRETTY_FUNCTION__, mapID];
@"%s has been replaced by -[MGLMapView setStyleURL:].\n\n"
@"If you previously set this style ID in a storyboard inspectable, select the MGLMapView in Interface Builder and delete the “styleID” entry from the User Defined Runtime Attributes section of the Identity inspector. "
@"Then go to the Attributes inspector and enter “mapbox://styles/%@” into the “Style URL” field.",
__PRETTY_FUNCTION__, styleID];
}

- (NS_ARRAY_OF(NSString *) *)styleClasses
Expand Down Expand Up @@ -3326,6 +3292,27 @@ void afterRender() override

@implementation MGLMapView (IBAdditions)

+ (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingStyleURL__
{
return [NSSet setWithObject:@"styleURL"];
}

- (nullable NSString *)styleURL__
{
return self.styleURL.absoluteString;
}

- (void)setStyleURL__:(nullable NSString *)URLString
{
NSURL *url = URLString.length ? [NSURL URLWithString:URLString] : nil;
if (URLString.length && !url)
{
[NSException raise:@"Invalid style URL" format:
@"“%@” is not a valid style URL.", URLString];
}
self.styleURL = url;
}

+ (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingLatitude
{
return [NSSet setWithObjects:@"centerCoordinate", @"camera", nil];
Expand Down