Bootstrap

Openlayers 报错记录 Failed to execute ‘toDataURL‘ on ‘HTMLCanvasElement‘:

cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/components/DrawMap/index.vue?vue&type=script&lang=js:133 Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.

原因是引用的图层得配置跨域问题。 这是浏览器对canvas 设置的导出安全策略。

Failed to execute 'toDataURL' on 'HTMLCanvasElement':

解决问题。 每个引用的图层添加一个

crossOrigin: 'anonymous',

即可、、、   不用谢、、

;