Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Update callout delegate example to use fixed coordinate
Browse files Browse the repository at this point in the history
`-showAnnotations:animated:` is broken for a single point: mapbox/mapbox-gl-native#5693.
  • Loading branch information
friedbunny committed Jul 14, 2016
1 parent b9e6cb7 commit c7a10cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 6 additions & 6 deletions Examples/ObjectiveC/CalloutDelegateUsageExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ - (void)viewDidLoad
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.mapView];

// remember to set the delegate (or much of this will not work)
// Remember to set the delegate.
self.mapView.delegate = self;

[self addAnnotation];
Expand All @@ -42,10 +42,10 @@ - (void)addAnnotation

[self.mapView addAnnotation:annotation];

// fit the map to the annotation(s)
[self.mapView showAnnotations:self.mapView.annotations animated:NO];
// Center the map on the annotation.
[self.mapView setCenterCoordinate:annotation.coordinate zoomLevel:17 animated:NO];

// pop-up the callout view
// Pop-up the callout view.
[self.mapView selectAnnotation:annotation animated:YES];
}

Expand All @@ -58,7 +58,7 @@ - (UIView *)mapView:(MGLMapView *)mapView leftCalloutAccessoryViewForAnnotation:
{
if ([annotation.title isEqualToString:@"Kinkaku-ji"])
{
// callout height is fixed; width expands to fit
// Callout height is fixed; width expands to fit its content.
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60.f, 50.f)];
label.textAlignment = NSTextAlignmentRight;
label.textColor = [UIColor colorWithRed:0.81f green:0.71f blue:0.23f alpha:1.f];
Expand All @@ -77,7 +77,7 @@ - (UIView *)mapView:(MGLMapView *)mapView rightCalloutAccessoryViewForAnnotation

- (void)mapView:(MGLMapView *)mapView annotation:(id<MGLAnnotation>)annotation calloutAccessoryControlTapped:(UIControl *)control
{
// hide the callout view
// Hide the callout view.
[self.mapView deselectAnnotation:annotation animated:NO];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:annotation.title
Expand Down
11 changes: 6 additions & 5 deletions Examples/Swift/CalloutDelegateUsageExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CalloutDelegateUsageExample_Swift: UIViewController,

view.addSubview(mapView)

// remember to set the delegate (or much of this will not work)
// Remember to set the delegate.
mapView.delegate = self

addAnnotation()
Expand All @@ -37,10 +37,10 @@ class CalloutDelegateUsageExample_Swift: UIViewController,

mapView.addAnnotation(annotation)

// fit the map to the annotation(s)
mapView.showAnnotations(mapView.annotations!, animated: false)
// Center the map on the annotation.
mapView.setCenterCoordinate(annotation.coordinate, zoomLevel: 17, animated: false)

// pop-up the callout view
// Pop-up the callout view.
mapView.selectAnnotation(annotation, animated: true)
}

Expand All @@ -50,6 +50,7 @@ class CalloutDelegateUsageExample_Swift: UIViewController,

func mapView(mapView: MGLMapView, leftCalloutAccessoryViewForAnnotation annotation: MGLAnnotation) -> UIView? {
if (annotation.title! == "Kinkaku-ji") {
// Callout height is fixed; width expands to fit its content.
let label = UILabel(frame: CGRectMake(0, 0, 60, 50))
label.textAlignment = .Right
label.textColor = UIColor(red: 0.81, green: 0.71, blue: 0.23, alpha: 1)
Expand All @@ -66,7 +67,7 @@ class CalloutDelegateUsageExample_Swift: UIViewController,
}

func mapView(mapView: MGLMapView, annotation: MGLAnnotation, calloutAccessoryControlTapped control: UIControl) {
// hide the callout view
// Hide the callout view.
mapView.deselectAnnotation(annotation, animated: false)

UIAlertView(title: annotation.title!!, message: "A lovely (if touristy) place.", delegate: nil, cancelButtonTitle: nil, otherButtonTitles: "OK").show()
Expand Down

0 comments on commit c7a10cc

Please sign in to comment.