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

Commit

Permalink
[iOS] Enable developers to change position of ornaments (#13911)
Browse files Browse the repository at this point in the history
* APIs for change position of ornaments

* Use anchors APIs and emove iOS8 layout code

* Add ornaments layout tests
  • Loading branch information
lloydsheng committed Mar 11, 2019
1 parent 5ccc5b7 commit 60ceac5
Show file tree
Hide file tree
Showing 13 changed files with 558 additions and 229 deletions.
4 changes: 4 additions & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Added an MGLMapView.prefetchesTiles property that you can disable if you don’t want to prefetch simplified tiles as a performance optimization. ([#14031](https://github.com/mapbox/mapbox-gl-native/pull/14031))
* Fixed an issue that caused `MGL_FUNCTION` to ignore multiple formatting parameters when passed a `format` function as parameter. ([#14064](https://github.com/mapbox/mapbox-gl-native/pull/14064))

### User interaction

* Added `MGLOrnamentPosition` enum and margins methods to customize MGLMapView's scale bar, compass, logo and attribution position. ([#13911](https://github.com/mapbox/mapbox-gl-native/pull/13911))

## 4.9.0 - February 27, 2019

* Fixed a bug where setting `MGLMapView.userTrackingMode` to `MGLUserTrackingModeFollowWithHeading` or `MGLUserTrackingModeFollowWithCourse` would be ignored if the user’s location was not already available. ([#13849](https://github.com/mapbox/mapbox-gl-native/pull/13849))
Expand Down
5 changes: 5 additions & 0 deletions platform/ios/app/MBXOrnamentsViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <UIKit/UIKit.h>

@interface MBXOrnamentsViewController : UIViewController

@end
94 changes: 94 additions & 0 deletions platform/ios/app/MBXOrnamentsViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#import "MBXOrnamentsViewController.h"

@import Mapbox;

@interface MBXOrnamentsViewController ()<MGLMapViewDelegate>

@property (nonatomic) MGLMapView *mapView;
@property (nonatomic) NSTimer *timer;
@property (nonatomic) NSInteger currentPositionIndex;

@end

@implementation MBXOrnamentsViewController

- (void)setCurrentPositionIndex:(NSInteger)currentPositionIndex {
MGLOrnamentPosition ornamentPositions[5][4] = {
{
MGLOrnamentPositionTopLeft,
MGLOrnamentPositionTopRight,
MGLOrnamentPositionBottomRight,
MGLOrnamentPositionBottomLeft
},
{
MGLOrnamentPositionTopRight,
MGLOrnamentPositionBottomRight,
MGLOrnamentPositionBottomLeft,
MGLOrnamentPositionTopLeft
},
{
MGLOrnamentPositionBottomRight,
MGLOrnamentPositionBottomLeft,
MGLOrnamentPositionTopLeft,
MGLOrnamentPositionTopRight
},
{
MGLOrnamentPositionBottomLeft,
MGLOrnamentPositionTopLeft,
MGLOrnamentPositionTopRight,
MGLOrnamentPositionBottomRight
},
{
MGLOrnamentPositionTopLeft,
MGLOrnamentPositionTopRight,
MGLOrnamentPositionBottomRight,
MGLOrnamentPositionBottomLeft
}
};
MGLOrnamentPosition *currentPosition = ornamentPositions[currentPositionIndex];
self.mapView.scaleBarPosition = currentPosition[0];
self.mapView.compassViewPosition = currentPosition[1];
self.mapView.logoViewPosition = currentPosition[2];
self.mapView.attributionButtonPosition = currentPosition[3];

_currentPositionIndex = currentPositionIndex;
}

- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Ornaments";

MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds];
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[mapView setCenterCoordinate:CLLocationCoordinate2DMake(39.915143, 116.404053)
zoomLevel:16
direction:30
animated:NO];
mapView.delegate = self;
mapView.showsScale = YES;
[self.view addSubview:mapView];

self.mapView = mapView;
}

- (void)viewDidDisappear:(BOOL)animated {
[self.timer invalidate];
self.timer = nil;
}

- (void)viewDidAppear:(BOOL)animated {
self.timer = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(onTimerTick)
userInfo:nil
repeats:YES];
}

- (void)onTimerTick {
self.currentPositionIndex ++;
if (self.currentPositionIndex >= 4) {
self.currentPositionIndex = 0;
}
}

@end
11 changes: 10 additions & 1 deletion platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#import "MBXUserLocationAnnotationView.h"
#import "LimeGreenStyleLayer.h"
#import "MBXEmbeddedMapViewController.h"
#import "MBXOrnamentsViewController.h"

#import "MBXFrameTimeGraphView.h"

Expand Down Expand Up @@ -104,8 +105,9 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
MBXSettingsMiscellaneousShowSnapshots,
MBXSettingsMiscellaneousShouldLimitCameraChanges,
MBXSettingsMiscellaneousShowCustomLocationManager,
MBXSettingsMiscellaneousOrnamentsPlacement,
MBXSettingsMiscellaneousPrintLogFile,
MBXSettingsMiscellaneousDeleteLogFile,
MBXSettingsMiscellaneousDeleteLogFile
};

// Utility methods
Expand Down Expand Up @@ -499,6 +501,7 @@ - (void)dismissSettings:(__unused id)sender
@"Show Snapshots",
[NSString stringWithFormat:@"%@ Camera Changes", (_shouldLimitCameraChanges ? @"Unlimit" : @"Limit")],
@"View Route Simulation",
@"Ornaments Placement",
]];

if (self.debugLoggingEnabled)
Expand Down Expand Up @@ -756,6 +759,12 @@ - (void)performActionForSettingAtIndexPath:(NSIndexPath *)indexPath
}
break;
}
case MBXSettingsMiscellaneousOrnamentsPlacement:
{
MBXOrnamentsViewController *ornamentsViewController = [[MBXOrnamentsViewController alloc] init];
[self.navigationController pushViewController:ornamentsViewController animated:YES];
break;
}
default:
NSAssert(NO, @"All miscellaneous setting rows should be implemented");
break;
Expand Down
18 changes: 18 additions & 0 deletions platform/ios/ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@
55E5666D21C2A2080008B8B5 /* NSData+MMEGZIP.h in Headers */ = {isa = PBXBuildFile; fileRef = 40834BCF1FE05D7100C1BD0D /* NSData+MMEGZIP.h */; };
632281DF1E6F855900D75A5D /* MBXEmbeddedMapViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 632281DE1E6F855900D75A5D /* MBXEmbeddedMapViewController.m */; };
6407D6701E0085FD00F6A9C3 /* MGLDocumentationExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6407D66F1E0085FD00F6A9C3 /* MGLDocumentationExampleTests.swift */; };
6F018BAE220031B8003E7269 /* UIView+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FAFA29B220023840088709E /* UIView+MGLAdditions.m */; };
6F018BAF220031BF003E7269 /* UIView+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FAFA29A220023840088709E /* UIView+MGLAdditions.h */; };
6F018BB0220031BF003E7269 /* UIView+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FAFA29A220023840088709E /* UIView+MGLAdditions.h */; };
6F018BB1220031C1003E7269 /* UIView+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FAFA29B220023840088709E /* UIView+MGLAdditions.m */; };
6FA9341721EF372100AA9CA8 /* MBXOrnamentsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FA9341521EF372100AA9CA8 /* MBXOrnamentsViewController.m */; };
74CB5EB1219B252C00102936 /* MGLStyleLayerManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 74CB5EAF219B252C00102936 /* MGLStyleLayerManager.h */; };
74CB5EB2219B252C00102936 /* MGLStyleLayerManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 74CB5EAF219B252C00102936 /* MGLStyleLayerManager.h */; };
74CB5EB3219B252C00102936 /* MGLStyleLayerManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 74CB5EB0219B252C00102936 /* MGLStyleLayerManager.mm */; };
Expand Down Expand Up @@ -1076,6 +1081,10 @@
632281DD1E6F855900D75A5D /* MBXEmbeddedMapViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBXEmbeddedMapViewController.h; sourceTree = "<group>"; };
632281DE1E6F855900D75A5D /* MBXEmbeddedMapViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBXEmbeddedMapViewController.m; sourceTree = "<group>"; };
6407D66F1E0085FD00F6A9C3 /* MGLDocumentationExampleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MGLDocumentationExampleTests.swift; path = ../../darwin/test/MGLDocumentationExampleTests.swift; sourceTree = "<group>"; };
6FA9341521EF372100AA9CA8 /* MBXOrnamentsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBXOrnamentsViewController.m; sourceTree = "<group>"; };
6FA9341621EF372100AA9CA8 /* MBXOrnamentsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBXOrnamentsViewController.h; sourceTree = "<group>"; };
6FAFA29A220023840088709E /* UIView+MGLAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIView+MGLAdditions.h"; sourceTree = "<group>"; };
6FAFA29B220023840088709E /* UIView+MGLAdditions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIView+MGLAdditions.m"; sourceTree = "<group>"; };
74CB5EAF219B252C00102936 /* MGLStyleLayerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLStyleLayerManager.h; sourceTree = "<group>"; };
74CB5EB0219B252C00102936 /* MGLStyleLayerManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLStyleLayerManager.mm; sourceTree = "<group>"; };
74CB5EB5219B280300102936 /* MGLHillshadeStyleLayer_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLHillshadeStyleLayer_Private.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1677,6 +1686,8 @@
30E578121DAA7D690050F07E /* UIImage+MGLAdditions.mm */,
DD9BE4F51EB263C50079A3AF /* UIViewController+MGLAdditions.h */,
DD9BE4F61EB263C50079A3AF /* UIViewController+MGLAdditions.m */,
6FAFA29A220023840088709E /* UIView+MGLAdditions.h */,
6FAFA29B220023840088709E /* UIView+MGLAdditions.m */,
);
name = Categories;
sourceTree = "<group>";
Expand Down Expand Up @@ -1950,6 +1961,8 @@
965DF51020F9430500438AAC /* MBXFrameTimeGraphView.m */,
632281DD1E6F855900D75A5D /* MBXEmbeddedMapViewController.h */,
632281DE1E6F855900D75A5D /* MBXEmbeddedMapViewController.m */,
6FA9341621EF372100AA9CA8 /* MBXOrnamentsViewController.h */,
6FA9341521EF372100AA9CA8 /* MBXOrnamentsViewController.m */,
DA821D051CCC6D59007508D4 /* Main.storyboard */,
DA821D041CCC6D59007508D4 /* LaunchScreen.storyboard */,
DA1DC99E1CB6E088006E619F /* Assets.xcassets */,
Expand Down Expand Up @@ -2421,6 +2434,7 @@
35E79F201D41266300957B9E /* MGLStyleLayer_Private.h in Headers */,
FA68F14A1E9D656600F9F6C2 /* MGLFillExtrusionStyleLayer.h in Headers */,
353933FB1D3FB7C0003F57D7 /* MGLRasterStyleLayer.h in Headers */,
6F018BB0220031BF003E7269 /* UIView+MGLAdditions.h in Headers */,
1FCAE2A820B88B3800C577DD /* MGLLocationManager_Private.h in Headers */,
DA8847EF1CBAFA5100AB86E3 /* MGLAccountManager.h in Headers */,
DA35A2C91CCAAAD200E826B2 /* NSValue+MGLAdditions.h in Headers */,
Expand Down Expand Up @@ -2629,6 +2643,7 @@
3510FFEB1D6D9C7A00F413B2 /* NSComparisonPredicate+MGLAdditions.h in Headers */,
35E1A4D91D74336F007AA97F /* MGLValueEvaluator.h in Headers */,
DABFB8701CBE9A0F00D62B32 /* MGLMapView+IBAdditions.h in Headers */,
6F018BAF220031BF003E7269 /* UIView+MGLAdditions.h in Headers */,
96E516EA2000560B00A02306 /* MGLAnnotationView_Private.h in Headers */,
96E516FB20005A4000A02306 /* MGLUserLocationHeadingBeamLayer.h in Headers */,
96E516DC2000547000A02306 /* MGLPolyline_Private.h in Headers */,
Expand Down Expand Up @@ -3083,6 +3098,7 @@
354B839C1D2E9B48005D9406 /* MBXUserLocationAnnotationView.m in Sources */,
965DF51120F9430500438AAC /* MBXFrameTimeGraphView.m in Sources */,
DA1DC9991CB6E054006E619F /* MBXAppDelegate.m in Sources */,
6FA9341721EF372100AA9CA8 /* MBXOrnamentsViewController.m in Sources */,
DA1DC96B1CB6C6B7006E619F /* MBXOfflinePacksTableViewController.m in Sources */,
DA1DC96A1CB6C6B7006E619F /* MBXCustomCalloutView.m in Sources */,
927FBCFC1F4DAA8300F8BF1F /* MBXSnapshotsViewController.m in Sources */,
Expand Down Expand Up @@ -3182,6 +3198,7 @@
40834C4A1FE05F7500C1BD0D /* TSKPinningValidator.m in Sources */,
967C864D210A9D3C004DF794 /* UIDevice+MGLAdditions.m in Sources */,
400533021DB0862B0069F638 /* NSArray+MGLAdditions.mm in Sources */,
6F018BAE220031B8003E7269 /* UIView+MGLAdditions.m in Sources */,
96036A03200565C700510F3D /* NSOrthography+MGLAdditions.m in Sources */,
ACA65F592140697200537748 /* MMEDispatchManager.m in Sources */,
40834BF31FE05E1800C1BD0D /* MMETimerManager.m in Sources */,
Expand Down Expand Up @@ -3318,6 +3335,7 @@
35136D431D42274500C20EFD /* MGLRasterStyleLayer.mm in Sources */,
967C864E210A9D3C004DF794 /* UIDevice+MGLAdditions.m in Sources */,
96036A04200565C700510F3D /* NSOrthography+MGLAdditions.m in Sources */,
6F018BB1220031C1003E7269 /* UIView+MGLAdditions.m in Sources */,
40834C071FE05E1800C1BD0D /* MMETimerManager.m in Sources */,
ACA65F5A2140697200537748 /* MMEDispatchManager.m in Sources */,
3538AA201D542239008EC33D /* MGLForegroundStyleLayer.mm in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions platform/ios/sdk-files.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"platform/ios/vendor/mapbox-events-ios/vendor/TrustKit/TSKPinningValidator.m",
"platform/ios/src/UIDevice+MGLAdditions.m",
"platform/darwin/src/NSArray+MGLAdditions.mm",
"platform/ios/src/UIView+MGLAdditions.m",
"platform/ios/src/NSOrthography+MGLAdditions.m",
"platform/ios/vendor/mapbox-events-ios/MapboxMobileEvents/MMEDispatchManager.m",
"platform/ios/vendor/mapbox-events-ios/MapboxMobileEvents/MMETimerManager.m",
Expand Down Expand Up @@ -234,6 +235,7 @@
"MGLShape_Private.h": "platform/darwin/src/MGLShape_Private.h",
"MGLPolygon_Private.h": "platform/darwin/src/MGLPolygon_Private.h",
"MGLStyleLayer_Private.h": "platform/darwin/src/MGLStyleLayer_Private.h",
"UIView+MGLAdditions.h": "platform/ios/src/UIView+MGLAdditions.h",
"MGLLocationManager_Private.h": "platform/darwin/src/MGLLocationManager_Private.h",
"MGLLoggingConfiguration_Private.h": "platform/darwin/src/MGLLoggingConfiguration_Private.h",
"NSComparisonPredicate+MGLAdditions.h": "platform/darwin/src/NSComparisonPredicate+MGLAdditions.h",
Expand Down
59 changes: 59 additions & 0 deletions platform/ios/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ typedef NS_ENUM(NSUInteger, MGLAnnotationVerticalAlignment) {
MGLAnnotationVerticalAlignmentBottom,
};

/**
The position of scale bar, compass, logo and attribution in a map view. Used with
`MGLMapView.scaleBarPosition`,
`MGLMapView.compassViewPosition`,
`MGLMapView.logoViewPosition`,
`MGLMapView.attributionButtonPosition`.
*/
typedef NS_ENUM(NSUInteger, MGLOrnamentPosition) {
/** Place the ornament in the top left of the map view. */
MGLOrnamentPositionTopLeft = 0,
/** Place the ornament in the top right of the map view. */
MGLOrnamentPositionTopRight,
/** Place the ornament in the bottom left of the map view. */
MGLOrnamentPositionBottomLeft,
/** Place the ornament in the bottom right of the map view. */
MGLOrnamentPositionBottomRight,
};

/**
The mode used to track the user location on the map. Used with
`MGLMapView.userTrackingMode`.
Expand Down Expand Up @@ -286,12 +304,32 @@ MGL_EXPORT IB_DESIGNABLE
*/
@property (nonatomic, readonly) UIView *scaleBar;

/**
The position of the scale bar. The default value is `MGLOrnamentPositionTopLeft`.
*/
@property (nonatomic, assign) MGLOrnamentPosition scaleBarPosition;

/**
A `CGPoint` indicating the position offset of the scale bar.
*/
@property (nonatomic, assign) CGPoint scaleBarMargins;

/**
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 position of the compass view. The default value is `MGLOrnamentPositionTopRight`.
*/
@property (nonatomic, assign) MGLOrnamentPosition compassViewPosition;

/**
A `CGPoint` indicating the position offset of the compass.
*/
@property (nonatomic, assign) CGPoint compassViewMargins;

/**
The Mapbox logo, positioned in the lower-left corner.
Expand All @@ -303,6 +341,17 @@ MGL_EXPORT IB_DESIGNABLE
*/
@property (nonatomic, readonly) UIImageView *logoView;

/**
The position of the logo view. The default value is `MGLOrnamentPositionBottomLeft`.
*/
@property (nonatomic, assign) MGLOrnamentPosition logoViewPosition;

/**
A `CGPoint` indicating the position offset of the logo.
*/
@property (nonatomic, assign) CGPoint logoViewMargins;


/**
A view showing legally required copyright notices and telemetry settings,
positioned at the bottom-right of the map view.
Expand All @@ -328,6 +377,16 @@ MGL_EXPORT IB_DESIGNABLE
*/
@property (nonatomic, readonly) UIButton *attributionButton;

/**
The position of the attribution button. The default value is `MGLOrnamentPositionBottomRight`.
*/
@property (nonatomic, assign) MGLOrnamentPosition attributionButtonPosition;

/**
A `CGPoint` indicating the position offset of the attribution.
*/
@property (nonatomic, assign) CGPoint attributionButtonMargins;

/**
Show the attribution and telemetry action sheet.
Expand Down
Loading

0 comments on commit 60ceac5

Please sign in to comment.