You are here

public function GeolocationShapes::alterMap in Geolocation Field 8.3

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

src/Plugin/geolocation/MapFeature/GeolocationShapes.php, line 164

Class

GeolocationShapes
Redraw locations as shapes.

Namespace

Drupal\geolocation\Plugin\geolocation\MapFeature

Code

public function alterMap(array $render_array, array $feature_settings, array $context = []) {
  $render_array = parent::alterMap($render_array, $feature_settings, $context);
  if (empty($render_array['#children']['locations'])) {
    return $render_array;
  }
  $coordinates = [];
  foreach ($render_array['#children']['locations'] as $location) {
    if (empty($location['#coordinates'])) {
      continue;
    }
    $coordinates[] = $location['#coordinates'];
  }
  if ($feature_settings['remove_markers']) {
    unset($render_array['#children']['locations']);
  }
  if ($feature_settings['polyline']) {
    $render_array['#children']['polyline'] = [
      '#type' => 'geolocation_map_polyline',
      '#coordinates' => $coordinates,
      '#title' => \Drupal::token()
        ->replace($feature_settings['polyline_title'], $context),
      '#stroke_color' => $feature_settings['strokeColor'],
      '#stroke_width' => $feature_settings['strokeWidth'],
      '#stroke_opacity' => $feature_settings['strokeOpacity'],
    ];
  }
  if ($feature_settings['polygon']) {
    $render_array['#children']['polygon'] = [
      '#type' => 'geolocation_map_polygon',
      '#coordinates' => $coordinates,
      '#title' => \Drupal::token()
        ->replace($feature_settings['polygon_title'], $context),
      '#stroke_color' => $feature_settings['strokeColor'],
      '#stroke_width' => $feature_settings['strokeWidth'],
      '#stroke_opacity' => $feature_settings['strokeOpacity'],
      '#fill_color' => $feature_settings['fillColor'],
      '#fill_opacity' => $feature_settings['fillOpacity'],
    ];
  }
  return $render_array;
}