1111
1212namespace Symfony \UX \Map \Bridge \Leaflet ;
1313
14+ use Symfony \UX \Map \Bridge \Leaflet \Option \AttributionControlOptions ;
1415use Symfony \UX \Map \Bridge \Leaflet \Option \TileLayer ;
16+ use Symfony \UX \Map \Bridge \Leaflet \Option \ZoomControlOptions ;
1517use Symfony \UX \Map \MapOptionsInterface ;
1618
1719/**
@@ -24,6 +26,10 @@ public function __construct(
2426 url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png ' ,
2527 attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> ' ,
2628 ),
29+ private bool $ attributionControl = true ,
30+ private AttributionControlOptions $ attributionControlOptions = new AttributionControlOptions (),
31+ private bool $ zoomControl = true ,
32+ private ZoomControlOptions $ zoomControlOptions = new ZoomControlOptions (),
2733 ) {
2834 }
2935
@@ -34,23 +40,77 @@ public function tileLayer(TileLayer|false $tileLayer): self
3440 return $ this ;
3541 }
3642
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+
3773 /**
3874 * @internal
3975 */
4076 public static function fromArray (array $ array ): MapOptionsInterface
4177 {
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 );
4595 }
4696
4797 /**
4898 * @internal
4999 */
50100 public function toArray (): array
51101 {
52- return [
102+ $ array = [
53103 'tileLayer ' => $ this ->tileLayer ? $ this ->tileLayer ->toArray () : false ,
54104 ];
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 ;
55115 }
56116}
0 commit comments