public function LeafletMarkerIcon::alterMap in Geolocation Field 8.2
Same name and namespace in other branches
- 8.3 modules/geolocation_leaflet/src/Plugin/geolocation/MapFeature/LeafletMarkerIcon.php \Drupal\geolocation_leaflet\Plugin\geolocation\MapFeature\LeafletMarkerIcon::alterMap()
Alter render array.
Parameters
array $render_array: Render array.
array $feature_settings: The current feature settings.
array $context: Context like field formatter, field widget or view.
Return value
array Render array.
Overrides MapFeatureBase::alterMap
File
- modules/
geolocation_leaflet/ src/ Plugin/ geolocation/ MapFeature/ LeafletMarkerIcon.php, line 155
Class
- LeafletMarkerIcon
- Provides marker icon adjustment.
Namespace
Drupal\geolocation_leaflet\Plugin\geolocation\MapFeatureCode
public function alterMap(array $render_array, array $feature_settings, array $context = []) {
$render_array = parent::alterMap($render_array, $feature_settings, $context);
$feature_settings = $this
->getSettings($feature_settings);
$render_array['#attached'] = BubbleableMetadata::mergeAttachments(empty($render_array['#attached']) ? [] : $render_array['#attached'], [
'library' => [
'geolocation_leaflet/mapfeature.' . $this
->getPluginId(),
],
'drupalSettings' => [
'geolocation' => [
'maps' => [
$render_array['#id'] => [
$this
->getPluginId() => [
'enable' => TRUE,
'iconSize' => [
'width' => (int) $feature_settings['icon_size']['width'],
'height' => (int) $feature_settings['icon_size']['height'],
],
'iconAnchor' => [
'x' => (int) $feature_settings['icon_anchor']['x'],
'y' => (int) $feature_settings['icon_anchor']['y'],
],
'popupAnchor' => [
'x' => (int) $feature_settings['popup_anchor']['x'],
'y' => (int) $feature_settings['popup_anchor']['y'],
],
'shadowSize' => [
'width' => (int) $feature_settings['shadow_size']['width'],
'height' => (int) $feature_settings['shadow_size']['height'],
],
'shadowAnchor' => [
'x' => (int) $feature_settings['shadow_anchor']['x'],
'y' => (int) $feature_settings['shadow_anchor']['y'],
],
],
],
],
],
],
]);
if (!empty($feature_settings['marker_icon_path'])) {
$data = [];
if (!empty($context['view'])) {
$data['view'] = $context['view'];
}
$iconPath = \Drupal::token()
->replace($feature_settings['marker_icon_path'], $data);
$iconUrl = file_url_transform_relative(file_create_url($iconPath));
$render_array['#attached']['drupalSettings']['geolocation']['maps'][$render_array['#id']][$this
->getPluginId()]['markerIconPath'] = $iconUrl;
}
if (!empty($feature_settings['marker_shadow_path'])) {
$data = [];
if (!empty($context['view'])) {
$data['view'] = $context['view'];
}
$shadowPath = \Drupal::token()
->replace($feature_settings['marker_shadow_path'], $data);
$shadowUrl = file_url_transform_relative(file_create_url($shadowPath));
$render_array['#attached']['drupalSettings']['geolocation']['maps'][$render_array['#id']][$this
->getPluginId()]['markerShadowPath'] = $shadowUrl;
}
return $render_array;
}