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

Commit

Permalink
[tvos] Press Play to tour world
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Oct 6, 2017
1 parent 4897710 commit 2f5742c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
8 changes: 8 additions & 0 deletions platform/ios/tvosapp/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="3pC-z4-awr" customClass="MGLMapView">
<rect key="frame" x="110" y="68" width="1700" height="944"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<gestureRecognizers/>
<connections>
<outlet property="delegate" destination="BYZ-38-t0r" id="R5G-s2-6ua"/>
<outletCollection property="gestureRecognizers" destination="NIw-pr-3Xt" appends="YES" id="WYu-GK-C9r"/>
</connections>
</view>
</subviews>
Expand All @@ -44,6 +46,12 @@
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
<tapGestureRecognizer id="NIw-pr-3Xt">
<pressTypeMask key="allowedPressTypes" playPause="YES"/>
<connections>
<action selector="startWorldTour:" destination="BYZ-38-t0r" id="W4s-ZY-cVe"/>
</connections>
</tapGestureRecognizer>
</objects>
</scene>
</scenes>
Expand Down
46 changes: 45 additions & 1 deletion platform/ios/tvosapp/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@

#import <Mapbox/Mapbox.h>

static const CLLocationCoordinate2D WorldTourDestinations[] = {
{ .latitude = 38.9099711, .longitude = -77.0361123 },
{ .latitude = 37.7884307, .longitude = -122.3998631 },
{ .latitude = 12.9813016, .longitude = 77.6405126 },
{ .latitude = -13.155846, .longitude = -74.2178934 },
};

@interface ViewController () <MGLMapViewDelegate>

@property (weak, nonatomic) IBOutlet MGLMapView *mapView;

@end

@implementation ViewController
@implementation ViewController {
BOOL _isTouringWorld;
}

- (void)viewDidLoad {
[super viewDidLoad];
Expand All @@ -21,5 +30,40 @@ - (void)didReceiveMemoryWarning {
// Dispose of any resources that can be recreated.
}

- (IBAction)startWorldTour:(id)sender {
_isTouringWorld = YES;

[self.mapView removeAnnotations:self.mapView.annotations];
NSUInteger numberOfAnnotations = sizeof(WorldTourDestinations) / sizeof(WorldTourDestinations[0]);
NSMutableArray *annotations = [NSMutableArray arrayWithCapacity:numberOfAnnotations];
for (NSUInteger i = 0; i < numberOfAnnotations; i++) {
MGLPointAnnotation *annotation = [[MGLPointAnnotation alloc] init];
annotation.coordinate = WorldTourDestinations[i];
[annotations addObject:annotation];
}
[self.mapView addAnnotations:annotations];
[self continueWorldTourWithRemainingAnnotations:annotations];
}

- (void)continueWorldTourWithRemainingAnnotations:(NS_MUTABLE_ARRAY_OF(MGLPointAnnotation *) *)annotations {
MGLPointAnnotation *nextAnnotation = annotations.firstObject;
if (!nextAnnotation || !_isTouringWorld) {
_isTouringWorld = NO;
return;
}

[annotations removeObjectAtIndex:0];
MGLMapCamera *camera = [MGLMapCamera cameraLookingAtCenterCoordinate:nextAnnotation.coordinate
fromDistance:10
pitch:arc4random_uniform(60)
heading:arc4random_uniform(360)];
__weak ViewController *weakSelf = self;
[self.mapView flyToCamera:camera completionHandler:^{
ViewController *strongSelf = weakSelf;
[strongSelf performSelector:@selector(continueWorldTourWithRemainingAnnotations:)
withObject:annotations
afterDelay:2];
}];
}

@end

0 comments on commit 2f5742c

Please sign in to comment.