Skip to content

Commit 5efb744

Browse files
committed
Added required "Zoom control position" to map element
1 parent 6e81c86 commit 5efb744

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

modules/os2forms_webform_maps/src/Element/WebformLeafletMapField.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public static function processWebformMapElement(&$element, FormStateInterface $f
9090
'zoomFiner' => $element['#zoomFiner'],
9191
'minZoom' => $element['#minZoom'],
9292
'maxZoom' => $element['#maxZoom'],
93+
'zoomControlPosition' => $element['#zoomControlPosition'] ?? 'topleft',
9394
'center' => [
9495
'lat' => (float) $element['#lat'],
9596
'lon' => (float) $element['#lon'],

modules/os2forms_webform_maps/src/Plugin/WebformElement/WebformLeafletMapField.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ class WebformLeafletMapField extends WebformElementBase {
2020

2121
use LeafletSettingsElementsTrait;
2222

23+
// Valid Leaflet control positions (cf.
24+
// https://github.com/Leaflet/Leaflet/blob/main/src/control/Control.js).
25+
private const string LEAFLET_POSITION_TOP_LEFT = 'topleft';
26+
private const string LEAFLET_POSITION_TOP_RIGHT = 'topright';
27+
private const string LEAFLET_POSITION_BOTTOM_LEFT = 'bottomleft';
28+
private const string LEAFLET_POSITION_BOTTOM_RIGHT = 'bottomright';
29+
2330
/**
2431
* {@inheritdoc}
2532
*/
@@ -33,10 +40,11 @@ public function defineDefaultProperties(): array {
3340
'minZoom' => 1,
3441
'maxZoom' => 18,
3542
'zoomFiner' => 0,
43+
'zoomControlPosition' => self::LEAFLET_POSITION_TOP_LEFT,
3644
'scrollWheelZoom' => 0,
3745
'doubleClickZoom' => 1,
3846

39-
'position' => 'topleft',
47+
'position' => self::LEAFLET_POSITION_TOP_LEFT,
4048
'marker' => 'defaultMarker',
4149
'drawPolyline' => 0,
4250
'drawRectangle' => 0,
@@ -72,6 +80,13 @@ public function form(array $form, FormStateInterface $form_state) {
7280
$form = parent::form($form, $form_state);
7381
$map_keys = array_keys(leaflet_map_get_info());
7482

83+
$positionOptions = [
84+
self::LEAFLET_POSITION_TOP_LEFT => $this->t('topleft'),
85+
self::LEAFLET_POSITION_TOP_RIGHT => $this->t('topright'),
86+
self::LEAFLET_POSITION_BOTTOM_LEFT => $this->t('bottomleft'),
87+
self::LEAFLET_POSITION_BOTTOM_RIGHT => $this->t('bottomright'),
88+
];
89+
7590
$form['mapstyles'] = [
7691
'#type' => 'fieldset',
7792
'#title' => $this->t('Map settings'),
@@ -139,6 +154,11 @@ public function form(array $form, FormStateInterface $form_state) {
139154
'#step' => 1,
140155
'#description' => $this->t('Value that might/will be added to default Fit Elements Bounds Zoom. (-5 / +5)'),
141156
],
157+
'zoomControlPosition' => [
158+
'#type' => 'select',
159+
'#title' => $this->t('Zoom control position'),
160+
'#options' => $positionOptions,
161+
],
142162
'scrollWheelZoom' => [
143163
'#type' => 'checkbox',
144164
'#title' => $this->t('Enable Scroll Wheel Zoom on click'),
@@ -159,12 +179,7 @@ public function form(array $form, FormStateInterface $form_state) {
159179
'position' => [
160180
'#type' => 'select',
161181
'#title' => $this->t('Toolbar position.'),
162-
'#options' => [
163-
'topleft' => $this->t('topleft'),
164-
'topright' => $this->t('topright'),
165-
'bottomleft' => $this->t('bottomleft'),
166-
'bottomright' => $this->t('bottomright'),
167-
],
182+
'#options' => $positionOptions,
168183
],
169184
'marker' => [
170185
'#type' => 'radios',

0 commit comments

Comments
 (0)