单张离线图块检索?

时间:2019-04-19 16:24:45

标签: android sqlite leaflet

几天来我一直在努力争取获得leaflet offline maps to work。我已经修改了getTileUrl中的leaflet-offline.js函数,以便它仅从数据库返回图块并消除了_getStorageKey()JavaScriptInterfacegetImage()都可以正常工作,并返回Bitmap类型,但是脱机切片不会被渲染。我尚不清楚的一件事是Promises,而枯萎的getImage()应该返回一个byte []而不是Bitmap。有人有我可以学习的单张脱机示例吗?

//*** From leaflet-offline.js ***\\
getTileUrl: function (coords) {
        var url = L.TileLayer.prototype.getTileUrl.call(this, coords);
        var resultPromise = this._tilesDb.getItem(url).then(function (data) {
            if (data && typeof data === 'object') {
                return URL.createObjectURL(data);
            }
        }).catch(function (err) {
            throw err;
        });
        return resultPromise;
    },

//*** From leaflet.html ***\\\
var tilesDb = {
    getItem: function (key) {
        return new Promise(
            function(resolve, reject) {
                var bitmap = Android.getImage(key);
                resolve(bitmap);
            }
        );
    },
    saveTiles: function (tileUrls) {
        // return Promise.
    },
    clear: function () {
        // return Promise.
    }
};

//*** From WebAppInterface.java ***\\
@JavascriptInterface
public Bitmap getImage(String key) { return parentActivity.getImage(key); }

//*** From MainActivity.java ***\\
public Bitmap getImage(String key) {
    String z, x, y;
    String[] strArray = key.split("/");
    if (settings.getString("OverlaymapSourceTitle", "") == "OpenStreetMap") {
        z = strArray[3];
        x = strArray[4];
        y = strArray[5].split("\\.")[0];
    } else {
        z = strArray[9];
        x = strArray[11];
        y = strArray[10];
    }
    Cursor cursor;
    cursor = db.rawQuery("SELECT _tile FROM Items WHERE _z=? AND _x=? AND _y=?", new String[]{z, x, y});
    if (cursor.getCount() > 0) {
        cursor.moveToFirst();
        byte[] byteArray = cursor.getBlob(cursor.getColumnIndex("_tile"));
        Bitmap bm = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
        cursor.close();
        return bm;
    }
    return null;
}

0 个答案:

没有答案