Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

MBTiles enhancements #134

Merged
merged 1 commit into from

2 participants

@incanus

Here are some enhancements to the MBTiles backend that we've been using for some time that would be of general use.

  • Allow for type of layer to be determined (base layer vs. partially-transparent overlay layer).
  • return of bounds metadata from SQLite such as tile set bounding box and whether the tile set has full world coverage.
  • Updated links to the MBTiles reference implementation as well as an example app on GitHub.
@vyskocil vyskocil merged commit 0bc6fbb into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
17 MapView/Map/RMMBTilesTileSource.h
@@ -31,7 +31,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
-// http://mapbox.com/documentation/mbtiles-file-format
+// http://mbtiles.org
+//
+// Example usage at https://github.com/mapbox/mbtiles-ios-example
//
#import <Foundation/Foundation.h>
@@ -42,9 +44,14 @@
#define kMBTilesDefaultTileSize 256
#define kMBTilesDefaultMinTileZoom 0
-#define kMBTilesDefaultMaxTileZoom 18
-#define kMBTilesDefaultLatLonBoundingBox ((RMSphericalTrapezium){ .northeast = { .latitude = 90, .longitude = 180 }, \
- .southwest = { .latitude = -90, .longitude = -180 } })
+#define kMBTilesDefaultMaxTileZoom 22
+#define kMBTilesDefaultLatLonBoundingBox ((RMSphericalTrapezium){ .northeast = { .latitude = 85, .longitude = 180 }, \
+ .southwest = { .latitude = -85, .longitude = -180 } })
+
+typedef enum {
+ RMMBTilesLayerTypeBaselayer = 0,
+ RMMBTilesLayerTypeOverlay = 1,
+} RMMBTilesLayerType;
@interface RMMBTilesTileSource : NSObject <RMTileSource>
{
@@ -66,6 +73,8 @@
- (void)setMinZoom:(NSUInteger)aMinZoom;
- (void)setMaxZoom:(NSUInteger)aMaxZoom;
- (RMSphericalTrapezium)latitudeLongitudeBoundingBox;
+- (BOOL)coversFullWorld;
+- (RMMBTilesLayerType)layerType;
- (void)didReceiveMemoryWarning;
- (NSString *)uniqueTilecacheKey;
- (NSString *)shortName;
View
66 MapView/Map/RMMBTilesTileSource.m
@@ -36,9 +36,8 @@
#import "RMTileImage.h"
#import "RMProjection.h"
#import "RMFractalTileProjection.h"
-#import "FMDatabase.h"
-#pragma mark -
+#import "FMDatabase.h"
@implementation RMMBTilesTileSource
@@ -184,9 +183,72 @@ - (void)setMaxZoom:(NSUInteger)aMaxZoom
- (RMSphericalTrapezium)latitudeLongitudeBoundingBox
{
+ FMResultSet *results = [db executeQuery:@"select value from metadata where name = 'bounds'"];
+
+ if ([db hadError])
+ return kMBTilesDefaultLatLonBoundingBox;
+
+ [results next];
+
+ NSString *boundsString = [results stringForColumnIndex:0];
+
+ [results close];
+
+ if (boundsString)
+ {
+ NSArray *parts = [boundsString componentsSeparatedByString:@","];
+
+ if ([parts count] == 4)
+ {
+ RMSphericalTrapezium bounds = {
+ .southwest = {
+ .longitude = [[parts objectAtIndex:0] doubleValue],
+ .latitude = [[parts objectAtIndex:1] doubleValue],
+ },
+ .northeast = {
+ .longitude = [[parts objectAtIndex:2] doubleValue],
+ .latitude = [[parts objectAtIndex:3] doubleValue],
+ },
+ };
+
+ return bounds;
+ }
+ }
+
return kMBTilesDefaultLatLonBoundingBox;
}
+- (BOOL)coversFullWorld
+{
+ 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;
+}
+
+- (RMMBTilesLayerType)layerType
+{
+ FMResultSet *results = [db executeQuery:@"select value from metadata where name = 'type'"];
+
+ if ([db hadError])
+ return RMMBTilesLayerTypeBaselayer;
+
+ [results next];
+
+ NSString *type = nil;
+
+ if ([results hasAnotherRow])
+ type = [results stringForColumn:@"value"];
+
+ [results close];
+
+ return ([type isEqualToString:@"overlay"] ? RMMBTilesLayerTypeOverlay : RMMBTilesLayerTypeBaselayer);
+}
+
- (void)didReceiveMemoryWarning
{
NSLog(@"*** didReceiveMemoryWarning in %@", [self class]);
Something went wrong with that request. Please try again.