11
11
12
12
namespace Symfony \UX \Map \Bridge \Leaflet ;
13
13
14
+ use Symfony \UX \Map \Bridge \Leaflet \Option \AttributionControlOptions ;
14
15
use Symfony \UX \Map \Bridge \Leaflet \Option \TileLayer ;
16
+ use Symfony \UX \Map \Bridge \Leaflet \Option \ZoomControlOptions ;
15
17
use Symfony \UX \Map \MapOptionsInterface ;
16
18
17
19
/**
@@ -24,6 +26,10 @@ public function __construct(
24
26
url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png ' ,
25
27
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> ' ,
26
28
),
29
+ private bool $ attributionControl = true ,
30
+ private AttributionControlOptions $ attributionControlOptions = new AttributionControlOptions (),
31
+ private bool $ zoomControl = true ,
32
+ private ZoomControlOptions $ zoomControlOptions = new ZoomControlOptions (),
27
33
) {
28
34
}
29
35
@@ -34,23 +40,77 @@ public function tileLayer(TileLayer|false $tileLayer): self
34
40
return $ this ;
35
41
}
36
42
43
+ public function attributionControl (bool $ enable = true ): self
44
+ {
45
+ $ this ->attributionControl = $ enable ;
46
+
47
+ return $ this ;
48
+ }
49
+
50
+ public function attributionControlOptions (AttributionControlOptions $ attributionControlOptions ): self
51
+ {
52
+ $ this ->attributionControl = true ;
53
+ $ this ->attributionControlOptions = $ attributionControlOptions ;
54
+
55
+ return $ this ;
56
+ }
57
+
58
+ public function zoomControl (bool $ enable = true ): self
59
+ {
60
+ $ this ->zoomControl = $ enable ;
61
+
62
+ return $ this ;
63
+ }
64
+
65
+ public function zoomControlOptions (ZoomControlOptions $ zoomControlOptions ): self
66
+ {
67
+ $ this ->zoomControl = true ;
68
+ $ this ->zoomControlOptions = $ zoomControlOptions ;
69
+
70
+ return $ this ;
71
+ }
72
+
37
73
/**
38
74
* @internal
39
75
*/
40
76
public static function fromArray (array $ array ): MapOptionsInterface
41
77
{
42
- return new self (
43
- tileLayer: $ array ['tileLayer ' ] ? TileLayer::fromArray ($ array ['tileLayer ' ]) : false ,
44
- );
78
+ $ array += ['attributionControl ' => false , 'zoomControl ' => false , 'tileLayer ' => false ];
79
+
80
+ if ($ array ['tileLayer ' ]) {
81
+ $ array ['tileLayer ' ] = TileLayer::fromArray ($ array ['tileLayer ' ]);
82
+ }
83
+
84
+ if (isset ($ array ['attributionControlOptions ' ])) {
85
+ $ array ['attributionControl ' ] = true ;
86
+ $ array ['attributionControlOptions ' ] = AttributionControlOptions::fromArray ($ array ['attributionControlOptions ' ]);
87
+ }
88
+
89
+ if (isset ($ array ['zoomControlOptions ' ])) {
90
+ $ array ['zoomControl ' ] = true ;
91
+ $ array ['zoomControlOptions ' ] = ZoomControlOptions::fromArray ($ array ['zoomControlOptions ' ]);
92
+ }
93
+
94
+ return new self (...$ array );
45
95
}
46
96
47
97
/**
48
98
* @internal
49
99
*/
50
100
public function toArray (): array
51
101
{
52
- return [
102
+ $ array = [
53
103
'tileLayer ' => $ this ->tileLayer ? $ this ->tileLayer ->toArray () : false ,
54
104
];
105
+
106
+ if ($ this ->attributionControl ) {
107
+ $ array ['attributionControlOptions ' ] = $ this ->attributionControlOptions ->toArray ();
108
+ }
109
+
110
+ if ($ this ->zoomControl ) {
111
+ $ array ['zoomControlOptions ' ] = $ this ->zoomControlOptions ->toArray ();
112
+ }
113
+
114
+ return $ array ;
55
115
}
56
116
}
0 commit comments