You are here

public function ViewsBoundaryFilter::alterMap in Geolocation Field 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/geolocation/MapCenter/ViewsBoundaryFilter.php \Drupal\geolocation\Plugin\geolocation\MapCenter\ViewsBoundaryFilter::alterMap()

Alter map..

Parameters

array $map: Map object.

int $center_option_id: MapCenter option ID.

array $center_option_settings: The current feature settings.

mixed $context: Context like field formatter, field widget or view.

Return value

array Map object.

Overrides MapCenterBase::alterMap

File

src/Plugin/geolocation/MapCenter/ViewsBoundaryFilter.php, line 45

Class

ViewsBoundaryFilter
Derive center from boundary filter.

Namespace

Drupal\geolocation\Plugin\geolocation\MapCenter

Code

public function alterMap(array $map, $center_option_id, array $center_option_settings, $context = NULL) {
  $map = parent::alterMap($map, $center_option_id, $center_option_settings, $context);
  if (!($displayHandler = self::getViewsDisplayHandler($context))) {
    return $map;
  }

  /** @var \Drupal\geolocation\Plugin\views\filter\ProximityFilter $handler */
  $handler = $displayHandler
    ->getHandler('filter', substr($center_option_id, 16));
  if (isset($handler->value['lat_north_east']) && $handler->value['lat_north_east'] !== "" && isset($handler->value['lng_north_east']) && $handler->value['lng_north_east'] !== "" && isset($handler->value['lat_south_west']) && $handler->value['lat_south_west'] !== "" && isset($handler->value['lng_south_west']) && $handler->value['lng_south_west'] !== "") {
    $map['#attached'] = array_merge_recursive($map['#attached'], [
      'library' => [
        'geolocation/map_center.viewsBoundaryFilter',
      ],
      'drupalSettings' => [
        'geolocation' => [
          'maps' => [
            $map['#id'] => [
              'map_center' => [
                'views_boundary_filter' => [
                  'latNorthEast' => (double) $handler->value['lat_north_east'],
                  'lngNorthEast' => (double) $handler->value['lng_north_east'],
                  'latSouthWest' => (double) $handler->value['lat_south_west'],
                  'lngSouthWest' => (double) $handler->value['lng_south_west'],
                ],
              ],
            ],
          ],
        ],
      ],
    ]);
  }
  return $map;
}