diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2017-10-05 23:31:57 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2019-07-28 15:58:24 -0700 |
commit | 1826897120e74bc2be6d1f4336d968c9431495e1 (patch) | |
tree | 14602a2a9e80412cdae86032234efa25f12cb020 | |
parent | 0a720aee8cf1f9616de04950a41e4eabde9b5d75 (diff) | |
download | qtlocation-mapboxgl-1826897120e74bc2be6d1f4336d968c9431495e1.tar.gz |
[tvos] Press Play to tour world
-rw-r--r-- | platform/ios/tvosapp/Base.lproj/Main.storyboard | 8 | ||||
-rw-r--r-- | platform/ios/tvosapp/ViewController.m | 47 |
2 files changed, 54 insertions, 1 deletions
diff --git a/platform/ios/tvosapp/Base.lproj/Main.storyboard b/platform/ios/tvosapp/Base.lproj/Main.storyboard index d215136351..e6832f217d 100644 --- a/platform/ios/tvosapp/Base.lproj/Main.storyboard +++ b/platform/ios/tvosapp/Base.lproj/Main.storyboard @@ -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> @@ -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> diff --git a/platform/ios/tvosapp/ViewController.m b/platform/ios/tvosapp/ViewController.m index a2eb306a0f..b86f67ef3c 100644 --- a/platform/ios/tvosapp/ViewController.m +++ b/platform/ios/tvosapp/ViewController.m @@ -2,13 +2,23 @@ #import <Mapbox/Mapbox.h> +static const CLLocationCoordinate2D WorldTourDestinations[] = { + { .latitude = 38.8999418, .longitude = -77.033996 }, + { .latitude = 37.7884307, .longitude = -122.3998631 }, + { .latitude = 52.5003103, .longitude = 13.4197763 }, + { .latitude = 60.1712627, .longitude = 24.9378866 }, + { .latitude = 53.8948782, .longitude = 27.5558476 }, +}; + @interface ViewController () <MGLMapViewDelegate> @property (weak, nonatomic) IBOutlet MGLMapView *mapView; @end -@implementation ViewController +@implementation ViewController { + BOOL _isTouringWorld; +} - (void)viewDidLoad { [super viewDidLoad]; @@ -21,6 +31,41 @@ // 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:(NSMutableArray<MGLPointAnnotation *> *)annotations { + MGLPointAnnotation *nextAnnotation = annotations.firstObject; + if (!nextAnnotation || !_isTouringWorld) { + _isTouringWorld = NO; + return; + } + + [annotations removeObjectAtIndex:0]; + MGLMapCamera *camera = [MGLMapCamera cameraLookingAtCenterCoordinate:nextAnnotation.coordinate + acrossDistance: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]; + }]; +} #pragma mark MGLMapViewDelegate methods |