You are here

class Spiderfying in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/Spiderfying.php \Drupal\geolocation_google_maps\Plugin\geolocation\MapFeature\Spiderfying

Provides Spiderfying.

Plugin annotation


@MapFeature(
  id = "spiderfying",
  name = @Translation("Spiderfying"),
  description = @Translation("Split up overlapping markers on click."),
  type = "google_maps",
)

Hierarchy

Expanded class hierarchy of Spiderfying

1 string reference to 'Spiderfying'
geolocation_google_maps.map_features.schema.yml in modules/geolocation_google_maps/config/schema/geolocation_google_maps.map_features.schema.yml
modules/geolocation_google_maps/config/schema/geolocation_google_maps.map_features.schema.yml

File

modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/Spiderfying.php, line 18

Namespace

Drupal\geolocation_google_maps\Plugin\geolocation\MapFeature
View source
class Spiderfying extends MapFeatureBase {

  /**
   * {@inheritdoc}
   */
  public static function getDefaultSettings() {
    return [
      'spiderfiable_marker_path' => base_path() . drupal_get_path('module', 'geolocation_google_maps') . '/images/marker-plus.svg',
      'markersWontMove' => TRUE,
      'markersWontHide' => FALSE,
      'keepSpiderfied' => TRUE,
      'ignoreMapClick' => FALSE,
      'nearbyDistance' => 20,
      'circleSpiralSwitchover' => 9,
      'circleFootSeparation' => 23,
      'spiralFootSeparation' => 26,
      'spiralLengthStart' => 11,
      'spiralLengthFactor' => 4,
      'legWeight' => 1.5,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getSettingsForm(array $settings, array $parents) {
    $form['spiderfiable_marker_path'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Marker Path'),
      '#description' => $this
        ->t('Set relative or absolute path to the image to be displayed while markers are spiderfiable. Tokens supported.'),
      '#default_value' => $settings['spiderfiable_marker_path'],
    ];
    $form['markersWontMove'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t("Markers won't move"),
      '#description' => $this
        ->t('If you know that you won’t be moving any of the markers you add to this instance, you can save memory by setting this to true.'),
      '#default_value' => $settings['markersWontMove'],
    ];
    $form['markersWontHide'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t("Markers won't hide"),
      '#description' => $this
        ->t('If you know that you won’t be hiding any of the markers you add to this instance, you can save memory by setting this to true.'),
      '#default_value' => $settings['markersWontHide'],
    ];
    $form['keepSpiderfied'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Keep spiderfied'),
      '#description' => $this
        ->t('By default, the OverlappingMarkerSpiderfier works like Google Earth, in that when you click a spiderfied marker, the markers unspiderfy before any other action takes place. Setting this to true overrides this behavior.'),
      '#default_value' => $settings['keepSpiderfied'],
    ];
    $form['ignoreMapClick'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Ignore map click'),
      '#description' => $this
        ->t('By default, clicking an empty spot on the map causes spiderfied markers to unspiderfy. Setting this option to true suppresses that behavior.'),
      '#default_value' => $settings['ignoreMapClick'],
    ];
    $form['nearbyDistance'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Nearby distance'),
      '#description' => $this
        ->t('This is the pixel radius within which a marker is considered to be overlapping a clicked marker.'),
      '#default_value' => $settings['nearbyDistance'],
    ];
    $form['circleSpiralSwitchover'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Circle spiral switchover'),
      '#description' => $this
        ->t('This is the lowest number of markers that will be fanned out into a spiral instead of a circle.'),
      '#default_value' => $settings['circleSpiralSwitchover'],
    ];
    $form['circleFootSeparation'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Circle foot separation'),
      '#description' => $this
        ->t('Determines the positioning of markers when spiderfied out into a circle.'),
      '#default_value' => $settings['circleFootSeparation'],
    ];
    $form['spiralFootSeparation'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Spiral Foot Separation'),
      '#description' => $this
        ->t('Determines the positioning of markers when spiderfied out into a spiral.'),
      '#default_value' => $settings['spiralFootSeparation'],
    ];
    $form['spiralLengthStart'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Spiral length start'),
      '#default_value' => $settings['spiralLengthStart'],
    ];
    $form['spiralLengthFactor'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Spiral length factor'),
      '#default_value' => $settings['spiralLengthFactor'],
    ];
    $form['legWeight'] = [
      '#type' => 'number',
      '#step' => '.1',
      '#title' => $this
        ->t('Leg weight'),
      '#description' => $this
        ->t('This determines the thickness of the lines joining spiderfied markers to their original locations.'),
      '#default_value' => $settings['legWeight'],
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function alterMap(array $render_array, array $feature_settings, array $context = []) {
    $render_array = parent::alterMap($render_array, $feature_settings, $context);
    $render_array['#attached'] = BubbleableMetadata::mergeAttachments(empty($render_array['#attached']) ? [] : $render_array['#attached'], [
      'library' => [
        'geolocation_google_maps/mapfeature.' . $this
          ->getPluginId(),
      ],
      'drupalSettings' => [
        'geolocation' => [
          'maps' => [
            $render_array['#id'] => [
              $this
                ->getPluginId() => [
                'enable' => TRUE,
                'spiderfiable_marker_path' => $feature_settings['spiderfiable_marker_path'],
                'markersWontMove' => $feature_settings['markersWontMove'],
                'markersWontHide' => $feature_settings['markersWontHide'],
                'keepSpiderfied' => $feature_settings['keepSpiderfied'],
                'ignoreMapClick' => $feature_settings['ignoreMapClick'],
                'nearbyDistance' => $feature_settings['nearbyDistance'],
                'circleSpiralSwitchover' => $feature_settings['circleSpiralSwitchover'],
                'circleFootSeparation' => $feature_settings['circleFootSeparation'],
                'spiralFootSeparation' => $feature_settings['spiralFootSeparation'],
                'spiralLengthStart' => $feature_settings['spiralLengthStart'],
                'spiralLengthFactor' => $feature_settings['spiralLengthFactor'],
                'legWeight' => $feature_settings['legWeight'],
              ],
            ],
          ],
        ],
      ],
    ]);
    if (!empty($feature_settings['spiderfiable_marker_path'])) {
      $path = \Drupal::token()
        ->replace($feature_settings['spiderfiable_marker_path'], $context);
      $render_array['#attached']['drupalSettings']['geolocation']['maps'][$render_array['#id']]['spiderfying']['spiderfiable_marker_path'] = $path;
    }
    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
MapFeatureBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 2
MapFeatureBase::getSettings public function Provide map feature specific settings ready to handover to JS. Overrides MapFeatureInterface::getSettings
MapFeatureBase::getSettingsSummary public function Provide a summary array to use in field formatters. Overrides MapFeatureInterface::getSettingsSummary 2
MapFeatureBase::validateSettingsForm public function Validate Feature Form. Overrides MapFeatureInterface::validateSettingsForm 5
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.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92
Spiderfying::alterMap public function Alter render array. Overrides MapFeatureBase::alterMap
Spiderfying::getDefaultSettings public static function Provide a populated settings array. Overrides MapFeatureBase::getDefaultSettings
Spiderfying::getSettingsForm public function Provide a generic map settings form array. Overrides MapFeatureBase::getSettingsForm
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.