Authored by Justin R. Miller

fixes #122: added RMMBTilesSource centerCoordinate & centerZoom

@@ -57,10 +57,18 @@ @@ -57,10 +57,18 @@
57 57
58 /** @name Querying Tile Source Information */ 58 /** @name Querying Tile Source Information */
59 59
  60 +/** Any available HTML-formatted map legend data for the tile source, suitable for display in a UIWebView. */
  61 +- (NSString *)legend;
  62 +
  63 +/** A suggested starting center coordinate for the map layer. */
  64 +- (CLLocationCoordinate2D)centerCoordinate;
  65 +
  66 +/** A suggested starting center zoom level for the map layer. */
  67 +- (float)centerZoom;
  68 +
60 /** Returns YES if the tile source provides full-world coverage; otherwise, returns NO. */ 69 /** Returns YES if the tile source provides full-world coverage; otherwise, returns NO. */
61 - (BOOL)coversFullWorld; 70 - (BOOL)coversFullWorld;
62 71
63 -/** Any available HTML-formatted map legend data for the tile source, suitable for display in a UIWebView. */  
64 -- (NSString *)legend; 72 +
65 73
66 @end 74 @end
@@ -248,18 +248,6 @@ @@ -248,18 +248,6 @@
248 return bounds; 248 return bounds;
249 } 249 }
250 250
251 -- (BOOL)coversFullWorld  
252 -{  
253 - RMSphericalTrapezium ownBounds = [self latitudeLongitudeBoundingBox];  
254 - RMSphericalTrapezium defaultBounds = kMBTilesDefaultLatLonBoundingBox;  
255 -  
256 - if (ownBounds.southWest.longitude <= defaultBounds.southWest.longitude + 10 &&  
257 - ownBounds.northEast.longitude >= defaultBounds.northEast.longitude - 10)  
258 - return YES;  
259 -  
260 - return NO;  
261 -}  
262 -  
263 - (NSString *)legend 251 - (NSString *)legend
264 { 252 {
265 __block NSString *legend; 253 __block NSString *legend;
@@ -281,6 +269,57 @@ @@ -281,6 +269,57 @@
281 return legend; 269 return legend;
282 } 270 }
283 271
  272 +- (CLLocationCoordinate2D)centerCoordinate
  273 +{
  274 + __block CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(0, 0);
  275 +
  276 + [queue inDatabase:^(FMDatabase *db)
  277 + {
  278 + FMResultSet *results = [db executeQuery:@"select value from metadata where name = 'center'"];
  279 +
  280 + [results next];
  281 +
  282 + if ([results stringForColumn:@"value"] && [[[results stringForColumn:@"value"] componentsSeparatedByString:@","] count] >= 2)
  283 + centerCoordinate = CLLocationCoordinate2DMake([[[[results stringForColumn:@"value"] componentsSeparatedByString:@","] objectAtIndex:1] doubleValue],
  284 + [[[[results stringForColumn:@"value"] componentsSeparatedByString:@","] objectAtIndex:0] doubleValue]);
  285 +
  286 + [results close];
  287 + }];
  288 +
  289 + return centerCoordinate;
  290 +}
  291 +
  292 +- (float)centerZoom
  293 +{
  294 + __block CGFloat centerZoom = [self minZoom];
  295 +
  296 + [queue inDatabase:^(FMDatabase *db)
  297 + {
  298 + FMResultSet *results = [db executeQuery:@"select value from metadata where name = 'center'"];
  299 +
  300 + [results next];
  301 +
  302 + if ([results stringForColumn:@"value"] && [[[results stringForColumn:@"value"] componentsSeparatedByString:@","] count] >= 3)
  303 + centerZoom = [[[[results stringForColumn:@"value"] componentsSeparatedByString:@","] objectAtIndex:2] floatValue];
  304 +
  305 + [results close];
  306 + }];
  307 +
  308 + return centerZoom;
  309 +}
  310 +
  311 +- (BOOL)coversFullWorld
  312 +{
  313 + RMSphericalTrapezium ownBounds = [self latitudeLongitudeBoundingBox];
  314 + RMSphericalTrapezium defaultBounds = kMBTilesDefaultLatLonBoundingBox;
  315 +
  316 + if (ownBounds.southWest.longitude <= defaultBounds.southWest.longitude + 10 &&
  317 + ownBounds.northEast.longitude >= defaultBounds.northEast.longitude - 10)
  318 + return YES;
  319 +
  320 + return NO;
  321 +}
  322 +
284 - (void)didReceiveMemoryWarning 323 - (void)didReceiveMemoryWarning
285 { 324 {
286 NSLog(@"*** didReceiveMemoryWarning in %@", [self class]); 325 NSLog(@"*** didReceiveMemoryWarning in %@", [self class]);