33 * @Author : zk
44 * @Date : 2021-11-18 15:08:54
55 * @LastEditors : zk
6- * @LastEditTime : 2022-06-13 19:14:58
6+ * @LastEditTime : 2022-06-22 10:16:55
77 */
88import { fabric } from 'fabric' ;
99import PlotPolylineObject from '../PlotPolylineObject' ;
@@ -17,11 +17,20 @@ const PlotIrregularShape = fabric.util.createClass(PlotPolylineObject, {
1717 } ) ;
1818 return boundingBox ;
1919 } ,
20+ _calcStrokeOrFillGeometry ( coords ) {
21+ // 非规则符号使用外部设置函数进行控制点填充
22+ const strokeCoords = this . _elem . applyFuncToStorkeGeometry ( coords ) ;
23+ // 非规则符号使用完整几何进行填充
24+ const fillCoords = this . _elem . applyFuncToFillGeometry ( coords ) ;
25+ return { strokeCoords, fillCoords } ;
26+ } ,
2027 _pathElementRender : function _pathElementRender ( ctx , coords ) {
2128 const style = this . _elem . getContextStyle ( ) ;
2229 const lineWidth = this . calcMapScaleLineWidth ( style . lineWidth ) ;
2330 style . lineWidth = lineWidth ;
24- this . _pointsToPath ( ctx , style , coords ) ;
31+
32+ const { strokeCoords, fillCoords } = this . _calcStrokeOrFillGeometry ( coords ) ;
33+ this . _pointsToPath ( ctx , style , strokeCoords , fillCoords ) ;
2534 } ,
2635 _comparePathElementRender : function _comparePathElementRender ( ctx , coords ) {
2736 const style = this . _elem . getContextStyle ( ) ;
@@ -39,8 +48,41 @@ const PlotIrregularShape = fabric.util.createClass(PlotPolylineObject, {
3948 } )
4049 ) ;
4150 if ( _compareStyle ) {
42- this . _pointsToPath ( ctx , _compareStyle , coords ) ;
51+ const { strokeCoords, fillCoords } = this . _calcStrokeOrFillGeometry ( coords ) ;
52+ this . _pointsToPath ( ctx , style , strokeCoords , fillCoords ) ;
53+ }
54+ } ,
55+
56+ _pointsToPath : function _pointsToPath ( ctx , style , strokeCoords , fillCoords ) {
57+ // stroke
58+ ctx . save ( ) ;
59+ const strokeCoordsPnts = strokeCoords . filter ( ( s ) => s . length !== 0 ) ;
60+ for ( let j = 0 ; j < strokeCoordsPnts . length ; j += 1 ) {
61+ const tempPnts = strokeCoordsPnts [ j ] ;
62+ const tempPntsLen = tempPnts . length ;
63+ ctx . beginPath ( ) ;
64+ ctx . moveTo ( tempPnts [ 0 ] . x + this . m_offsetX , tempPnts [ 0 ] . y + this . m_offsetY ) ;
65+ for ( let m = 1 ; m < tempPntsLen ; m += 1 ) {
66+ ctx . lineTo ( tempPnts [ m ] . x + this . m_offsetX , tempPnts [ m ] . y + this . m_offsetY ) ;
67+ }
68+ this . _drawPath ( ctx , Object . assign ( { } , style , { fillStyle : 'none' } ) ) ;
69+ }
70+ ctx . restore ( ) ;
71+
72+ // fill
73+ ctx . save ( ) ;
74+ const fillPnts = fillCoords . filter ( ( s ) => s . length !== 0 ) ;
75+ for ( let j = 0 ; j < fillPnts . length ; j += 1 ) {
76+ const tempPnts = fillPnts [ j ] ;
77+ const tempPntsLen = tempPnts . length ;
78+ ctx . beginPath ( ) ;
79+ ctx . moveTo ( tempPnts [ 0 ] . x + this . m_offsetX , tempPnts [ 0 ] . y + this . m_offsetY ) ;
80+ for ( let m = 1 ; m < tempPntsLen ; m += 1 ) {
81+ ctx . lineTo ( tempPnts [ m ] . x + this . m_offsetX , tempPnts [ m ] . y + this . m_offsetY ) ;
82+ }
83+ this . _drawPath ( ctx , Object . assign ( { } , style , { strokeStyle : 'none' } ) ) ;
4384 }
85+ ctx . restore ( ) ;
4486 } ,
4587 _render ( ctx ) {
4688 const coords = this . _elem . cacheCoords || this . _elem . getCoords ( ) ;
0 commit comments