1

I create my .mbtiles following this steps

  1. I use osm-carto style and sources from geofabrik the create my map
  2. I use Kosmtik editor to see the map and a plugin(kosmtik-mbtiles-exporter) to export the .mbtiles

this is my swift code to load my bundle .mbtiles file

override func viewDidLoad() {
    super.viewDidLoad()
    
    map = NTMapView()
    map.frame = view.bounds
    
    //Need to add as a subview,
    view.addSubview(map)
    
    // Get base projection from mapView
    let projection = map.getOptions().getBaseProjection();
    
    // Create a local vector data source
    let source: NTTileDataSource? = createTileDataSource()
    let baseLayer = NTCartoOnlineVectorTileLayer(style: .CARTO_BASEMAP_STYLE_VOYAGER)
    let decoder: NTVectorTileDecoder? = baseLayer?.getTileDecoder()
    
    let layer = NTVectorTileLayer(dataSource: source, decoder: decoder)
    map?.getLayers()?.add(layer)
    
    map.getOptions().setPanningMode(NTPanningMode.PANNING_MODE_STICKY)
    
}

func createTileDataSource() -> NTTileDataSource {
    let name: String = "cuba.output"
    let format : String = "mbtiles"
    // file-based local offline datasource
    let source: String? = Bundle.main.path(forResource: name, ofType: format)
    let vectorTileDataSource: NTTileDataSource? = NTMBTilesTileDataSource(minZoom: 0, maxZoom: 14, path: source)
    return vectorTileDataSource!
}}

But when run the app give me this error

Sep 18 12:53:00 WeGoCuba[1547] : MBTilesTileDataSource::loadTile: Loading MapTile [x=0, y=0, zoom=0, frameNr=0, id=0]

Sep 18 12:53:00 WeGoCuba[1547] : MBVectorTileDecoder::decodeTile: Exception while decoding: unknown pbf type

Sep 18 12:53:00 WeGoCuba[1547] : VectorTileLayer::FetchTask:Failed to decode tile

Why is give me this error? Is the .mbtiles file wrong? If so you could give the steps to create a correct one?

Community
  • 1
  • 1
Randy Hector
  • 89
  • 1
  • 1
  • 9
  • Can you share your .mbtiles ? Most probably it is not readable by SDK, we have not tried kosmtik-mbtiles-exporter really. What is your map area? CARTO SDK provides OSM as MBTILES as built-in function, so in principle you should not need to create the mbtiles yourself at all. – JaakL Sep 20 '17 at 08:36
  • Another note here: CARTO_BASEMAP_STYLE_VOYAGER what you use works only with carto.streets (openmaptiles) vector tile schema. Every vector style works only with compatible vector data structure. I do not know what osm-carto / kosmtik-mbtiles-exporter generates, but most probably this is different schema, or even with raster tiles. – JaakL Sep 20 '17 at 08:39
  • @JaakL CARTO SDK provides OSM as MBTILES as built-in function, but i thinks this is a paid service??, my month salary where i live is lower than $30, so i can't afford it. But if you could give it to me the method of creating vector mbtiles it would be much apprecited, i am quite new and i dont have much experiencie creating maps. – Randy Hector Sep 20 '17 at 19:44
  • @RandyHector you could get MBTiles from https://openmaptiles.org to be used offline with Carto SDK – xarlymg89 Jul 25 '18 at 06:58

1 Answers1

1

It seems that with kosmtik you get raster mbtiles, not vector ones. These can be added to the map easily with following, but these are pre-styled as any raster datasource would be.

MBTilesTileDataSource mbTileDataSource = new MBTilesTileDataSource(0, 18, path); // mbtiles file has to be in storage!
RasterTileLayer mbTileRasterLayer = new RasterTileLayer(mbTileDataSource);
mapView.getLayers().add(mbTileRasterLayer);
JaakL
  • 4,107
  • 5
  • 24
  • 37
  • sorry for the delay in responding, I also came to this answer, late yesterday evening after a long read. but it feels good to know that someone else comes to the same conclusion, thanks for your help and of course I will mark it as the correct one. – Randy Hector Sep 20 '17 at 18:57