1111
1212namespace Symfony \UX \Map ;
1313
14+ use Symfony \UX \Map \Exception \InvalidArgumentException ;
15+
1416/**
1517 * Represents a marker on a map.
1618 *
1921final readonly class Marker
2022{
2123 /**
22- * @param array<string, mixed> $extra Extra data, can be used by the developer to store additional information and use them later JavaScript side
24+ * @param array<string, mixed> $extra Extra data, can be used by the developer to store additional information and
25+ * use them later JavaScript side
2326 */
2427 public function __construct (
2528 private Point $ position ,
@@ -29,6 +32,14 @@ public function __construct(
2932 ) {
3033 }
3134
35+ /**
36+ * @return array{
37+ * position: array{lat: float, lng: float},
38+ * title: string|null,
39+ * infoWindow: array<string, mixed>|null,
40+ * extra: object,
41+ * }
42+ */
3243 public function toArray (): array
3344 {
3445 return [
@@ -38,4 +49,28 @@ public function toArray(): array
3849 'extra ' => (object ) $ this ->extra ,
3950 ];
4051 }
52+
53+ /**
54+ * @param array{
55+ * position: array{lat: float, lng: float},
56+ * title: string|null,
57+ * infoWindow: array<string, mixed>|null,
58+ * extra: object,
59+ * } $marker
60+ *
61+ * @internal
62+ */
63+ public static function fromArray (array $ marker ): self
64+ {
65+ if (!isset ($ marker ['position ' ])) {
66+ throw new InvalidArgumentException ('The "position" parameter is required. ' );
67+ }
68+ $ marker ['position ' ] = Point::fromArray ($ marker ['position ' ]);
69+
70+ if (isset ($ marker ['infoWindow ' ])) {
71+ $ marker ['infoWindow ' ] = InfoWindow::fromArray ($ marker ['infoWindow ' ]);
72+ }
73+
74+ return new self (...$ marker );
75+ }
4176}
0 commit comments