You are here

class GoogleMaps in Geolocation Field 8.2

Same name and namespace in other branches
  1. 8.3 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

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\MapProvider
View source
class GoogleMaps extends GoogleMapsProviderBase {

  /**
   * Google map max zoom level.
   *
   * @var int
   */
  public static $MAXZOOMLEVEL = 18;

  /**
   * 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,
      'rotateControl' => FALSE,
      '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['rotateControl'] = (bool) $settings['rotateControl'];
    $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['control_settings'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Controls'),
    ];
    $form['rotateControl'] = [
      '#group' => $parents_string . 'control_settings',
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Rotate control'),
      '#description' => $this
        ->t('Show rotate control.'),
      '#default_value' => $settings['rotateControl'],
    ];
    $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 = []) {
    $map_settings = $this
      ->getSettings($map_settings);
    $render_array['#attached'] = BubbleableMetadata::mergeAttachments(empty($render_array['#attached']) ? [] : $render_array['#attached'], [
      'library' => [
        'geolocation_google_maps/googlemapsapi',
        'geolocation_google_maps/google',
      ],
      'drupalSettings' => [
        'geolocation' => [
          'maps' => [
            $render_array['#id'] => [
              'settings' => [
                'google_map_settings' => $map_settings,
              ],
            ],
          ],
        ],
      ],
    ]);
    $render_array = parent::alterRenderArray($render_array, $map_settings, $context);
    return $render_array;
  }

  /**
   * {@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

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
GoogleMaps::$GOOGLEMAPSAPIURLPATH public static property Google maps url from PR China. Overrides GoogleMapsProviderBase::$GOOGLEMAPSAPIURLPATH
GoogleMaps::$MAXZOOMLEVEL public static property Google map max zoom level.
GoogleMaps::$MINZOOMLEVEL public static property Google map min zoom level.
GoogleMaps::alterCommonMap public function Alter common map build array. Overrides MapProviderBase::alterCommonMap
GoogleMaps::alterRenderArray public function Alter render array. Overrides MapProviderBase::alterRenderArray
GoogleMaps::getControlPositions public static function Return available control positions. Overrides MapProviderBase::getControlPositions
GoogleMaps::getDefaultSettings public static function Provide a populated settings array. Overrides GoogleMapsProviderBase::getDefaultSettings
GoogleMaps::getGoogleMapsApiParameters public function Return all module and custom defined parameters. Overrides GoogleMapsProviderBase::getGoogleMapsApiParameters
GoogleMaps::getSettings public function Provide map provider specific settings ready to handover to JS. Overrides GoogleMapsProviderBase::getSettings
GoogleMaps::getSettingsForm public function Provide a generic map settings form array. Overrides GoogleMapsProviderBase::getSettingsForm
GoogleMapsProviderBase::$GOOGLEMAPSAPIURLBASE public static property Google maps url.
GoogleMapsProviderBase::$GOOGLEMAPSAPIURLBASECHINA public static property Google maps url from PR China.
GoogleMapsProviderBase::$HYBRID public static property Google map style - Hybrid.
GoogleMapsProviderBase::$ROADMAP public static property Google map style - Roadmap.
GoogleMapsProviderBase::$SATELLITE public static property Google map style - Satellite.
GoogleMapsProviderBase::$TERRAIN public static property Google map style - Terrain.
GoogleMapsProviderBase::getGoogleMapsApiUrl public function Return the fully build URL to load Google Maps API.
GoogleMapsProviderBase::getMapTypes private function An array of all available map types.
GoogleMapsProviderBase::getSettingsSummary public function Provide a summary array to use in field formatters. Overrides MapProviderBase::getSettingsSummary
MapProviderBase::$mapFeatureManager protected property Map feature manager.
MapProviderBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
MapProviderBase::validateMapFeatureForms public function Validate form.
MapProviderBase::__construct public function Constructs a new GeocoderBase object. Overrides PluginBase::__construct
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.