Open mb72 opened 5 years ago
@HarelM have you had this issue?
I was unable to make Cordova 9.0 fully work on my machine (Win 10). I'm still using 8 due to that fact...
Which version of Cordova 8 are you running? I tried installing some versions of 8 and had the same problem.
go to \plugins\cordova-sqlite-ext\scripts\beforePluginInstall.js
add --> var Q = require('q'); and comment --> var Q = context.requireCordovaModule('q');
Thanks for the tip!
@kiRyyy I'm still getting the error and cordova-sqlite-ext
is still not installing.
@HarelM What build of Cordova is this working on for you? I tried running Cordova 8 and got the same problem.
@mb72 I have now switch to latest - 9.0.
I'm not using sqlite-ext
anymore but rather dexie
which is a wrapper of IndexDB.
I have created a fork of mapbox-gl-js, added a hook for getting custom tiles and written the code I needed. So basically, I'm not using this library.
The following is my fork of mabpox:
https://github.com/IsraelHikingMap/mapbox-gl-js
And the relevant code that uses the hook can be found here:
https://github.com/IsraelHikingMap/Site/blob/d11d20d9e7b1c2b92e800e421f4045d8b5b56d44/IsraelHiking.Web/sources/application/services/database.service.ts#L79
I think the problem in my case of migrating to Cordova 9.0 was that I used cordova-android-play-services-gradle-release
- removing it allowed me to move forward, I think.
@HarelM Thanks, but I'm not seeing how your project integrates with Cordova. What are the steps for turning it into an app? Where do the mbtiles files go? I don't see any way to submit issues for your project. Can you add that? Thanks.
@mb72 there are several "moving parts" involved here, I'll see if I can better explain then:
I don't see a good reason to allow issues in my fork of mapbox-gl as I have only added a simple hook. The code that uses this library, IsraelHikinhMap project, is a cordova app that uses the mapbox fork using patch-package
library.
Feel free to submit an issue there, the main issue that covers this topic is the following:
https://github.com/IsraelHikingMap/Site/issues/783
You can see related commits to this issue, or we can continue the discussion there.
I have create a small piece of code in nodejs to convert mbtiles file into a json file, here's the relevant code:
var sqlite3 = require('sqlite3').verbose();
var fs = require('fs');
var pako = require('pako');
var main = require('async-main').default;
let dbFilePath = process.argv[2];
let filePrefix = process.argv[3];
let recordsSplit = process.argv[4];
console.log(`Database file name: ${dbFilePath}`);
console.log(`Output file name prefix: ${filePrefix}`);
console.log(`Maximal number of record in each file: ${recordsSplit}`);
main(async () => {
var sqlDb = new sqlite3.Database(dbFilePath, sqlite3.OPEN_READONLY);
var data = await new Promise((resolve, reject) => {
var res = []
sqlDb.all('SELECT * FROM tiles', (err, rows) => {
for (let row of rows) {
var y = Math.pow(2, row.zoom_level) - row.tile_row - 1;
var id = `${row.zoom_level}_${row.tile_column}_${y}`;
var rawData = row.tile_data;
let isGzipped = rawData[0] === 0x1f && rawData[1] === 0x8b;
if (isGzipped) {
rawData = new Buffer(pako.inflate(rawData).buffer);
}
console.log(id);
res.push({id: id, x: row.tile_column, y: y, z: row.zoom_level, data: rawData.toString("base64")});
}
resolve(res);
});
});
let fileNameIndex = 0;
let promisesArray = [];
while (data.length > 0) {
let dataToDump = data.splice(0, recordsSplit);
let fileNameIndexString = fileNameIndex.toString();
let fileName = filePrefix + fileNameIndexString.padStart(10, '0') + ".json";
fileNameIndex++;
let promise = new Promise((resolve, reject) => {
fs.writeFile(fileName, JSON.stringify(dataToDump), (err) => {
if (err) {
reject(err);
}
console.log(`Finished writing: ${fileName}`);
resolve();
})
});
promisesArray.push(promise);
}
await Promise.all(promisesArray);
});
After I have this file containing json data I can load it the browser database as a document and fetch it with the custom hook. It's a bit complex, but extremely powerful. Feel free to continue this discussion is the issue above I linked as I think it's off topic for this issue.
I had the original issue here, too, and followed these suggestions to fix it:
cordova platform rm android
cordova plugin rm cordova-sqlite-ext
npm i cordova-sqlite-ext@latest
cordova plugin add cordova-sqlite-ext
cordova platform add android
I get an error when adding Cordova platforms - "Failed to install 'cordova-sqlite-ext': CordovaError: Using "requireCordovaModule" to load non-cordova module "q" is not supported. Instead, add this module to your dependencies and use regular "require" to load it."