You are here

function openlayers_views_style_data::options_form in Openlayers 7.2

Same name and namespace in other branches
  1. 6.2 modules/openlayers_views/views/openlayers_views_style_data.inc \openlayers_views_style_data::options_form()

Options form

Overrides views_plugin_style->options_form

Overrides views_plugin_style::options_form

File

modules/openlayers_views/views/openlayers_views_style_data.inc, line 73
This file holds style plugin for OpenLayers Views

Class

openlayers_views_style_data
@class Extension of the Views Plugin Style for OpenLayers

Code

function options_form(&$form, &$form_state) {
  parent::options_form($form, $form_state);

  // Get list of fields in this view & flag available geodata fields
  $handlers = $this->display->handler
    ->get_handlers('field');

  // Check for any fields, as the view needs them
  if (empty($handlers)) {
    $form['error_markup'] = array(
      '#value' => t('You need to enable at least one field before you can ' . 'configure your field settings'),
      '#prefix' => '<div class="error form-item description">',
      '#suffix' => '</div>',
    );
    return;
  }
  $fields = array();
  foreach ($handlers as $field_id => $handler) {
    $fields[$field_id] = $handler
      ->ui_name() . ' (' . $field_id . ')';
  }
  $projections = array();
  foreach (openlayers_get_all_projections() as $projection) {
    $projections[$projection->identifier] = $projection
      ->getLocalizedMessage();
  }
  $form['data_source'] = array(
    '#type' => 'fieldset',
    '#tree' => TRUE,
    '#title' => t('Data Source'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['data_source']['value'] = array(
    '#type' => 'select',
    '#title' => t('Map Data Sources'),
    '#description' => t('Choose which sources of data that the map will ' . 'provide features for.'),
    '#options' => array(
      'other_latlon' => t('Lat/Lon Pair'),
      'other_boundingbox' => t('Bounding Box'),
      'wkt' => t('WKT'),
    ),
    '#default_value' => $this->options['data_source']['value'],
  );
  if (count($fields > 0)) {
    $form['data_source']['other_lat'] = array(
      '#type' => 'select',
      '#title' => t('Latitude Field'),
      '#description' => t('Choose a field for Latitude.  This should be a ' . 'field that is a decimal or float value.'),
      '#options' => $fields,
      '#default_value' => $this->options['data_source']['other_lat'],
      '#states' => $this
        ->datasource_dependent('other_latlon'),
    );
    $form['data_source']['other_lon'] = array(
      '#type' => 'select',
      '#title' => t('Longitude Field'),
      '#description' => t('Choose a field for Longitude.  This should be a ' . 'field that is a decimal or float value.'),
      '#options' => $fields,
      '#default_value' => $this->options['data_source']['other_lon'],
      '#states' => $this
        ->datasource_dependent('other_latlon'),
    );
    $form['data_source']['wkt'] = array(
      '#type' => 'select',
      '#title' => t('WKT Field'),
      '#description' => t('Choose the OpenLayers WKT field.'),
      '#options' => $fields,
      '#default_value' => $this->options['data_source']['wkt'],
      '#states' => $this
        ->datasource_dependent('wkt'),
    );
    $form['data_source']['projection'] = array(
      '#type' => 'select',
      '#title' => t('Projection'),
      '#description' => t('Choose the projection of the WKT field.'),
      '#options' => $projections,
      '#default_value' => $this->options['data_source']['projection'],
      '#states' => $this
        ->datasource_dependent('wkt'),
    );
    $form['data_source']['other_top'] = array(
      '#type' => 'select',
      '#title' => t('Top Field'),
      '#description' => t('Choose a field for Top.  This should be a ' . 'field that is a decimal or float value.'),
      '#options' => $fields,
      '#default_value' => $this->options['data_source']['other_top'],
      '#states' => $this
        ->datasource_dependent('other_boundingbox'),
    );
    $form['data_source']['other_right'] = array(
      '#type' => 'select',
      '#title' => t('Right Field'),
      '#description' => t('Choose a field for Right.  This should be a field ' . 'that is a decimal or float value.'),
      '#options' => $fields,
      '#default_value' => $this->options['data_source']['other_right'],
      '#states' => $this
        ->datasource_dependent('other_boundingbox'),
    );
    $form['data_source']['other_bottom'] = array(
      '#type' => 'select',
      '#title' => t('Bottom Field'),
      '#description' => t('Choose a field for Bottom.  This should be a ' . 'field that is a decimal or float value.'),
      '#options' => $fields,
      '#default_value' => $this->options['data_source']['other_bottom'],
      '#states' => $this
        ->datasource_dependent('other_boundingbox'),
    );
    $form['data_source']['other_left'] = array(
      '#type' => 'select',
      '#title' => t('Left Field'),
      '#description' => t('Choose a field for Left.  This should be a field ' . 'that is a decimal or float value.'),
      '#options' => $fields,
      '#default_value' => $this->options['data_source']['other_left'],
      '#states' => $this
        ->datasource_dependent('other_boundingbox'),
    );
  }
  $form['data_source']['name_field'] = array(
    '#type' => 'select',
    '#title' => t('Title Field'),
    '#description' => t('Choose the field which will appear as a title on ' . 'tooltips.'),
    '#options' => array_merge(array(
      '' => '',
    ), $fields),
    '#default_value' => $this->options['data_source']['name_field'],
  );
  $desc_options = array_merge(array(
    '' => '',
    '#row' => '<' . t('entire row') . '>',
  ), $fields);

  // Description field
  $form['data_source']['description_field'] = array(
    '#type' => 'select',
    '#title' => t('Description Content'),
    '#description' => t('Choose the field or rendering method which will
        appear as a description on tooltips or popups.'),
    '#required' => FALSE,
    '#options' => $desc_options,
    '#default_value' => $this->options['data_source']['description_field'],
  );

  // A simple way to display attributes and styling
  $form['attributes'] = array(
    '#type' => 'fieldset',
    '#title' => t('Attributes and Styling'),
    '#description' => t('Attributes are field data attached to each ' . 'feature.  This can be used with styling to create Variable styling.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $variable_fields = array();
  foreach ($this->view->display_handler
    ->get_handlers('field') as $field => $handler) {
    $variable_fields[$field] = '${' . $field . '}';
  }
  if (!empty($this->options['data_source']['name_field'])) {
    $variable_fields['name'] = '${name}';
  }
  if (!empty($this->options['data_source']['description_field'])) {
    $variable_fields['description'] = '${description}';
  }
  $form['attributes']['display'] = array(
    '#title' => 'Select attributes to include in the features',
    '#type' => 'checkboxes',
    '#options' => $variable_fields,
    '#default_value' => !empty($this->options['attributes']['display']) ? $this->options['attributes']['display'] : array_combine(array_keys($variable_fields), array_keys($variable_fields)),
    '#description' => t('Any fields that you select will be attached to ' . 'their respective feature (point, line, polygon) as attributes.  ' . 'These attributes can then be used to add variable styling to your ' . 'themes.  This is accomplished by using the %syntax syntax in the ' . 'values for a style.  You can see a list of available variables in ' . 'the view preview; these can be placed right in the style interface. ' . 'The field has been processed by Views.' . 'By disabling some of them, you can reduce the size ' . 'of the Javascript included in your pages.' . 'Please note that this does not apply to Grouped Displays.', array(
      '%syntax' => '${field_name}',
    )),
  );
}