You are here

public function Leaflet::render in Leaflet 8

Same name and namespace in other branches
  1. 2.1.x modules/leaflet_views/src/Plugin/views/style/Leaflet.php \Drupal\leaflet_views\Plugin\views\style\Leaflet::render()
  2. 2.0.x modules/leaflet_views/src/Plugin/views/style/Leaflet.php \Drupal\leaflet_views\Plugin\views\style\Leaflet::render()

Render the display in this style.

Overrides StylePluginBase::render

File

modules/leaflet_views/src/Plugin/views/style/Leaflet.php, line 193

Class

Leaflet
Style plugin to render a View output as a Leaflet map.

Namespace

Drupal\leaflet_views\Plugin\views\style

Code

public function render() {
  $features = [];
  foreach ($this->view->attachment_before as $id => $attachment) {
    if (!empty($attachment['#leaflet-attachment'])) {
      $features = array_merge($features, $attachment['rows']);
      $this->view->element['#attached'] = NestedArray::mergeDeep($this->view->element['#attached'], $attachment['#attached']);
      unset($this->view->attachment_before[$id]);
    }
  }
  $map_info = leaflet_map_get_info($this->options['map']);

  // Enable layer control by default, if we have more than one feature group.
  if (self::hasFeatureGroups($features)) {
    $map_info['settings'] += [
      'layerControl' => TRUE,
    ];
  }
  $element = $this->leafletService
    ->leafletRenderMap($map_info, $features, $this->options['height'] . 'px');

  // Merge #attached libraries.
  $this->view->element['#attached'] = NestedArray::mergeDeep($this->view->element['#attached'], $element['#attached']);
  $element['#attached'] =& $this->view->element['#attached'];
  return $element;
}