Error decoding tiles in Bundle MBTiles file using CartoDB SDK

271 views Asked by At

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?

1

There are 1 answers

1
JaakL On BEST ANSWER

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);