* @function StyleUtils.getDefaultStyle * @description 将样式对象转换成openlayer要求的ol.style * @param {string} style - 样式对象 * @param {string} type - feature的类型 * @returns {Promise }
(style, type)
| 597 | * @returns {Promise<ol.style.Style>} |
| 598 | */ |
| 599 | static async toOpenLayersStyle(style, type) { |
| 600 | style = style || this.getDefaultStyle(); |
| 601 | let olStyle = new Style(); |
| 602 | let newImage, newFill, newStroke; |
| 603 | let { |
| 604 | fillColor, |
| 605 | fillOpacity, |
| 606 | strokeColor, |
| 607 | strokeWidth, |
| 608 | strokeOpacity, |
| 609 | radius, |
| 610 | lineCap, |
| 611 | src, |
| 612 | scale, |
| 613 | offsetX, |
| 614 | offsetY, |
| 615 | //size, |
| 616 | //imgSize, |
| 617 | anchor |
| 618 | } = style; |
| 619 | let fillColorArray = this.hexToRgb(fillColor); |
| 620 | if (fillColorArray) { |
| 621 | fillColorArray.push(fillOpacity); |
| 622 | } |
| 623 | |
| 624 | let strokeColorArray = this.hexToRgb(strokeColor); |
| 625 | if (strokeColorArray) { |
| 626 | strokeColorArray.push(strokeOpacity); |
| 627 | } |
| 628 | if (type === "POINT") { |
| 629 | if (src) { |
| 630 | if (/.+(\.svg$)/.test(src)) { |
| 631 | if (!this.svgDiv) { |
| 632 | this.svgDiv = document.createElement('div'); |
| 633 | document.body.appendChild(this.svgDiv); |
| 634 | } |
| 635 | await this.getCanvasFromSVG(src, this.svgDiv, (canvas) => { |
| 636 | newImage = new Icon({ |
| 637 | img: canvas, |
| 638 | scale: radius / canvas.width, |
| 639 | imgSize: [canvas.width, canvas.height], |
| 640 | anchor: [0.5, 0.5] |
| 641 | }) |
| 642 | }) |
| 643 | } else { |
| 644 | newImage = new Icon({ |
| 645 | src: src, |
| 646 | scale: scale, |
| 647 | anchor: anchor |
| 648 | }); |
| 649 | } |
| 650 | } else { |
| 651 | newImage = new CircleStyle({ |
| 652 | radius, |
| 653 | fill: new FillStyle({ |
| 654 | color: fillColorArray |
| 655 | }), |
| 656 | stroke: new StrokeStyle({ |
no test coverage detected