You are here

protected function LeafletSettingsElementsTrait::setAdditionalMapOptions in Leaflet 8

Same name and namespace in other branches
  1. 2.1.x src/LeafletSettingsElementsTrait.php \Drupal\leaflet\LeafletSettingsElementsTrait::setAdditionalMapOptions()
  2. 2.0.x src/LeafletSettingsElementsTrait.php \Drupal\leaflet\LeafletSettingsElementsTrait::setAdditionalMapOptions()

Set Map additional map Settings.

Parameters

array $map: The map object.

array $options: The options from where to set additional options.

3 calls to LeafletSettingsElementsTrait::setAdditionalMapOptions()
LeafletDefaultFormatter::viewElements in src/Plugin/Field/FieldFormatter/LeafletDefaultFormatter.php
This function is called from parent::view().
LeafletDefaultWidget::formElement in src/Plugin/Field/FieldWidget/LeafletDefaultWidget.php
Returns the form for a single field widget.
LeafletMap::render in modules/leaflet_views/src/Plugin/views/style/LeafletMap.php
Renders the View.

File

src/LeafletSettingsElementsTrait.php, line 643

Class

LeafletSettingsElementsTrait
Class GeofieldMapFieldTrait.

Namespace

Drupal\leaflet

Code

protected function setAdditionalMapOptions(array &$map, array $options) {
  $default_settings = $this::getDefaultSettings();

  // Add additional settings to the Map, with fallback on the
  // hook_leaflet_map_info ones.
  $map['settings']['map_position_force'] = isset($options['map_position']['force']) ? $options['map_position']['force'] : $default_settings['map_position']['force'];
  $map['settings']['zoom'] = isset($options['map_position']['zoom']) ? (int) $options['map_position']['zoom'] : $default_settings['map_position']['zoom'];
  $map['settings']['zoomFiner'] = isset($options['map_position']['zoomFiner']) ? (int) $options['map_position']['zoomFiner'] : $default_settings['map_position']['zoomFiner'];
  $map['settings']['minZoom'] = isset($options['map_position']['minZoom']) ? (int) $options['map_position']['minZoom'] : $default_settings['settings']['minZoom'];
  $map['settings']['maxZoom'] = isset($options['map_position']['maxZoom']) ? (int) $options['map_position']['maxZoom'] : $default_settings['settings']['maxZoom'];
  $map['settings']['center'] = isset($options['map_position']['center']['lat']) && isset($options['map_position']['center']['lon']) ? [
    'lat' => floatval($options['map_position']['center']['lat']),
    'lon' => floatval($options['map_position']['center']['lon']),
  ] : $default_settings['map_position']['center'];
  $map['settings']['scrollWheelZoom'] = !empty($options['disable_wheel']) ? !(bool) $options['disable_wheel'] : (isset($map['settings']['scrollWheelZoom']) ? $map['settings']['scrollWheelZoom'] : TRUE);
  $map['settings']['path'] = isset($options['path']) && !empty($options['path']) ? $options['path'] : (isset($map['path']) ? Json::encode($map['path']) : Json::encode($default_settings['path']));
  $map['settings']['leaflet_markercluster'] = isset($options['leaflet_markercluster']) ? $options['leaflet_markercluster'] : NULL;
  $map['settings']['fullscreen_control'] = isset($options['fullscreen_control']) ? $options['fullscreen_control'] : $default_settings['fullscreen_control'];
  $map['settings']['gestureHandling'] = isset($options['gesture_handling']) ? $options['gesture_handling'] : $default_settings['gesture_handling'];
  $map['settings']['reset_map'] = isset($options['reset_map']) ? $options['reset_map'] : $default_settings['reset_map'];
  $map['settings']['geocoder'] = isset($options['geocoder']) ? $options['geocoder'] : $default_settings['geocoder'];
}