@@ -103,22 +103,21 @@ public function addPolygon(Polygon $polygon): self
103
103
public function addPolyline (Polyline $ polyline ): self
104
104
{
105
105
$ this ->polylines [] = $ polyline ;
106
-
107
106
return $ this ;
108
107
}
109
-
108
+
110
109
public function toArray (): array
111
110
{
112
111
if (!$ this ->fitBoundsToMarkers ) {
113
112
if (null === $ this ->center ) {
114
113
throw new InvalidArgumentException ('The map "center" must be explicitly set when not enabling "fitBoundsToMarkers" feature. ' );
115
114
}
116
-
115
+
117
116
if (null === $ this ->zoom ) {
118
117
throw new InvalidArgumentException ('The map "zoom" must be explicitly set when not enabling "fitBoundsToMarkers" feature. ' );
119
118
}
120
119
}
121
-
120
+
122
121
return [
123
122
'center ' => $ this ->center ?->toArray(),
124
123
'zoom ' => $ this ->zoom ,
@@ -146,32 +145,31 @@ public function toArray(): array
146
145
public static function fromArray (array $ map ): self
147
146
{
148
147
$ map ['fitBoundsToMarkers ' ] = true ;
149
-
150
148
if (isset ($ map ['center ' ])) {
151
149
$ map ['center ' ] = Point::fromArray ($ map ['center ' ]);
152
150
}
153
-
151
+
154
152
if (isset ($ map ['zoom ' ]) || isset ($ map ['center ' ])) {
155
153
$ map ['fitBoundsToMarkers ' ] = false ;
156
154
}
157
-
155
+
158
156
$ map ['markers ' ] ??= [];
159
157
if (!\is_array ($ map ['markers ' ])) {
160
158
throw new InvalidArgumentException ('The "markers" parameter must be an array. ' );
161
159
}
162
160
$ map ['markers ' ] = array_map (Marker::fromArray (...), $ map ['markers ' ]);
163
-
161
+
164
162
$ map ['polygons ' ] ??= [];
165
163
if (!\is_array ($ map ['polygons ' ])) {
166
164
throw new InvalidArgumentException ('The "polygons" parameter must be an array. ' );
167
165
}
168
166
$ map ['polygons ' ] = array_map (Polygon::fromArray (...), $ map ['polygons ' ]);
169
-
167
+
170
168
$ map ['polylines ' ] ??= [];
171
169
if (!\is_array ($ map ['polylines ' ])) {
172
170
throw new InvalidArgumentException ('The "polylines" parameter must be an array. ' );
173
171
}
174
- $ map ['polylines ' ] = array_map (Polygon ::fromArray (...), $ map ['polylines ' ]);
172
+ $ map ['polylines ' ] = array_map (Polyline ::fromArray (...), $ map ['polylines ' ]);
175
173
176
174
return new self (...$ map );
177
175
}
0 commit comments