public function ViewsBoundaryArgument::alterMap in Geolocation Field 8.3
Same name and namespace in other branches
- 8.2 src/Plugin/geolocation/MapCenter/ViewsBoundaryArgument.php \Drupal\geolocation\Plugin\geolocation\MapCenter\ViewsBoundaryArgument::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/ ViewsBoundaryArgument.php, line 45
Class
- ViewsBoundaryArgument
- Derive center from boundary filter.
Namespace
Drupal\geolocation\Plugin\geolocation\MapCenterCode
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\argument\BoundaryArgument $argument */
$argument = $displayHandler
->getHandler('argument', substr($center_option_id, 18));
if ($values = $argument
->getParsedBoundary()) {
if (isset($values['lat_north_east']) && $values['lat_north_east'] !== "" && isset($values['lng_north_east']) && $values['lng_north_east'] !== "" && isset($values['lat_south_west']) && $values['lat_south_west'] !== "" && isset($values['lng_south_west']) && $values['lng_south_west'] !== "") {
$map['#attached'] = BubbleableMetadata::mergeAttachments($map['#attached'], [
'library' => [
'geolocation/map_center.viewsBoundaryArgument',
],
'drupalSettings' => [
'geolocation' => [
'maps' => [
$map['#id'] => [
'map_center' => [
'views_boundary_argument' => [
'latNorthEast' => (double) $values['lat_north_east'],
'lngNorthEast' => (double) $values['lng_north_east'],
'latSouthWest' => (double) $values['lat_south_west'],
'lngSouthWest' => (double) $values['lng_south_west'],
],
],
],
],
],
],
]);
}
}
return $map;
}