|
6 | 6 | #import <Cocoa/Cocoa.h>
|
7 | 7 | #endif
|
8 | 8 |
|
| 9 | +#import "MGLAccountManager.h" |
9 | 10 | #import "MGLMapCamera.h"
|
10 | 11 | #import "NSArray+MGLAdditions.h"
|
| 12 | +#import "NSBundle+MGLAdditions.h" |
11 | 13 | #import "NSString+MGLAdditions.h"
|
12 | 14 |
|
13 | 15 | #include <string>
|
@@ -126,13 +128,34 @@ - (instancetype)initWithTitle:(NSAttributedString *)title URL:(NSURL *)URL {
|
126 | 128 | }
|
127 | 129 |
|
128 | 130 | - (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 { |
129 | 135 | if (!self.feedbackLink) {
|
130 | 136 | return nil;
|
131 | 137 | }
|
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 | + |
136 | 159 | return components.URL;
|
137 | 160 | }
|
138 | 161 |
|
|
0 commit comments