protected function LeafletSettingsElementsTrait::generateMapPositionElement in Leaflet 2.0.x
Same name and namespace in other branches
- 8 src/LeafletSettingsElementsTrait.php \Drupal\leaflet\LeafletSettingsElementsTrait::generateMapPositionElement()
- 2.1.x src/LeafletSettingsElementsTrait.php \Drupal\leaflet\LeafletSettingsElementsTrait::generateMapPositionElement()
Generate the Leaflet Map Position Form Element.
Parameters
array $map_position_options: The map position options array definition.
Return value
array The Leaflet Map Position Form Element.
3 calls to LeafletSettingsElementsTrait::generateMapPositionElement()
- LeafletDefaultFormatter::settingsForm in src/
Plugin/ Field/ FieldFormatter/ LeafletDefaultFormatter.php - Returns a form to configure settings for the formatter.
- LeafletDefaultWidget::settingsForm in src/
Plugin/ Field/ FieldWidget/ LeafletDefaultWidget.php - LeafletMap::buildOptionsForm in modules/
leaflet_views/ src/ Plugin/ views/ style/ LeafletMap.php - Provide a form to edit options for this plugin.
File
- src/
LeafletSettingsElementsTrait.php, line 213
Class
- LeafletSettingsElementsTrait
- Class GeofieldMapFieldTrait.
Namespace
Drupal\leafletCode
protected function generateMapPositionElement(array $map_position_options) {
$element = [
'#type' => 'fieldset',
'#title' => $this
->t('Starting Map State'),
];
if (isset($this->fieldDefinition)) {
$force_checkbox_selector = ':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][map_position][force]"]';
$force_checkbox_selector_widget = ':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][map][map_position][force]"]';
}
elseif ($this instanceof ViewsPluginInterface) {
$force_checkbox_selector = ':input[name="style_options[map_position][force]"]';
}
$element['description'] = [
'#type' => 'container',
'html_tag' => [
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => $this
->t('These settings will be applied in case of single Marker Map (otherwise the Zoom will be set to Fit Elements bounds).'),
],
'#states' => [
'invisible' => isset($force_checkbox_selector_widget) ? [
[
$force_checkbox_selector => [
'checked' => TRUE,
],
],
'or',
[
$force_checkbox_selector_widget => [
'checked' => TRUE,
],
],
] : [
$force_checkbox_selector => [
'checked' => TRUE,
],
],
],
];
$element['force'] = [
'#type' => 'checkbox',
'#description' => $this
->t('These settings will be forced anyway as starting Map state.'),
'#default_value' => $map_position_options['force'],
'#return_value' => 1,
];
$element['#title'] = $this
->t('Custom Map Center & Zoom');
$element['description']['#value'] = $this
->t('These settings will be applied in case of empty Map.');
$element['force']['#title'] = $this
->t('Force Map Center & Zoom');
$element['center'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Map Center'),
'lat' => [
'#title' => $this
->t('Latitude'),
'#type' => 'number',
'#step' => 'any',
'#size' => 4,
'#default_value' => $map_position_options['center']['lat'] ?? $this
->getDefaultSettings()['map_position']['center']['lat'],
'#required' => FALSE,
],
'lon' => [
'#title' => $this
->t('Longitude'),
'#type' => 'number',
'#step' => 'any',
'#size' => 4,
'#default_value' => $map_position_options['center']['lon'] ?? $this
->getDefaultSettings()['map_position']['center']['lon'],
'#required' => FALSE,
],
];
$element['zoom'] = [
'#title' => $this
->t('Zoom'),
'#type' => 'number',
'#min' => 0,
'#max' => 22,
'#default_value' => $map_position_options['zoom'] ?? $this
->getDefaultSettings()['map_position']['zoom'],
'#required' => TRUE,
'#element_validate' => [
[
get_class($this),
'zoomLevelValidate',
],
],
];
if ($this instanceof ViewsPluginInterface) {
$element['zoom']['#description'] = $this
->t('These setting will be applied (anyway) to a single Marker Map.');
}
$element['minZoom'] = [
'#title' => $this
->t('Min. Zoom'),
'#type' => 'number',
'#min' => 0,
'#max' => 22,
'#default_value' => $map_position_options['minZoom'] ?? $this
->getDefaultSettings()['map_position']['minZoom'],
'#required' => TRUE,
];
$element['maxZoom'] = [
'#title' => $this
->t('Max. Zoom'),
'#type' => 'number',
'#min' => 1,
'#max' => 22,
'#default_value' => $map_position_options['maxZoom'] ?? $this
->getDefaultSettings()['map_position']['maxZoom'],
'#element_validate' => [
[
get_class($this),
'maxZoomLevelValidate',
],
],
'#required' => TRUE,
];
$element['zoomFiner'] = [
'#title' => $this
->t('Zoom Finer'),
'#type' => 'number',
'#max' => 5,
'#min' => -5,
'#step' => 1,
'#description' => $this
->t('Value that might/will be added to default Fit Elements Bounds Zoom. (-5 / +5)'),
'#default_value' => $map_position_options['zoomFiner'] ?? $this
->getDefaultSettings()['map_position']['zoomFiner'],
'#states' => [
'invisible' => isset($force_checkbox_selector_widget) ? [
[
$force_checkbox_selector => [
'checked' => TRUE,
],
],
'or',
[
$force_checkbox_selector_widget => [
'checked' => TRUE,
],
],
] : [
$force_checkbox_selector => [
'checked' => TRUE,
],
],
],
];
return $element;
}