You are here

private function GeofieldMapFieldTrait::setMapZoomAndPanElement in Geofield Map 8.2

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

Set Map Zoom and Pan Element.

Parameters

array $settings: The Form Settings.

array $default_settings: The default_settings.

array $elements: The Form element to alter.

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

File

src/GeofieldMapFieldTrait.php, line 563

Class

GeofieldMapFieldTrait
Class GeofieldMapFieldTrait.

Namespace

Drupal\geofield_map

Code

private function setMapZoomAndPanElement(array $settings, array $default_settings, array &$elements) {
  if (isset($this->fieldDefinition)) {
    $force_center_selector = ':input[name="fields[' . $this->fieldDefinition
      ->getName() . '][settings_edit_form][settings][map_center][center_force]"]';
    $force_zoom_selector = ':input[name="fields[' . $this->fieldDefinition
      ->getName() . '][settings_edit_form][settings][map_zoom_and_pan][zoom][force]"]';
    $map_reset_selector = ':input[name="fields[' . $this->fieldDefinition
      ->getName() . '][settings_edit_form][settings][map_zoom_and_pan][map_reset]"]';
  }
  else {
    $force_center_selector = ':input[name="style_options[map_center][center_force]"]';
    $force_zoom_selector = ':input[name="style_options[map_zoom_and_pan][zoom][force]"]';
    $map_reset_selector = ':input[name="style_options[map_zoom_and_pan][map_reset]"]';
  }
  $elements['map_zoom_and_pan'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Map Zoom and Pan'),
  ];
  $elements['map_zoom_and_pan']['zoom'] = [
    'initial' => [
      '#type' => 'number',
      '#min' => $settings['map_zoom_and_pan']['zoom']['min'],
      '#max' => $settings['map_zoom_and_pan']['zoom']['max'],
      '#title' => $this
        ->t('Start Zoom'),
      '#default_value' => $settings['map_zoom_and_pan']['zoom']['initial'],
      '#description' => $this
        ->t('The Initial Zoom level of the Google Map.'),
      '#element_validate' => [
        [
          get_class($this),
          'zoomLevelValidate',
        ],
      ],
    ],
    'force' => [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Force the Start Zoom'),
      '#description' => $this
        ->t('In case of multiple GeoMarkers, the Map will naturally focus zoom on the input Geofields bounds.<br>This option will instead force the Map Zoom on the input Start Zoom value'),
      '#default_value' => $settings['map_zoom_and_pan']['zoom']['force'],
      '#return_value' => 1,
      '#states' => [
        'visible' => [
          $force_center_selector => [
            'checked' => FALSE,
          ],
        ],
      ],
    ],
    'min' => [
      '#type' => 'number',
      '#min' => isset($default_settings['map_zoom_and_pan']['default']) ? $default_settings['map_zoom_and_pan']['default']['zoom']['min'] : $default_settings['map_zoom_and_pan']['zoom']['min'],
      '#max' => $settings['map_zoom_and_pan']['zoom']['max'],
      '#title' => $this
        ->t('Min Zoom Level'),
      '#default_value' => $settings['map_zoom_and_pan']['zoom']['min'],
      '#description' => $this
        ->t('The Minimum Zoom level for the Map.'),
    ],
    'max' => [
      '#type' => 'number',
      '#min' => $settings['map_zoom_and_pan']['zoom']['min'],
      '#max' => isset($default_settings['map_zoom_and_pan']['default']) ? $default_settings['map_zoom_and_pan']['default']['zoom']['max'] : $default_settings['map_zoom_and_pan']['zoom']['max'],
      '#title' => $this
        ->t('Max Zoom Level'),
      '#default_value' => $settings['map_zoom_and_pan']['zoom']['max'],
      '#description' => $this
        ->t('The Maximum Zoom level for the Map.'),
      '#element_validate' => [
        [
          get_class($this),
          'maxZoomLevelValidate',
        ],
      ],
    ],
    'finer' => [
      '#title' => $this
        ->t('Zoom Finer'),
      '#type' => 'number',
      '#max' => 3,
      '#min' => -3,
      '#step' => 1,
      '#description' => $this
        ->t('Value that might/will be added to default Fit Markers Bounds Zoom. (-3 / +3)'),
      '#default_value' => $settings['map_zoom_and_pan']['zoom']['finer'] ?? $this->defaultSettings['map_zoom_and_pan']['zoom']['finer'],
      '#states' => [
        'invisible' => [
          $force_zoom_selector => [
            'checked' => TRUE,
          ],
        ],
      ],
    ],
  ];
  $elements['map_zoom_and_pan']['gestureHandling'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Gesture Handling (Controlling Zoom and Pan)'),
    '#options' => [
      'auto' => $this
        ->t('auto'),
      'greedy' => $this
        ->t('greedy'),
      'cooperative' => $this
        ->t('cooperative'),
      'none' => $this
        ->t('none'),
    ],
    '#default_value' => isset($settings['map_zoom_and_pan']['gestureHandling']) ? $settings['map_zoom_and_pan']['gestureHandling'] : 'auto',
    '#description' => $this
      ->t("This control sets how users can zoom and pan the map, and also whether the user's page scrolling actions take priority over the map's zooming and panning.<br>Visit the @google_map_page to inspect and learn the corresponding behaviours of the different options.", [
      '@google_map_page' => $this->link
        ->generate(t("Official Google Maps Javascript API 'Controlling Zoom and Pan' page"), Url::fromUri('https://developers.google.com/maps/documentation/javascript/interaction', [
        'absolute' => TRUE,
        'attributes' => [
          'target' => 'blank',
        ],
      ])),
    ]),
  ];
  $elements['map_zoom_and_pan']['scrollwheel'] = [
    '#type' => 'hidden',
    '#default_value' => $settings['map_zoom_and_pan']['scrollwheel'],
  ];
  $elements['map_zoom_and_pan']['draggable'] = [
    '#type' => 'hidden',
    '#default_value' => $settings['map_zoom_and_pan']['draggable'],
  ];
  $elements['map_zoom_and_pan']['map_reset'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable Map Reset Control'),
    '#description' => $this
      ->t('This will show a "Reset Map" button to reset the Map to its initial center & zoom state'),
    '#default_value' => isset($settings['map_zoom_and_pan']['map_reset']) ? $settings['map_zoom_and_pan']['map_reset'] : 0,
    '#return_value' => 1,
  ];
  $elements['map_zoom_and_pan']['map_reset_position'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Map Reset Control Position'),
    '#options' => $this->controlPositionsOptions,
    '#default_value' => isset($settings['map_zoom_and_pan']['map_reset_position']) ? $settings['map_zoom_and_pan']['map_reset_position'] : 'TOP_RIGHT',
    '#states' => [
      'visible' => [
        $map_reset_selector => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
}