@@ -42,8 +42,8 @@ class Polygon implements Draw
42
42
public function __construct (string $ strokeColor , int $ strokeWeight , string $ fillColor )
43
43
{
44
44
$ this ->strokeColor = \str_replace ('# ' , '' , $ strokeColor );
45
- $ this ->strokeWeight = $ strokeWeight ;
46
- $ this ->fillColor = $ fillColor ;
45
+ $ this ->strokeWeight = $ strokeWeight > 0 ? $ strokeWeight : 0 ;
46
+ $ this ->fillColor = \str_replace ( ' # ' , '' , $ fillColor) ;
47
47
}
48
48
49
49
/**
@@ -78,31 +78,34 @@ function (LatLng $p) use ($mapData) {
78
78
$ this ->points
79
79
);
80
80
81
- $ dImage = Image::newCanvas ($ image ->getWidth (), $ image ->getHeight ());
82
-
83
- $ dImage ->drawPolygon (
84
- \array_reduce (
85
- $ cPoints ,
86
- function (array $ acc , XY $ p ) {
87
- $ acc [] = $ p ->getX ();
88
- $ acc [] = $ p ->getY ();
89
- return $ acc ;
90
- },
91
- []
92
- ),
93
- $ this ->fillColor
81
+ $ image ->pasteOn (
82
+ Image::newCanvas ($ image ->getWidth (), $ image ->getHeight ())
83
+ ->drawPolygon (
84
+ \array_reduce (
85
+ $ cPoints ,
86
+ function (array $ acc , XY $ p ) {
87
+ $ acc [] = $ p ->getX ();
88
+ $ acc [] = $ p ->getY ();
89
+ return $ acc ;
90
+ },
91
+ []
92
+ ),
93
+ $ this ->fillColor
94
+ ),
95
+ 0 ,
96
+ 0
94
97
);
95
98
96
- foreach ($ cPoints as $ k => $ point ) {
97
- $ pK = $ k - 1 ;
98
- if (!isset ($ cPoints [$ pK ])) {
99
- $ pK = \count ($ cPoints ) - 1 ;
99
+ if ($ this ->strokeWeight > 0 ) {
100
+ foreach ($ cPoints as $ k => $ point ) {
101
+ $ pK = $ k - 1 ;
102
+ if (!isset ($ cPoints [$ pK ])) {
103
+ $ pK = \count ($ cPoints ) - 1 ;
104
+ }
105
+ $ image ->drawLine ($ cPoints [$ pK ]->getX (), $ cPoints [$ pK ]->getY (), $ point ->getX (), $ point ->getY (), $ this ->strokeWeight , $ this ->strokeColor );
100
106
}
101
- $ dImage ->drawLine ($ cPoints [$ pK ]->getX (), $ cPoints [$ pK ]->getY (), $ point ->getX (), $ point ->getY (), $ this ->strokeWeight , $ this ->strokeColor );
102
107
}
103
108
104
- $ image ->pasteOn ($ dImage , 0 , 0 );
105
-
106
109
return $ this ;
107
110
}
108
111
}
0 commit comments