Authored by Justin R. Miller

fixes #468: support v4 + access tokens

... ... @@ -51,6 +51,8 @@
* Example: `MyMapApp/1.2` */
@property (nonatomic, retain) NSString *userAgent;
@property (nonatomic, retain) NSString *accessToken;
@end
#pragma mark -
... ...
... ... @@ -85,6 +85,7 @@ static RMConfiguration *RMConfigurationSharedInstance = nil;
}
@synthesize userAgent=_userAgent;
@synthesize accessToken=_accessToken;
+ (instancetype)configuration
{
... ...
... ... @@ -538,8 +538,17 @@ RMTilePoint RMInteractiveSourceNormalizedTilePointForMapView(CGPoint point, RMMa
// ensure JSONP format
//
if ( ! [gridURLString hasSuffix:@"?callback=grid"])
gridURLString = [gridURLString stringByAppendingString:@"?callback=grid"];
if (NSEqualRanges([gridURLString rangeOfString:@"callback=grid"], NSMakeRange(NSNotFound, 0)))
{
if ([[NSURL URLWithString:gridURLString] query])
{
gridURLString = [gridURLString stringByAppendingString:@"&callback=grid"];
}
else
{
gridURLString = [gridURLString stringByAppendingString:@"?callback=grid"];
}
}
// get the data for this tile
//
... ...
... ... @@ -168,9 +168,7 @@
- (id)initWithMapID:(NSString *)mapID enablingDataOnMapView:(RMMapView *)mapView
{
NSString *referenceURLString = [NSString stringWithFormat:@"https://api.tiles.mapbox.com/v3/%@.json", mapID];
return [self initWithReferenceURL:[NSURL URLWithString:referenceURLString] enablingDataOnMapView:mapView];
return [self initWithReferenceURL:[self canonicalURLForMapID:mapID] enablingDataOnMapView:mapView];
}
- (void)dealloc
... ... @@ -183,9 +181,17 @@
#pragma mark
- (NSURL *)canonicalURLForMapID:(NSString *)mapID
{
NSString *version = ([[RMConfiguration configuration] accessToken] ? @"v4" : @"v3");
NSString *accessToken = ([[RMConfiguration configuration] accessToken] ? [@"&access_token=" stringByAppendingString:[[RMConfiguration configuration] accessToken]] : @"");
return [NSURL URLWithString:[NSString stringWithFormat:@"https://api.tiles.mapbox.com/%@/%@.json?secure%@", version, mapID, accessToken]];
}
- (NSURL *)tileJSONURL
{
return [NSURL URLWithString:[NSString stringWithFormat:@"https://api.tiles.mapbox.com/v3/%@.json", self.infoDictionary[@"id"]]];
return [self canonicalURLForMapID:self.infoDictionary[@"id"]];
}
- (NSURL *)URLForTile:(RMTile)tile
... ...
... ... @@ -140,13 +140,17 @@
- (id)initWithMapboxMarkerImage:(NSString *)symbolName tintColorHex:(NSString *)colorHex sizeString:(NSString *)sizeString
{
BOOL useRetina = ([[UIScreen mainScreen] scale] > 1.0);
NSURL *imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.tiles.mapbox.com/v3/marker/pin-%@%@%@%@.png",
NSString *version = ([[RMConfiguration configuration] accessToken] ? @"v4" : @"v3");
NSString *accessToken = ([[RMConfiguration configuration] accessToken] ? [@"?access_token=" stringByAppendingString:[[RMConfiguration configuration] accessToken]] : @"");
BOOL useRetina = ([[UIScreen mainScreen] scale] > 1.0);
NSURL *imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.tiles.mapbox.com/%@/marker/pin-%@%@%@%@.png%@",
version,
(sizeString ? [sizeString substringToIndex:1] : @"m"),
(symbolName ? [@"-" stringByAppendingString:symbolName] : @""),
(colorHex ? [@"+" stringByAppendingString:[colorHex stringByReplacingOccurrencesOfString:@"#" withString:@""]] : @"+ff0000"),
(useRetina ? @"@2x" : @"")]];
(useRetina ? @"@2x" : @""),
accessToken]];
UIImage *image = nil;
... ...