From ecaa6767daa8418450874cf340e271d8e74d21b4 Mon Sep 17 00:00:00 2001
From: sano <55648-sano@users.noreply.drupalcode.org>
Date: Sun, 19 Jan 2025 05:49:05 +0000
Subject: [PATCH] styling for features, support for popups

---
 src/Plugin/Style/Cluster/Cluster.php | 120 ++++++++++++++++++++++++++-
 1 file changed, 117 insertions(+), 3 deletions(-)

diff --git a/src/Plugin/Style/Cluster/Cluster.php b/src/Plugin/Style/Cluster/Cluster.php
index 427bbd57..ad372064 100644
--- a/src/Plugin/Style/Cluster/Cluster.php
+++ b/src/Plugin/Style/Cluster/Cluster.php
@@ -5,12 +5,126 @@ namespace Drupal\openlayers\Plugin\Style\Cluster;
 use Drupal\openlayers\Types\Style;
 
 /**
- * FIX - Insert short comment here.
+ * Enhanced cluster style with SVG icon support and circle fallbacks.
  *
  * @OpenlayersPlugin(
  *  id = "Cluster"
  * )
  */
 class Cluster extends Style {
-  // FIX: Provide options to let user customize the cluster style.
-}
+  /**
+   * {@inheritdoc}
+   */
+  public function optionsForm(array &$form, array &$form_state) {
+    // Icon configuration
+    $form['options']['single_icon'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Single Camera Icon URL'),
+      '#default_value' => $this->getOption('single_icon', ''),
+      '#description' => t('URL for the single camera icon. SVG format recommended. Leave empty to use circle style.'),
+    );
+
+    $form['options']['single_icon_scale'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Single Icon Scale'),
+      '#default_value' => $this->getOption('single_icon_scale', '0.25'),
+      '#description' => t('Scale factor for single camera icons (e.g., 0.5 for half size).'),
+    );
+
+    $form['options']['group_icon'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Group Icon URL'),
+      '#default_value' => $this->getOption('group_icon', ''),
+      '#description' => t('URL for the group camera icon. SVG format recommended. Leave empty to use circle style.'),
+    );
+
+    $form['options']['group_icon_scale'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Group Icon Scale'),
+      '#default_value' => $this->getOption('group_icon_scale', '0.75'),
+      '#description' => t('Scale factor for grouped camera icons.'),
+    );
+
+    $form['options']['single_radius'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Single Feature Radius'),
+      '#default_value' => $this->getOption('single_radius', 8),
+      '#description' => t('Radius of the circle for single features.'),
+//      '#fieldset' => 'single_styles',
+    );
+
+    $form['options']['single_fill_color'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Single Feature Fill Color'),
+      '#default_value' => $this->getOption('single_fill_color', '#3388ff'),
+      '#description' => t('Fill color for single feature circles (hex format).'),
+    );
+
+    $form['options']['single_stroke_color'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Single Feature Stroke Color'),
+      '#default_value' => $this->getOption('single_stroke_color', '#ffffff'),
+      '#description' => t('Stroke (outline) color for single feature circles (hex format).'),
+    );
+
+    $form['options']['single_stroke_width'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Single Feature Stroke Width'),
+      '#default_value' => $this->getOption('single_stroke_width', 2),
+      '#description' => t('Stroke (outline) width for single feature circles.'),
+    );
+
+    $form['options']['group_radius'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Group Feature Radius'),
+      '#default_value' => $this->getOption('group_radius', 16),
+      '#description' => t('Radius of the circle for grouped features.'),
+    );
+
+    $form['options']['group_fill_color'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Group Feature Fill Color'),
+      '#default_value' => $this->getOption('group_fill_color', '#c025bd'),
+      '#description' => t('Fill color for group circles (hex format).'),
+    );
+
+    $form['options']['group_stroke_color'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Group Feature Stroke Color'),
+      '#default_value' => $this->getOption('group_stroke_color', '#ffffff'),
+      '#description' => t('Stroke (outline) color for group circles (hex format).'),
+    );
+
+    $form['options']['group_stroke_width'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Group Feature Stroke Width'),
+      '#default_value' => $this->getOption('group_stroke_width', 2),
+      '#description' => t('Stroke (outline) width for group circles.'),
+    );
+
+    return $form;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function optionsFormSubmit(array $form, array &$form_state) {
+    parent::optionsFormSubmit($form, $form_state);
+    
+    // Ensure numeric values are properly typed
+    $numeric_fields = [
+      'single_icon_scale',
+      'group_icon_scale',
+      'single_radius',
+      'single_stroke_width',
+      'group_radius',
+      'group_stroke_width'
+    ];
+
+    foreach ($numeric_fields as $field) {
+      if (isset($form_state['values']['options'][$field])) {
+        $form_state['values']['options'][$field] = (float) $form_state['values']['options'][$field];
+      }
+    }
+  }
+}
\ No newline at end of file
-- 
GitLab