* @function StyleUtils.getCanvasFromSVG * @description 将SVG转换成Canvas * @param {string} svgUrl - 颜色数组 * @param {Object} divDom - div的dom对象 * @param {function} callBack - 转换成功执行的回调函数
(svgUrl, divDom, callBack)
| 965 | * @param {function} callBack - 转换成功执行的回调函数 |
| 966 | */ |
| 967 | static async getCanvasFromSVG(svgUrl, divDom, callBack) { |
| 968 | //一个图层对应一个canvas |
| 969 | const canvgs = Canvg; |
| 970 | let canvas = document.createElement('canvas'); |
| 971 | canvas.id = 'dataviz-canvas-' + Util.newGuid(8); |
| 972 | canvas.style.display = "none"; |
| 973 | divDom.appendChild(canvas); |
| 974 | try { |
| 975 | const ctx = canvas.getContext('2d'); |
| 976 | const v = await canvgs.from(ctx, svgUrl, { |
| 977 | ignoreMouse: true, |
| 978 | ignoreAnimation: true, |
| 979 | forceRedraw: () => false |
| 980 | }) |
| 981 | v.start(); |
| 982 | if (canvas.width > 300 || canvas.height > 300) { |
| 983 | return; |
| 984 | } |
| 985 | callBack(canvas); |
| 986 | } catch (e) { |
| 987 | return; |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | /** |
| 992 | * @function StyleUtils.getMarkerDefaultStyle 获取默认标注图层feature的样式 |
no test coverage detected