diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2015-04-02 10:04:19 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2015-04-03 12:34:36 -0700 |
commit | 836de8bc1c9ebbe86e0b20cf11291ef449faccfd (patch) | |
tree | d66e36ccfc12dca66f93e48bc72947f915a3acfb | |
parent | da13225a816ca40b8be209639c8ad0dc67681089 (diff) | |
download | qtlocation-mapboxgl-836de8bc1c9ebbe86e0b20cf11291ef449faccfd.tar.gz |
Made lat/lon/zoom inspectable
Declared these IB-specific inspectables in a separate category that developers are not expected to import. Currently these inspectables are order-dependent due to #1181.
Ref #929
-rw-r--r-- | gyp/platform-ios.gypi | 1 | ||||
-rw-r--r-- | include/mbgl/ios/MGLMapView+IBAdditions.h | 29 | ||||
-rw-r--r-- | include/mbgl/ios/MGLMapView.h | 14 | ||||
-rw-r--r-- | platform/ios/MGLMapView.mm | 66 |
4 files changed, 103 insertions, 7 deletions
diff --git a/gyp/platform-ios.gypi b/gyp/platform-ios.gypi index 998a0d1b8f..f707431182 100644 --- a/gyp/platform-ios.gypi +++ b/gyp/platform-ios.gypi @@ -20,6 +20,7 @@ '../include/mbgl/ios/MGLMapboxEvents.h', '../platform/ios/MGLMapboxEvents.m', '../include/mbgl/ios/MGLMapView.h', + '../include/mbgl/ios/MGLMapView+IBAdditions.h', '../platform/ios/MGLMapView.mm', '../include/mbgl/ios/MGLAnnotation.h', '../include/mbgl/ios/MGLUserLocation.h', diff --git a/include/mbgl/ios/MGLMapView+IBAdditions.h b/include/mbgl/ios/MGLMapView+IBAdditions.h new file mode 100644 index 0000000000..4661e549e5 --- /dev/null +++ b/include/mbgl/ios/MGLMapView+IBAdditions.h @@ -0,0 +1,29 @@ +#import "MGLMapView.h" + +@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. + +@property (nonatomic) IBInspectable NSString *accessToken; +@property (nonatomic) IBInspectable NSString *mapID; + +// Some 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. + +/// Initial latitude at which the receiver is centered. +@property (nonatomic) IBInspectable double latitude; + +/// Initial longitude at which the receiver is centered. +@property (nonatomic) IBInspectable double longitude; + +/// Initial zoom level of the receiver. +@property (nonatomic) IBInspectable double zoomLevel; + +@end diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h index 4139ef51cc..632175a308 100644 --- a/include/mbgl/ios/MGLMapView.h +++ b/include/mbgl/ios/MGLMapView.h @@ -39,9 +39,8 @@ IB_DESIGNABLE /** @name Authorizing Access */ -/** Sets a Mapbox API access token for the map view. -* @param accessToken A Mapbox API token. */ -@property (nonatomic) IBInspectable NSString *accessToken; +/** Mapbox API access token for the map view. */ +@property (nonatomic) NSString *accessToken; #pragma mark - Managing Constraints @@ -166,10 +165,11 @@ IB_DESIGNABLE /** @name Styling the Map */ /** Mapbox map ID of the style currently displayed in the receiver, or `nil` if the style does not have a map ID. - - The style may lack a map ID if it is located at an HTTP, HTTPS, or asset: URL. Use -styleURL to get the URL in these cases. - */ -@property (nonatomic) IBInspectable NSString *mapID; +* +* The style may lack a map 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) NSString *mapID; /** Returns the URLs to the styles bundled with the library. */ - (NSArray *)bundledStyleURLs; diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index b1a2eeadbb..2ad9db6882 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -1,4 +1,5 @@ #import "MGLMapView.h" +#import "MGLMapView+IBAdditions.h" #import <mbgl/platform/log.hpp> #import <mbgl/platform/gl.hpp> @@ -92,6 +93,8 @@ static NSURL *MGLURLForBundledStyleNamed(NSString *styleName) @implementation MGLMapView { BOOL _isTargetingInterfaceBuilder; + CLLocationDegrees _pendingLatitude; + CLLocationDegrees _pendingLongitude; } #pragma mark - Setup & Teardown - @@ -365,6 +368,8 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; // set initial position // mbglMap->setLatLngZoom(mbgl::LatLng(0, 0), mbglMap->getMinZoom()); + _pendingLatitude = NAN; + _pendingLongitude = NAN; // setup change delegate queue // @@ -1126,6 +1131,11 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; #pragma mark - Geography - ++ (NSSet *)keyPathsForValuesAffectingCenterCoordinate +{ + return [NSSet setWithObjects:@"latitude", @"longitude", nil]; +} + - (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated preservingTracking:(BOOL)tracking { self.userTrackingMode = (tracking ? self.userTrackingMode : MGLUserTrackingModeNone); @@ -2388,3 +2398,59 @@ class MBGLView : public mbgl::View }; @end + +@implementation MGLMapView (IBAdditions) + ++ (NSSet *)keyPathsForValuesAffectingLatitude +{ + return [NSSet setWithObject:@"centerCoordinate"]; +} + +- (double)latitude +{ + return self.centerCoordinate.latitude; +} + +- (void)setLatitude:(double)latitude +{ + if ( ! isnan(_pendingLongitude)) + { + self.centerCoordinate = CLLocationCoordinate2DMake(latitude, _pendingLongitude); + _pendingLatitude = NAN; + _pendingLongitude = NAN; + } + else + { + // Not enough info to make a valid center coordinate yet. Stash this + // latitude away until the longitude is set too. + _pendingLatitude = latitude; + } +} + ++ (NSSet *)keyPathsForValuesAffectingLongitude +{ + return [NSSet setWithObject:@"centerCoordinate"]; +} + +- (double)longitude +{ + return self.centerCoordinate.longitude; +} + +- (void)setLongitude:(double)longitude +{ + if ( ! isnan(_pendingLatitude)) + { + self.centerCoordinate = CLLocationCoordinate2DMake(_pendingLatitude, longitude); + _pendingLatitude = NAN; + _pendingLongitude = NAN; + } + else + { + // Not enough info to make a valid center coordinate yet. Stash this + // longitude away until the latitude is set too. + _pendingLongitude = longitude; + } +} + +@end |