@@ -42,8 +42,8 @@ class Polygon implements Draw
4242 public function __construct (string $ strokeColor , int $ strokeWeight , string $ fillColor )
4343 {
4444 $ 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) ;
4747 }
4848
4949 /**
@@ -78,31 +78,34 @@ function (LatLng $p) use ($mapData) {
7878 $ this ->points
7979 );
8080
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
9497 );
9598
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 );
100106 }
101- $ dImage ->drawLine ($ cPoints [$ pK ]->getX (), $ cPoints [$ pK ]->getY (), $ point ->getX (), $ point ->getY (), $ this ->strokeWeight , $ this ->strokeColor );
102107 }
103108
104- $ image ->pasteOn ($ dImage , 0 , 0 );
105-
106109 return $ this ;
107110 }
108111}
0 commit comments