diff --git a/MapView/Map/RMMapBoxSource.h b/MapView/Map/RMMapBoxSource.h index d8238d275..3a17c38d3 100644 --- a/MapView/Map/RMMapBoxSource.h +++ b/MapView/Map/RMMapBoxSource.h @@ -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 @@ -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 diff --git a/MapView/Map/RMMapBoxSource.m b/MapView/Map/RMMapBoxSource.m index cb302480f..523d6e773 100644 --- a/MapView/Map/RMMapBoxSource.m +++ b/MapView/Map/RMMapBoxSource.m @@ -48,7 +48,7 @@ - (id)initWithInfo:(NSDictionary *)info; @implementation RMMapBoxSource -@synthesize infoDictionary=_infoDictionary; +@synthesize infoDictionary=_infoDictionary, imageQuality=_imageQuality; - (id)initWithTileJSON:(NSString *)tileJSON { @@ -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]; }