Reputation: 1361
I'm actually working on a cordova application that is reading (not writing) a .mbtiles file. That is a database filed with tiles in order to show an offline map with leaflet.
Everything concerning the file (call it test.mbtiles) is working : downloading and openning. But there is still a big issue. I'm not able to read the tables. Here's the non functionnal sample of my code :
getTileUrl: function (tilePoint, callBack) {
var x = tilePoint.x;
var y = tilePoint.y;
var z = tilePoint.z;
var base64Prefix = 'data:image/png;base64,';
var db2 = new window.sqlitePlugin.openDatabase({name: 'test.mbtiles'});
db2.transaction(function(tx) {
tx.executeSql("SELECT tile_data FROM images INNER JOIN map ON images.tile_id = map.tile_id WHERE zoom_level = ? AND tile_column = ? AND tile_row = ?", [z, x, y], function (tx, res) {
if(res.rows.length>0) {
console.log("success");
var src = base64Prefix + res.rows.item(0).tile_data;
callBack(src);
}
else {
console.log("response : no data");
}
}, function (tx, er) {
console.log('error with executeSql : ', er.message);
return;
});
});
}
So now everytime I try to use the offline map (using tiles from the test.mbtiles which is present on the device) i get this error :
error with executeSql : no such table: images (code 1): , while compiling: SELECT tile_data FROM images INNER JOIN map ON images.tile_id = map.tile_id WHERE zoom_level = ? AND tile_column = ? AND tile_row = ?
So I assume that the file I'm getting, the test.mbtiles is not good because it doesn't have any images
table. But that's wrong. I used SQLite Database Browser
in order to look at my database scheme, and found that the images
table is here and filled with the right data.
Has anyone else had this error and know how to fix it ?
Btw I'm using latest release versions of SQLite Plugin and Cordova, and mainly testing on android (will port to ios if android works). And as much as possible i would like to use only .js files, no addition in any java class or such (would destroy the whole workflow).
Thanks.
Upvotes: 1
Views: 707