Skip to content

Commit 4199d4a

Browse files
author
Danny van Wijk
committed
[Map] Add option to configure attribution and zoom control position
1 parent 8f02bd6 commit 4199d4a

20 files changed

+305
-311
lines changed

src/Map/src/Bridge/Leaflet/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Using `new LeafletOptions(tileLayer: false)` will now disable the default `TileLayer`.
66
Useful when using a custom tiles layer rendering engine not configurable with `L.tileLayer().addTo(map)` method
77
(e.g.: [Esri/esri-leaflet-vector](https://github.com/Esri/esri-leaflet-vector))
8+
- Added option to configure attribution and zoom control position.
89

910
## 2.25
1011

src/Map/src/Bridge/Leaflet/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ You can use the `LeafletOptions` class to configure your `Map`::
3333

3434
```php
3535
use Symfony\UX\Map\Bridge\Leaflet\LeafletOptions;
36+
use Symfony\UX\Map\Bridge\Leaflet\Option\AttributionControlOptions;
37+
use Symfony\UX\Map\Bridge\Leaflet\Option\ControlPosition;
3638
use Symfony\UX\Map\Bridge\Leaflet\Option\TileLayer;
39+
use Symfony\UX\Map\Bridge\Leaflet\Option\ZoomControlOptions;
3740
use Symfony\UX\Map\Point;
3841
use Symfony\UX\Map\Map;
3942

@@ -50,6 +53,10 @@ $leafletOptions = (new LeafletOptions())
5053
'maxZoom' => 10,
5154
]
5255
))
56+
->attributionControl(false)
57+
->attributionControlOptions(new AttributionControlOptions(ControlPosition::BOTTOM_LEFT))
58+
->zoomControl(false)
59+
->zoomControlOptions(new ZoomControlOptions(ControlPosition::TOP_LEFT))
5360
;
5461

5562
// Add the custom options to the map

src/Map/src/Bridge/Leaflet/assets/dist/map_controller.d.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/Map/src/Bridge/Leaflet/assets/dist/map_controller.js

Lines changed: 0 additions & 252 deletions
This file was deleted.

src/Map/src/Bridge/Leaflet/assets/src/map_controller.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import type {
1818
PopupOptions,
1919
} from 'leaflet';
2020

21-
type MapOptions = Pick<LeafletMapOptions, 'center' | 'zoom'> & {
21+
type MapOptions = Pick<LeafletMapOptions, 'center' | 'zoom' | 'attributionControl' | 'zoomControl' > & {
22+
attributionControlOptions?: Record<string, unknown>;
23+
zoomControlOptions?: Record<string, unknown>;
2224
tileLayer: { url: string; attribution: string; options: Record<string, unknown> } | false;
2325
};
2426

@@ -75,6 +77,10 @@ export default class extends AbstractMapController<
7577
zoom,
7678
options,
7779
}: { center: Point | null; zoom: number | null; options: MapOptions }): L.Map {
80+
// We assume the following control options are enabled if their options are set
81+
options.attributionControl = typeof options.attributionControlOptions !== 'undefined';
82+
options.zoomControl = typeof options.zoomControlOptions !== 'undefined';
83+
7884
const map = L.map(this.element, {
7985
...options,
8086
center: center === null ? undefined : center,
@@ -88,6 +94,14 @@ export default class extends AbstractMapController<
8894
}).addTo(map);
8995
}
9096

97+
if (options.attributionControl) {
98+
map.attributionControl.setPosition(options.attributionControlOptions.position);
99+
}
100+
101+
if (options.zoomControl) {
102+
map.zoomControl.setPosition(options.zoomControlOptions.position);
103+
}
104+
91105
return map;
92106
}
93107

0 commit comments

Comments
 (0)