You are here

ScaleLine.php in Openlayers 8.4

File

src/Plugin/OpenlayersControl/ScaleLine.php
View source
<?php

namespace Drupal\openlayers\Plugin\OpenlayersControl;

use Drupal\Component\Utility\Color;
use Drupal\Component\Utility\Rectangle;
use Drupal\Core\Form\FormStateInterface;
use Drupal\openlayers\OpenlayersConfigurablePluginBase;

/**
 * Defines the Scale Line control for an Openlayers map.
 *
 * @OpenlayersControl(
 *   id = "ol_control_scaleline",
 *   label = @Translation("Scale line"),
 *   description = @Translation("Define a scale line control."),
 *   type = "control",
 *   ol_id = "ScaleLine"
 * )
 */
class ScaleLine extends OpenlayersConfigurablePluginBase {

  /**
   * {@inheritdoc}
   */
  public function getSummary() {
    $summary = [
      '#theme' => 'openlayers_control_summary',
      //  TODO - ???
      '#data' => $this->configuration,
    ];
    $summary += parent::getSummary();
    return $summary;
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'className' => 'ol-scale-line',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['className'] = [
      '#type' => 'textfield',
      '#default_value' => $this->configuration['className'],
      '#title' => t('Class name'),
      '#description' => t('CSS class name.'),
      '#size' => 50,
      '#maxlength' => 50,
      '#required' => FALSE,
    ];
    $form['collapsible'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Collapsible'),
      '#description' => t('Specify if attributions can be collapsed.'),
    );
    $form['collapsed'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Collapsed'),
      '#description' => t('Specify if attributions should be collapsed at startup.'),
    );
    $form['tipLabel'] = [
      '#type' => 'textfield',
      '#title' => t('Tip label'),
      '#description' => t('Text label to use for the button tip.'),
      //      '#default_value' => $this->configuration['tipLabel'],
      '#size' => 100,
      '#maxlength' => 100,
      '#required' => FALSE,
    ];
    $form['label'] = [
      '#type' => 'textfield',
      //      '#default_value' => $this->configuration['label'],
      '#title' => t('Label'),
      '#description' => t('Text label to use for the collapsed attributions button.'),
      '#size' => 100,
      '#maxlength' => 100,
      '#required' => FALSE,
    ];
    $form['collapseLabel'] = [
      '#type' => 'textfield',
      //      '#default_value' => $this->configuration['collapseLabel'],
      '#title' => t('Collapse label'),
      '#description' => t('Text label to use for the expanded attributions button.'),
      '#size' => 100,
      '#maxlength' => 100,
      '#required' => FALSE,
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {

    /*
        if (!$form_state->isValueEmpty('color') && !Color::validateHex($form_state->getValue('color'))) {
          $form_state->setErrorByName('color', $this->t('Color must be a hexadecimal color value.'));
        }
    */
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    parent::submitConfigurationForm($form, $form_state);
    $this->configuration['className'] = $form_state
      ->getValue('className');

    /*
        $this->configuration['collapsible'] = $form_state->getValue('collapsible');
        $this->configuration['collapsed'] = $form_state->getValue('collapsed');
        $this->configuration['tipLabel'] = $form_state->getValue('tipLabel');
        $this->configuration['label'] = $form_state->getValue('label');
        $this->configuration['collapseLabel'] = $form_state->getValue('collapseLabel');
    */
  }

}

Classes

Namesort descending Description
ScaleLine Defines the Scale Line control for an Openlayers map.