Skip to content

Commit

Permalink
fixes Outdooractive#21: add image quality API support
Browse files Browse the repository at this point in the history
  • Loading branch information
incanus committed Nov 2, 2012
1 parent 1867055 commit d49a091
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
18 changes: 17 additions & 1 deletion MapView/Map/RMMapBoxSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,19 @@
#define kMapBoxDefaultLatLonBoundingBox ((RMSphericalTrapezium){ .northEast = { .latitude = 90, .longitude = 180 }, \
.southWest = { .latitude = -90, .longitude = -180 } })

@class RMMapView;
// constants for the image quality API (see http://mapbox.com/developers/api/#image_quality)
typedef enum : NSUInteger {
RMMapBoxSourceQualityFull = 0, // default
RMMapBoxSourceQualityPNG32 = 1, // 32 color indexed PNG
RMMapBoxSourceQualityPNG64 = 2, // 64 color indexed PNG
RMMapBoxSourceQualityPNG128 = 3, // 128 color indexed PNG
RMMapBoxSourceQualityPNG256 = 4, // 256 color indexed PNG
RMMapBoxSourceQualityJPEG70 = 5, // 70% quality JPEG
RMMapBoxSourceQualityJPEG80 = 6, // 80% quality JPEG
RMMapBoxSourceQualityJPEG90 = 7 // 90% quality JPEG
} RMMapBoxSourceQuality;

@class RMMapView;

/** An RMMapBoxSource is used to display map tiles from a network-based map hosted on [MapBox](http://mapbox.com/plans) or the open source [TileStream](https://github.com/mapbox/tilestream) software. Maps are reference by their [TileJSON](http://mapbox.com/developers/tilejson/) endpoint or file. */
@interface RMMapBoxSource : RMAbstractWebMapSource
Expand Down Expand Up @@ -86,4 +97,9 @@
/** Info about the TileJSON in a Cocoa-native format. */
@property (nonatomic, readonly, retain) NSDictionary *infoDictionary;

/** Image quality that is retrieved from the network. Useful for lower-bandwidth environments. The default is to provide full-quality imagery.
*
* Note that you may want to clear the tile cache after changing this value in order to provide a consistent experience. */
@property (nonatomic, assign) RMMapBoxSourceQuality imageQuality;

@end
57 changes: 56 additions & 1 deletion MapView/Map/RMMapBoxSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ - (id)initWithInfo:(NSDictionary *)info;

@implementation RMMapBoxSource

@synthesize infoDictionary=_infoDictionary;
@synthesize infoDictionary=_infoDictionary, imageQuality=_imageQuality;

- (id)initWithTileJSON:(NSString *)tileJSON
{
Expand Down Expand Up @@ -190,6 +190,61 @@ - (NSURL *)URLForTile:(RMTile)tile
tileURLString = [tileURLString stringByReplacingOccurrencesOfString:@"{x}" withString:[[NSNumber numberWithInteger:x] stringValue]];
tileURLString = [tileURLString stringByReplacingOccurrencesOfString:@"{y}" withString:[[NSNumber numberWithInteger:y] stringValue]];

if (_imageQuality != RMMapBoxSourceQualityFull)
{
NSString *qualityExtension;

switch (_imageQuality)
{
case RMMapBoxSourceQualityPNG32:
{
qualityExtension = @".png32";
break;
}
case RMMapBoxSourceQualityPNG64:
{
qualityExtension = @".png64";
break;
}
case RMMapBoxSourceQualityPNG128:
{
qualityExtension = @".png128";
break;
}
case RMMapBoxSourceQualityPNG256:
{
qualityExtension = @".png256";
break;
}
case RMMapBoxSourceQualityJPEG70:
{
qualityExtension = @".jpg70";
break;
}
case RMMapBoxSourceQualityJPEG80:
{
qualityExtension = @".jpg80";
break;
}
case RMMapBoxSourceQualityJPEG90:
{
qualityExtension = @".jpg90";
break;
}
case RMMapBoxSourceQualityFull:
default:
{
qualityExtension = @".png";
break;
}
}

tileURLString = [tileURLString stringByReplacingOccurrencesOfString:@".png"
withString:qualityExtension
options:NSAnchoredSearch | NSBackwardsSearch
range:NSMakeRange(0, [tileURLString length])];
}

return [NSURL URLWithString:tileURLString];
}

Expand Down

0 comments on commit d49a091

Please sign in to comment.