You are here

public function LeafletTileLayer::alterMap in Geolocation Field 8.2

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

Class

LeafletTileLayer
Provides map tile layer support.

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);
  $feature_settings = $this
    ->getSettings($feature_settings);
  $tileLayer = [
    'enable' => TRUE,
    'tileLayerProvider' => str_replace(' ', '.', $feature_settings['tile_layer_provider']),
  ];
  $provider = explode('.', $feature_settings['tile_layer_provider'])[0];
  if (isset($feature_settings['tile_provider_options'][$provider])) {
    $tileLayer['tileLayerOptions'] = $feature_settings['tile_provider_options'][$provider];
  }
  $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() => $tileLayer,
          ],
        ],
      ],
    ],
  ]);
  return $render_array;
}