class LeafletTileLayerOverlay in Geolocation Field 8.3
Provides map tile layer overlay support.
Plugin annotation
@MapFeature(
id = "leaflet_tile_layer_overlay",
name = @Translation("Tile Layer - Overlays"),
description = @Translation("Select a map tile layer overlay."),
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\LeafletTileLayerOverlay
- class \Drupal\geolocation\MapFeatureBase implements ContainerFactoryPluginInterface, MapFeatureInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of LeafletTileLayerOverlay
File
- modules/
geolocation_leaflet/ src/ Plugin/ geolocation/ MapFeature/ LeafletTileLayerOverlay.php, line 21
Namespace
Drupal\geolocation_leaflet\Plugin\geolocation\MapFeatureView source
class LeafletTileLayerOverlay extends MapFeatureBase {
/**
* {@inheritdoc}
*/
public static function getDefaultSettings() {
return [
'tile_layer_overlay' => 'OpenInfraMap.Power',
];
}
/**
* Return options array for tile overlay.
*
* @param string $overlay
* Map tile overlay selected.
*
* @return array
* Options form.
*/
public static function getOptionsForm($overlay) {
$form = [
'#prefix' => '<div id="tile-overlay-settings">',
'#suffix' => '</div>',
];
if ($overlay == 'OpenWeatherMap') {
$form['apiKey'] = [
'#type' => 'textfield',
'#title' => t('API key'),
'#default_value' => '',
'#description' => t('Get your API Key here <a href="@url">@overlay</a>.', [
'@url' => 'https://openweathermap.org/',
'@overlay' => $overlay,
]),
];
}
return $form;
}
/**
* Return settings array for tile overlay after select change.
*
* @param array $form
* Form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Current From State.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* Settings form.
*/
public static function addTileOverlaySettingsFormAjax(array $form, FormStateInterface $form_state) {
$ajax_response = new AjaxResponse();
$triggering_element_value = $form_state
->getTriggeringElement()['#value'];
$overlay = explode('.', $triggering_element_value)[0];
$form = LeafletTileLayerOverlay::getOptionsForm($overlay);
$ajax_response
->addCommand(new ReplaceCommand('#tile-overlay-settings', $form));
return $ajax_response;
}
/**
* {@inheritdoc}
*/
public function getSettingsForm(array $settings, array $parents) {
$settings = array_replace_recursive(self::getDefaultSettings(), $settings);
$form['tile_layer_overlay'] = [
'#type' => 'select',
'#options' => $this
->getTileOverlays(),
'#default_value' => $settings['tile_layer_overlay'],
'#ajax' => [
'callback' => [
$this,
'addTileOverlaySettingsFormAjax',
],
'wrapper' => 'tile-overlay-settings',
'effect' => 'fade',
],
];
$overlay = explode('.', $settings['tile_layer_overlay'])[0];
$form['tile_overlay_options'] = LeafletTileLayerOverlay::getOptionsForm($overlay);
return $form;
}
/**
* {@inheritdoc}
*/
public function alterMap(array $render_array, array $feature_settings, array $context = []) {
$render_array = parent::alterMap($render_array, $feature_settings, $context);
$tileLayer = [
'enable' => TRUE,
'tileLayerOverlay' => $feature_settings['tile_layer_overlay'],
];
if (isset($feature_settings['tile_overlay_options'])) {
$tileLayer['tileLayerOptions'] = $feature_settings['tile_overlay_options'];
}
$render_array['#attached'] = BubbleableMetadata::mergeAttachments(empty($render_array['#attached']) ? [] : $render_array['#attached'], [
'library' => [
'geolocation_leaflet/mapfeature.tilelayeroverlay',
],
'drupalSettings' => [
'geolocation' => [
'maps' => [
$render_array['#id'] => [
$this
->getPluginId() => $tileLayer,
],
],
],
],
]);
return $render_array;
}
/**
* Provide some available tile overlays.
*
* @return array
* An array containing tile overlay IDs.
*/
private function getTileOverlays() {
return [
'OpenInfraMap' => [
'OpenInfraMap.Power' => 'OpenInfraMap Power',
'OpenInfraMap.Telecom' => 'OpenInfraMap Telecom',
'OpenInfraMap.Petroleum' => 'OpenInfraMap Petroleum',
'OpenInfraMap.Water' => 'OpenInfraMap Water',
],
'OpenSeaMap' => [
'OpenSeaMap' => 'OpenSeaMap',
],
'OpenPtMap' => [
'OpenPtMap' => 'OpenPtMap',
],
'OpenRailwayMap' => [
'OpenRailwayMap' => 'OpenRailwayMap',
],
'OpenFireMap' => [
'OpenFireMap' => 'OpenFireMap',
],
'SafeCast' => [
'SafeCast' => 'SafeCast',
],
'OpenMapSurfer' => [
'OpenMapSurfer.AdminBounds' => 'OpenMapSurfer AdminBounds',
],
'Hydda' => [
'Hydda.RoadsAndLabels' => 'Hydda RoadsAndLabels',
],
'Stamen' => [
'Stamen.TonerHybrid' => 'Stamen TonerHybrid',
'Stamen.TonerLines' => 'Stamen TonerLines',
'Stamen.TonerLabels' => 'Stamen TonerLabels',
'Stamen.TopOSMFeatures' => 'Stamen TopOSMFeatures',
],
'OpenWeatherMap' => [
'OpenWeatherMap.Clouds' => 'OpenWeatherMap Clouds',
'OpenWeatherMap.CloudsClassic' => 'OpenWeatherMap CloudsClassic',
'OpenWeatherMap.Precipitation' => 'OpenWeatherMap Precipitation',
'OpenWeatherMap.PrecipitationClassic' => 'OpenWeatherMap PrecipitationClassic',
'OpenWeatherMap.Rain' => 'OpenWeatherMap Rain',
'OpenWeatherMap.RainClassic' => 'OpenWeatherMap RainClassic',
'OpenWeatherMap.Pressure' => 'OpenWeatherMap Pressure',
'OpenWeatherMap.PressureContour' => 'OpenWeatherMap PressureContour',
'OpenWeatherMap.Wind' => 'OpenWeatherMap Wind',
'OpenWeatherMap.Temperature' => 'OpenWeatherMap Temperature',
'OpenWeatherMap.Snow' => 'OpenWeatherMap Snow',
],
'JusticeMap' => [
'JusticeMap.income' => 'JusticeMap income',
'JusticeMap.americanIndian' => 'JusticeMap americanIndian',
'JusticeMap.asian' => 'JusticeMap asian',
'JusticeMap.black' => 'JusticeMap black',
'JusticeMap.hispanic' => 'JusticeMap hispanic',
'JusticeMap.multi' => 'JusticeMap multi',
'JusticeMap.nonWhite' => 'JusticeMap nonWhite',
'JusticeMap.white' => 'JusticeMap white',
'JusticeMap.plurality' => 'JusticeMap plurality',
],
];
}
}
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 | |
LeafletTileLayerOverlay:: |
public static | function | Return settings array for tile overlay after select change. | |
LeafletTileLayerOverlay:: |
public | function |
Alter render array. Overrides MapFeatureBase:: |
|
LeafletTileLayerOverlay:: |
public static | function |
Provide a populated settings array. Overrides MapFeatureBase:: |
|
LeafletTileLayerOverlay:: |
public static | function | Return options array for tile overlay. | |
LeafletTileLayerOverlay:: |
public | function |
Provide a generic map settings form array. Overrides MapFeatureBase:: |
|
LeafletTileLayerOverlay:: |
private | function | Provide some available tile overlays. | |
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:: |
2 |
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. |