You are here

protected function YamapsDefaultWidget::initMap in Yandex.Maps 8

Create map container and .

Parameters

array $elements:

$map_id:

$placemarks:

1 call to YamapsDefaultWidget::initMap()
YamapsDefaultWidget::formElement in src/Plugin/Field/FieldWidget/YamapsDefaultWidget.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/YamapsDefaultWidget.php, line 124

Class

YamapsDefaultWidget
Plugin implementation of the 'yamaps_default' widget.

Namespace

Drupal\yamaps\Plugin\Field\FieldWidget

Code

protected function initMap(&$element, $map_id, $coords) {
  $element['map_container'] = [
    '#title' => $this
      ->t('Preview'),
    '#type' => 'html_tag',
    '#tag' => 'div',
    '#attributes' => [
      'id' => $map_id,
      'class' => 'yamaps-field-map',
      'style' => 'width: 100%; height: 400px;',
    ],
  ];
  $element['coords'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Coordinates'),
    '#default_value' => $coords,
    '#attributes' => [
      'class' => [
        'field-yamaps-coords-' . $map_id,
      ],
    ],
  ];
  $element['type'] = [
    '#type' => 'hidden',
    '#default_value' => 'yandex#map',
  ];
  $coords = Json::decode($coords);
  $this->map['init'] = [
    'center' => $coords['center'] ?? NULL,
    'zoom' => $coords['zoom'] ?? NULL,
    'type' => 'yandex#map',
    'behaviors' => [
      'scrollZoom',
      'dblClickZoom',
      'drag',
    ],
  ];
  $this->map['display_options'] = [
    'display_type' => 'map',
    'open_button_text' => 'Open map',
    'close_button_text' => 'Close map',
    'width' => '100%',
    'height' => '400px',
  ];
  $this->map['controls'] = 1;
  $this->map['edit'] = TRUE;
}