我按照以下步骤创建我的.mbtiles

  • 我使用osm-carto样式和来自geofabrik的资源来创建我的 map
  • 我使用Kosmtik编辑器查看 map ,并使用插件(kosmtik-mbtiles-exporter)导出.mbtiles

  • 这是我的快速代码,用于加载我的捆绑包.mbtiles文件
    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!
    }}
    
    但是当运行应用程序时给我这个错误

    9月18日12:53:00 WeGoCuba [1547]:MBTilesTileDataSource::loadTile:正在加载MapTile [x = 0,y = 0,zoom = 0,frameNr = 0,id = 0]
    9月18日12:53:00 WeGoCuba [1547]:MBVectorTileDecoder::decodeTile:解码时异常:未知的pbf类型
    9月18日12:53:00 WeGoCuba [1547]:VectorTileLayer::FetchTask:未能解码图块

    为什么给我这个错误?
    .mbtiles文件是否错误?如果是这样的话
    您可以给出创建正确的步骤吗?

    最佳答案

    似乎使用kosmtik可以得到栅格对象,而不是矢量对象。这些内容可以通过以下轻松添加到 map 中,但是它们就像任何栅格数据源一样都已预先设置样式。

    MBTilesTileDataSource mbTileDataSource = new MBTilesTileDataSource(0, 18, path); // mbtiles file has to be in storage!
    RasterTileLayer mbTileRasterLayer = new RasterTileLayer(mbTileDataSource);
    mapView.getLayers().add(mbTileRasterLayer);
    

    10-06 00:18