You are here

protected function YaMaps::overridePlacemarkTitle in Yandex.Maps 8

Override Placemark title.

Parameters

array $placemark: Placemark.

\Drupal\views\ResultRow $row: Row.

1 call to YaMaps::overridePlacemarkTitle()
YaMaps::render in src/Plugin/views/style/YaMaps.php
Render the display in this style.

File

src/Plugin/views/style/YaMaps.php, line 617

Class

YaMaps
Allow to display several field items on a yandex map.

Namespace

Drupal\yamaps\Plugin\views\style

Code

protected function overridePlacemarkTitle(array &$placemark, ResultRow $row) {
  if (isset($this->options['placemark_title'], $this->view->field[$this->options['placemark_title']]) && $this->options['placemark_title'] !== static::PLACEMARK_DEFAULT_FIELD) {

    // Prepare placemark title.
    $marker_title = $this
      ->preparePlacemarkTitle($row);
    $field_title_settings = $this->view->field[$this->options['placemark_title']];
    if (isset($field_title_settings->field_info['type'])) {
      switch ($field_title_settings->field_info['type']) {
        case 'image':
          if (isset($row->{'field_' . $this->options['placemark_title']}[0]['rendered']['#image_style'], $row->{'field_' . $this->options['placemark_title']}[0]['raw']['uri'])) {

            // Special logic for image fields.
            // Placemark type.
            $placemark['options']['iconLayout'] = 'default#image';

            // Image href.
            $placemark['options']['iconImageHref'] = ImageStyle::load($row->{'field_' . $this->options['placemark_title']}[0]['rendered']['#image_style'])
              ->buildUrl($row->{'field_' . $this->options['placemark_title']}[0]['raw']['uri']);
            $image_dimensions = getimagesize($placemark['options']['iconImageHref']);

            // Placemark image size.
            $placemark['options']['iconImageSize'] = [
              $image_dimensions[0],
              $image_dimensions[1],
            ];

            // Icon image offset of upper left angle.
            $placemark['options']['iconImageOffset'] = [
              -($image_dimensions[0] / 2),
              $image_dimensions[1] * 0.1 - $image_dimensions[1],
            ];
          }
          else {
            $this
              ->prepareDefaultPlacemarkTitle($placemark, $marker_title);
          }
          break;
        default:
          $this
            ->prepareDefaultPlacemarkTitle($placemark, $marker_title);
          break;
      }
    }
    else {
      $this
        ->prepareDefaultPlacemarkTitle($placemark, $marker_title);
    }
  }
}