You are here

class openlayers_layer_type_wms in Openlayers 7.2

Same name and namespace in other branches
  1. 6.2 includes/layer_types/wms.inc \openlayers_layer_type_wms

OpenLayers WMS Layer Type class

Hierarchy

Expanded class hierarchy of openlayers_layer_type_wms

1 string reference to 'openlayers_layer_type_wms'
_openlayers_openlayers_layers in includes/openlayers.layers.inc
Internal callback Helper function to return default layers.

File

plugins/layer_types/openlayers_layer_type_wms.inc, line 10
WMS Layer Type

View source
class openlayers_layer_type_wms extends openlayers_layer_type {

  /**
   * Provide initial values for options.
   */
  function options_init() {
    $options = array(
      'layer_handler' => 'wms',
    ) + parent::options_init();

    // Discard hard-codes resolution because the client can calculate them usually
    unset($options['serverResolutions']);
    unset($options['maxExtent']);
    unset($options['resolutions']);
    return $options;
  }

  /**
   * Options form which generates layers
   */
  function options_form($defaults = array()) {
    if (isset($this->data['base_url'])) {
      $base_url = is_array($this->data['base_url']) ? implode("\r\n", $this->data['base_url']) : $this->data['base_url'];
    }
    else {
      $base_url = '';
    }
    return array(
      'base_url' => array(
        '#type' => 'textarea',
        '#title' => t('Base URL'),
        '#default_value' => $base_url,
        '#description' => t('Add one url per line'),
      ),
      // TODO: swap terms
      'params' => array(
        // TODO: validate the field, only positive integers shall be allowed
        'buffer' => array(
          '#type' => 'textfield',
          '#default_value' => isset($this->data['params']['buffer']) ? $this->data['params']['buffer'] : 2,
          '#title' => t('Buffer'),
          '#description' => t('Used only when not in single-tile mode, this specifies umber of extra rows and colums of tiles on each side which will surround the minimum grid tiles to cover the map'),
        ),
        // TODO: validate the field, only positive numbers shall be allowed
        //       numbers below 1 might also not make much sense
        'ratio' => array(
          '#type' => 'textfield',
          '#default_value' => isset($this->data['params']['ratio']) ? $this->data['params']['ratio'] : 1.5,
          '#title' => t('Ratio'),
          '#description' => t('Used only when in single-tile mode, this specifies the ratio of the size of the single tile to the size of the map'),
        ),
        'singleTile' => array(
          '#type' => 'checkbox',
          '#default_value' => isset($this->data['params']['singleTile']) ? $this->data['params']['singleTile'] : FALSE,
          '#title' => t('Single tile'),
          '#description' => t('Check to make this layer untiled'),
        ),
        'opacity' => array(
          '#type' => 'textfield',
          '#default_value' => isset($this->data['params']['opacity']) ? $this->data['params']['opacity'] : 1,
          '#title' => t('Opacity'),
          '#description' => t('Opacity of the layer'),
        ),
      ),
      'options' => array(
        'TRANSPARENT' => array(
          '#type' => 'checkbox',
          '#default_value' => isset($this->data['options']['TRANSPARENT']) ? $this->data['options']['TRANSPARENT'] : FALSE,
          '#return_value' => 'true',
          '#title' => t('Transparent'),
          '#description' => t('When a PNG, make the background color transparent'),
        ),
        'exceptions' => array(
          '#type' => 'select',
          '#title' => t('Exceptions'),
          '#options' => array(
            'application/vnd.ogc.se_xml' => 'application/vnd.ogc.se_xml',
            'application/vnd.ogc.se_inimage' => 'application/vnd.ogc.se_inimage',
          ),
          '#default_value' => isset($this->data['options']['exceptions']) ? $this->data['options']['exceptions'] : 'application/vnd.ogc.se_inimage',
          '#description' => t('Select the exception handler'),
        ),
        'format' => array(
          '#type' => 'select',
          '#title' => t('File Format'),
          '#options' => array(
            'image/png' => 'image/png',
            'image/gif' => 'image/gif',
            'image/jpeg' => 'image/jpeg',
          ),
          '#default_value' => isset($this->data['options']['format']) ? $this->data['options']['format'] : 'image/png',
        ),
        'layers' => array(
          '#type' => 'textarea',
          '#title' => t('Layers'),
          // TODO: Should be required to be non-empty as not having a layer leads to invalid requests
          '#default_value' => !empty($this->data['options']['layers']) ? implode("\r\n", $this->data['options']['layers']) : '',
          '#description' => t('Specifies which layers to show. One per line.'),
        ),
        'styles' => array(
          '#type' => 'textfield',
          '#title' => t('Styles'),
          '#default_value' => isset($this->data['options']['styles']) ? $this->data['options']['styles'] : '',
        ),
      ),
    );
  }

  /**
   * hook_validate()
   */
  function options_form_validate($form, &$form_state) {
    $form_state['data']['options']['layers'] = explode("\r\n", $form_state['data']['options']['layers']);
    $form_state['data']['base_url'] = explode("\r\n", $form_state['data']['base_url']);
  }

  /**
   * Render.
   */
  function render(&$map) {
    drupal_add_js(drupal_get_path('module', 'openlayers') . '/plugins/layer_types/openlayers_layer_type_wms.js');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
openlayers_layer_type::$data public property Stores the options for this layer.
openlayers_layer_type::$map public property Stores the current map.
openlayers_layer_type::getProjections public function
openlayers_layer_type::options_form_submit function Submit the options_form(). 6
openlayers_layer_type::settings_form function Options form to configure layer-type-wide options. 3
openlayers_layer_type::__construct function Set configuration and store map.
openlayers_layer_type_wms::options_form function Options form which generates layers Overrides openlayers_layer_type::options_form
openlayers_layer_type_wms::options_form_validate function hook_validate() Overrides openlayers_layer_type::options_form_validate
openlayers_layer_type_wms::options_init function Provide initial values for options. Overrides openlayers_layer_type::options_init
openlayers_layer_type_wms::render function Render. Overrides openlayers_layer_type::render