地图canvas生成图片空白问题
const canvas = document.getElementById('canvas');
const url = canvas.toDataURL()
- 高德地图2.0版本可以使用 preserveDrawingBuffer属性
new AMap.Map('map',
{
WebGLParams:{
preserveDrawingBuffer:true
}
}
)
- 1版本使用无效,可以强制增加原型中,应该适用所有地图canvas截屏白屏问题(未验证)
HTMLCanvasElement.prototype.getContext = (function (origFun) {
return function (type, attributes) {
if (type === 'webgl') {
attributes = Object.assign({}, attributes, {
preserveDrawingBuffer: true,
})
}
return origFun.call(this, type, attributes)
}
})(HTMLCanvasElement.prototype.getContext)