2020 */
2121final class Map
2222{
23+ private Markers $ markers ;
24+ private Polygons $ polygons ;
25+ private Polylines $ polylines ;
26+
27+ /**
28+ * @param Marker[] $markers
29+ * @param Polyline[] $polylines
30+ * @param Polygone[] $polygons
31+ */
2332 public function __construct (
2433 private readonly ?string $ rendererName = null ,
2534 private ?MapOptionsInterface $ options = null ,
2635 private ?Point $ center = null ,
2736 private ?float $ zoom = null ,
2837 private bool $ fitBoundsToMarkers = false ,
29- /**
30- * @var array<Marker>
31- */
32- private array $ markers = [],
33-
34- /**
35- * @var array<Polygon>
36- */
37- private array $ polygons = [],
38-
39- /**
40- * @var array<Polyline>
41- */
42- private array $ polylines = [],
38+ array $ markers = [],
39+ array $ polygons = [],
40+ array $ polylines = [],
4341 ) {
42+ $ this ->markers = new Markers ($ markers );
43+ $ this ->polylines = new Polylines ($ polylines );
44+ $ this ->polygons = new Polygons ($ polygons );
4445 }
4546
4647 public function getRendererName (): ?string
@@ -88,21 +89,42 @@ public function hasOptions(): bool
8889
8990 public function addMarker (Marker $ marker ): self
9091 {
91- $ this ->markers [] = $ marker ;
92+ $ this ->markers ->add ($ marker );
93+
94+ return $ this ;
95+ }
96+
97+ public function removeMarker (Marker |string $ markerOrId ): self
98+ {
99+ $ this ->markers ->remove ($ markerOrId );
92100
93101 return $ this ;
94102 }
95103
96104 public function addPolygon (Polygon $ polygon ): self
97105 {
98- $ this ->polygons [] = $ polygon ;
106+ $ this ->polygons ->add ($ polygon );
107+
108+ return $ this ;
109+ }
110+
111+ public function removePolygon (Polygon |string $ polygonOrId ): self
112+ {
113+ $ this ->polygons ->remove ($ polygonOrId );
99114
100115 return $ this ;
101116 }
102117
103118 public function addPolyline (Polyline $ polyline ): self
104119 {
105- $ this ->polylines [] = $ polyline ;
120+ $ this ->polylines ->add ($ polyline );
121+
122+ return $ this ;
123+ }
124+
125+ public function removePolyline (Polyline |string $ polylineOrId ): self
126+ {
127+ $ this ->polylines ->remove ($ polylineOrId );
106128
107129 return $ this ;
108130 }
@@ -124,9 +146,9 @@ public function toArray(): array
124146 'zoom ' => $ this ->zoom ,
125147 'fitBoundsToMarkers ' => $ this ->fitBoundsToMarkers ,
126148 'options ' => $ this ->options ? MapOptionsNormalizer::normalize ($ this ->options ) : [],
127- 'markers ' => array_map ( static fn ( Marker $ marker ) => $ marker ->toArray (), $ this -> markers ),
128- 'polygons ' => array_map ( static fn ( Polygon $ polygon ) => $ polygon ->toArray (), $ this -> polygons ),
129- 'polylines ' => array_map ( static fn ( Polyline $ polyline ) => $ polyline ->toArray (), $ this -> polylines ),
149+ 'markers ' => $ this -> markers ->toArray (),
150+ 'polygons ' => $ this -> polygons ->toArray (),
151+ 'polylines ' => $ this -> polylines ->toArray (),
130152 ];
131153 }
132154
0 commit comments