You are here

public function LeafletMarkerClusterer::alterMap in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 modules/geolocation_leaflet/src/Plugin/geolocation/MapFeature/LeafletMarkerClusterer.php \Drupal\geolocation_leaflet\Plugin\geolocation\MapFeature\LeafletMarkerClusterer::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_leaflet/src/Plugin/geolocation/MapFeature/LeafletMarkerClusterer.php, line 76

Class

LeafletMarkerClusterer
Provides marker clusterer.

Namespace

Drupal\geolocation_leaflet\Plugin\geolocation\MapFeature

Code

public function alterMap(array $render_array, array $feature_settings, array $context = []) {
  $render_array = parent::alterMap($render_array, $feature_settings, $context);
  $cluster_settings = NULL;
  if (isset($feature_settings['cluster_settings'])) {
    $cluster_settings = $feature_settings['cluster_settings'];
  }
  $render_array['#attached'] = BubbleableMetadata::mergeAttachments(empty($render_array['#attached']) ? [] : $render_array['#attached'], [
    'library' => [
      'geolocation_leaflet/mapfeature.' . $this
        ->getPluginId(),
    ],
    'drupalSettings' => [
      'geolocation' => [
        'maps' => [
          $render_array['#id'] => [
            $this
              ->getPluginId() => [
              'enable' => TRUE,
              'showCoverageOnHover' => $cluster_settings['show_coverage_on_hover'],
              'zoomToBoundsOnClick' => $cluster_settings['zoom_to_bounds_on_click'],
              'disableClusteringAtZoom' => (int) $feature_settings['disable_clustering_at_zoom'],
              'customMarkerSettings' => Json::decode($feature_settings['custom_marker_settings']),
            ],
          ],
        ],
      ],
    ],
  ]);
  return $render_array;
}