You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 25, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 25, 2023. It is now read-only.
This should be straightforward based on RMMBTilesSource. However, linking to SQLite is a problem if we want to keep things simple for installation. Two thoughts right now:
For CocoaPods, make MBTiles suppert a subspec. Linking isn't much of a big deal here anyway since it's managed.
For manual install, just make a macro at the top of the file to #ifdef out the SQLite code by default. Then, if the dev wants, they can flip the macro bit and link it themselves. This gets around people having to link before use.
Being able to have offline overlays that come built into an app is essential to some of the apps we are working on. I was hoping to use MBTiles for this, and this seems like a great feature to integrate in.
This would indeed be a major breakthrough... having the comfort and slickness of MapKit, combined with the flexibility of offline mbtiles sources. Great!
per the new MapKit API. For MBTiles, URLForTilePath: would not be used and instead loadTileAtPath:result: would just hit the SQLite directly for the tile defined by path (i.e. the tile z/x/y).
There is probably some work to be done around the threading model based on how MapKit works vs. how the iOS SDK (via CATiledLayer) does, but since the existing SQLite code uses the FMDatabaseQueue serial queue API for thread safety, a first cut should work pretty well.
I've had some success playing with offline tiles on the MapKit side (i.e. not involving MBXMapKit) by subclassing MKTileOverlay. Here are the main things you'll need to do to make the API work:
Get an MKMapView set up in a view controller that implements MKMapViewDelegate protocol. The view controller should be set as the MKMapView's delegate.
In the view controller, implement - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay so that it will return a [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay] when it gets called with your subclassed MKTileOverlay as the overlay.
Subclass MKTileOverlay with the following important bits:
- (MKMapRect)boundingMapRect
{
// This works to test with, but you should figure out the actual bounding box
return MKMapRectWorld;
}
- (BOOL)isGeometryFlipped
{
// Default coordinate system is upside down relative to an MBTiles from TileMill, so flip it
return YES;
}
- (void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *tileData, NSError *error))result
{
// Find your MBTiles file and open it with sqlite, FMDB, or whatever
// Figure out if path represents a valid tile in your MBTiles file
// Assuming it does, make this query to get the tile...
NSString *query = [NSString stringWithFormat:@"select tile_data from tiles where zoom_level = %ld and tile_column = %ld and tile_row = %ld",(long)path.z,(long)path.x,(long)path.y];
// Based on what comes back from your query, initialize these objects appropriately...
NSData *myTileData;
NSError *myErrorStatus;
// Invoke the argument block to complete the asynchronous load...
result(myTileData, myErrorStatus);
}
Back in your view controller, in viewDidLoad or someplace, do something kinda like this to add your overlay to the MKMapView:
I like the approach over in #20 of doing this with defines for the folks that really need it. Leaving this open until this is addressed and integrated either in #20 directly or the aggregate #38 pull.
The ability to use vector-mbtiles would be awesome, though I am not sure how easy this would be to implement within this confined project. As far as I understand, there would have to be some mechanism to render those on-the-fly then. Would something like this be feasible?
@wsnook My changes are on my fork ready for inspection. (issue3-mbtiles branch)
Give it a spin and tell me if you would prefer a different approach.
The ideas behind my changes were:
Reduce number of calls to sqlite API by using the same connection to the same mbtiles file.
Use a serial dispatch queue to access an mbtiles databse in a background thread without needing locks.
Use the same method structure to retrieve data from the database as is used for the offline cache variant. I had the idea that the worker-block could be used if the data needs preprocessing in the future like an image filter or (and there my imagination went probably a bit too wild) if the tiles might not contain image data but ::drumrolling:: vector data that needs to be rendered into images first.
Reduce number of calls to sqlite API by using the same connection to the same mbtiles file.
Use a serial dispatch queue to access an mbtiles databse in a background thread without needing locks.
This is starting to sound like FMDB reinvention territory. This is the library we use over the SDK for serial queued SQLite calls to great effect. If we are going to go this route, I think we should look into using that well-tested library than continuing to build up custom SQLite handling.
@incanus I would agree if I would actually have done it in such an abstract way, but I think my implementation is far simpler and less abstract than FMDB.
I'll happily improve my code to your suggestions. I'm sure there is still many things to improve on. I also looked at FMDB months ago but I found it overly complex at that time for this particular purpose.
@wsnook Please point out any rough edges and I'll get on it asap.
Yeah, #110 should include everything. the only thing is, that I had some 1,5MB mbtiles testfile in there and as far as I understand, it is still there in the history.
That's why I wrote the obscure comment on the pull request. You'll have to decide if this is acceptable or not.
ghost added a commit that references this issue on Jul 1, 2014
Activity
radven commentedon Oct 4, 2013
Being able to have offline overlays that come built into an app is essential to some of the apps we are working on. I was hoping to use MBTiles for this, and this seems like a great feature to integrate in.
kontextbewusst commentedon Oct 14, 2013
This would indeed be a major breakthrough... having the comfort and slickness of MapKit, combined with the flexibility of offline mbtiles sources. Great!
thdlx commentedon Nov 8, 2013
MBTiles support would be great for my project !
MBXMapKit is a nice approach combining the SDK map kit and Mapbox.
Good job team !
incanus commentedon Nov 19, 2013
Still not able to get to this in the near term. But to lay out the strategy I was planning:
MBXMapKit.matmbxmapkit/MBXMapKit.m
Lines 83 to 103 in a9bc909
regionthat is set inmbxmapkit/MBXMapKit.m
Lines 115 to 130 in a9bc909
mbxmapkit/MBXMapKit.m
Lines 155 to 240 in a9bc909
URLForTilePath:would not be used and insteadloadTileAtPath:result:would just hit the SQLite directly for the tile defined bypath(i.e. the tilez/x/y).UIImageobjects from it, whereasloadTileAtPath:result:in MapKit would just act on theNSDatadirectly.CATiledLayer) does, but since the existing SQLite code uses theFMDatabaseQueueserial queue API for thread safety, a first cut should work pretty well.willsnookrz commentedon Nov 22, 2013
I've had some success playing with offline tiles on the MapKit side (i.e. not involving MBXMapKit) by subclassing MKTileOverlay. Here are the main things you'll need to do to make the API work:
Get an MKMapView set up in a view controller that implements MKMapViewDelegate protocol. The view controller should be set as the MKMapView's delegate.
In the view controller, implement
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlayso that it will return a[[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay]when it gets called with your subclassed MKTileOverlay as the overlay.Subclass MKTileOverlay with the following important bits:
Back in your view controller, in viewDidLoad or someplace, do something kinda like this to add your overlay to the MKMapView:
incanus commentedon Feb 18, 2014
I like the approach over in #20 of doing this with defines for the folks that really need it. Leaving this open until this is addressed and integrated either in #20 directly or the aggregate #38 pull.
tkrajacic commentedon Apr 14, 2014
The ability to use vector-mbtiles would be awesome, though I am not sure how easy this would be to implement within this confined project. As far as I understand, there would have to be some mechanism to render those on-the-fly then. Would something like this be feasible?
incanus commentedon Apr 21, 2014
Yes, but this is a separate from MBTiles proper -- MBTiles is more the transport medium than the rendering. We're looking into vector rendering now.
radven commentedon May 1, 2014
Is "this can wait" referring to vector rendering, or MBTiles overall?
The ability to have offline maps bundled with an app seems to be a pretty central feature to MBXMapKit, at least how I envision using it.
Thoughts? Is there another more preferred way than MBTiles suggested?
21 remaining items
tkrajacic commentedon Jun 28, 2014
@wsnook My changes are on my fork ready for inspection. (issue3-mbtiles branch)
Give it a spin and tell me if you would prefer a different approach.
The ideas behind my changes were:
incanus commentedon Jun 30, 2014
This is starting to sound like FMDB reinvention territory. This is the library we use over the SDK for serial queued SQLite calls to great effect. If we are going to go this route, I think we should look into using that well-tested library than continuing to build up custom SQLite handling.
tkrajacic commentedon Jun 30, 2014
@incanus I would agree if I would actually have done it in such an abstract way, but I think my implementation is far simpler and less abstract than FMDB.
incanus commentedon Jun 30, 2014
Ok, fair enough. Just wanted to put it on the radar. I haven't looked at @tkrajacic's code in depth yet.
tkrajacic commentedon Jun 30, 2014
I'll happily improve my code to your suggestions. I'm sure there is still many things to improve on. I also looked at FMDB months ago but I found it overly complex at that time for this particular purpose.
@wsnook Please point out any rough edges and I'll get on it asap.
tkrajacic commentedon Jun 30, 2014
Yeah, #110 should include everything. the only thing is, that I had some 1,5MB mbtiles testfile in there and as far as I understand, it is still there in the history.
That's why I wrote the obscure comment on the pull request. You'll have to decide if this is acceptable or not.
Revert "#3 Roughing in API suggestion from @tkrajacic"
tkrajacic commentedon Feb 2, 2015
Still watching here indeed! ;)
Thanks for making this available!