@@ -6,7 +6,7 @@ import { StringExt } from '@supermap/iclient-common/commontypes/BaseTypes';
6
6
import { StyleMap } from '../overlay/vectortile/StyleMap' ;
7
7
import { DeafultCanvasStyle } from '../overlay/vectortile/DeafultCanvasStyle' ;
8
8
import { Util } from '../core/Util' ;
9
- import canvg from 'canvg' ;
9
+ import Canvg from 'canvg' ;
10
10
import Style from 'ol/style/Style' ;
11
11
import Icon from 'ol/style/Icon' ;
12
12
import CircleStyle from 'ol/style/Circle' ;
@@ -23,7 +23,6 @@ const ZERO = 0.0000001;
23
23
* @private
24
24
*/
25
25
export class StyleUtils {
26
-
27
26
/**
28
27
* @function StyleUtils.getValidStyleFromLayerInfo
29
28
* @description 通过图层信息获取有效的样式。
@@ -595,9 +594,9 @@ export class StyleUtils {
595
594
* @description 将样式对象转换成openlayer要求的ol.style
596
595
* @param {string } style - 样式对象
597
596
* @param {string } type - feature的类型
598
- * @returns {ol.style.Style }
597
+ * @returns {Promise< ol.style.Style> }
599
598
*/
600
- static toOpenLayersStyle ( style , type ) {
599
+ static async toOpenLayersStyle ( style , type ) {
601
600
style = style || this . getDefaultStyle ( ) ;
602
601
let olStyle = new Style ( ) ;
603
602
let newImage , newFill , newStroke ;
@@ -633,7 +632,7 @@ export class StyleUtils {
633
632
this . svgDiv = document . createElement ( 'div' ) ;
634
633
document . body . appendChild ( this . svgDiv ) ;
635
634
}
636
- this . getCanvasFromSVG ( src , this . svgDiv , ( canvas ) => {
635
+ await this . getCanvasFromSVG ( src , this . svgDiv , ( canvas ) => {
637
636
newImage = new Icon ( {
638
637
img : canvas ,
639
638
scale : radius / canvas . width ,
@@ -965,33 +964,39 @@ export class StyleUtils {
965
964
* @param {Object } divDom - div的dom对象
966
965
* @param {function } callBack - 转换成功执行的回调函数
967
966
*/
968
- static getCanvasFromSVG ( svgUrl , divDom , callBack ) {
967
+ static async getCanvasFromSVG ( svgUrl , divDom , callBack ) {
969
968
//一个图层对应一个canvas
970
- let canvgs = window . canvg ? window . canvg : canvg ;
969
+ const canvgs = window . canvg && window . canvg . default ? window . canvg . default : Canvg ;
971
970
let canvas = document . createElement ( 'canvas' ) ;
972
971
canvas . id = 'dataviz-canvas-' + Util . newGuid ( 8 ) ;
973
972
canvas . style . display = "none" ;
974
973
divDom . appendChild ( canvas ) ;
975
974
try {
976
- canvgs ( canvas . id , svgUrl , {
975
+ const ctx = canvas . getContext ( '2d' ) ;
976
+ const v = await canvgs . from ( ctx , svgUrl , {
977
977
ignoreMouse : true ,
978
978
ignoreAnimation : true ,
979
- renderCallback : function ( ) {
980
- if ( canvas . width > 300 || canvas . height > 300 ) {
981
- // Util.showMessage(DataViz.Language.sizeIsWrong,'WARNING');
982
- return ;
983
- }
984
- callBack ( canvas ) ;
985
- } ,
986
- forceRedraw : function ( ) {
987
- return false
988
- }
989
- } ) ;
979
+ forceRedraw : ( ) => false
980
+ } )
981
+ v . start ( ) ;
982
+ if ( canvas . width > 300 || canvas . height > 300 ) {
983
+ return ;
984
+ }
985
+ callBack ( canvas ) ;
990
986
} catch ( e ) {
991
987
return ;
992
988
}
993
989
}
994
990
991
+ /**
992
+ * @function StyleUtils.stopCanvg
993
+ * @description 调用Canvg实例的stop();
994
+ */
995
+ static stopCanvg ( ) {
996
+ this . canvgsV . forEach ( v => v . stop ( ) ) ;
997
+ this . canvgsV = [ ] ;
998
+ }
999
+
995
1000
/**
996
1001
* @function StyleUtils.getMarkerDefaultStyle 获取默认标注图层feature的样式
997
1002
* @param {string } featureType feature的类型
@@ -1041,16 +1046,16 @@ export class StyleUtils {
1041
1046
* @param {string } styleParams 样式参数
1042
1047
* @param {string } featureType feature类型
1043
1048
* @param {boolean } isRank 是否为等级符号
1044
- * @returns {Object } style对象
1049
+ * @returns {Promise<ol.style.Style> }
1045
1050
*/
1046
- static getOpenlayersStyle ( styleParams , featureType , isRank ) {
1051
+ static async getOpenlayersStyle ( styleParams , featureType , isRank ) {
1047
1052
let style ;
1048
1053
if ( styleParams . type === "BASIC_POINT" ) {
1049
- style = this . toOpenLayersStyle ( styleParams , featureType ) ;
1054
+ style = await this . toOpenLayersStyle ( styleParams , featureType ) ;
1050
1055
} else if ( styleParams . type === "SYMBOL_POINT" ) {
1051
1056
style = this . getSymbolStyle ( styleParams , isRank ) ;
1052
1057
} else if ( styleParams . type === "SVG_POINT" ) {
1053
- style = this . getSVGStyle ( styleParams ) ;
1058
+ style = await this . getSVGStyle ( styleParams ) ;
1054
1059
} else if ( styleParams . type === 'IMAGE_POINT' ) {
1055
1060
style = this . getImageStyle ( styleParams ) ;
1056
1061
}
@@ -1103,17 +1108,17 @@ export class StyleUtils {
1103
1108
/**
1104
1109
* @function StyleUtils.getSVGStyle 获取svg的样式
1105
1110
* @param {Object } styleParams - 样式参数
1106
- * @returns {Object } style对象
1111
+ * @returns {Promise<ol.style.Style> }
1107
1112
*/
1108
- static getSVGStyle ( styleParams ) {
1113
+ static async getSVGStyle ( styleParams ) {
1109
1114
let style , that = this ;
1110
1115
if ( ! that . svgDiv ) {
1111
1116
that . svgDiv = document . createElement ( 'div' ) ;
1112
1117
document . body . appendChild ( that . svgDiv ) ;
1113
1118
}
1114
1119
const { url, radius, offsetX, offsetY, fillOpacity, rotation } = styleParams ;
1115
1120
let anchor = this . getIconAnchor ( offsetX , offsetY ) ;
1116
- StyleUtils . getCanvasFromSVG ( url , that . svgDiv , function ( canvas ) {
1121
+ await StyleUtils . getCanvasFromSVG ( url , that . svgDiv , function ( canvas ) {
1117
1122
style = new Style ( {
1118
1123
image : new Icon ( {
1119
1124
img : that . setColorToCanvas ( canvas , styleParams ) ,
0 commit comments