summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-04-02 10:04:19 -0700
committerMinh Nguyễn <mxn@1ec5.org>2015-04-03 12:34:36 -0700
commit836de8bc1c9ebbe86e0b20cf11291ef449faccfd (patch)
treed66e36ccfc12dca66f93e48bc72947f915a3acfb /platform
parentda13225a816ca40b8be209639c8ad0dc67681089 (diff)
downloadqtlocation-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
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/MGLMapView.mm66
1 files changed, 66 insertions, 0 deletions
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