按照html2canvas正常操作是可以进行截图操作的,但是发现没有截取到地球,发现cesium内也需要进行设置
需要先安装html2canvas 引入
cesium创建视图时也需要添加对应参数preserveDrawingBuffer
上代码!!
const viewer = new Cesium.Viewer("cesiumContainer", {
contextOptions: {
requestWebgl2: true,
// Cesium状态下允许canvas转图片convertToImage
webgl: {
preserveDrawingBuffer: true,
},
webgl2: true,
},
vrButton: true,
animation: false, //是否显示动画控件
baseLayerPicker: false, //是否显示图层选择控件
geocoder: false, //是否显示地名查找控件
timeline: false, //是否显示时间线控件
sceneModePicker: false, //是否显示投影方式控件
navigationHelpButton: false, //是否显示帮助信息控件
fullscreenButton: false, //是否显示全屏按钮
infoBox: false, //是否显示点击要素之后显示的信息
homeButton: false, //是否显示Home按钮
selectionIndicator: false,
terrainProvider: Cesium.createWorldTerrain({
requestWaterMask: true, //水面特效
});
setTimeout(() => {
let canvasElement = document.getElementById("cesiumContainer");
// 转换为图片进行输出
let opts = {
useCORS: true, // 【重要】开启跨域配置
allowTaint: true,
};
html2canvas(canvasElement, opts).then(function (canvas) {
var link = document.createElement("a");
link.setAttribute("download", "map.png");
if (canvas.toBlob) {
canvas.toBlob(function (blob) {
link.href = URL.createObjectURL(blob);
link.click();
});
} else {
var dataUrl = canvas.toDataURL("image/jpeg", 1.0);
link.href = dataUrl;
link.click();
}
});
}, 3000);
标签:控件,截图,false,canvas,html2canvas,link,Cesium,true
From: https://blog.csdn.net/qq_43523901/article/details/145181754