diff options
author | Lloyd Sheng <i@lloydsheng.com> | 2019-01-30 15:39:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-30 15:39:29 +0800 |
commit | e22d28c285c1543ebbf75d205f0129e74b0fbb8a (patch) | |
tree | 09e5ebae51df26d3e68cb8f0f95ff0296673b808 /platform/ios/app/MBXOrnamentsViewController.m | |
parent | 44fbba8514554dd05a0d8abc3f33f21840a73033 (diff) | |
download | qtlocation-mapboxgl-e22d28c285c1543ebbf75d205f0129e74b0fbb8a.tar.gz |
[ios] Enable customize positions of mapview ornaments (#13556)
* APIs for customize positions of ornaments
* Adopt anchors layout
* Remove iOS8 layout code
Diffstat (limited to 'platform/ios/app/MBXOrnamentsViewController.m')
-rw-r--r-- | platform/ios/app/MBXOrnamentsViewController.m | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/platform/ios/app/MBXOrnamentsViewController.m b/platform/ios/app/MBXOrnamentsViewController.m new file mode 100644 index 0000000000..5e575f8c7d --- /dev/null +++ b/platform/ios/app/MBXOrnamentsViewController.m @@ -0,0 +1,93 @@ +#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 { + NSArray *ornamentPositions = @[@[ + @(MGLOrnamentPositionTopLeft), + @(MGLOrnamentPositionTopRight), + @(MGLOrnamentPositionBottomRight), + @(MGLOrnamentPositionBottomLeft) + ], + @[ + @(MGLOrnamentPositionTopRight), + @(MGLOrnamentPositionBottomRight), + @(MGLOrnamentPositionBottomLeft), + @(MGLOrnamentPositionTopLeft) + ], + @[ + @(MGLOrnamentPositionBottomRight), + @(MGLOrnamentPositionBottomLeft), + @(MGLOrnamentPositionTopLeft), + @(MGLOrnamentPositionTopRight) + ], + @[ + @(MGLOrnamentPositionBottomLeft), + @(MGLOrnamentPositionTopLeft), + @(MGLOrnamentPositionTopRight), + @(MGLOrnamentPositionBottomRight) + ], + @[ + @(MGLOrnamentPositionTopLeft), + @(MGLOrnamentPositionTopRight), + @(MGLOrnamentPositionBottomRight), + @(MGLOrnamentPositionBottomLeft) + ], + ]; + NSArray *currentPosition = ornamentPositions[currentPositionIndex]; + self.mapView.scaleBarPosition = [currentPosition[0] integerValue]; + self.mapView.compassViewPosition = [currentPosition[1] integerValue]; + self.mapView.logoViewPosition = [currentPosition[2] integerValue]; + self.mapView.attributionButtonPosition = [currentPosition[3] integerValue]; + + _currentPositionIndex = currentPositionIndex; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + self.title = @"Ornaments"; + + MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:self.view.frame]; + 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 |