11
11
12
12
namespace Symfony \UX \Map ;
13
13
14
+ use Symfony \UX \Map \Exception \InvalidArgumentException ;
15
+
14
16
/**
15
17
* Represents a marker on a map.
16
18
*
19
21
final readonly class Marker
20
22
{
21
23
/**
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
23
26
*/
24
27
public function __construct (
25
28
private Point $ position ,
@@ -29,6 +32,14 @@ public function __construct(
29
32
) {
30
33
}
31
34
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
+ */
32
43
public function toArray (): array
33
44
{
34
45
return [
@@ -38,4 +49,28 @@ public function toArray(): array
38
49
'extra ' => (object ) $ this ->extra ,
39
50
];
40
51
}
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
+ }
41
76
}
0 commit comments