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

Commit f1698c8

Browse files
committed
[ios, macos] Updated feedback URL
1 parent 8c73cb1 commit f1698c8

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-11
lines changed

platform/darwin/src/MGLAttributionInfo.mm

+20-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#import <Cocoa/Cocoa.h>
77
#endif
88

9+
#import "MGLAccountManager.h"
910
#import "MGLMapCamera.h"
1011
#import "NSArray+MGLAdditions.h"
1112
#import "NSString+MGLAdditions.h"
@@ -126,13 +127,29 @@ - (instancetype)initWithTitle:(NSAttributedString *)title URL:(NSURL *)URL {
126127
}
127128

128129
- (nullable NSURL *)feedbackURLAtCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel {
130+
return [self feedbackURLForStyleURL:nil atCenterCoordinate:centerCoordinate zoomLevel:zoomLevel];
131+
}
132+
133+
- (nullable NSURL *)feedbackURLForStyleURL:(nullable NSURL *)styleURL atCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel {
129134
if (!self.feedbackLink) {
130135
return nil;
131136
}
132-
133-
NSURLComponents *components = [NSURLComponents componentsWithURL:self.URL resolvingAgainstBaseURL:NO];
137+
138+
NSURLComponents *components = [NSURLComponents componentsWithString:@"https://www.mapbox.com/feedback/"];
134139
components.fragment = [NSString stringWithFormat:@"/%.5f/%.5f/%i",
135-
centerCoordinate.longitude, centerCoordinate.latitude, (int)round(zoomLevel + 1)];
140+
centerCoordinate.longitude, centerCoordinate.latitude, (int)round(zoomLevel)];
141+
142+
if ([styleURL.scheme isEqualToString:@"mapbox"] && [styleURL.host isEqualToString:@"styles"]) {
143+
NSArray<NSString *> *stylePathComponents = styleURL.pathComponents;
144+
if (stylePathComponents.count >= 3) {
145+
components.queryItems = @[
146+
[NSURLQueryItem queryItemWithName:@"owner" value:stylePathComponents[1]],
147+
[NSURLQueryItem queryItemWithName:@"id" value:stylePathComponents[2]],
148+
[NSURLQueryItem queryItemWithName:@"access_token" value:[MGLAccountManager accessToken]],
149+
];
150+
}
151+
}
152+
136153
return components.URL;
137154
}
138155

platform/darwin/src/MGLAttributionInfo_Private.h

+14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ NS_ASSUME_NONNULL_BEGIN
2020

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

23+
/**
24+
Returns a copy of the `URL` property modified to account for the given style
25+
URL, center coordinate, and zoom level.
26+
27+
@param styleURL The map’s style URL.
28+
@param centerCoordinate The map’s center coordinate.
29+
@param zoomLevel The map’s zoom level. See the `MGLMapView.zoomLevel` property
30+
for more information.
31+
@return A modified URL containing a fragment that points to the specified
32+
viewport. If the `feedbackLink` property is set to `NO`, this method returns
33+
`nil`.
34+
*/
35+
- (nullable NSURL *)feedbackURLForStyleURL:(nullable NSURL *)styleURL atCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel;
36+
2337
@end
2438

2539
@interface NSMutableArray (MGLAttributionInfoAdditions)

platform/darwin/test/MGLAttributionInfoTests.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ - (void)testParsing {
4747
XCTAssertEqualObjects(infos[3].URL, [NSURL URLWithString:@"https://www.mapbox.com/map-feedback/"]);
4848
XCTAssertTrue(infos[3].feedbackLink);
4949
XCTAssertEqualObjects([infos[3] feedbackURLAtCenterCoordinate:mapbox zoomLevel:14],
50-
[NSURL URLWithString:@"https://www.mapbox.com/map-feedback/#/77.63680/12.98108/15"]);
50+
[NSURL URLWithString:@"https://www.mapbox.com/feedback/#/77.63680/12.98108/14"]);
5151
}
5252

5353
- (void)testStyle {

platform/ios/src/MGLMapView.mm

+4-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
#import "MGLCompactCalloutView.h"
6565
#import "MGLAnnotationContainerView.h"
6666
#import "MGLAnnotationContainerView_Private.h"
67-
#import "MGLAttributionInfo.h"
67+
#import "MGLAttributionInfo_Private.h"
6868

6969
#include <algorithm>
7070
#include <cstdlib>
@@ -1907,8 +1907,9 @@ - (void)showAttribution
19071907
{
19081908
if (info.feedbackLink)
19091909
{
1910-
url = [info feedbackURLAtCenterCoordinate:self.centerCoordinate
1911-
zoomLevel:self.zoomLevel];
1910+
url = [info feedbackURLForStyleURL:self.styleURL
1911+
atCenterCoordinate:self.centerCoordinate
1912+
zoomLevel:self.zoomLevel];
19121913
}
19131914
[[UIApplication sharedApplication] openURL:url];
19141915
}

platform/macos/src/MGLMapView.mm

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#import "MGLMapView_Private.h"
2-
#import "MGLAnnotationImage_Private.h"
2+
33
#import "MGLAttributionButton.h"
4-
#import "MGLAttributionInfo.h"
54
#import "MGLCompassCell.h"
65
#import "MGLOpenGLLayer.h"
76
#import "MGLStyle.h"
87

8+
#import "MGLAnnotationImage_Private.h"
9+
#import "MGLAttributionInfo_Private.h"
910
#import "MGLFeature_Private.h"
11+
#import "MGLFoundation_Private.h"
1012
#import "MGLGeometry_Private.h"
1113
#import "MGLMultiPoint_Private.h"
1214
#import "MGLOfflineStorage_Private.h"
1315
#import "MGLStyle_Private.h"
14-
#import "MGLFoundation_Private.h"
1516

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

0 commit comments

Comments
 (0)