[iOS] Replaced styleID property with styleURL__ inspectable

The new styleURL__ inspectable property is carefully named to masquerade as a URL property in Interface Builder, even though IB supports no such thing.

If the user enters an invalid URL into the “Style URL” inspectable, throw an error instead of silently setting the style to the default. This check is not required in -setStyleURL:, which takes a real NSURL.
This commit is contained in:
Minh Nguyễn
2015-10-15 14:14:52 -07:00
committed by Minh Nguyễn
parent 0f866d9db6
commit e3934df8d4
4 changed files with 35 additions and 31 deletions

View File

@@ -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))

View File

@@ -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

View File

@@ -227,13 +227,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;

View File

@@ -192,7 +192,7 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
+ (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingStyleURL
{
return [NSSet setWithObject:@"styleID"];
return [NSSet setWithObjects:@"styleURL__", nil];
}
- (nonnull NSURL *)styleURL
@@ -2012,37 +2012,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
@@ -3326,6 +3310,27 @@ class MBGLView : public mbgl::View
@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];