Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ before starting to add changes. Use example [placed in the end of the page](#exa

## [Unreleased]

- [PR-289](https://github.com/OS2Forms/os2forms/pull/289)
Added required "Zoom control position" to map element

## [5.0.0] 2025-11-18

- [PR-192](https://github.com/OS2Forms/os2forms/pull/192)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
webformmap:
version: 1.x
css:
theme:
css/webform_map.css: {}
js:
js/webform_map.js: {}
dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public static function processWebformMapElement(&$element, FormStateInterface $f
'zoomFiner' => $element['#zoomFiner'],
'minZoom' => $element['#minZoom'],
'maxZoom' => $element['#maxZoom'],
'zoomControlPosition' => $element['#zoomControlPosition'] ?? 'topleft',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since one of the main ideas of this PR was to get rid of defining the constants more than once, I though this would be a good place to reuse the already defined constants.
However these contstants are defined as private. Maybe in the future we can consider adding extra abstraction level - e.g. interface just for that.

but it's a minor thing, i think it's also fine as it is.

'center' => [
'lat' => (float) $element['#lat'],
'lon' => (float) $element['#lon'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class WebformLeafletMapField extends WebformElementBase {

use LeafletSettingsElementsTrait;

// Valid Leaflet control positions (cf.
// https://github.com/Leaflet/Leaflet/blob/main/src/control/Control.js).
private const string LEAFLET_POSITION_TOP_LEFT = 'topleft';
private const string LEAFLET_POSITION_TOP_RIGHT = 'topright';
private const string LEAFLET_POSITION_BOTTOM_LEFT = 'bottomleft';
private const string LEAFLET_POSITION_BOTTOM_RIGHT = 'bottomright';

/**
* {@inheritdoc}
*/
Expand All @@ -33,10 +40,11 @@ public function defineDefaultProperties(): array {
'minZoom' => 1,
'maxZoom' => 18,
'zoomFiner' => 0,
'zoomControlPosition' => self::LEAFLET_POSITION_TOP_LEFT,
'scrollWheelZoom' => 0,
'doubleClickZoom' => 1,

'position' => 'topleft',
'position' => self::LEAFLET_POSITION_TOP_LEFT,
'marker' => 'defaultMarker',
'drawPolyline' => 0,
'drawRectangle' => 0,
Expand Down Expand Up @@ -72,6 +80,13 @@ public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$map_keys = array_keys(leaflet_map_get_info());

$positionOptions = [
self::LEAFLET_POSITION_TOP_LEFT => $this->t('topleft'),
self::LEAFLET_POSITION_TOP_RIGHT => $this->t('topright'),
self::LEAFLET_POSITION_BOTTOM_LEFT => $this->t('bottomleft'),
self::LEAFLET_POSITION_BOTTOM_RIGHT => $this->t('bottomright'),
];

$form['mapstyles'] = [
'#type' => 'fieldset',
'#title' => $this->t('Map settings'),
Expand Down Expand Up @@ -139,6 +154,11 @@ public function form(array $form, FormStateInterface $form_state) {
'#step' => 1,
'#description' => $this->t('Value that might/will be added to default Fit Elements Bounds Zoom. (-5 / +5)'),
],
'zoomControlPosition' => [
'#type' => 'select',
'#title' => $this->t('Zoom control position'),
'#options' => $positionOptions,
],
'scrollWheelZoom' => [
'#type' => 'checkbox',
'#title' => $this->t('Enable Scroll Wheel Zoom on click'),
Expand All @@ -159,12 +179,7 @@ public function form(array $form, FormStateInterface $form_state) {
'position' => [
'#type' => 'select',
'#title' => $this->t('Toolbar position.'),
'#options' => [
'topleft' => $this->t('topleft'),
'topright' => $this->t('topright'),
'bottomleft' => $this->t('bottomleft'),
'bottomright' => $this->t('bottomright'),
],
'#options' => $positionOptions,
],
'marker' => [
'#type' => 'radios',
Expand Down
Loading