20
20
*/
21
21
final class Map
22
22
{
23
+ private Markers $ markers ;
24
+ private Polygons $ polygons ;
25
+ private Polylines $ polylines ;
26
+
23
27
public function __construct (
24
28
private readonly ?string $ rendererName = null ,
25
29
private ?MapOptionsInterface $ options = null ,
26
30
private ?Point $ center = null ,
27
31
private ?float $ zoom = null ,
28
32
private bool $ fitBoundsToMarkers = false ,
29
33
/**
30
- * @var array< Marker>
34
+ * @var Marker[]
31
35
*/
32
- private array $ markers = [],
33
-
36
+ array $ markers = [],
34
37
/**
35
- * @var array< Polygon>
38
+ * @var Polygon[]
36
39
*/
37
- private array $ polygons = [],
38
-
40
+ array $ polygons = [],
39
41
/**
40
- * @var array< Polyline>
42
+ * @var Polyline[]
41
43
*/
42
- private array $ polylines = [],
44
+ array $ polylines = [],
43
45
) {
46
+ $ this ->markers = new Markers ($ markers );
47
+ $ this ->polylines = new Polylines ($ polylines );
48
+ $ this ->polygons = new Polygons ($ polygons );
44
49
}
45
50
46
51
public function getRendererName (): ?string
@@ -88,21 +93,42 @@ public function hasOptions(): bool
88
93
89
94
public function addMarker (Marker $ marker ): self
90
95
{
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 );
92
104
93
105
return $ this ;
94
106
}
95
107
96
108
public function addPolygon (Polygon $ polygon ): self
97
109
{
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 );
99
118
100
119
return $ this ;
101
120
}
102
121
103
122
public function addPolyline (Polyline $ polyline ): self
104
123
{
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 );
106
132
107
133
return $ this ;
108
134
}
@@ -124,9 +150,9 @@ public function toArray(): array
124
150
'zoom ' => $ this ->zoom ,
125
151
'fitBoundsToMarkers ' => $ this ->fitBoundsToMarkers ,
126
152
'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 (),
130
156
];
131
157
}
132
158
0 commit comments