Cesium 导出地图
原理:canvas画布出图
解决方法
1.直接使用底层canvas
2.使用插件如html2canvas.
直接上代码,这里用的是方法1
const sceneExport = {
saveToFile(filename,viewer) {
viewer.scene.render();
let canvas = viewer.scene.canvas;
let image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
let link = document.createElement("a");
let blob = this.dataURLtoBlob(image);
let objUrl = URL.createObjectURL(blob);
link.download = filename + ".png";
link.href = objUrl;
link.click();
},
dataURLtoBlob(dataUrl) {
let arr = dataUrl.split(','),
mime = arr[0].match(/:(.*?);/)[1],
bStr = atob(arr[1]),
n = bStr.length,
u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bStr.charCodeAt(n);
}
return new Blob([u8arr], { type: mime });
}
}
export default sceneExport;