class GoogleMaps in Geolocation Field 8.3
Same name and namespace in other branches
- 8.2 modules/geolocation_google_maps/src/Plugin/geolocation/MapProvider/GoogleMaps.php \Drupal\geolocation_google_maps\Plugin\geolocation\MapProvider\GoogleMaps
Provides Google Maps.
Plugin annotation
@MapProvider(
id = "google_maps",
name = @Translation("Google Maps"),
description = @Translation("You do require an API key for this plugin to work."),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\geolocation\MapProviderBase implements ContainerFactoryPluginInterface, MapProviderInterface
- class \Drupal\geolocation_google_maps\GoogleMapsProviderBase
- class \Drupal\geolocation_google_maps\Plugin\geolocation\MapProvider\GoogleMaps
- class \Drupal\geolocation_google_maps\GoogleMapsProviderBase
- class \Drupal\geolocation\MapProviderBase implements ContainerFactoryPluginInterface, MapProviderInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of GoogleMaps
4 files declare their use of GoogleMaps
- ControlElementBase.php in modules/
geolocation_google_maps/ src/ Plugin/ geolocation/ MapFeature/ ControlElementBase.php - GoogleGeocodingAPI.php in modules/
geolocation_google_maps/ src/ Plugin/ geolocation/ Geocoder/ GoogleGeocodingAPI.php - GooglePlacesAPI.php in modules/
geolocation_google_maps/ modules/ geolocation_google_places_api/ src/ Plugin/ geolocation/ Geocoder/ GooglePlacesAPI.php - MarkerClusterer.php in modules/
geolocation_google_maps/ src/ Plugin/ geolocation/ MapFeature/ MarkerClusterer.php
File
- modules/
geolocation_google_maps/ src/ Plugin/ geolocation/ MapProvider/ GoogleMaps.php, line 17
Namespace
Drupal\geolocation_google_maps\Plugin\geolocation\MapProviderView source
class GoogleMaps extends GoogleMapsProviderBase {
/**
* Google map max zoom level.
*
* @var int
*/
public static $maxZoomLevel = 20;
/**
* Google map min zoom level.
*
* @var int
*/
public static $minZoomLevel = 0;
/**
* {@inheritdoc}
*/
public static $googleMapsApiUrlPath = '/maps/api/js';
/**
* {@inheritdoc}
*/
public function getGoogleMapsApiParameters(array $additional_parameters = []) {
$parameters = parent::getGoogleMapsApiParameters($additional_parameters);
$parameters['callback'] = 'Drupal.geolocation.google.load';
if (!empty($parameters['client'])) {
unset($parameters['key']);
}
return $parameters;
}
/**
* {@inheritdoc}
*/
public static function getDefaultSettings() {
return array_replace_recursive(parent::getDefaultSettings(), [
'minZoom' => static::$minZoomLevel,
'maxZoom' => static::$maxZoomLevel,
'gestureHandling' => 'auto',
'map_features' => [
'marker_infowindow' => [
'enabled' => TRUE,
],
'control_locate' => [
'enabled' => TRUE,
],
'control_zoom' => [
'enabled' => TRUE,
],
'control_maptype' => [
'enabled' => TRUE,
],
],
]);
}
/**
* {@inheritdoc}
*/
public static function getControlPositions() {
return [
'LEFT_TOP' => t('Left top'),
'LEFT_CENTER' => t('Left center'),
'LEFT_BOTTOM' => t('Left bottom'),
'TOP_LEFT' => t('Top left'),
'TOP_CENTER' => t('Top center'),
'TOP_RIGHT' => t('Top right'),
'RIGHT_TOP' => t('Right top'),
'RIGHT_CENTER' => t('Right center'),
'RIGHT_BOTTOM' => t('Right bottom'),
'BOTTOM_LEFT' => t('Bottom left'),
'BOTTOM_CENTER' => t('Bottom center'),
'BOTTOM_RIGHT' => t('Bottom right'),
];
}
/**
* {@inheritdoc}
*/
public function getSettings(array $settings) {
$settings = parent::getSettings($settings);
$settings['minZoom'] = (int) $settings['minZoom'];
$settings['maxZoom'] = (int) $settings['maxZoom'];
return $settings;
}
/**
* {@inheritdoc}
*/
public function getSettingsForm(array $settings, array $parents = []) {
$settings = $this
->getSettings($settings);
$parents_string = '';
if ($parents) {
$parents_string = implode('][', $parents) . '][';
}
$form = parent::getSettingsForm($settings, $parents);
$form['zoom']['#min'] = static::$minZoomLevel;
$form['zoom']['#max'] = static::$maxZoomLevel;
$form['maxZoom'] = [
'#group' => $parents_string . 'general_settings',
'#type' => 'number',
'#min' => static::$minZoomLevel,
'#max' => static::$maxZoomLevel,
'#title' => $this
->t('Max Zoom level'),
'#description' => $this
->t('The maximum zoom level of the map. If omitted, or set to null, the default maximum zoom from the current map type is used instead.'),
'#default_value' => $settings['maxZoom'],
'#process' => [
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'processGroup',
],
],
'#pre_render' => [
[
'\\Drupal\\Core\\Render\\Element\\Number',
'preRenderNumber',
],
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'preRenderGroup',
],
],
];
$form['minZoom'] = [
'#group' => $parents_string . 'general_settings',
'#type' => 'number',
'#min' => static::$minZoomLevel,
'#max' => static::$maxZoomLevel,
'#title' => $this
->t('Min Zoom level'),
'#description' => $this
->t('The minimum zoom level of the map. If omitted, or set to null, the default minimum zoom from the current map type is used instead.'),
'#default_value' => $settings['minZoom'],
'#process' => [
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'processGroup',
],
],
'#pre_render' => [
[
'\\Drupal\\Core\\Render\\Element\\Number',
'preRenderNumber',
],
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'preRenderGroup',
],
],
];
$form['behavior_settings'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Behavior'),
];
$form['gestureHandling'] = [
'#group' => $parents_string . 'behavior_settings',
'#type' => 'select',
'#title' => $this
->t('Gesture Handling'),
'#default_value' => $settings['gestureHandling'],
'#description' => $this
->t('Define how to handle interactions with map on mobile. Read the <a href=":introduction">introduction</a> for handling or the <a href=":details">details</a>, <i>available as of v3.27 / Nov. 2016</i>.', [
':introduction' => 'https://googlegeodevelopers.blogspot.de/2016/11/smart-scrolling-comes-to-mobile-web-maps.html',
':details' => 'https://developers.google.com/maps/documentation/javascript/3.exp/reference#MapOptions',
]),
'#options' => [
'auto' => $this
->t('auto (default)'),
'cooperative' => $this
->t('cooperative'),
'greedy' => $this
->t('greedy'),
'none' => $this
->t('none'),
],
'#process' => [
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'processGroup',
],
[
'\\Drupal\\Core\\Render\\Element\\Select',
'processSelect',
],
],
'#pre_render' => [
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'preRenderGroup',
],
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function alterRenderArray(array $render_array, array $map_settings, array $context = []) {
$render_array['#attached'] = BubbleableMetadata::mergeAttachments(empty($render_array['#attached']) ? [] : $render_array['#attached'], [
'library' => [
'geolocation_google_maps/google',
],
'drupalSettings' => [
'geolocation' => [
'maps' => [
$render_array['#id'] => [
'settings' => [
'google_map_settings' => $map_settings,
],
],
],
],
],
]);
return parent::alterRenderArray($render_array, $map_settings, $context);
}
/**
* {@inheritdoc}
*/
public function alterCommonMap(array $render_array, array $map_settings, array $context) {
$render_array['#attached'] = BubbleableMetadata::mergeAttachments(empty($render_array['#attached']) ? [] : $render_array['#attached'], [
'library' => [
'geolocation_google_maps/commonmap.google',
],
]);
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 | |
GoogleMaps:: |
public static | property |
Google maps url from PR China. Overrides GoogleMapsProviderBase:: |
|
GoogleMaps:: |
public static | property | Google map max zoom level. | |
GoogleMaps:: |
public static | property | Google map min zoom level. | |
GoogleMaps:: |
public | function |
Alter common map build array. Overrides MapProviderBase:: |
|
GoogleMaps:: |
public | function |
Alter render array. Overrides MapProviderBase:: |
|
GoogleMaps:: |
public static | function |
Return available control positions. Overrides MapProviderBase:: |
|
GoogleMaps:: |
public static | function |
Provide a populated settings array. Overrides GoogleMapsProviderBase:: |
|
GoogleMaps:: |
public | function |
Return all module and custom defined parameters. Overrides GoogleMapsProviderBase:: |
|
GoogleMaps:: |
public | function |
Provide map provider specific settings ready to handover to JS. Overrides GoogleMapsProviderBase:: |
|
GoogleMaps:: |
public | function |
Provide a generic map settings form array. Overrides GoogleMapsProviderBase:: |
|
GoogleMapsProviderBase:: |
public static | property | Google maps url. | |
GoogleMapsProviderBase:: |
public static | property | Google maps url from PR China. | |
GoogleMapsProviderBase:: |
public static | property | Google map style - Hybrid. | |
GoogleMapsProviderBase:: |
public static | property | Google map style - Roadmap. | |
GoogleMapsProviderBase:: |
public static | property | Google map style - Satellite. | |
GoogleMapsProviderBase:: |
public static | property | Google map style - Terrain. | |
GoogleMapsProviderBase:: |
public | function | Return the fully build URL to load Google Maps API. | |
GoogleMapsProviderBase:: |
private | function | An array of all available map types. | |
GoogleMapsProviderBase:: |
public | function |
Provide a summary array to use in field formatters. Overrides MapProviderBase:: |
|
MapProviderBase:: |
protected | property | Map feature manager. | |
MapProviderBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
MapProviderBase:: |
public | function | Validate form. | |
MapProviderBase:: |
public | function |
Constructs a new GeocoderBase object. Overrides PluginBase:: |
|
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. | |
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. |