@@ -11,80 +11,80 @@ import {CesiumUtil} from "../../Utils/CesiumUtil";
1111import SvgElementInstance from "./SvgElementInstance" ;
1212
1313export default class RegularSurfaceElementInstance extends SvgElementInstance {
14- svgToGeomInstances ( elem , options ) {
15- const { surfaceBorderWidth } = options
16- this . polylineOutInstance = null ;
17- this . polygonRect = new Bounds ( ) ;
18- this . _borderColor = Cesium . Color . RED ;
19- this . _surfaceBorderWidth = surfaceBorderWidth ;
20-
21- const pathElements = [ ] ;
22- const instances = [ ] ;
23-
24- elem . getPathElem ( pathElements ) ;
25-
26- const styleObject = pathElements [ 0 ] . getContextStyle ( ) ;
27- if ( styleObject ) {
28- if ( styleObject . strokeStyle !== "none" ) {
29- this . _borderColor = Cesium . Color . fromCssColorString (
30- styleObject . strokeStyle
31- ) ;
32- }
33-
34- // 边线线宽为像素值,界面显示效果太差,因此边线宽度取固定值
35- // if(pathElements[0].getStyle('stroke-width').hasValue()){
36- // const v=Math.round(pathElements[0].getStyle('stroke-width').getNumber())/2
37- // this._surfaceBorderWidth=v
38- // }
39-
14+ svgToGeomInstances ( elem , options , callback ) {
15+ const { surfaceBorderWidth} = options
16+ this . polylineOutInstance = null ;
17+ this . polygonRect = new Bounds ( ) ;
18+ this . _borderColor = Cesium . Color . RED ;
19+ this . _surfaceBorderWidth = surfaceBorderWidth ;
20+
21+ const pathElements = [ ] ;
22+ const instances = [ ] ;
23+
24+ elem . getPathElem ( pathElements ) ;
25+
26+ const styleObject = pathElements [ 0 ] . getContextStyle ( ) ;
27+ if ( styleObject ) {
28+ if ( styleObject . strokeStyle !== "none" ) {
29+ this . _borderColor = Cesium . Color . fromCssColorString (
30+ styleObject . strokeStyle
31+ ) ;
32+ }
33+
34+ // 边线线宽为像素值,界面显示效果太差,因此边线宽度取固定值
35+ // if(pathElements[0].getStyle('stroke-width').hasValue()){
36+ // const v=Math.round(pathElements[0].getStyle('stroke-width').getNumber())/2
37+ // this._surfaceBorderWidth=v
38+ // }
39+
40+ }
41+
42+ pathElements . forEach ( ( s ) => {
43+ instances . push ( this . pathElemToGeomInstance ( s ) ) ;
44+ } ) ;
45+
46+ const exportInstance = instances . flat ( ) ;
47+ callback ( {
48+ instances : exportInstance ,
49+ polylineOutInstance : this . polylineOutInstance ,
50+ polygonRect : this . polygonRect ,
51+ borderColor : this . _borderColor
52+ } ) ;
4053 }
4154
42- pathElements . forEach ( ( s ) => {
43- instances . push ( this . pathElemToGeomInstance ( s ) ) ;
44- } ) ;
45-
46- const exportInstance = instances . flat ( ) ;
47- return {
48- instances : exportInstance ,
49- polylineOutInstance : this . polylineOutInstance ,
50- polygonRect :this . polygonRect ,
51- borderColor :this . _borderColor
52- } ;
53- }
54-
55- pathElemToGeomInstance ( elem ) {
56- const _parts = elem . cacheCoords || elem . getCoords ( ) ;
57-
58- const polygonparts = _parts
59- . flatMap ( ( s ) =>
60- s . map ( ( t ) => {
61- this . polygonRect . addPnt ( t . x , t . y ) ;
62- const latlng = CesiumUtil . WebMercatorUnProject ( t . x , t . y ) ;
63- return [ latlng . x , latlng . y ] ;
64- } )
65- )
66- . flat ( ) ;
67-
68- const polygon = new Cesium . PolygonGeometry ( {
69- polygonHierarchy : new Cesium . PolygonHierarchy (
70- Cesium . Cartesian3 . fromDegreesArray ( polygonparts )
71- ) ,
72- } ) ;
73-
74- const groundPolyline = new Cesium . GroundPolylineGeometry ( {
75- positions : Cesium . Cartesian3 . fromDegreesArray ( polygonparts ) ,
76- width : this . _surfaceBorderWidth ,
77- } ) ;
78-
79- const instance = new Cesium . GeometryInstance ( {
80- geometry : polygon ,
81- } ) ;
82-
83- this . polylineOutInstance = new Cesium . GeometryInstance ( {
84- geometry : groundPolyline ,
85- } ) ;
86-
87- return instance ;
88- }
55+ pathElemToGeomInstance ( elem ) {
56+ const _parts = elem . cacheCoords || elem . getCoords ( ) ;
57+
58+ const polygonparts = _parts
59+ . flatMap ( ( s ) =>
60+ s . map ( ( t ) => {
61+ this . polygonRect . addPnt ( t . x , t . y ) ;
62+ const latlng = CesiumUtil . WebMercatorUnProject ( t . x , t . y ) ;
63+ return [ latlng . x , latlng . y ] ;
64+ } )
65+ )
66+ . flat ( ) ;
67+
68+ const polygon = new Cesium . PolygonGeometry ( {
69+ polygonHierarchy : new Cesium . PolygonHierarchy (
70+ Cesium . Cartesian3 . fromDegreesArray ( polygonparts )
71+ ) ,
72+ } ) ;
73+
74+ const groundPolyline = new Cesium . GroundPolylineGeometry ( {
75+ positions : Cesium . Cartesian3 . fromDegreesArray ( polygonparts ) ,
76+ width : this . _surfaceBorderWidth ,
77+ } ) ;
78+
79+ const instance = new Cesium . GeometryInstance ( {
80+ geometry : polygon ,
81+ } ) ;
82+
83+ this . polylineOutInstance = new Cesium . GeometryInstance ( {
84+ geometry : groundPolyline ,
85+ } ) ;
86+
87+ return instance ;
88+ }
8989
9090}
0 commit comments