You are here

public function Spiderfying::alterMap 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::alterMap()

Alter render array.

Parameters

array $render_array: Render array.

array $feature_settings: The current feature settings.

array $context: Context like field formatter, field widget or view.

Return value

array Render array.

Overrides MapFeatureBase::alterMap

File

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

Class

Spiderfying
Provides Spiderfying.

Namespace

Drupal\geolocation_google_maps\Plugin\geolocation\MapFeature

Code

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;
}