当前位置: 首页 > 工具软件 > dc-sdk > 使用案例 >

Cesium DC-SDK自定义导出地图

张建树
2023-12-01
// 地图场景导出
const sceneExport = {
    saveToFile(filename) {
        const {viewer} = global;
        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;

参考地址:https://blog.csdn.net/xietao20/article/details/109401838

 类似资料: