Skip to content

Commit b077a9c

Browse files
authored
Merge pull request #289 from itk-dev/feature/maps-element
Make map element work
2 parents e3dcb38 + 423219b commit b077a9c

4 files changed

Lines changed: 28 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ before starting to add changes. Use example [placed in the end of the page](#exa
1111

1212
## [Unreleased]
1313

14+
- [PR-289](https://github.com/OS2Forms/os2forms/pull/289)
15+
Added required "Zoom control position" to map element
16+
1417
## [5.0.0] 2025-11-18
1518

1619
- [PR-192](https://github.com/OS2Forms/os2forms/pull/192)

modules/os2forms_webform_maps/os2forms_webform_maps.libraries.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
webformmap:
22
version: 1.x
3-
css:
4-
theme:
5-
css/webform_map.css: {}
63
js:
74
js/webform_map.js: {}
85
dependencies:

modules/os2forms_webform_maps/src/Element/WebformLeafletMapField.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Drupal\Core\Form\FormStateInterface;
66
use Drupal\Core\Render\Element\FormElement;
77
use Drupal\webform\Element\WebformCompositeFormElementTrait;
8+
use Drupal\os2forms_webform_maps\Plugin\WebformElement\WebformLeafletMapField as WebformLeafletMapElement;
89

910
/**
1011
* Provides a webform_map_field.
@@ -36,7 +37,7 @@ public function getInfo() {
3637
'#minZoom' => 1,
3738
'#maxZoom' => 18,
3839
'#zoomFiner' => 0,
39-
'#position' => 'topleft',
40+
'#position' => WebformLeafletMapElement::LEAFLET_POSITION_TOP_LEFT,
4041
'#marker' => 'defaultMarker',
4142
'#drawPolyline' => 0,
4243
'#drawRectangle' => 0,
@@ -90,6 +91,7 @@ public static function processWebformMapElement(&$element, FormStateInterface $f
9091
'zoomFiner' => $element['#zoomFiner'],
9192
'minZoom' => $element['#minZoom'],
9293
'maxZoom' => $element['#maxZoom'],
94+
'zoomControlPosition' => $element['#zoomControlPosition'] ?? WebformLeafletMapElement::LEAFLET_POSITION_TOP_LEFT,
9395
'center' => [
9496
'lat' => (float) $element['#lat'],
9597
'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+
const string LEAFLET_POSITION_TOP_LEFT = 'topleft';
26+
const string LEAFLET_POSITION_TOP_RIGHT = 'topright';
27+
const string LEAFLET_POSITION_BOTTOM_LEFT = 'bottomleft';
28+
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)