You are here

private function GeofieldMapFieldTrait::setMapOmsElement in Geofield Map 8

Same name and namespace in other branches
  1. 8.2 src/GeofieldMapFieldTrait.php \Drupal\geofield_map\GeofieldMapFieldTrait::setMapOmsElement()

Set Overlapping Marker Spiderfier Element.

Parameters

array $settings: The Form Settings.

array $default_settings: The default settings array.

array $elements: The Form element to alter.

1 call to GeofieldMapFieldTrait::setMapOmsElement()
GeofieldMapFieldTrait::generateGmapSettingsForm in src/GeofieldMapFieldTrait.php
Generate the Google Map Settings Form.

File

src/GeofieldMapFieldTrait.php, line 903

Class

GeofieldMapFieldTrait
Class GeofieldMapFieldTrait.

Namespace

Drupal\geofield_map

Code

private function setMapOmsElement(array $settings, array $default_settings, array &$elements) {
  $elements['map_oms'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Overlapping Markers'),
    '#description' => $this
      ->t('<b>Note: </b>To make this working in conjunction with the Markercluster Option (see below) a "maxZoom" property should be set in the Marker Cluster Additional Options.'),
    '#description_display' => 'before',
  ];
  $elements['map_oms']['map_oms_control'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Spiderfy overlapping markers'),
    '#description' => $this
      ->t('Use the standard setup of the @overlapping_marker_spiderfier to manage Overlapping Markers located in the exact same position.', [
      '@overlapping_marker_spiderfier' => $this->link
        ->generate(t('Overlapping Marker Spiderfier Library (for Google Maps)'), Url::fromUri('https://github.com/jawj/OverlappingMarkerSpiderfier#overlapping-marker-spiderfier-for-google-maps-api-v3', [
        'absolute' => TRUE,
        'attributes' => [
          'target' => 'blank',
        ],
      ])),
    ]),
    '#default_value' => isset($settings['map_oms']['map_oms_control']) ? $settings['map_oms']['map_oms_control'] : $default_settings['map_oms']['map_oms_control'],
    '#return_value' => 1,
  ];
  $elements['map_oms']['map_oms_options'] = [
    '#type' => 'textarea',
    '#rows' => 2,
    '#title' => $this
      ->t('Markers Spiderfy Options'),
    '#description' => $this
      ->t('An object literal of Spiderfy options, that comply with the Overlapping Marker Spiderfier Library (see link above).<br>The syntax should respect the javascript object notation (json) format.<br>Always use double quotes (") both for the indexes and the string values.<br><b>Note: </b>This first three default options are the library ones suggested to save memory and CPU (in the simplest/standard implementation).'),
    '#default_value' => isset($settings['map_oms']['map_oms_options']) ? $settings['map_oms']['map_oms_options'] : $default_settings['map_oms']['map_oms_options'],
    '#placeholder' => '{"markersWontMove": "true", "markersWontHide": "true", "basicFormatEvents": "true", "nearbyDistance": 3}',
    '#element_validate' => [
      [
        get_class($this),
        'jsonValidate',
      ],
    ],
  ];
  if (isset($this->fieldDefinition)) {
    $elements['map_oms']['map_oms_options']['#states'] = [
      'visible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][map_oms][map_oms_control]"]' => [
          'checked' => TRUE,
        ],
      ],
    ];
  }
  else {
    $elements['map_oms']['map_oms_options']['#states'] = [
      'visible' => [
        ':input[name="style_options[map_oms][map_oms_control]"]' => [
          'checked' => TRUE,
        ],
      ],
    ];
  }
}