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

Commit a39116a

Browse files
authored
Migrate to GL JS–powered feedback form (#9078)
* [ios, macos] Updated feedback URL * [ios, macos] Add referrer, heading, pitch to feedback URL * [ios, macos] Updated changelogs for feedback changes * [ios] Vary referrer by platform
1 parent 608fd66 commit a39116a

10 files changed

+89
-24
lines changed

platform/darwin/src/MGLAttributionInfo.mm

+27-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
#import <Cocoa/Cocoa.h>
77
#endif
88

9+
#import "MGLAccountManager.h"
910
#import "MGLMapCamera.h"
1011
#import "NSArray+MGLAdditions.h"
12+
#import "NSBundle+MGLAdditions.h"
1113
#import "NSString+MGLAdditions.h"
1214

1315
#include <string>
@@ -126,13 +128,34 @@ - (instancetype)initWithTitle:(NSAttributedString *)title URL:(NSURL *)URL {
126128
}
127129

128130
- (nullable NSURL *)feedbackURLAtCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel {
131+
return [self feedbackURLForStyleURL:nil atCenterCoordinate:centerCoordinate zoomLevel:zoomLevel direction:0 pitch:0];
132+
}
133+
134+
- (nullable NSURL *)feedbackURLForStyleURL:(nullable NSURL *)styleURL atCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel direction:(CLLocationDirection)direction pitch:(CGFloat)pitch {
129135
if (!self.feedbackLink) {
130136
return nil;
131137
}
132-
133-
NSURLComponents *components = [NSURLComponents componentsWithURL:self.URL resolvingAgainstBaseURL:NO];
134-
components.fragment = [NSString stringWithFormat:@"/%.5f/%.5f/%i",
135-
centerCoordinate.longitude, centerCoordinate.latitude, (int)round(zoomLevel + 1)];
138+
139+
NSURLComponents *components = [NSURLComponents componentsWithString:@"https://www.mapbox.com/feedback/"];
140+
components.fragment = [NSString stringWithFormat:@"/%.5f/%.5f/%.2f/%.1f/%i",
141+
centerCoordinate.longitude, centerCoordinate.latitude, zoomLevel,
142+
direction, (int)round(pitch)];
143+
144+
NSURLQueryItem *referrerQueryItem = [NSURLQueryItem queryItemWithName:@"referrer"
145+
value:[NSBundle mgl_applicationBundleIdentifier]];
146+
NSMutableArray<NSURLQueryItem *> *queryItems = [NSMutableArray arrayWithObject:referrerQueryItem];
147+
if ([styleURL.scheme isEqualToString:@"mapbox"] && [styleURL.host isEqualToString:@"styles"]) {
148+
NSArray<NSString *> *stylePathComponents = styleURL.pathComponents;
149+
if (stylePathComponents.count >= 3) {
150+
[queryItems addObjectsFromArray:@[
151+
[NSURLQueryItem queryItemWithName:@"owner" value:stylePathComponents[1]],
152+
[NSURLQueryItem queryItemWithName:@"id" value:stylePathComponents[2]],
153+
[NSURLQueryItem queryItemWithName:@"access_token" value:[MGLAccountManager accessToken]],
154+
]];
155+
}
156+
}
157+
components.queryItems = queryItems;
158+
136159
return components.URL;
137160
}
138161

platform/darwin/src/MGLAttributionInfo_Private.h

+18
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ 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+
@param direction The heading of the map, measured in degrees clockwise from
32+
true north.
33+
@param pitch Pitch toward the horizon measured in degrees, with 0 degrees
34+
resulting in a two-dimensional map.
35+
@return A modified URL containing a fragment that points to the specified
36+
viewport. If the `feedbackLink` property is set to `NO`, this method returns
37+
`nil`.
38+
*/
39+
- (nullable NSURL *)feedbackURLForStyleURL:(nullable NSURL *)styleURL atCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel direction:(CLLocationDirection)direction pitch:(CGFloat)pitch;
40+
2341
@end
2442

2543
@interface NSMutableArray (MGLAttributionInfoAdditions)

platform/darwin/src/MGLOfflineStorage.mm

+3-11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#import "MGLOfflinePack_Private.h"
88
#import "MGLOfflineRegion_Private.h"
99
#import "MGLTilePyramidOfflineRegion.h"
10+
#import "NSBundle+MGLAdditions.h"
1011
#import "NSValue+MGLAdditions.h"
1112

1213
#include <mbgl/util/string.hpp>
@@ -132,7 +133,7 @@ + (NSURL *)cacheURLIncludingSubdirectory:(BOOL)useSubdirectory {
132133
appropriateForURL:nil
133134
create:YES
134135
error:nil];
135-
NSString *bundleIdentifier = [self bundleIdentifier];
136+
NSString *bundleIdentifier = [NSBundle mgl_applicationBundleIdentifier];
136137
if (!bundleIdentifier) {
137138
// There’s no main bundle identifier when running in a unit test bundle.
138139
bundleIdentifier = [NSBundle bundleForClass:self].bundleIdentifier;
@@ -166,7 +167,7 @@ + (NSString *)legacyCachePath {
166167
NSString *legacyCachePath = [legacyPaths.firstObject stringByAppendingPathComponent:MGLOfflineStorageFileName3_2_0_beta_1];
167168
#elif TARGET_OS_MAC
168169
// ~/Library/Caches/tld.app.bundle.id/offline.db
169-
NSString *bundleIdentifier = [self bundleIdentifier];
170+
NSString *bundleIdentifier = [NSBundle mgl_applicationBundleIdentifier];
170171
NSURL *legacyCacheDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory
171172
inDomain:NSUserDomainMask
172173
appropriateForURL:nil
@@ -219,15 +220,6 @@ - (instancetype)init {
219220
return self;
220221
}
221222

222-
+ (NSString *)bundleIdentifier {
223-
NSString *bundleIdentifier = [NSBundle mainBundle].bundleIdentifier;
224-
if (!bundleIdentifier) {
225-
// There’s no main bundle identifier when running in a unit test bundle.
226-
bundleIdentifier = [NSBundle bundleForClass:self].bundleIdentifier;
227-
}
228-
return bundleIdentifier;
229-
}
230-
231223
- (void)dealloc {
232224
[[NSNotificationCenter defaultCenter] removeObserver:self];
233225
[[MGLNetworkConfiguration sharedManager] removeObserver:self forKeyPath:@"apiBaseURL"];

platform/darwin/src/NSBundle+MGLAdditions.h

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ NS_ASSUME_NONNULL_BEGIN
3636

3737
+ (nullable NS_DICTIONARY_OF(NSString *, id) *)mgl_frameworkInfoDictionary;
3838

39+
+ (nullable NSString *)mgl_applicationBundleIdentifier;
40+
3941
@end
4042

4143
NS_ASSUME_NONNULL_END

platform/darwin/src/NSBundle+MGLAdditions.m

+9
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,13 @@ + (nullable NSString *)mgl_frameworkBundleIdentifier {
3131
return bundle.infoDictionary;
3232
}
3333

34+
+ (nullable NSString *)mgl_applicationBundleIdentifier {
35+
NSString *bundleIdentifier = [NSBundle mainBundle].bundleIdentifier;
36+
if (!bundleIdentifier) {
37+
// There’s no main bundle identifier when running in a unit test bundle.
38+
bundleIdentifier = [NSBundle bundleForClass:[MGLAccountManager class]].bundleIdentifier;
39+
}
40+
return bundleIdentifier;
41+
}
42+
3443
@end

platform/darwin/test/MGLAttributionInfoTests.m

+11-1
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,18 @@ - (void)testParsing {
4646
XCTAssertEqualObjects(infos[3].title.string, @"Improve this map");
4747
XCTAssertEqualObjects(infos[3].URL, [NSURL URLWithString:@"https://www.mapbox.com/map-feedback/"]);
4848
XCTAssertTrue(infos[3].feedbackLink);
49+
NSURL *styleURL = [MGLStyle satelliteStreetsStyleURLWithVersion:99];
50+
#if TARGET_OS_IPHONE
51+
XCTAssertEqualObjects([infos[3] feedbackURLAtCenterCoordinate:mapbox zoomLevel:14],
52+
[NSURL URLWithString:@"https://www.mapbox.com/feedback/?referrer=com.mapbox.sdk.ios#/77.63680/12.98108/14.00/0.0/0"]);
53+
XCTAssertEqualObjects([infos[3] feedbackURLForStyleURL:styleURL atCenterCoordinate:mapbox zoomLevel:3.14159 direction:90.9 pitch:12.5],
54+
[NSURL URLWithString:@"https://www.mapbox.com/feedback/?referrer=com.mapbox.sdk.ios&owner=mapbox&id=satellite-streets-v99&access_token#/77.63680/12.98108/3.14/90.9/13"]);
55+
#else
4956
XCTAssertEqualObjects([infos[3] feedbackURLAtCenterCoordinate:mapbox zoomLevel:14],
50-
[NSURL URLWithString:@"https://www.mapbox.com/map-feedback/#/77.63680/12.98108/15"]);
57+
[NSURL URLWithString:@"https://www.mapbox.com/feedback/?referrer=com.mapbox.MapboxGL#/77.63680/12.98108/14.00/0.0/0"]);
58+
XCTAssertEqualObjects([infos[3] feedbackURLForStyleURL:styleURL atCenterCoordinate:mapbox zoomLevel:3.14159 direction:90.9 pitch:12.5],
59+
[NSURL URLWithString:@"https://www.mapbox.com/feedback/?referrer=com.mapbox.MapboxGL&owner=mapbox&id=satellite-streets-v99&access_token#/77.63680/12.98108/3.14/90.9/13"]);
60+
#endif
5161
}
5262

5363
- (void)testStyle {

platform/ios/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
3737
* Fixed an issue where gesture recognizers associated with map view interactivity were not disabled when their related interactions were disabled. ([#8304](https://github.com/mapbox/mapbox-gl-native/pull/8304))
3838
* Fixed an issue preventing the Mapbox Telemetry confirmation dialog from appearing when opened from within a map view in a modal view controller. ([#9027](https://github.com/mapbox/mapbox-gl-native/pull/9027))
3939
* Corrected the size of MGLMapView’s compass. ([#9060](https://github.com/mapbox/mapbox-gl-native/pull/9060))
40+
* The Improve This Map button in the attribution action sheet now leads to a feedback tool that matches MGLMapView’s rotation and pitch. `-[MGLAttributionInfo feedbackURLAtCenterCoordinate:zoomLevel:]` no longer respects the feedback URL specified in TileJSON. ([#9078](https://github.com/mapbox/mapbox-gl-native/pull/9078))
4041

4142
### Other changes
4243

platform/ios/src/MGLMapView.mm

+7-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>
@@ -1895,8 +1895,12 @@ - (void)showAttribution
18951895
{
18961896
if (info.feedbackLink)
18971897
{
1898-
url = [info feedbackURLAtCenterCoordinate:self.centerCoordinate
1899-
zoomLevel:self.zoomLevel];
1898+
MGLMapCamera *camera = self.camera;
1899+
url = [info feedbackURLForStyleURL:self.styleURL
1900+
atCenterCoordinate:camera.centerCoordinate
1901+
zoomLevel:self.zoomLevel
1902+
direction:camera.heading
1903+
pitch:camera.pitch];
19001904
}
19011905
[[UIApplication sharedApplication] openURL:url];
19021906
}

platform/macos/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* Fixed a crash when calling `MGLMultiPolygon.coordinate` [#8713](https://github.com/mapbox/mapbox-gl-native/pull/8713)
2626
* Fixed an issue causing attribution button text to appear blue instead of black. ([#8701](https://github.com/mapbox/mapbox-gl-native/pull/8701))
2727
* Fixed a crash or console spew when MGLMapView is initialized with a frame smaller than 64 points wide by 64 points tall. ([#8562](https://github.com/mapbox/mapbox-gl-native/pull/8562))
28+
* The Improve This Map button in the attribution action sheet now leads to a feedback tool that matches MGLMapView’s rotation and pitch. `-[MGLAttributionInfo feedbackURLAtCenterCoordinate:zoomLevel:]` no longer respects the feedback URL specified in TileJSON. ([#9078](https://github.com/mapbox/mapbox-gl-native/pull/9078))
2829
* The error passed into `-[MGLMapViewDelegate mapViewDidFailLoadingMap:withError:]` now includes a more specific description and failure reason. ([#8418](https://github.com/mapbox/mapbox-gl-native/pull/8418))
2930
* The `MGLPolyline.coordinate` and `MGLPolygon.coordinate` properties now return the midpoint and centroid, respectively, instead of the first coordinate. ([#8713](https://github.com/mapbox/mapbox-gl-native/pull/8713))
3031
* Improved CPU and battery performance while animating a tilted map’s camera in an area with many labels. ([#9031](https://github.com/mapbox/mapbox-gl-native/pull/9031))

platform/macos/src/MGLMapView.mm

+10-5
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"
@@ -1735,11 +1736,15 @@ - (IBAction)rotate:(NSSlider *)sender {
17351736
}
17361737

17371738
- (IBAction)giveFeedback:(id)sender {
1738-
CLLocationCoordinate2D centerCoordinate = self.centerCoordinate;
1739+
MGLMapCamera *camera = self.camera;
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
1744+
atCenterCoordinate:camera.centerCoordinate
1745+
zoomLevel:zoomLevel
1746+
direction:camera.heading
1747+
pitch:camera.pitch];
17431748
if (url) {
17441749
[urls addObject:url];
17451750
}

0 commit comments

Comments
 (0)