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

Commit

Permalink
Merge pull request #1497 from mapbox/1ec5-info-menu
Browse files Browse the repository at this point in the history
Attribute Mapbox and OpenStreetMap in-app
  • Loading branch information
1ec5 committed May 11, 2015
2 parents 5ef362b + 965bc41 commit e7ba65c
Showing 1 changed file with 46 additions and 12 deletions.
58 changes: 46 additions & 12 deletions platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

#pragma mark - Private -

@interface MGLMapView () <UIGestureRecognizerDelegate, GLKViewDelegate, CLLocationManagerDelegate>
@interface MGLMapView () <UIGestureRecognizerDelegate, GLKViewDelegate, CLLocationManagerDelegate, UIActionSheetDelegate>

@property (nonatomic) EAGLContext *context;
@property (nonatomic) GLKView *glView;
Expand All @@ -63,6 +63,7 @@ @interface MGLMapView () <UIGestureRecognizerDelegate, GLKViewDelegate, CLLocati
@property (nonatomic) UIImageView *compass;
@property (nonatomic) UIImageView *logoBug;
@property (nonatomic) UIButton *attributionButton;
@property (nonatomic) UIActionSheet *attributionSheet;
@property (nonatomic) UIPanGestureRecognizer *pan;
@property (nonatomic) UIPinchGestureRecognizer *pinch;
@property (nonatomic) UIRotationGestureRecognizer *rotate;
Expand Down Expand Up @@ -303,9 +304,19 @@ - (BOOL)commonInit
//
_attributionButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
_attributionButton.accessibilityLabel = @"Attribution info";
[_attributionButton addTarget:self action:@selector(showAttribution:) forControlEvents:UIControlEventTouchUpInside];
[_attributionButton addTarget:self action:@selector(showAttribution) forControlEvents:UIControlEventTouchUpInside];
_attributionButton.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_attributionButton];

_attributionSheet = [[UIActionSheet alloc] initWithTitle:@"Mapbox GL for iOS"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:
@"© Mapbox",
@"© OpenStreetMap",
@"Improve This Map",
nil];

// setup compass
//
Expand Down Expand Up @@ -647,6 +658,11 @@ - (void)layoutSubviews
{
_mbglMap->update();
}

if (self.attributionSheet.visible)
{
[self.attributionSheet dismissWithClickedButtonIndex:self.attributionSheet.cancelButtonIndex animated:YES];
}
}

#pragma mark - Life Cycle -
Expand Down Expand Up @@ -1251,6 +1267,34 @@ - (void)trackGestureEvent:(NSString *)gestureID forRecognizer:(UIGestureRecogniz
}];
}

#pragma mark - Attribution -

- (void)showAttribution
{
[self.attributionSheet showFromRect:self.attributionButton.frame inView:self animated:YES];
}

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == actionSheet.firstOtherButtonIndex)
{
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:@"https://www.mapbox.com/about/maps/"]];
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 1)
{
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:@"http://www.openstreetmap.org/about/"]];
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 2)
{
NSString *feedbackURL = [NSString stringWithFormat:@"https://www.mapbox.com/map-feedback/#/%.5f/%.5f/%i",
self.longitude, self.latitude, (int)round(self.zoomLevel)];
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:feedbackURL]];
}
}

#pragma mark - Properties -

+ (NSSet *)keyPathsForValuesAffectingZoomEnabled
Expand All @@ -1268,16 +1312,6 @@ + (NSSet *)keyPathsForValuesAffectingRotateEnabled
return [NSSet setWithObject:@"allowsRotating"];
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"

- (void)showAttribution:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.mapbox.com/about/maps/"]];
}

#pragma clang diagnostic pop

- (void)setDebugActive:(BOOL)debugActive
{
_mbglMap->setDebug(debugActive);
Expand Down

0 comments on commit e7ba65c

Please sign in to comment.