class LeafletMarkerIcon 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
Provides marker icon adjustment.
Plugin annotation
@MapFeature(
id = "leaflet_marker_icon",
name = @Translation("Marker Icon Adjustment"),
description = @Translation("Icon properties."),
type = "leaflet",
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\geolocation\MapFeatureBase implements ContainerFactoryPluginInterface, MapFeatureInterface
- class \Drupal\geolocation_leaflet\Plugin\geolocation\MapFeature\LeafletMarkerIcon
- class \Drupal\geolocation\MapFeatureBase implements ContainerFactoryPluginInterface, MapFeatureInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of LeafletMarkerIcon
File
- modules/
geolocation_leaflet/ src/ Plugin/ geolocation/ MapFeature/ LeafletMarkerIcon.php, line 18
Namespace
Drupal\geolocation_leaflet\Plugin\geolocation\MapFeatureView source
class LeafletMarkerIcon extends MapFeatureBase {
/**
* {@inheritdoc}
*/
public static function getDefaultSettings() {
return [
'marker_icon_path' => '',
'icon_size' => [
'width' => NULL,
'height' => NULL,
],
'icon_anchor' => [
'x' => NULL,
'y' => NULL,
],
'popup_anchor' => [
'x' => 0,
'y' => 0,
],
'marker_shadow_path' => '',
'shadow_size' => [
'width' => NULL,
'height' => NULL,
],
'shadow_anchor' => [
'x' => NULL,
'y' => NULL,
],
];
}
/**
* {@inheritdoc}
*/
public function getSettingsForm(array $settings, array $parents) {
$settings = $this
->getSettings($settings);
$form['marker_icon_path'] = [
'#type' => 'textfield',
'#title' => $this
->t('Icon path'),
'#description' => $this
->t('Set relative or absolute path to custom marker icon. Tokens supported. Empty for default. Attention: In views contexts, additional icon source options are available in the style settings.'),
'#default_value' => $settings['marker_icon_path'],
];
$form['icon_size'] = [
'#type' => 'item',
'#description' => $this
->t('Size of the icon image in pixels.'),
'width' => [
'#type' => 'number',
'#title' => $this
->t('Icon Size - Width'),
'#default_value' => $settings['icon_size']['width'],
'#min' => 0,
],
'height' => [
'#type' => 'number',
'#title' => $this
->t('Icon Size - Height'),
'#default_value' => $settings['icon_size']['height'],
'#min' => 0,
],
];
$form['icon_anchor'] = [
'#type' => 'item',
'#description' => $this
->t('The coordinates of the "tip" of the icon (relative to its top left corner). The icon will be aligned so that this point is at the marker\'s geographical location. Centered by default if size is specified.'),
'x' => [
'#type' => 'number',
'#title' => $this
->t('Icon Anchor - X'),
'#default_value' => $settings['icon_anchor']['x'],
],
'y' => [
'#type' => 'number',
'#title' => $this
->t('Icon Anchor - Y'),
'#default_value' => $settings['icon_anchor']['y'],
],
];
$form['popup_anchor'] = [
'#type' => 'item',
'#description' => $this
->t('The coordinates of the point from which popups will "open", relative to the icon anchor.'),
'x' => [
'#type' => 'number',
'#title' => $this
->t('Popup Anchor - X'),
'#default_value' => $settings['popup_anchor']['x'],
],
'y' => [
'#type' => 'number',
'#title' => $this
->t('Popup Anchor - Y'),
'#default_value' => $settings['popup_anchor']['y'],
],
];
$form['marker_shadow_path'] = [
'#type' => 'textfield',
'#title' => $this
->t('Shadow path'),
'#description' => $this
->t('Set relative or absolute path to custom marker shadow. Tokens supported. Empty for default. Attention: In views contexts, additional shadow source options are available in the style settings.'),
'#default_value' => $settings['marker_shadow_path'],
];
$form['shadow_size'] = [
'#type' => 'item',
'#description' => $this
->t('Size of the shadow image in pixels.'),
'width' => [
'#type' => 'number',
'#title' => $this
->t('Shadow Size - Width'),
'#default_value' => $settings['shadow_size']['width'],
'#min' => 0,
],
'height' => [
'#type' => 'number',
'#title' => $this
->t('Shadow Size - Height'),
'#default_value' => $settings['shadow_size']['height'],
'#min' => 0,
],
];
$form['shadow_anchor'] = [
'#type' => 'item',
'#description' => $this
->t('The coordinates of the "tip" of the shadow (relative to its top left corner) (the same as iconAnchor if not specified).'),
'x' => [
'#type' => 'number',
'#title' => $this
->t('Shadow Anchor - X'),
'#default_value' => $settings['shadow_anchor']['x'],
],
'y' => [
'#type' => 'number',
'#title' => $this
->t('Shadow Anchor - Y'),
'#default_value' => $settings['shadow_anchor']['y'],
],
];
return $form;
}
/**
* {@inheritdoc}
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
LeafletMarkerIcon:: |
public | function |
Alter render array. Overrides MapFeatureBase:: |
|
LeafletMarkerIcon:: |
public static | function |
Provide a populated settings array. Overrides MapFeatureBase:: |
|
LeafletMarkerIcon:: |
public | function |
Provide a generic map settings form array. Overrides MapFeatureBase:: |
|
MapFeatureBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
2 |
MapFeatureBase:: |
public | function |
Provide map feature specific settings ready to handover to JS. Overrides MapFeatureInterface:: |
|
MapFeatureBase:: |
public | function |
Provide a summary array to use in field formatters. Overrides MapFeatureInterface:: |
1 |
MapFeatureBase:: |
public | function |
Validate Feature Form. Overrides MapFeatureInterface:: |
5 |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |