20
20
*/
21
21
final class Map
22
22
{
23
+ private Markers $ markers ;
24
+ private Polygons $ polygons ;
25
+ private Polylines $ polylines ;
26
+
27
+ /**
28
+ * @param Marker[] $markers
29
+ * @param Polygon[] $polygons
30
+ * @param Polyline[] $polylines
31
+ */
23
32
public function __construct (
24
33
private readonly ?string $ rendererName = null ,
25
34
private ?MapOptionsInterface $ options = null ,
26
35
private ?Point $ center = null ,
27
36
private ?float $ zoom = null ,
28
37
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 = [],
43
41
) {
42
+ $ this ->markers = new Markers ($ markers );
43
+ $ this ->polygons = new Polygons ($ polygons );
44
+ $ this ->polylines = new Polylines ($ polylines );
44
45
}
45
46
46
47
public function getRendererName (): ?string
@@ -88,21 +89,42 @@ public function hasOptions(): bool
88
89
89
90
public function addMarker (Marker $ marker ): self
90
91
{
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 );
92
100
93
101
return $ this ;
94
102
}
95
103
96
104
public function addPolygon (Polygon $ polygon ): self
97
105
{
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 );
99
114
100
115
return $ this ;
101
116
}
102
117
103
118
public function addPolyline (Polyline $ polyline ): self
104
119
{
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 );
106
128
107
129
return $ this ;
108
130
}
@@ -124,9 +146,9 @@ public function toArray(): array
124
146
'zoom ' => $ this ->zoom ,
125
147
'fitBoundsToMarkers ' => $ this ->fitBoundsToMarkers ,
126
148
'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 (),
130
152
];
131
153
}
132
154
0 commit comments