class GoogleStaticMaps in Geolocation Field 8.2
Same name and namespace in other branches
- 8.3 modules/geolocation_google_maps/modules/geolocation_google_static_maps/src/Plugin/geolocation/MapProvider/GoogleStaticMaps.php \Drupal\geolocation_google_static_maps\Plugin\geolocation\MapProvider\GoogleStaticMaps
Provides Google Maps.
Plugin annotation
@MapProvider(
id = "google_static_maps",
name = @Translation("Google Static 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_static_maps\Plugin\geolocation\MapProvider\GoogleStaticMaps
- 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 GoogleStaticMaps
File
- modules/
geolocation_google_maps/ modules/ geolocation_google_static_maps/ src/ Plugin/ geolocation/ MapProvider/ GoogleStaticMaps.php, line 18
Namespace
Drupal\geolocation_google_static_maps\Plugin\geolocation\MapProviderView source
class GoogleStaticMaps extends GoogleMapsProviderBase {
/**
* {@inheritdoc}
*/
public static $GOOGLEMAPSAPIURLPATH = '/maps/api/staticmap';
/**
* {@inheritdoc}
*/
public static function getDefaultSettings() {
return array_replace_recursive(parent::getDefaultSettings(), [
'height' => '400',
'width' => '400',
]);
}
/**
* {@inheritdoc}
*/
public function getSettingsForm(array $settings, array $parents = []) {
$form = parent::getSettingsForm($settings, $parents);
$parents_string = '';
if ($parents) {
$parents_string = implode('][', $parents) . '][';
}
$form['width'] = array_replace($form['width'], [
'#type' => 'number',
'#description' => $this
->t('Enter width in pixels. Free users maximum 640.'),
'#process' => [
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'processGroup',
],
],
'#pre_render' => [
[
'\\Drupal\\Core\\Render\\Element\\Number',
'preRenderNumber',
],
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'preRenderGroup',
],
],
]);
$form['height'] = array_replace($form['height'], [
'#type' => 'number',
'#description' => $this
->t('Enter height in pixels. Free users maximum 640.'),
'#process' => [
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'processGroup',
],
],
'#pre_render' => [
[
'\\Drupal\\Core\\Render\\Element\\Number',
'preRenderNumber',
],
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'preRenderGroup',
],
],
]);
$form['scale'] = [
'#group' => $parents_string . 'general_settings',
'#type' => 'select',
'#title' => $this
->t('Scale Value'),
'#options' => [
'1' => $this
->t('1 (default)'),
'2' => $this
->t('2'),
'4' => $this
->t('4 - Google Maps APIs Premium Plan only'),
],
'#default_value' => $settings['scale'],
'#process' => [
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'processGroup',
],
[
'\\Drupal\\Core\\Render\\Element\\Select',
'processSelect',
],
],
'#pre_render' => [
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'preRenderGroup',
],
],
];
$form['format'] = [
'#group' => $parents_string . 'general_settings',
'#type' => 'select',
'#title' => $this
->t('Image Format'),
'#options' => [
'png' => $this
->t('8-bit PNG (default)'),
'png32' => $this
->t('32-bit PNG'),
'gif' => $this
->t('GIF'),
'jpg' => $this
->t('JPEG'),
'jpg-baseline' => $this
->t('non-progressive JPEG'),
],
'#default_value' => $settings['format'],
'#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 = []) {
$additional_parameters = [
'type' => strtolower($map_settings['type']),
'size' => filter_var($map_settings['width'], FILTER_SANITIZE_NUMBER_INT) . 'x' . filter_var($map_settings['height'], FILTER_SANITIZE_NUMBER_INT),
'zoom' => $map_settings['zoom'],
'scale' => (int) $map_settings['scale'],
'format' => $map_settings['format'],
];
// 0,0 is the default behavior anyway, so just ignore it for fitlocations.
if (!empty($render_array['#centre']['lat']) || !empty($render_array['#centre']['lng'])) {
$additional_parameters['center'] = $render_array['#centre']['lat'] . ',' . $render_array['#centre']['lng'];
}
$static_map_url = $this
->getGoogleMapsApiUrl($additional_parameters);
$locations = GeolocationMap::getLocations($render_array);
foreach ($locations as $location) {
$marker_string = '&markers=';
if (!empty($location['#icon'])) {
$marker_string .= 'icon:' . Url::fromRoute('<front>', [], [
'absolute' => TRUE,
])
->toString() . $location['#icon'] . urlencode('|');
}
$marker_string .= $location['#position']['lat'] . ',' . $location['#position']['lng'];
$static_map_url .= $marker_string;
}
return [
'#markup' => '<img src="' . $static_map_url . '">',
];
}
}
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 | |
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 all module and custom defined parameters. | 1 |
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 map provider specific settings ready to handover to JS. Overrides MapProviderBase:: |
1 |
GoogleMapsProviderBase:: |
public | function |
Provide a summary array to use in field formatters. Overrides MapProviderBase:: |
|
GoogleStaticMaps:: |
public static | property |
Google maps url from PR China. Overrides GoogleMapsProviderBase:: |
|
GoogleStaticMaps:: |
public | function |
Alter render array. Overrides MapProviderBase:: |
|
GoogleStaticMaps:: |
public static | function |
Provide a populated settings array. Overrides GoogleMapsProviderBase:: |
|
GoogleStaticMaps:: |
public | function |
Provide a generic map settings form array. Overrides GoogleMapsProviderBase:: |
|
MapProviderBase:: |
protected | property | Map feature manager. | |
MapProviderBase:: |
public | function |
Alter common map build array. Overrides MapProviderInterface:: |
4 |
MapProviderBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
MapProviderBase:: |
public static | function |
Return available control positions. Overrides MapProviderInterface:: |
4 |
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. |