MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / getCanvasFromSVG

Method getCanvasFromSVG

src/openlayers/core/StyleUtils.js:967–989  ·  view source on GitHub ↗

* @function StyleUtils.getCanvasFromSVG * @description 将SVG转换成Canvas * @param {string} svgUrl - 颜色数组 * @param {Object} divDom - div的dom对象 * @param {function} callBack - 转换成功执行的回调函数

(svgUrl, divDom, callBack)

Source from the content-addressed store, hash-verified

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的样式

Callers 3

toOpenLayersStyleMethod · 0.95
getSVGStyleMethod · 0.45

Calls 3

createElementMethod · 0.80
getContextMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected