ViewsBoundaryFilter.php in Geolocation Field 8.2
File
src/Plugin/geolocation/MapCenter/ViewsBoundaryFilter.php
View source
<?php
namespace Drupal\geolocation\Plugin\geolocation\MapCenter;
use Drupal\geolocation\MapCenterInterface;
use Drupal\geolocation\MapCenterBase;
use Drupal\geolocation\ViewsContextTrait;
class ViewsBoundaryFilter extends MapCenterBase implements MapCenterInterface {
use ViewsContextTrait;
public function getAvailableMapCenterOptions($context) {
$options = [];
if ($displayHandler = self::getViewsDisplayHandler($context)) {
foreach ($displayHandler
->getHandlers('filter') as $filter_id => $filter) {
if ($filter
->getPluginId() == 'geolocation_filter_boundary') {
$options['boundary_filter_' . $filter_id] = $this
->t('Boundary filter') . ' - ' . $filter
->adminLabel();
}
}
}
return $options;
}
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;
}
$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;
}
}