* @function StyleUtils.getSVGStyle 获取svg的样式 * @param {Object} styleParams - 样式参数 * @returns {Promise }
(styleParams)
| 1102 | * @returns {Promise<ol.style.Style>} |
| 1103 | */ |
| 1104 | static async getSVGStyle(styleParams) { |
| 1105 | let style, that = this; |
| 1106 | if (!that.svgDiv) { |
| 1107 | that.svgDiv = document.createElement('div'); |
| 1108 | document.body.appendChild(that.svgDiv); |
| 1109 | } |
| 1110 | const { url, radius, offsetX, offsetY, fillOpacity, rotation } = styleParams; |
| 1111 | let anchor = this.getIconAnchor(offsetX, offsetY); |
| 1112 | await StyleUtils.getCanvasFromSVG(url, that.svgDiv, function (canvas) { |
| 1113 | style = new Style({ |
| 1114 | image: new Icon({ |
| 1115 | img: that.setColorToCanvas(canvas, styleParams), |
| 1116 | scale: 2 * radius / canvas.width, |
| 1117 | imgSize: [canvas.width, canvas.height], |
| 1118 | anchor: anchor || [0.5, 0.5], |
| 1119 | opacity: fillOpacity, |
| 1120 | anchorOrigin: 'bottom-right', |
| 1121 | rotation |
| 1122 | }) |
| 1123 | }); |
| 1124 | }); |
| 1125 | return style; |
| 1126 | } |
| 1127 | |
| 1128 | /** |
| 1129 | * @function StyleUtils.setColorToCanvas 将颜色,透明度等样式设置到canvas上 |
no test coverage detected