You are here

class openlayers_layer_type in Openlayers 7.2

Same name and namespace in other branches
  1. 6.2 openlayers.module \openlayers_layer_type

We define base classes in the core module. All other parent classes can be autoloaded through ctools.

Hierarchy

Expanded class hierarchy of openlayers_layer_type

5 string references to 'openlayers_layer_type'
hook_openlayers_layer_types in docs/openlayers.api.php
OpenLayers Layer Types
openlayers_layer_type_image::options_form_submit in plugins/layer_types/openlayers_layer_type_image.inc
hook_submit() of the form.
openlayers_views_openlayers_views_image_openlayers_layer_types in modules/openlayers_views/plugins/layer_types/openlayers_views_image.inc
Ctools plugin definition
openlayers_views_openlayers_views_vector_openlayers_layer_types in modules/openlayers_views/plugins/layer_types/openlayers_views_vector.inc
Ctools plugin definition
_openlayers_openlayers_layer_types in includes/openlayers.layer_types.inc
Internal callback Helper function to return default layer types.

File

./openlayers.module, line 1256
Main OpenLayers API File

View source
class openlayers_layer_type {

  /**
   * Stores the options for this layer.
   * @var array
   */
  public $data = array();

  /**
   * Stores the current map.
   * @var array
   */
  public $map;

  /**
   * Set configuration and store map.
   *
   * @param stdClass $layer
   *   Configuration object with the options for the layer.
   * @param $map
   *   Array with the current map.
   */
  function __construct($layer = array(), $map = array()) {
    foreach (array(
      'name',
      'title',
      'description',
      'data',
      'export_type',
    ) as $k) {
      if (isset($layer->{$k})) {
        $this->{$k} = $layer->{$k};
      }
    }

    // Extend options with the defaults.
    $this->data += $this
      ->options_init();
    $this->map = $map;
  }

  /**
   * @return array<openlayers_projection>
   *   List of all projections that are supported by the layer.
   */
  public function getProjections() {
    $projections = array();

    // TODO Ignore incomplete data until cause is fixed (projection for every layer set during migration)
    if (isset($this->data['projection'])) {
      foreach ($this->data['projection'] as $projection) {
        $projections[] = openlayers_get_projection_by_identifier($projection);
      }
    }
    return $projections;
  }

  /**
   * Provides the default options for the layer.
   *
   * @return
   *   An associative array with the default options.
   */
  function options_init() {
    return array(
      'layer_type' => get_class($this),
      'isBaseLayer' => TRUE,
      // TODO: Remove hard-coded resolutions
      'projection' => array(
        'EPSG:900913',
      ),
      'serverResolutions' => openlayers_get_resolutions('EPSG:900913'),
      'resolutions' => openlayers_get_resolutions('EPSG:900913'),
      'base_url' => NULL,
      'transitionEffect' => 'resize',
      'weight' => 0,
    );
  }

  /**
   * Options form to configure layer instance options.
   *
   * @return
   *   Array with form elements.
   */
  function options_form($default = array()) {
    $allProjectionOptions = array();
    foreach (openlayers_get_all_projections() as $projection) {
      $allProjectionOptions[$projection->identifier] = $projection
        ->getLocalizedMessage();
    }
    return array(
      'projection' => array(
        '#type' => 'select',
        '#title' => t('Projection'),
        '#multiple' => TRUE,
        '#options' => $allProjectionOptions,
        '#default_value' => isset($default->data['projection']) ? $default->data['projection'] : openlayers_get_projection('EPSG', '3857')->identifier,
      ),
      'isBaseLayer' => array(
        '#type' => 'checkbox',
        '#title' => t('Base Layer'),
        '#description' => t('Uncheck to make this map an overlay'),
        '#default_value' => !empty($default->data['isBaseLayer']) ? $default->data['isBaseLayer'] : FALSE,
      ),
    );
  }

  /**
   * Validate the options_form().
   *
   * @param array $default
   */
  function options_form_validate($form, &$form_state) {
  }

  /**
   * Submit the options_form().
   *
   * @param array $form
   * @param array $form_state
   */
  function options_form_submit($form, &$form_state) {
    $form_state['values']['data']['projection'] = array_keys($form_state['values']['data']['projection']);

    // TODO Resolutions should be processed only in layers
    // that provide a form field for it.
    $form_state['values']['data']['resolutions'] = array_map('floatval', array_values($form_state['values']['data']['resolutions']));
  }

  /**
   * Options form to configure layer-type-wide options.
   *
   * @return
   *   Array with form elements.
   */
  function settings_form() {
    return array();
  }

  /**
   * Render the layer and return the layer options.
   *
   * Has no return value.
   *
   * @param $map
   */
  function render(&$map) {
  }

}

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 function Options form to configure layer instance options. 18
openlayers_layer_type::options_form_submit function Submit the options_form(). 6
openlayers_layer_type::options_form_validate function Validate the options_form(). 11
openlayers_layer_type::options_init function Provides the default options for the layer. 18
openlayers_layer_type::render function Render the layer and return the layer options. 18
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.