有两种方式,一种是遍历全量下载
另一种是根据已经请求到的下载
需要在Cesium3DTile.prototype.requestContent函数中将请求到的arrabuffer下载
function downloadFile(name,blob){
const url = window.URL.createObjectURL(new Blob([blob]))
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', name)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
let name = content.url.split('?')[0];
name = name.substr(tileset.baseIndex+1,name.length)
downloadFile(name,arrayBuffer)
另一种是json,在Cesium3DTileset.prototype.loadTileset中进行下载
function saveJson(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
if(typeof data === "object"){
data = JSON.stringify(data, undefined, 4)
}
var blob = new Blob([data], {type: 'text/json'}),
e = document.createEvent('MouseEvents'),
a = document.createElement('a')
a.download = filename
a.href = window.URL.createObjectURL(blob)
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
}
if(this.baseIndex){
let name = resource.url.split('?')[0];
name = name.substr(this.baseIndex+1,name.length)
saveJson(tilesetJson, name);
}
下载后的文件都在同一级,需要分离文件到对应的文件夹中,用一小段python代码即可
import os
import shutil
def getfiles():
filenames=os.listdir(r'./')
for i in range(len(filenames)):
if(filenames[i].endswith('b3dm')):
name = filenames[i];
nameList = name.split('_');
if(len(nameList)>1):
yijimulu = './'+str(nameList[0])
if(os.path.exists(yijimulu)==False):
os.mkdir(yijimulu)
erjimulu = yijimulu+ '/'+str(nameList[1])
if (os.path.exists(erjimulu)==False):
os.mkdir(erjimulu)
shutil.move(name, erjimulu+'/'+nameList[2])
getfiles()