mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

Support for Offline Tilesets?

Open kongakon opened this issue 9 years ago • 5 comments

I used mbtiles for my project using legacy mapbox ios sdk (1.6.1). Now with this new gl version, I have to use "Offline pack" to store map tiles locally. I also uploaded a tileset from old mbtiles and add it to a new style. Unfortunately, as stated in #8174 , map data is only downloaded in base style. Tileset data is not downloaded along, so without network connection it's unavailable. jfirebaugh said that we could download offline data with an auxiliary style including just that tileset source and nitrag said that he was able to do this but I couldn't download the pack.

I tried:

  • NSURL *styleURL = [NSURL URLWithString:@"mapbox://styles/myUsername/myStyleHash"]; -> download base style only, show tileset correctly when online, but got error when offline, got "[Setup]: loading style failed: The request timed out".

  • NSURL *styleURL = [[NSBundle mainBundle] URLForResource:@"mapbox-raster-v8" withExtension:@"json"]; -> got "response class is not NSHTTPURLResponse" at "offlinePackDidReceiveError:" with 0 of 1 resource when downloading.

  • create a blank style, turn off compositing, add the tileset as the only layer as nitrag said -> no success.

kongakon avatar Sep 14 '17 09:09 kongakon

Do you have any success on this? I have similar task, many custom tilesets should be downloaded for offline. They are shown on map view like this now let source = MGLRasterSource(identifier: "source \(mapId)", tileURLTemplates: [ "http://a.tiles.mapbox.com/v4/\(mapId)/{z}/{x}/{y}.png?access_token=\(token)", "http://b.tiles.mapbox.com/v4/\(mapId)/{z}/{x}/{y}.png?access_token=\(token)"], options: nil) mapView.style?.addSource(source) where mapId is username.tilesetId I've got from our server. Didn't work when I created source from url like mapbox://username.tilesetId though, maybe did something wrong. This works good online, but have no working solution on how it should be downloaded. As I understand mapbox://styles/... should be used for styles only, but tilesets are not styles, not sure. Only possible solution I see should be using "asset://" like urls for styles, where styles described in json file like this but I'm scared on how many work it requires: get mapId from server, save json files for each, then download for offline. Moreover not sure it will work. Maybe someone can suggest better solution? At least something without persistent files.

pavelkorolevxyz avatar Sep 18 '17 08:09 pavelkorolevxyz

Hi, thanks for using Mapbox. For "how do I" questions like this, please refer to our help documentation, and if you can't find the answer there, contact support. This issue tracker is for reporting bugs and feature requests. Thank you!

jfirebaugh avatar Oct 04 '17 23:10 jfirebaugh

jfirebaugh can you please point me to the article in your help documentation that explains how to download raster tile sets from non mapbox sources so they can be used offline?

amphib avatar Jul 06 '18 17:07 amphib

@jfirebaugh I would also like to know the location of any "how to" documentation or whether this is possible on Mapbox? Can't seem to find anything on your site explaining how to download raster tiles from a non-mapbox style url.

jackdewhurst avatar Aug 05 '19 14:08 jackdewhurst

If anyone comes across this and is still interested please read on. You need to create a Mapbox style.json file manually with your raster tile-set URL as a source and corresponding layer included.

After this upload it somewhere online (S3 for example) and use the URL in the MGLTilePyramidOfflineRegion(styleURL:URL! etc...) initialization call. You can even apply this url to the mapview as it's style url which is pretty neat.

jackdewhurst avatar Aug 05 '19 15:08 jackdewhurst