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

Commit

Permalink
[ios, macos] Updated feedback URL
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed May 23, 2017
1 parent 8c73cb1 commit f1698c8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
23 changes: 20 additions & 3 deletions platform/darwin/src/MGLAttributionInfo.mm
Expand Up @@ -6,6 +6,7 @@
#import <Cocoa/Cocoa.h>
#endif

#import "MGLAccountManager.h"
#import "MGLMapCamera.h"
#import "NSArray+MGLAdditions.h"
#import "NSString+MGLAdditions.h"
Expand Down Expand Up @@ -126,13 +127,29 @@ - (instancetype)initWithTitle:(NSAttributedString *)title URL:(NSURL *)URL {
}

- (nullable NSURL *)feedbackURLAtCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel {
return [self feedbackURLForStyleURL:nil atCenterCoordinate:centerCoordinate zoomLevel:zoomLevel];
}

- (nullable NSURL *)feedbackURLForStyleURL:(nullable NSURL *)styleURL atCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel {
if (!self.feedbackLink) {
return nil;
}

NSURLComponents *components = [NSURLComponents componentsWithURL:self.URL resolvingAgainstBaseURL:NO];
NSURLComponents *components = [NSURLComponents componentsWithString:@"https://www.mapbox.com/feedback/"];
components.fragment = [NSString stringWithFormat:@"/%.5f/%.5f/%i",
centerCoordinate.longitude, centerCoordinate.latitude, (int)round(zoomLevel + 1)];
centerCoordinate.longitude, centerCoordinate.latitude, (int)round(zoomLevel)];

if ([styleURL.scheme isEqualToString:@"mapbox"] && [styleURL.host isEqualToString:@"styles"]) {
NSArray<NSString *> *stylePathComponents = styleURL.pathComponents;
if (stylePathComponents.count >= 3) {
components.queryItems = @[
[NSURLQueryItem queryItemWithName:@"owner" value:stylePathComponents[1]],
[NSURLQueryItem queryItemWithName:@"id" value:stylePathComponents[2]],
[NSURLQueryItem queryItemWithName:@"access_token" value:[MGLAccountManager accessToken]],
];
}
}

return components.URL;
}

Expand Down
14 changes: 14 additions & 0 deletions platform/darwin/src/MGLAttributionInfo_Private.h
Expand Up @@ -20,6 +20,20 @@ NS_ASSUME_NONNULL_BEGIN

+ (NSAttributedString *)attributedStringForAttributionInfos:(NS_ARRAY_OF(MGLAttributionInfo *) *)attributionInfos;

/**
Returns a copy of the `URL` property modified to account for the given style
URL, center coordinate, and zoom level.
@param styleURL The map’s style URL.
@param centerCoordinate The map’s center coordinate.
@param zoomLevel The map’s zoom level. See the `MGLMapView.zoomLevel` property
for more information.
@return A modified URL containing a fragment that points to the specified
viewport. If the `feedbackLink` property is set to `NO`, this method returns
`nil`.
*/
- (nullable NSURL *)feedbackURLForStyleURL:(nullable NSURL *)styleURL atCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel;

@end

@interface NSMutableArray (MGLAttributionInfoAdditions)
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/test/MGLAttributionInfoTests.m
Expand Up @@ -47,7 +47,7 @@ - (void)testParsing {
XCTAssertEqualObjects(infos[3].URL, [NSURL URLWithString:@"https://www.mapbox.com/map-feedback/"]);
XCTAssertTrue(infos[3].feedbackLink);
XCTAssertEqualObjects([infos[3] feedbackURLAtCenterCoordinate:mapbox zoomLevel:14],
[NSURL URLWithString:@"https://www.mapbox.com/map-feedback/#/77.63680/12.98108/15"]);
[NSURL URLWithString:@"https://www.mapbox.com/feedback/#/77.63680/12.98108/14"]);
}

- (void)testStyle {
Expand Down
7 changes: 4 additions & 3 deletions platform/ios/src/MGLMapView.mm
Expand Up @@ -64,7 +64,7 @@
#import "MGLCompactCalloutView.h"
#import "MGLAnnotationContainerView.h"
#import "MGLAnnotationContainerView_Private.h"
#import "MGLAttributionInfo.h"
#import "MGLAttributionInfo_Private.h"

#include <algorithm>
#include <cstdlib>
Expand Down Expand Up @@ -1907,8 +1907,9 @@ - (void)showAttribution
{
if (info.feedbackLink)
{
url = [info feedbackURLAtCenterCoordinate:self.centerCoordinate
zoomLevel:self.zoomLevel];
url = [info feedbackURLForStyleURL:self.styleURL
atCenterCoordinate:self.centerCoordinate
zoomLevel:self.zoomLevel];
}
[[UIApplication sharedApplication] openURL:url];
}
Expand Down
9 changes: 5 additions & 4 deletions platform/macos/src/MGLMapView.mm
@@ -1,17 +1,18 @@
#import "MGLMapView_Private.h"
#import "MGLAnnotationImage_Private.h"

#import "MGLAttributionButton.h"
#import "MGLAttributionInfo.h"
#import "MGLCompassCell.h"
#import "MGLOpenGLLayer.h"
#import "MGLStyle.h"

#import "MGLAnnotationImage_Private.h"
#import "MGLAttributionInfo_Private.h"
#import "MGLFeature_Private.h"
#import "MGLFoundation_Private.h"
#import "MGLGeometry_Private.h"
#import "MGLMultiPoint_Private.h"
#import "MGLOfflineStorage_Private.h"
#import "MGLStyle_Private.h"
#import "MGLFoundation_Private.h"

#import "MGLAccountManager.h"
#import "MGLMapCamera.h"
Expand Down Expand Up @@ -1739,7 +1740,7 @@ - (IBAction)giveFeedback:(id)sender {
double zoomLevel = self.zoomLevel;
NSMutableArray *urls = [NSMutableArray array];
for (MGLAttributionInfo *info in [self.style attributionInfosWithFontSize:0 linkColor:nil]) {
NSURL *url = [info feedbackURLAtCenterCoordinate:centerCoordinate zoomLevel:zoomLevel];
NSURL *url = [info feedbackURLForStyleURL:self.styleURL atCenterCoordinate:centerCoordinate zoomLevel:zoomLevel];
if (url) {
[urls addObject:url];
}
Expand Down

0 comments on commit f1698c8

Please sign in to comment.