fixes #21: add image quality API support
Showing
2 changed files
with
73 additions
and
2 deletions
@@ -39,8 +39,19 @@ | @@ -39,8 +39,19 @@ | ||
39 | #define kMapBoxDefaultLatLonBoundingBox ((RMSphericalTrapezium){ .northEast = { .latitude = 90, .longitude = 180 }, \ | 39 | #define kMapBoxDefaultLatLonBoundingBox ((RMSphericalTrapezium){ .northEast = { .latitude = 90, .longitude = 180 }, \ |
40 | .southWest = { .latitude = -90, .longitude = -180 } }) | 40 | .southWest = { .latitude = -90, .longitude = -180 } }) |
41 | 41 | ||
42 | -@class RMMapView; | 42 | +// constants for the image quality API (see http://mapbox.com/developers/api/#image_quality) |
43 | +typedef enum : NSUInteger { | ||
44 | + RMMapBoxSourceQualityFull = 0, // default | ||
45 | + RMMapBoxSourceQualityPNG32 = 1, // 32 color indexed PNG | ||
46 | + RMMapBoxSourceQualityPNG64 = 2, // 64 color indexed PNG | ||
47 | + RMMapBoxSourceQualityPNG128 = 3, // 128 color indexed PNG | ||
48 | + RMMapBoxSourceQualityPNG256 = 4, // 256 color indexed PNG | ||
49 | + RMMapBoxSourceQualityJPEG70 = 5, // 70% quality JPEG | ||
50 | + RMMapBoxSourceQualityJPEG80 = 6, // 80% quality JPEG | ||
51 | + RMMapBoxSourceQualityJPEG90 = 7 // 90% quality JPEG | ||
52 | +} RMMapBoxSourceQuality; | ||
43 | 53 | ||
54 | +@class RMMapView; | ||
44 | 55 | ||
45 | /** 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. */ | 56 | /** 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. */ |
46 | @interface RMMapBoxSource : RMAbstractWebMapSource | 57 | @interface RMMapBoxSource : RMAbstractWebMapSource |
@@ -86,4 +97,9 @@ | @@ -86,4 +97,9 @@ | ||
86 | /** Info about the TileJSON in a Cocoa-native format. */ | 97 | /** Info about the TileJSON in a Cocoa-native format. */ |
87 | @property (nonatomic, readonly, retain) NSDictionary *infoDictionary; | 98 | @property (nonatomic, readonly, retain) NSDictionary *infoDictionary; |
88 | 99 | ||
100 | +/** Image quality that is retrieved from the network. Useful for lower-bandwidth environments. The default is to provide full-quality imagery. | ||
101 | +* | ||
102 | +* Note that you may want to clear the tile cache after changing this value in order to provide a consistent experience. */ | ||
103 | +@property (nonatomic, assign) RMMapBoxSourceQuality imageQuality; | ||
104 | + | ||
89 | @end | 105 | @end |
@@ -48,7 +48,7 @@ | @@ -48,7 +48,7 @@ | ||
48 | 48 | ||
49 | @implementation RMMapBoxSource | 49 | @implementation RMMapBoxSource |
50 | 50 | ||
51 | -@synthesize infoDictionary=_infoDictionary; | 51 | +@synthesize infoDictionary=_infoDictionary, imageQuality=_imageQuality; |
52 | 52 | ||
53 | - (id)initWithTileJSON:(NSString *)tileJSON | 53 | - (id)initWithTileJSON:(NSString *)tileJSON |
54 | { | 54 | { |
@@ -190,6 +190,61 @@ | @@ -190,6 +190,61 @@ | ||
190 | tileURLString = [tileURLString stringByReplacingOccurrencesOfString:@"{x}" withString:[[NSNumber numberWithInteger:x] stringValue]]; | 190 | tileURLString = [tileURLString stringByReplacingOccurrencesOfString:@"{x}" withString:[[NSNumber numberWithInteger:x] stringValue]]; |
191 | tileURLString = [tileURLString stringByReplacingOccurrencesOfString:@"{y}" withString:[[NSNumber numberWithInteger:y] stringValue]]; | 191 | tileURLString = [tileURLString stringByReplacingOccurrencesOfString:@"{y}" withString:[[NSNumber numberWithInteger:y] stringValue]]; |
192 | 192 | ||
193 | + if (_imageQuality != RMMapBoxSourceQualityFull) | ||
194 | + { | ||
195 | + NSString *qualityExtension; | ||
196 | + | ||
197 | + switch (_imageQuality) | ||
198 | + { | ||
199 | + case RMMapBoxSourceQualityPNG32: | ||
200 | + { | ||
201 | + qualityExtension = @".png32"; | ||
202 | + break; | ||
203 | + } | ||
204 | + case RMMapBoxSourceQualityPNG64: | ||
205 | + { | ||
206 | + qualityExtension = @".png64"; | ||
207 | + break; | ||
208 | + } | ||
209 | + case RMMapBoxSourceQualityPNG128: | ||
210 | + { | ||
211 | + qualityExtension = @".png128"; | ||
212 | + break; | ||
213 | + } | ||
214 | + case RMMapBoxSourceQualityPNG256: | ||
215 | + { | ||
216 | + qualityExtension = @".png256"; | ||
217 | + break; | ||
218 | + } | ||
219 | + case RMMapBoxSourceQualityJPEG70: | ||
220 | + { | ||
221 | + qualityExtension = @".jpg70"; | ||
222 | + break; | ||
223 | + } | ||
224 | + case RMMapBoxSourceQualityJPEG80: | ||
225 | + { | ||
226 | + qualityExtension = @".jpg80"; | ||
227 | + break; | ||
228 | + } | ||
229 | + case RMMapBoxSourceQualityJPEG90: | ||
230 | + { | ||
231 | + qualityExtension = @".jpg90"; | ||
232 | + break; | ||
233 | + } | ||
234 | + case RMMapBoxSourceQualityFull: | ||
235 | + default: | ||
236 | + { | ||
237 | + qualityExtension = @".png"; | ||
238 | + break; | ||
239 | + } | ||
240 | + } | ||
241 | + | ||
242 | + tileURLString = [tileURLString stringByReplacingOccurrencesOfString:@".png" | ||
243 | + withString:qualityExtension | ||
244 | + options:NSAnchoredSearch | NSBackwardsSearch | ||
245 | + range:NSMakeRange(0, [tileURLString length])]; | ||
246 | + } | ||
247 | + | ||
193 | return [NSURL URLWithString:tileURLString]; | 248 | return [NSURL URLWithString:tileURLString]; |
194 | } | 249 | } |
195 | 250 |
-
Please register or login to post a comment