2020 */
2121final class Map
2222{
23+ private Markers $ markers ;
24+ private Polygons $ polygons ;
25+ private Polylines $ polylines ;
26+
2327 public function __construct (
2428 private readonly ?string $ rendererName = null ,
2529 private ?MapOptionsInterface $ options = null ,
2630 private ?Point $ center = null ,
2731 private ?float $ zoom = null ,
2832 private bool $ fitBoundsToMarkers = false ,
2933 /**
30- * @var array< Marker>
34+ * @var Marker[]
3135 */
32- private array $ markers = [],
33-
36+ array $ markers = [],
3437 /**
35- * @var array< Polygon>
38+ * @var Polygon[]
3639 */
37- private array $ polygons = [],
38-
40+ array $ polygons = [],
3941 /**
40- * @var array< Polyline>
42+ * @var Polyline[]
4143 */
42- private array $ polylines = [],
44+ array $ polylines = [],
4345 ) {
46+ $ this ->markers = new Markers ($ markers );
47+ $ this ->polylines = new Polylines ($ polylines );
48+ $ this ->polygons = new Polygons ($ polygons );
4449 }
4550
4651 public function getRendererName (): ?string
@@ -88,21 +93,42 @@ public function hasOptions(): bool
8893
8994 public function addMarker (Marker $ marker ): self
9095 {
91- $ this ->markers [] = $ marker ;
96+ $ this ->markers ->add ($ marker );
97+
98+ return $ this ;
99+ }
100+
101+ public function removeMarker (Marker |string $ markerOrId ): self
102+ {
103+ $ this ->markers ->remove ($ markerOrId );
92104
93105 return $ this ;
94106 }
95107
96108 public function addPolygon (Polygon $ polygon ): self
97109 {
98- $ this ->polygons [] = $ polygon ;
110+ $ this ->polygons ->add ($ polygon );
111+
112+ return $ this ;
113+ }
114+
115+ public function removePolygon (Polygon |string $ polygonOrId ): self
116+ {
117+ $ this ->polygons ->remove ($ polygonOrId );
99118
100119 return $ this ;
101120 }
102121
103122 public function addPolyline (Polyline $ polyline ): self
104123 {
105- $ this ->polylines [] = $ polyline ;
124+ $ this ->polylines ->add ($ polyline );
125+
126+ return $ this ;
127+ }
128+
129+ public function removePolyline (Polyline |string $ polylineOrId ): self
130+ {
131+ $ this ->polylines ->remove ($ polylineOrId );
106132
107133 return $ this ;
108134 }
@@ -124,9 +150,9 @@ public function toArray(): array
124150 'zoom ' => $ this ->zoom ,
125151 'fitBoundsToMarkers ' => $ this ->fitBoundsToMarkers ,
126152 '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 ),
153+ 'markers ' => $ this -> markers ->toArray (),
154+ 'polygons ' => $ this -> polygons ->toArray (),
155+ 'polylines ' => $ this -> polylines ->toArray (),
130156 ];
131157 }
132158
0 commit comments