按照这个步骤创建我的.mbtile
这是我加载我的软件包.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:加载MapTile [x = 0,y = 0,zoom = 0,frameNr = 0,id = 0]
Sep 18 12:53:00 WeGoCuba [1547]:MBVectorTileDecoder :: decodeTile:解码时出现异常:未知的pbf类型
Sep 18 12:53:00 WeGoCuba [1547]:VectorTileLayer :: FetchTask:无法解码磁贴
为什么给我这个错误? .mbtiles文件错了吗?如果是这样 你可以给出创建正确的步骤吗?
答案 0 :(得分:1)
似乎与kosmtik你得到光栅mbtiles,而不是矢量。这些可以通过以下方式轻松添加到地图中,但这些都预先设置为任何栅格数据源。
MBTilesTileDataSource mbTileDataSource = new MBTilesTileDataSource(0, 18, path); // mbtiles file has to be in storage!
RasterTileLayer mbTileRasterLayer = new RasterTileLayer(mbTileDataSource);
mapView.getLayers().add(mbTileRasterLayer);