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 ,
33+
2934 /**
30- * @var array< Marker>
35+ * @var Marker[]
3136 */
32- private array $ markers = [],
37+ array $ markers = [],
3338
3439 /**
35- * @var array< Polygon>
40+ * @var Polygon[]
3641 */
37- private array $ polygons = [],
42+ array $ polygons = [],
3843
3944 /**
40- * @var array< Polyline>
45+ * @var Polyline[]
4146 */
42- private array $ polylines = [],
47+ array $ polylines = [],
4348 ) {
49+ $ this ->markers = new Markers ($ markers );
50+ $ this ->polylines = new Polylines ($ polylines );
51+ $ this ->polygons = new Polygons ($ polygons );
4452 }
4553
4654 public function getRendererName (): ?string
@@ -88,21 +96,42 @@ public function hasOptions(): bool
8896
8997 public function addMarker (Marker $ marker ): self
9098 {
91- $ this ->markers [] = $ marker ;
99+ $ this ->markers ->add ($ marker );
100+
101+ return $ this ;
102+ }
103+
104+ public function removeMarker (Marker |string $ markerOrId ): self
105+ {
106+ $ this ->markers ->remove ($ markerOrId );
92107
93108 return $ this ;
94109 }
95110
96111 public function addPolygon (Polygon $ polygon ): self
97112 {
98- $ this ->polygons [] = $ polygon ;
113+ $ this ->polygons ->add ($ polygon );
114+
115+ return $ this ;
116+ }
117+
118+ public function removePolygon (Polygon |string $ polygonOrId ): self
119+ {
120+ $ this ->polygons ->remove ($ polygonOrId );
99121
100122 return $ this ;
101123 }
102124
103125 public function addPolyline (Polyline $ polyline ): self
104126 {
105- $ this ->polylines [] = $ polyline ;
127+ $ this ->polylines ->add ($ polyline );
128+
129+ return $ this ;
130+ }
131+
132+ public function removePolyline (Polyline |string $ polylineOrId ): self
133+ {
134+ $ this ->polylines ->remove ($ polylineOrId );
106135
107136 return $ this ;
108137 }
@@ -124,9 +153,9 @@ public function toArray(): array
124153 'zoom ' => $ this ->zoom ,
125154 'fitBoundsToMarkers ' => $ this ->fitBoundsToMarkers ,
126155 '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 ),
156+ 'markers ' => $ this -> markers ->toArray (),
157+ 'polygons ' => $ this -> polygons ->toArray (),
158+ 'polylines ' => $ this -> polylines ->toArray (),
130159 ];
131160 }
132161
0 commit comments