You are here

public function MarkerClusterer::alterMap in Geolocation Field 8.2

Same name and namespace in other branches
  1. 8.3 modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/MarkerClusterer.php \Drupal\geolocation_google_maps\Plugin\geolocation\MapFeature\MarkerClusterer::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/MarkerClusterer.php, line 131

Class

MarkerClusterer
Provides marker clusterer.

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);
  $feature_settings = $this
    ->getSettings($feature_settings);
  if (!empty($feature_settings['styles']) && is_string($feature_settings['styles'])) {
    $feature_settings['styles'] = json_decode($feature_settings['styles']);
  }
  $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,
              'imagePath' => $feature_settings['image_path'],
              'styles' => $feature_settings['styles'],
              'maxZoom' => (int) $feature_settings['max_zoom'],
              'gridSize' => (int) $feature_settings['grid_size'],
              'zoomOnClick' => (bool) $feature_settings['zoom_on_click'],
              'averageCenter' => (int) $feature_settings['average_center'],
              'minimumClusterSize' => (int) $feature_settings['minimum_cluster_size'],
            ],
          ],
        ],
      ],
    ],
  ]);
  return $render_array;
}