我想用maplibre-gl-js加载一个本地.mbtiles (带有矢量瓦片)(在一个科尔多瓦应用中,如果知道这一点很重要的话)。据我所知,我应该使用addProtocol方法。这很好,因为我得到了我的console.log,但我不知道如何加载磁贴然后…
这是我的代码:
maplibregl.addProtocol('mbtiles', (params, callback) => {
console.log('I get this log.');
// but what to do here to get local mbtiles vector tiles loaded?
});
样式的定义如下:
...
"sources": {
"openmaptiles": {
"type": "vector",
"url": "mbtiles://map/data/test.mbtiles"
}
},
...
感谢任何帮助/提示:)
如果您需要更多信息,请随时询问。
另外,我以前用过mapbox-gl-cordova-offline,并试图理解这个插件是如何加载磁贴的,但我还不能弄明白。
发布于 2021-11-15 20:05:49
以下是我为实现这一目标所做的工作:
maplibregl.addProtocol("custom", (params, callback) => {
// tileBuffer = get a arrayBuffer of a specific tile using params.url
if (tileBuffer) {
callback(null, tileBuffer, null, null);
} else {
let message = `Tile is not in DB: ${params.url}`;
callback(new Error(message));
}
return { cancel: () => { } };
});
我使用cordova-sqlite-ext
是为了能够在Cordova中使用预先填充的数据库。该样式有一个tiles: [custom://database-name/{z}/{x}/{y}]
,以便知道要获取哪个磁贴。
值得注意的是,我在maplibre中添加了addProtocol
方法,特别是为了这个目的。:-)
https://stackoverflow.com/questions/68853853
复制相似问题