cesium + html2canvas 导出图片异常
导出:
export default function saveImg(areaId, imgTitle) {
html2canvas(document.querySelector(`#${areaId}`)).then(canvas => {
let url = canvas.toDataURL();//图片地址
let a = document.createElement('a'); // 创建一个a节点插入的document
let event =new MouseEvent('click')// 模拟鼠标click点击事件
a.download = imgTitle +'.png' // 设置a节点的download属性值
a.href = url; // 将图片的src赋值给a节点的href
a.dispatchEvent(event)
});
}
cesium 配置:
imageryProvider:new QuarkGIS.WebMapServiceImageryProvider(
contextOptions: {
webgl: {
alpha:true,
depth:true,
stencil:true,
antialias:true,
premultipliedAlpha:true,
//通过canvas.toDataURL()实现截图需要将该项设置为true
preserveDrawingBuffer:true,
failIfMajorPerformanceCaveat:true
}
}
)