public function Location::alterMap in Geolocation Field 8.3
Same name and namespace in other branches
- 8.2 src/Plugin/geolocation/MapCenter/Location.php \Drupal\geolocation\Plugin\geolocation\MapCenter\Location::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/ Location.php, line 132
Class
- Location
- Location based map center.
Namespace
Drupal\geolocation\Plugin\geolocation\MapCenterCode
public function alterMap(array $map, $center_plugin_id, array $center_option_settings, $context = NULL) {
if (!$this->locationManager
->hasDefinition($center_plugin_id)) {
return $map;
}
/** @var \Drupal\geolocation\LocationInterface $location */
$location = $this->locationManager
->createInstance($center_plugin_id);
if (!empty($center_option_settings['location_option_id'])) {
$location_id = $center_option_settings['location_option_id'];
}
else {
$location_id = $center_plugin_id;
}
$map['#attached']['drupalSettings']['geolocation']['maps'][$map['#id']]['map_center']['location_plugins_' . $location_id] = $map['#attached']['drupalSettings']['geolocation']['maps'][$map['#id']]['map_center']['location_plugins'];
unset($map['#attached']['drupalSettings']['geolocation']['maps'][$map['#id']]['map_center']['location_plugins']);
$map_center = $location
->getCoordinates($location_id, $center_option_settings, $context);
if (!empty($map_center)) {
$map['#centre'] = $map_center;
}
$map['#attached'] = BubbleableMetadata::mergeAttachments($map['#attached'], [
'library' => [
'geolocation/map_center.static_location',
],
'drupalSettings' => [
'geolocation' => [
'maps' => [
$map['#id'] => [
'map_center' => [
'location_plugins_' . $location_id => [
'success' => !empty($map_center),
],
],
],
],
],
],
]);
return $map;
}