summaryrefslogtreecommitdiff
path: root/platform/ios/app/MBXOrnamentsViewController.m
blob: 489b3062b64e90283e9d8c9e1218ddcc6cb453fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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