From 24e4c4da09c0cc9cbf6afff914c23e37bac893be Mon Sep 17 00:00:00 2001
From: itamair <itamair@me.com>
Date: Sat, 25 Mar 2023 00:14:37 +0100
Subject: [PATCH] Correct limitations of default Options (and Schema) of
 LeafletDefaultWidget ('Issue #3344455 by ekes')

---
 config/schema/leaflet.schema.yml              | 21 +++++------
 .../FieldWidget/LeafletDefaultWidget.php      | 37 ++++++++++++++++---
 2 files changed, 41 insertions(+), 17 deletions(-)

diff --git a/config/schema/leaflet.schema.yml b/config/schema/leaflet.schema.yml
index 880c90f..3b1395e 100644
--- a/config/schema/leaflet.schema.yml
+++ b/config/schema/leaflet.schema.yml
@@ -115,9 +115,9 @@ field.widget.settings.leaflet_widget_default:
         options:
           type: text
           label: 'Options'
-    locate:
+    fullscreen:
       type: mapping
-      label: 'Locate User Position'
+      label: 'Leaflet Fullscreen'
       mapping:
         control:
           type: boolean
@@ -125,12 +125,12 @@ field.widget.settings.leaflet_widget_default:
         options:
           type: text
           label: 'Options'
-        automatic:
-          type: boolean
-          label: 'Automatically locate user current position'
-    fullscreen:
+    path:
+      type: text
+      label: 'Path'
+    locate:
       type: mapping
-      label: 'Leaflet Fullscreen'
+      label: 'Locate User Position'
       mapping:
         control:
           type: boolean
@@ -138,10 +138,9 @@ field.widget.settings.leaflet_widget_default:
         options:
           type: text
           label: 'Options'
-
-    path:
-      type: text
-      label: 'Path'
+        automatic:
+          type: boolean
+          label: 'Automatically locate user current position'
     geocoder:
       type: mapping
       label: 'Gecoder map control'
diff --git a/src/Plugin/Field/FieldWidget/LeafletDefaultWidget.php b/src/Plugin/Field/FieldWidget/LeafletDefaultWidget.php
index 1a71525..1dfc653 100644
--- a/src/Plugin/Field/FieldWidget/LeafletDefaultWidget.php
+++ b/src/Plugin/Field/FieldWidget/LeafletDefaultWidget.php
@@ -169,7 +169,7 @@ class LeafletDefaultWidget extends GeofieldDefaultWidget {
   public static function defaultSettings() {
     $base_layers = self::getLeafletMaps();
 
-    $options = array_merge(parent::defaultSettings(), [
+    return array_merge(parent::defaultSettings(), [
       'map' => [
         'leaflet_map' => array_shift($base_layers),
         'height' => 400,
@@ -195,12 +195,37 @@ class LeafletDefaultWidget extends GeofieldDefaultWidget {
         'removalMode' => TRUE,
         'rotateMode' => FALSE,
       ],
+      'reset_map' => [
+        'control' => FALSE,
+        'options' => '{"position": "topleft", "title": "Reset View"}',
+      ],
+      'fullscreen' => [
+        'control' => FALSE,
+        'options' => '{"position":"topleft","pseudoFullscreen":false}',
+      ],
+      'path' => '{"color":"#3388ff","opacity":"1.0","stroke":true,"weight":3,"fill":"depends","fillColor":"*","fillOpacity":"0.2","radius":"6"}',
+      'feature_properties' => [
+        'values' => '',
+      ],
+      'locate' => [
+        'control' => FALSE,
+        'options' => '{"position": "topright", "setView": "untilPanOrZoom", "returnToPrevBounds":true, "keepCurrentZoomLevel": true, "strings": {"title": "Locate my position"}}',
+        'automatic' => FALSE,
+      ],
+      'geocoder' => [
+        'control' => FALSE,
+        'settings' => [
+          'position' => 'topright',
+          'input_size' => 20,
+          'providers' => [],
+          'min_terms' => 4,
+          'delay' => 800,
+          'zoom' => 16,
+          'popup' => FALSE,
+          'options' => '',
+        ],
+      ],
     ]);
-    $leaflet_map_default_settings = [];
-    foreach (self::getDefaultSettings() as $k => $setting) {
-      $leaflet_map_default_settings[$k] = $setting;
-    }
-    return $options + $leaflet_map_default_settings;
   }
 
   /**
-- 
GitLab