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 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Im trying to use an MBTiles file as a source for tiles in an iOS application. It looks like there is currently no support for this.
Is this a planned feature?
If i were to implement it would the PR be considered for merging?
Reacted by Tore Halset, Jason Schloer, Tomás Francisco, Wei Zhuo, Ollie Snowden, Victor Berchet, Lauri Kajan, Eimantas, Pavel Minaev, Htain Lin Shwe and 11 more
It’s designed so that you can package the potentially thousands of files that make up a tileset and move them around, eventually uploading to Mapbox or using in a web or mobile application.
My questions are:
Is there any officially supported way to use MBTiles with the current versions of the mobile SDKs?
If MBTiles can't be used with the current SDKs, what options are available for including map tiles in an application bundle so that no additional downloads are required after app install? Links to sample code would be helpful.
Is support for MBTiles something that you'd consider adding, or accepting as a PR?
More background on my client's use case:
The apps currently use MBTiles with a legacy version (Mapbox iOS 1.6) of the Mapbox SDK. The map information they need in their apps is for specific geographic areas and they want to continue including the map tiles in the application bundle so that the app is ready for offline use as soon as it's downloaded by the user.
Reacted by shelart, Jan Chaloupecky and Aleksei Degtiarev
If i were to implement it would the PR be considered for merging?
We have discussed internally recently, and things along the lines of your (@JesseCrocker) work in #6940 are more generically useful given that you can provide a tile as needed from whatever format you like. We are hesitant to broaden the source API options given that we still have yet to port image (#1350) and video (#601) sources from our own spec across from GL JS.
@robmaceachern To answer your questions, OTOH here is how I would clarify:
MBTiles is still a fully-supported format for our API, given that Tippecanoe exports to it and our upload API accepts it. It's still the best way to transport lots of raster or vector tiles.
In implementing offline support in Offline (mbgl-core implementation) #3715, we decided to not promise to support the MBTiles format for the internal offline storage format, despite both being in SQLite. The reasoning was the additional metadata such as HTTP headers, cache checking and conditional fetching, and other offline-related functionality that didn't make sense for a generic file storage format. While we may merge the two in the future, we decided to keep the offline format API-private to give us the flexibility to change internal implementation in the future. We haven't yet prioritized such a change.
So to answer your questions @robmaceachern, I'm afraid there are no good approaches right now. Helping shepherd #6940 would be the best way to get flexible local access to tiles into the SDKs (especially Android), at which point you could just serve up SQLite-based tiles easily with some minor linkage code.
I hope this clarifies. This just hasn't been on our radar for a while given many other priorities around internal/GL JS parity, performance and stability, and new work like 3D extrusions.
In case anybody is interested, I've managed to display MBTiles in an MGLMapView by hosting a web server within my app and pointing the map to localhost. I've posted my solution here:
hai @namannik, can u help me? i use your class, but in let tileImage = UIImage(data: tileData) always return nil ( i use let path = Bundle.main.path(forResource: "countries", ofType: "mbtiles") to get path), thanks before
Hi, @dije. I've made some changes so it won't matter if UIImage(data: tileData) returns nil. However, it probably still won't work for you, as I suspect your data is vector pbf data. (Your MBTiles file is from here, correct?) The MGLMapView+MBTiles.swift gist currently only works with raster (jpg, png) data.
Any other discussion about MGLMapView+MBTiles.swift should take place over on the gist's page to not confuse this issue's discussion.
Building on @JesseCrocker’s work in #6940, MGLComputedShapeSource will ship with Android map SDK v6.0.0, iOS map SDK v4.0.0, and macOS map SDK v0.7.0. That should in theory make it possible to implement an MBTiles-backed vector source. It’s more likely that this source would be implemented as a plugin than going straight into the SDK proper, so I opened mapbox/mapbox-plugins-ios#19. An MBTiles-backed raster source, meanwhile, is blocked by #7471.
I don't agree that MGLComputedShapeSource eliminates the need for an MBTiles source that works with vector tiles, because unless something has changed recently there are no publicly exposed classes/methods for parsing vector tiles, so the app developer would still have to implement that, and MGLComputedShapeSource has no way to provide data in multiple layers, which is common in vector tiles.
Thanks, those are good points. I didn’t mean to rule out eventually adding MBTiles support to the SDK in some form – any plugin can potentially be folded into the SDK at a later date. But I figure mapbox/mapbox-plugins-ios#19 is a first step towards making that possible.
@asheemmamoowala
Thanks for your remind! But I can't find CustomGeometrySource and GeometryTileProvider in the latest release (v5.3.1) in android sdk, unless using 6.0.0-SNAPSHOT.
Referenced by Docs, I thought they were already added in sdk after v5.2.1. Is there anything I missed?
@namannik@JanC
I am done with similar Implementation for vector tiles by Kotlin in Android, solution is here
@asheemmamoowala
Also, I found that even running localhost for Vector/Raster source, we still need network connection when doing request. I thought we don't skip request when host is localhost, related code is here:
Using a custom NSURLProtocol that handles a custom URL scheme like mbtiles:// and add it to MGLNetworkConfiguration.sharedManager.sessionConfiguration.protocolClasses seem to be a bit simpler than embedding a web server.
Activity
robmaceachern commentedon Mar 17, 2017
Hi Mapbox team @incanus @boundsj @jfirebaugh. Can somebody clarify the current state & future plans for MBTiles in the mobile SDKs?
Earlier comments indicated that MBTile support was likely:
#584 (comment)
#3053 (comment)
There seemed to be progress here #2939, but it was closed in favour of #3715 which doesn't seem to include MBTile support.
The marketing and help page copy currently implies that MBTiles are supported:
https://www.mapbox.com/help/an-open-platform/#storing-tiles
https://www.mapbox.com/help/define-mbtiles/
My questions are:
More background on my client's use case:
The apps currently use MBTiles with a legacy version (Mapbox iOS 1.6) of the Mapbox SDK. The map information they need in their apps is for specific geographic areas and they want to continue including the map tiles in the application bundle so that the app is ready for offline use as soon as it's downloaded by the user.
incanus commentedon Mar 17, 2017
First, to address the OP:
We have discussed internally recently, and things along the lines of your (@JesseCrocker) work in #6940 are more generically useful given that you can provide a tile as needed from whatever format you like. We are hesitant to broaden the source API options given that we still have yet to port image (#1350) and video (#601) sources from our own spec across from GL JS.
@robmaceachern To answer your questions, OTOH here is how I would clarify:
MBTiles is still a fully-supported format for our API, given that Tippecanoe exports to it and our upload API accepts it. It's still the best way to transport lots of raster or vector tiles.
offline-capable file source #2939 was a bit of a precursor to a broader API such as the above-mentioned Computed (on-demand) shape source #6940.
In implementing offline support in Offline (mbgl-core implementation) #3715, we decided to not promise to support the MBTiles format for the internal offline storage format, despite both being in SQLite. The reasoning was the additional metadata such as HTTP headers, cache checking and conditional fetching, and other offline-related functionality that didn't make sense for a generic file storage format. While we may merge the two in the future, we decided to keep the offline format API-private to give us the flexibility to change internal implementation in the future. We haven't yet prioritized such a change.
https://www.mapbox.com/help/an-open-platform/#storing-tiles is somewhat out of date given mention of the raster mobile tools (in intent) as well as TileMill. We'll revise this. /cc @mapbox/support
So to answer your questions @robmaceachern, I'm afraid there are no good approaches right now. Helping shepherd #6940 would be the best way to get flexible local access to tiles into the SDKs (especially Android), at which point you could just serve up SQLite-based tiles easily with some minor linkage code.
I hope this clarifies. This just hasn't been on our radar for a while given many other priorities around internal/GL JS parity, performance and stability, and new work like 3D extrusions.
namannik commentedon Dec 31, 2017
In case anybody is interested, I've managed to display MBTiles in an
MGLMapViewby hosting a web server within my app and pointing the map tolocalhost. I've posted my solution here:https://gist.github.com/namannik/3b7c8b69c2d0768d0c2b48d2ed5ff71c
dije commentedon Jan 2, 2018
hai @namannik, can u help me? i use your class, but in let tileImage = UIImage(data: tileData) always return nil ( i use let path = Bundle.main.path(forResource: "countries", ofType: "mbtiles") to get path), thanks before
namannik commentedon Jan 2, 2018
Hi, @dije. I've made some changes so it won't matter if
UIImage(data: tileData)returnsnil. However, it probably still won't work for you, as I suspect your data is vector pbf data. (Your MBTiles file is from here, correct?) The MGLMapView+MBTiles.swift gist currently only works with raster (jpg, png) data.Any other discussion about MGLMapView+MBTiles.swift should take place over on the gist's page to not confuse this issue's discussion.
dije commentedon Jan 3, 2018
Thanks for the answer @namannik, ill go check latest gist, and try again
typebrook commentedon Jan 3, 2018
@dije
As @namannik said, if your mbtiles are download from OpenMapTiles, then the data stored in sql is .mvt.
In this case, replace MGLRaterSource with MGLVectorSource should works, if you have other question or feedback, let's discuss in the gist
1ec5 commentedon Jan 10, 2018
Building on @JesseCrocker’s work in #6940, MGLComputedShapeSource will ship with Android map SDK v6.0.0, iOS map SDK v4.0.0, and macOS map SDK v0.7.0. That should in theory make it possible to implement an MBTiles-backed vector source. It’s more likely that this source would be implemented as a plugin than going straight into the SDK proper, so I opened mapbox/mapbox-plugins-ios#19. An MBTiles-backed raster source, meanwhile, is blocked by #7471.
JesseCrocker commentedon Jan 10, 2018
I don't agree that MGLComputedShapeSource eliminates the need for an MBTiles source that works with vector tiles, because unless something has changed recently there are no publicly exposed classes/methods for parsing vector tiles, so the app developer would still have to implement that, and MGLComputedShapeSource has no way to provide data in multiple layers, which is common in vector tiles.
But if support for MBTiles is not going to make it into the core SDK it seems like a great feature for a plugin, because it can be implemented in a self contained fashion by a class that implements
MGLOfflineStorageDelegateand transforms mbtiles:// urls to http://localhost urls, and runs a local http server that serves the tiles.1ec5 commentedon Jan 10, 2018
Thanks, those are good points. I didn’t mean to rule out eventually adding MBTiles support to the SDK in some form – any plugin can potentially be folded into the SDK at a later date. But I figure mapbox/mapbox-plugins-ios#19 is a first step towards making that possible.
asheemmamoowala commentedon Jan 10, 2018
Even if there was a decoder for vector tiles, #10494 would still be needed before you got blocked by the multiple layers issue.
typebrook commentedon Jan 20, 2018
@asheemmamoowala
Thanks for your remind! But I can't find
CustomGeometrySourceandGeometryTileProviderin the latest release (v5.3.1) in android sdk, unless using 6.0.0-SNAPSHOT.Referenced by Docs, I thought they were already added in sdk after v5.2.1. Is there anything I missed?
asheemmamoowala commentedon Jan 22, 2018
@typebrook Sorry for the confusion. These classes are not included in the released SDK as yet. The docs should not have those classes visible yet.
JanC commentedon Feb 12, 2018
Hi,
so is there any plan to include local mbtile support to the SDK or do we need to use @namannik 's custom implementation ?
typebrook commentedon Feb 12, 2018
@namannik @JanC
I am done with similar Implementation for vector tiles by Kotlin in Android, solution is here
@asheemmamoowala
Also, I found that even running localhost for Vector/Raster source, we still need network connection when doing request. I thought we don't skip request when host is localhost, related code is here:
mapbox-gl-native/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
Lines 78 to 79 in 982fcc9
Am I thinking wrong?
JesseCrocker commentedon Sep 12, 2018
closing issue because im guessing this is never going to happen.
tsemerad commentedon Jun 13, 2019
@typebrook Did you ever come up with a workaround to getting your app able to request MBTiles hosted on localhost while offline?
halset commentedon Dec 28, 2019
Using a custom NSURLProtocol that handles a custom URL scheme like
mbtiles://and add it toMGLNetworkConfiguration.sharedManager.sessionConfiguration.protocolClassesseem to be a bit simpler than embedding a web server.typebrook commentedon May 26, 2020
@tsemerad
Yes. With the help from other user, gist is already updated