Authored by Thomas Rasch

o Some tile sources cleanup and reorganization

... ... @@ -33,7 +33,7 @@
//
// http://mbtiles.org
//
// Example usage at https://github.com/mapbox/mbtiles-ios-example
// See samples/MBTilesDemo for example usage
//
#import <Foundation/Foundation.h>
... ...
... ... @@ -46,19 +46,19 @@
{
if ( ! [super init])
return nil;
tileProjection = [[RMFractalTileProjection alloc] initFromProjection:[self projection]
tileSideLength:kMBTilesDefaultTileSize
maxZoom:kMBTilesDefaultMaxTileZoom
minZoom:kMBTilesDefaultMinTileZoom];
queue = [[FMDatabaseQueue databaseQueueWithPath:[tileSetURL relativePath]] retain];
if ( ! queue)
return nil;
[[queue database] setShouldCacheStatements:YES];
return self;
}
... ... @@ -93,9 +93,9 @@
NSInteger zoom = tile.zoom;
NSInteger x = tile.x;
NSInteger y = pow(2, zoom) - tile.y - 1;
__block UIImage *image;
[queue inDatabase:^(FMDatabase *db)
{
FMResultSet *results = [db executeQuery:@"select tile_data from tiles where zoom_level = ? and tile_column = ? and tile_row = ?",
... ... @@ -105,17 +105,16 @@
if ([db hadError])
image = [RMTileImage errorTile];
[results next];
NSData *data = [results dataForColumn:@"tile_data"];
if ( ! data)
image = [RMTileImage errorTile];
else
image = [UIImage imageWithData:data];
[results close];
}];
... ... @@ -150,42 +149,42 @@
- (float)minZoom
{
__block double minZoom;
[queue inDatabase:^(FMDatabase *db)
{
FMResultSet *results = [db executeQuery:@"select min(zoom_level) from tiles"];
if ([db hadError])
minZoom = kMBTilesDefaultMinTileZoom;
[results next];
minZoom = [results doubleForColumnIndex:0];
[results close];
}];
return minZoom;
}
- (float)maxZoom
{
__block double maxZoom;
[queue inDatabase:^(FMDatabase *db)
{
FMResultSet *results = [db executeQuery:@"select max(zoom_level) from tiles"];
if ([db hadError])
maxZoom = kMBTilesDefaultMaxTileZoom;
[results next];
maxZoom = [results doubleForColumnIndex:0];
[results close];
}];
return maxZoom;
}
... ... @@ -202,21 +201,21 @@
- (RMSphericalTrapezium)latitudeLongitudeBoundingBox
{
__block RMSphericalTrapezium bounds = kMBTilesDefaultLatLonBoundingBox;
[queue inDatabase:^(FMDatabase *db)
{
FMResultSet *results = [db executeQuery:@"select value from metadata where name = 'bounds'"];
[results next];
NSString *boundsString = [results stringForColumnIndex:0];
[results close];
if (boundsString)
{
NSArray *parts = [boundsString componentsSeparatedByString:@","];
if ([parts count] == 4)
{
bounds.southWest.longitude = [[parts objectAtIndex:0] doubleValue];
... ... @@ -225,9 +224,8 @@
bounds.northEast.latitude = [[parts objectAtIndex:3] doubleValue];
}
}
}];
return bounds;
}
... ... @@ -235,18 +233,18 @@
{
RMSphericalTrapezium ownBounds = [self latitudeLongitudeBoundingBox];
RMSphericalTrapezium defaultBounds = kMBTilesDefaultLatLonBoundingBox;
if (ownBounds.southWest.longitude <= defaultBounds.southWest.longitude + 10 &&
ownBounds.northEast.longitude >= defaultBounds.northEast.longitude - 10)
return YES;
return NO;
}
- (NSString *)legend
{
__block NSString *legend;
[queue inDatabase:^(FMDatabase *db)
{
FMResultSet *results = [db executeQuery:@"select value from metadata where name = 'legend'"];
... ... @@ -260,7 +258,7 @@
[results close];
}];
return legend;
}
... ... @@ -277,49 +275,49 @@
- (NSString *)shortName
{
__block NSString *shortName;
[queue inDatabase:^(FMDatabase *db)
{
FMResultSet *results = [db executeQuery:@"select value from metadata where name = 'name'"];
if ([db hadError])
shortName = nil;
[results next];
shortName = [results stringForColumnIndex:0];
[results close];
}];
return shortName;
}
- (NSString *)longDescription
{
__block NSString *description;
[queue inDatabase:^(FMDatabase *db)
{
FMResultSet *results = [db executeQuery:@"select value from metadata where name = 'description'"];
if ([db hadError])
description = nil;
[results next];
description = [results stringForColumnIndex:0];
[results close];
}];
return [NSString stringWithFormat:@"%@ - %@", [self shortName], description];
}
- (NSString *)shortAttribution
{
__block NSString *attribution;
[queue inDatabase:^(FMDatabase *db)
{
FMResultSet *results = [db executeQuery:@"select value from metadata where name = 'attribution'"];
... ... @@ -333,7 +331,7 @@
[results close];
}];
return attribution;
}
... ...
//
// RMMapQuestOSMSource.h
//
// Copyright (c) 2008-2011, Route-Me Contributors
// Copyright (c) 2008-2012, Route-Me Contributors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
... ... @@ -29,4 +29,4 @@
@interface RMMapQuestOSMSource : RMAbstractWebMapSource
@end
\ No newline at end of file
@end
... ...
//
// RMMapQuestOSMSource.m
//
// Copyright (c) 2008-2011, Route-Me Contributors
// Copyright (c) 2008-2012, Route-Me Contributors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
... ... @@ -29,13 +29,14 @@
@implementation RMMapQuestOSMSource
-(id) init
- (id)init
{
if(self = [super init])
{
[self setMaxZoom:18];
[self setMinZoom:1];
}
if (!(self = [super init]))
return nil;
[self setMaxZoom:18];
[self setMinZoom:1];
return self;
}
... ... @@ -44,27 +45,31 @@
NSAssert4(((tile.zoom >= self.minZoom) && (tile.zoom <= self.maxZoom)),
@"%@ tried to retrieve tile with zoomLevel %d, outside source's defined range %f to %f",
self, tile.zoom, self.minZoom, self.maxZoom);
return [NSURL URLWithString:[NSString stringWithFormat:@"http://otile1.mqcdn.com/tiles/1.0.0/osm/%d/%d/%d.png", tile.zoom, tile.x, tile.y]];
}
-(NSString*) uniqueTilecacheKey
- (NSString *)uniqueTilecacheKey
{
return @"MapQuestOSM";
}
-(NSString *)shortName
- (NSString *)shortName
{
return @"MapQuest";
}
-(NSString *)longDescription
- (NSString *)longDescription
{
return @"Map tiles courtesy of MapQuest.";
}
-(NSString *)shortAttribution
- (NSString *)shortAttribution
{
return @"Tiles courtesy of MapQuest.";
}
-(NSString *)longAttribution
- (NSString *)longAttribution
{
return @"Tiles courtesy of MapQuest and OpenStreetMap contributors.";
}
... ...
//
// OpenCycleMapSource.h
//
// Copyright (c) 2008, Route-Me Contributors
// Copyright (c) 2008-2012, Route-Me Contributors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
... ... @@ -32,6 +32,7 @@
Provides key-based access to tiles from the Open Cycle Map project.
*/
@interface RMOpenCycleMapSource : RMAbstractWebMapSource
@end
\ No newline at end of file
@end
... ...
//
// OpenCycleMapSource.m
//
// Copyright (c) 2008-2009, Route-Me Contributors
// Copyright (c) 2008-2012, Route-Me Contributors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
... ... @@ -70,7 +70,7 @@
return @"© OpenCycleMap CC-BY-SA";
}
-(NSString *)longAttribution
- (NSString *)longAttribution
{
return @"Map data © OpenCycleMap, licensed under Creative Commons Share Alike By Attribution.";
}
... ...
//
// RMOpenSeaMapSource.h
//
// Copyright (c) 2008-2009, Route-Me Contributors
// Copyright (c) 2008-2012, Route-Me Contributors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
... ...
//
// RMOpenSeaMapSource.m
//
// Copyright (c) 2008-2009, Route-Me Contributors
// Copyright (c) 2008-2012, Route-Me Contributors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
... ... @@ -73,7 +73,7 @@
return @"© OpenStreetMap CC-BY-SA";
}
-(NSString *)longAttribution
- (NSString *)longAttribution
{
return @"Map data © OpenStreetMap, licensed under Creative Commons Share Alike By Attribution.";
}
... ...
//
// OpenStreetMapsSource.h
//
// Copyright (c) 2008-2009, Route-Me Contributors
// Copyright (c) 2008-2012, Route-Me Contributors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
... ... @@ -32,6 +32,7 @@
Provides key-based access to tiles from the Open Street Map project.
*/
@interface RMOpenStreetMapSource : RMAbstractWebMapSource
@end
... ...
//
// OpenStreetMapsSource.m
//
// Copyright (c) 2008-2009, Route-Me Contributors
// Copyright (c) 2008-2012, Route-Me Contributors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
... ... @@ -70,7 +70,7 @@
return @"© OpenStreetMap CC-BY-SA";
}
-(NSString *)longAttribution
- (NSString *)longAttribution
{
return @"Map data © OpenStreetMap, licensed under Creative Commons Share Alike By Attribution.";
}
... ...
... ... @@ -32,7 +32,7 @@
//
// http://mapbox.com/hosting/api/
//
// Example usage at https://github.com/mapbox/tilestream-ios-example
// See samples/MBTilesDemo for example usage
//
// This class supports both the paid, hosted version of TileStream, as well as the
// open source, self-hosted version.
... ...
... ... @@ -47,9 +47,11 @@
- (id)initWithInfo:(NSDictionary *)info
{
if (self = [super init])
infoDictionary = [[NSDictionary dictionaryWithDictionary:info] retain];
if (!(self = [super init]))
return nil;
infoDictionary = [[NSDictionary dictionaryWithDictionary:info] retain];
return self;
}
... ... @@ -61,7 +63,6 @@
- (void)dealloc
{
[infoDictionary release];
[super dealloc];
}
... ... @@ -74,13 +75,13 @@
NSInteger zoom = tile.zoom;
NSInteger x = tile.x;
NSInteger y = pow(2, zoom) - tile.y - 1;
NSString *tileURLString = [self.infoDictionary objectForKey:@"tileURL"];
tileURLString = [tileURLString stringByReplacingOccurrencesOfString:@"{z}" withString:[[NSNumber numberWithInteger:zoom] stringValue]];
tileURLString = [tileURLString stringByReplacingOccurrencesOfString:@"{x}" withString:[[NSNumber numberWithInteger:x] stringValue]];
tileURLString = [tileURLString stringByReplacingOccurrencesOfString:@"{y}" withString:[[NSNumber numberWithInteger:y] stringValue]];
return [NSURL URLWithString:tileURLString];
}
... ... @@ -97,7 +98,7 @@
- (RMSphericalTrapezium)latitudeLongitudeBoundingBox
{
NSArray *parts = [[self.infoDictionary objectForKey:@"bounds"] componentsSeparatedByString:@","];
if ([parts count] == 4)
{
RMSphericalTrapezium bounds = {
... ... @@ -110,10 +111,10 @@
.latitude = [[parts objectAtIndex:3] doubleValue],
},
};
return bounds;
}
return kTileStreamDefaultLatLonBoundingBox;
}
... ... @@ -121,11 +122,11 @@
{
RMSphericalTrapezium ownBounds = [self latitudeLongitudeBoundingBox];
RMSphericalTrapezium defaultBounds = kTileStreamDefaultLatLonBoundingBox;
if (ownBounds.southWest.longitude <= defaultBounds.southWest.longitude + 10 &&
ownBounds.northEast.longitude >= defaultBounds.northEast.longitude - 10)
return YES;
return NO;
}
... ...
... ... @@ -344,14 +344,18 @@
children = (
D1437B33122869E400888DAE /* RMDBMapSource.h */,
D1437B32122869E400888DAE /* RMDBMapSource.m */,
DD8CDB4814E0507100B73EB9 /* RMMapQuestOSMSource.h */,
DD8CDB4914E0507100B73EB9 /* RMMapQuestOSMSource.m */,
DD2B375314CF8197008DE8CB /* RMMBTilesTileSource.h */,
DD2B375414CF8197008DE8CB /* RMMBTilesTileSource.m */,
1606C9FC13D86BA300547581 /* RMOpenCycleMapSource.h */,
1606C9FD13D86BA300547581 /* RMOpenCycleMapSource.m */,
B83E64ED0E80E73F001663B6 /* RMOpenStreetMapSource.h */,
B83E64EE0E80E73F001663B6 /* RMOpenStreetMapSource.m */,
16128CF3148D295300C23C0E /* RMOpenSeaMapSource.h */,
16128CF4148D295300C23C0E /* RMOpenSeaMapSource.m */,
DD8CDB4814E0507100B73EB9 /* RMMapQuestOSMSource.h */,
DD8CDB4914E0507100B73EB9 /* RMMapQuestOSMSource.m */,
B83E64ED0E80E73F001663B6 /* RMOpenStreetMapSource.h */,
B83E64EE0E80E73F001663B6 /* RMOpenStreetMapSource.m */,
DD98B6F814D76B930092882F /* RMTileStreamSource.h */,
DD98B6F914D76B930092882F /* RMTileStreamSource.m */,
);
name = "Map sources";
sourceTree = "<group>";
... ... @@ -507,10 +511,6 @@
16EC85CD133CA6C300219947 /* RMAbstractMercatorTileSource.m */,
16EC85CE133CA6C300219947 /* RMAbstractWebMapSource.h */,
16EC85CF133CA6C300219947 /* RMAbstractWebMapSource.m */,
DD2B375314CF8197008DE8CB /* RMMBTilesTileSource.h */,
DD2B375414CF8197008DE8CB /* RMMBTilesTileSource.m */,
DD98B6F814D76B930092882F /* RMTileStreamSource.h */,
DD98B6F914D76B930092882F /* RMTileStreamSource.m */,
);
name = "Tile Source";
sourceTree = "<group>";
... ...