diff --git a/src/Map/src/Map.php b/src/Map/src/Map.php index 3053d524df2..530e9a5c6cb 100644 --- a/src/Map/src/Map.php +++ b/src/Map/src/Map.php @@ -103,22 +103,21 @@ public function addPolygon(Polygon $polygon): self public function addPolyline(Polyline $polyline): self { $this->polylines[] = $polyline; - return $this; } - + public function toArray(): array { if (!$this->fitBoundsToMarkers) { if (null === $this->center) { throw new InvalidArgumentException('The map "center" must be explicitly set when not enabling "fitBoundsToMarkers" feature.'); } - + if (null === $this->zoom) { throw new InvalidArgumentException('The map "zoom" must be explicitly set when not enabling "fitBoundsToMarkers" feature.'); } } - + return [ 'center' => $this->center?->toArray(), 'zoom' => $this->zoom, @@ -146,32 +145,31 @@ public function toArray(): array public static function fromArray(array $map): self { $map['fitBoundsToMarkers'] = true; - if (isset($map['center'])) { $map['center'] = Point::fromArray($map['center']); } - + if (isset($map['zoom']) || isset($map['center'])) { $map['fitBoundsToMarkers'] = false; } - + $map['markers'] ??= []; if (!\is_array($map['markers'])) { throw new InvalidArgumentException('The "markers" parameter must be an array.'); } $map['markers'] = array_map(Marker::fromArray(...), $map['markers']); - + $map['polygons'] ??= []; if (!\is_array($map['polygons'])) { throw new InvalidArgumentException('The "polygons" parameter must be an array.'); } $map['polygons'] = array_map(Polygon::fromArray(...), $map['polygons']); - + $map['polylines'] ??= []; if (!\is_array($map['polylines'])) { throw new InvalidArgumentException('The "polylines" parameter must be an array.'); } - $map['polylines'] = array_map(Polygon::fromArray(...), $map['polylines']); + $map['polylines'] = array_map(Polyline::fromArray(...), $map['polylines']); return new self(...$map); }