Local tiles stored in SQLite DB not rendering on loadTile(at path:result:) with MKTileOverlayRenderer

无人久伴 提交于 2020-07-10 10:24:26

问题


I'm use SQLite3 to query for tile blobs I downloaded from openmaptiles. I'm able to get the blob from my DB and convert it into a Data however when I pass the Data to result of loadTile(at path:result:) I don't see the tile rendering. I'm wondering if maybe I need to convert it to some type of image data for it to render. However I'm fairly certain that .mbtiles uses blob data from png or jpeg image types which should be fine. Why might tiles not render on screen if I have appropriate Data and am calling loadTile on every render? I'm using MKTileOverlayRenderer

This is how I convert the blob into Data:

guard let blob = sqlite3_column_blob(queryStatement, 0) else { return nil }    
let blobLength = sqlite3_column_bytes(queryStatement, 0)

return Data(bytes: blob, count: Int(blobLength))

This is how I pass it to result of loadTile:

override func loadTile(at path: MKTileOverlayPath, result: @escaping (Data?, Error?) -> Void) {
    
    if let tilesURL = Bundle.main.url(forResource: "NYC", withExtension: "mbtiles"),
        let db = try? SQLiteDatabase.open(path: tilesURL.absoluteString),
        let tileData = db.map(Int32(path.z), x: Int32(path.x), y: Int32(path.y)) {
        result(tileData, nil)
    }
    
}

Previously I was able to render overlay tiles that were .png stored on device using url(forTilePath path:). This leads me to wonder if there is something wrong with my Data and passing that Data to loadTile(at path:result:). However like I said .mbtiles uses blob data from png or jpeg image types which should be fine. I don't think the data is corrupted because I was able to render these tiles on the web.

Something interesting I noticed is if I try to create a UIImage with that data then the image in nil.

let data = Data(bytes: dataBlob, count: Int(dataBlobLength))
let image = UIImage(data: data)

Setting a breakpoint at result(tileData, nil) is hit on every call. Why might tiles not render on screen if I am calling loadTile and pass its result a Data?

来源:https://stackoverflow.com/questions/62824057/local-tiles-stored-in-sqlite-db-not-rendering-on-loadtileat-pathresult-with

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!