Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

MBTiles source #6862

Closed
JesseCrocker opened this issue Oct 31, 2016 · 19 comments
Closed

MBTiles source #6862

JesseCrocker opened this issue Oct 31, 2016 · 19 comments
Labels
Android Mapbox Maps SDK for Android archived Archived because of inactivity feature icebox Things we want to do in the future. iOS Mapbox Maps SDK for iOS needs discussion

Comments

@JesseCrocker
Copy link
Contributor

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?

@boundsj boundsj added iOS Mapbox Maps SDK for iOS feature needs discussion labels Nov 2, 2016
@robmaceachern
Copy link

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

You can also use MBTiles files offline on mobile devices with Mapbox iOS toolkits.

https://www.mapbox.com/help/define-mbtiles/

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:

  1. Is there any officially supported way to use MBTiles with the current versions of the mobile SDKs?
  2. 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.
  3. 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.

@incanus incanus added the Android Mapbox Maps SDK for Android label Mar 17, 2017
@incanus
Copy link
Contributor

incanus commented Mar 17, 2017

First, to address the OP:

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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
Copy link
Contributor

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:

https://gist.github.com/namannik/3b7c8b69c2d0768d0c2b48d2ed5ff71c

@dije
Copy link

dije commented 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
Copy link
Contributor

namannik commented Jan 2, 2018

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.

@dije
Copy link

dije commented Jan 3, 2018

Thanks for the answer @namannik, ill go check latest gist, and try again

@typebrook
Copy link

typebrook commented 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
Copy link
Contributor

1ec5 commented 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
Copy link
Contributor Author

JesseCrocker commented 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 MGLOfflineStorageDelegate and transforms mbtiles:// urls to http://localhost urls, and runs a local http server that serves the tiles.

@1ec5
Copy link
Contributor

1ec5 commented 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
Copy link
Contributor

Even if there was a decoder for vector tiles, #10494 would still be needed before you got blocked by the multiple layers issue.

@typebrook
Copy link

@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?

@asheemmamoowala
Copy link
Contributor

@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.

@1ec5 1ec5 mentioned this issue Feb 3, 2018
7 tasks
@JanC
Copy link

JanC commented 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
Copy link

typebrook commented 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:

// Don't try a request to remote server if we aren't connected
if (!Mapbox.isConnected() && !host.equals("127.0.0.1") && !host.equals("localhost")) {

Am I thinking wrong?

@JesseCrocker
Copy link
Contributor Author

closing issue because im guessing this is never going to happen.

@chloekraw chloekraw added the icebox Things we want to do in the future. label Oct 23, 2018
@chloekraw chloekraw added the archived Archived because of inactivity label Mar 19, 2019
@tsemerad
Copy link

@typebrook Did you ever come up with a workaround to getting your app able to request MBTiles hosted on localhost while offline?

@halset
Copy link
Contributor

halset commented Dec 28, 2019

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.

@typebrook
Copy link

typebrook commented May 26, 2020

@tsemerad

Did you ever come up with a workaround to getting your app able to request MBTiles hosted on localhost while offline?

Yes. With the help from other user, gist is already updated

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android archived Archived because of inactivity feature icebox Things we want to do in the future. iOS Mapbox Maps SDK for iOS needs discussion
Projects
None yet
Development

No branches or pull requests