ios - 使用 CartoDB SDK 解码 Bundle MBTiles 文件中的图 block 时出错

标签 ios swift bundle offline carto-mobile

我按照这些步骤创建我的 .mbtiles

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

这是加载我的 bundle .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!
}}

但是当运行应用程序时给我这个错误

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

为什么给我这个错误? .mbtiles 文件有误吗?如果是这样 你能给出创建正确的步骤吗?

最佳答案

似乎使用 kosmtik 你会得到光栅 mbtiles,而不是矢量 mbtiles。这些可以通过以下方式轻松添加到 map 中,但这些都是预先设计好的,就像任何栅格数据源一样。

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

关于ios - 使用 CartoDB SDK 解码 Bundle MBTiles 文件中的图 block 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46288762/

相关文章:

swift - 如何使用自动布局以编程方式水平对齐具有不同宽度的标签循环

python - 什么相当于 Python 中的 Swift 完成 block ?

ruby-on-rails - 安装/bundle gem unf_ext -v '0.0.6' 时出错

javascript - Webpack 的 "npm run bundle"抛出 ERR!代码 生命周期

swift - 使用 Swift iOS 导入类

c# - Bundles 中的脚本使用 ~/Scripts 呈现,因此未找到

ios - 查找字符串数组的最长公共(public)子串

ios - 遮蔽图像时内存增加

ios - 带有动态部分的 Swift 静态表格 View

ios - iPad 应用程序在 iPad 3 上崩溃,在 iPad 2 上运行正常,内存不足警告