How to get fields in StylePluginBase i´m building a new nap view style. I get the map shown correctly, but only without the data of the view :-(.

class OpenlayersViews extends StylePluginBase {
  /**
   * Whether the display allows the use of a pager or not.
   *
   * @var bool
   */
  protected $usesPager = FALSE;

  /**
   * Whether the display allows the use of a 'more' link or not.
   *
   * @var bool
   */
  protected $usesMore = FALSE;

  /**
   * Whether the display allows area plugins.
   *
   * @var bool
   */
  protected $usesAreas = FALSE;

  /**
   * Does the style plugin support grouping of rows.
   */
  protected $usesGrouping = FALSE;

  /**
   * Does the style plugin for itself support to add fields to it's output.
   */
  protected $usesFields = TRUE;


  /**
   * {@inheritdoc}
   */
  public function evenEmpty() {
    // Render map even if there is no data.
    return TRUE;
  }

  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['openlayers_map'] = array('default' =&gt; 'none selected');
    return $options;
  }

   /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&amp;$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    $openlayers_map_options = [];
    foreach (openlayers_get_map() as $key =&gt; $map) {
      $openlayers_map_options[$key] = $this-&gt;t($map['label']);
    }

    $form['openlayers_map'] = [
      '#title' =&gt; $this-&gt;t('OpenLayers Map'),
      '#type' =&gt; 'select',
      '#options' =&gt; $openlayers_map_options,
      '#default_value' =&gt; $this-&gt;options['openlayers_map'],
      '#required' =&gt; TRUE,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function render() {
    dsm("OpenlayersViews:render");
    $map = openlayers_get_map($this-&gt;options['openlayers_map']);
    $mapid = Html::getUniqueId('openlayers_map');
    $features = array();

    /*
     * Here i need a function to get the result of the view
     */

    $element = openlayers_render_map($mapid, $map, $features, FALSE);
    return $element;
  }  
}


I do not know, if render is the right position for getting the data.
So maybe some of you can explain, what is the next step to do.

best regards
Normally you would iterate through the rows and call a row plugin to render the field values. As I understand the question you want to access the field values directly by row index and field id?

Then try StylePluginBase::getFieldValue:

$value = $this-&gt;getFieldValue($index, $field);




Normally a style plugin iterates the rows like this:

  public function render() {
    if (empty($this-&gt;view-&gt;rowPlugin)) {
      trigger_error('Missing row plugin', E_WARNING);
      return [];
    }
    $rows = [];

    foreach ($this-&gt;view-&gt;result as $row_index =&gt; $row) {
      $this-&gt;view-&gt;row_index = $row_index;
      $rows[] = $this-&gt;view-&gt;rowPlugin-&gt;render($row);
    }
    ...


For this to work you have to set protected $usesRowPlugin = TRUE; and configure a row plugin which renders the map.



If you want to do all rendering in the style plugin you can use the same loop and get the field values directly:

  public function render() {
    $rows = [];
    foreach ($this-&gt;view-&gt;result as $index =&gt; $row) {
      $rows[] = render_map(
        $this-&gt;getFieldValue($index, 'field1'),
        $this-&gt;getFieldValue($index, 'field2')
      );
    }
    ...