You are here

abstract class Map in Openlayers 7.3

Class Map.

Hierarchy

Expanded class hierarchy of Map

1 file declares its use of Map
OLMap.php in src/Plugin/Map/OLMap/OLMap.php
Map: Map.
31 string references to 'Map'
Base::getParents in src/Types/Base.php
Returns an array with the maps this object is attached on.
MapSwitcher::postBuild in modules/openlayers_library/src/Plugin/Component/MapSwitcher/MapSwitcher.php
Invoked after an objects render array is built.
OLMap::optionsForm in src/Plugin/Map/OLMap/OLMap.php
@TODO What is this return? If it is the form, why is form by reference?
openlayers.services.yml in ./openlayers.services.yml
openlayers.services.yml
openlayers::options_form in modules/openlayers_boxes/plugins/boxes/openlayers.php
Provide options to configure content.

... See full list

File

src/Types/Map.php, line 14
Class Map.

Namespace

Drupal\openlayers\Types
View source
abstract class Map extends Base implements MapInterface {

  /**
   * {@inheritdoc}
   *
   * @return MapInterface
   *   The Map object.
   */
  public function addLayer(LayerInterface $layer) {
    return $this
      ->addObject($layer);
  }

  /**
   * {@inheritdoc}
   *
   * @return MapInterface
   *   The Map object.
   */
  public function addControl(ControlInterface $control) {
    return $this
      ->addObject($control);
  }

  /**
   * {@inheritdoc}
   *
   * @return MapInterface
   *   The Map object.
   */
  public function addInteraction(InteractionInterface $interaction) {
    return $this
      ->addObject($interaction);
  }

  /**
   * {@inheritdoc}
   *
   * @return MapInterface
   *   The Map object.
   */
  public function addComponent(ComponentInterface $component) {
    return $this
      ->addObject($component);
  }

  /**
   * {@inheritdoc}
   *
   * @return MapInterface
   *   The Map object.
   */
  public function removeLayer($layer_id) {
    return $this
      ->removeObject($layer_id);
  }

  /**
   * {@inheritdoc}
   *
   * @return MapInterface
   *   The Map object.
   */
  public function removeComponent($component_id) {
    return $this
      ->removeObject($component_id);
  }

  /**
   * {@inheritdoc}
   *
   * @return MapInterface
   *   The Map object.
   */
  public function removeControl($control_id) {
    return $this
      ->removeObject($control_id);
  }

  /**
   * {@inheritdoc}
   *
   * @return MapInterface
   *   The Map object.
   */
  public function removeInteraction($interaction_id) {
    return $this
      ->removeObject($interaction_id);
  }

  /**
   * {@inheritdoc}
   */
  public function attached() {
    $attached = parent::attached();
    $settings = $this
      ->getCollection()
      ->getJS();
    $settings['map'] = array_shift($settings['map']);
    $attached['js'][] = array(
      'data' => array(
        'openlayers' => array(
          'maps' => array(
            $this
              ->getId() => $settings,
          ),
        ),
      ),
      'type' => 'setting',
    );
    return $attached;
  }

  /**
   * {@inheritdoc}
   */
  public function getJS() {
    $js = parent::getJS();
    unset($js['opt']['capabilities']);
    return $js;
  }

  /**
   * {@inheritdoc}
   */
  public function render() {
    $build = $this
      ->build();
    return drupal_render($build);
  }

  /**
   * {@inheritdoc}
   */
  public function build(array $build = array()) {
    $map = $this;

    // If this is an asynchronous map flag it as such.
    if ($asynchronous = $this
      ->isAsynchronous()) {
      $map
        ->setOption('async', $asynchronous);
    }
    if (!$map
      ->getOption('target', FALSE)) {
      $this
        ->setOption('target', $this
        ->getId());
    }

    // Transform the options into objects.
    $map
      ->getCollection()
      ->import($map
      ->optionsToObjects());

    // Run prebuild hook to all objects who implements it.
    $map
      ->preBuild($build, $map);
    $capabilities = array();
    if ((bool) $this
      ->getOption('capabilities', FALSE) === TRUE) {
      $items = array_values($this
        ->getOption(array(
        'capabilities',
        'options',
        'table',
      ), array()));
      array_walk($items, 'check_plain');
      $capabilities = array(
        '#weight' => 1,
        '#type' => $this
          ->getOption(array(
          'capabilities',
          'options',
          'container_type',
        ), 'fieldset'),
        '#collapsed' => TRUE,
        '#collapsible' => TRUE,
        '#attached' => array(
          'library' => array(
            array(
              'system',
              'drupal.collapse',
            ),
          ),
        ),
        /*
                '#attributes' => array(
                  'class' => array(
                    $this->getOption(array(
                      'capabilities',
                      'options',
                      'collapsible',
                    ), TRUE) ? 'collapsible' : '',
                    $this->getOption(array(
                      'capabilities',
                      'options',
                      'collapsed',
                    ), TRUE) ? 'collapsed' : '',
                  ),
                ),
        */
        '#title' => $this
          ->getOption(array(
          'capabilities',
          'options',
          'title',
        ), NULL),
        '#description' => $this
          ->getOption(array(
          'capabilities',
          'options',
          'description',
        ), NULL),
        array(
          '#theme' => 'item_list',
          '#items' => $items,
          '#title' => '',
          '#type' => 'ul',
        ),
      );
    }
    $build = array(
      '#theme' => 'openlayers',
      '#map' => $map,
      '#attached' => $map
        ->getCollection()
        ->getAttached(),
      'map_prefix' => array(),
      'map_suffix' => array(),
      'capabilities' => $capabilities,
    );
    $map
      ->postBuild($build, $map);
    return $build;
  }

  /**
   * {@inheritdoc}
   */
  public function optionsToObjects() {
    $import = array();

    // TODO: Simplify this.
    // Add the objects from the configuration.
    foreach (Openlayers::getPluginTypes(array(
      'map',
    )) as $weight_type => $type) {
      foreach ($this
        ->getOption($type . 's', array()) as $weight => $object) {
        if (!$this
          ->getCollection()
          ->getObjectById($type, $object)) {
          if ($merge_object = Openlayers::load($type, $object)) {
            $merge_object
              ->setWeight($weight_type . '.' . $weight);
            $import[$type . '_' . $merge_object
              ->getMachineName()] = $merge_object;
          }
        }
      }
    }
    foreach ($this
      ->getCollection()
      ->getFlatList() as $object) {
      $import[$object
        ->getType() . '_' . $object
        ->getMachineName()] = $object;
    }
    return $import;
  }

  /**
   * {@inheritdoc}
   */
  public function setSize(array $size = array()) {
    list($width, $height) = array_values($size);
    return $this
      ->setOption('width', $width)
      ->setOption('height', $height);
  }

  /**
   * {@inheritdoc}
   */
  public function getSize() {
    return array(
      $this
        ->getOption('width'),
      $this
        ->getOption('height'),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function setTarget($target) {
    return $this
      ->setOption('target', $target);
  }

  /**
   * {@inheritdoc}
   */
  public function getTarget() {
    return $this
      ->getOption('target');
  }

  /**
   * {@inheritdoc}
   */
  public function isAsynchronous() {
    return array_reduce($this
      ->getDependencies(), function ($res, $obj) {
      return $res + (int) $obj
        ->isAsynchronous();
    }, 0);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Base::$attached protected property Holds all the attachment used by this object. 6
Base::$collection protected property Holds the Collection object.
Base::$id protected property A unique ID for the object.
Base::$options protected property The array containing the options. 6
Base::addObject public function Add an object into the collection of the parent object. Overrides ObjectInterface::addObject
Base::clearOption public function Remove an option. Overrides ObjectInterface::clearOption
Base::dependencies public function Defines dependencies. Overrides ObjectInterface::dependencies 3
Base::getClassDirectory public function Returns the path to the plugin directory. Overrides ObjectInterface::getClassDirectory
Base::getClassPath public function Returns the path to the class file. Overrides ObjectInterface::getClassPath
Base::getCollection public function Return the Collection object linked to the object. Overrides ObjectInterface::getCollection
Base::getConfiguration public function Return the object configuration. Overrides ObjectInterface::getConfiguration
Base::getDependencies public function Return all the dependencies objects of the parent object. Overrides ObjectInterface::getDependencies
Base::getDescription public function Return the description of the object. Overrides ObjectInterface::getDescription
Base::getExport public function Return an object, CTools Exportable. Overrides ObjectInterface::getExport
Base::getFactoryService public function Return the Factory Service of the object. Overrides ObjectInterface::getFactoryService
Base::getId public function Return the object unique ID. Overrides ObjectInterface::getId
Base::getMachineName public function Return the unique machine name of the object. Overrides ObjectInterface::getMachineName
Base::getName public function Return the human name of the object. Overrides ObjectInterface::getName
Base::getObjects public function Return an array of OL objects indexed by their type. Overrides ObjectInterface::getObjects
Base::getOption public function Returns an option. Overrides ObjectInterface::getOption
Base::getOptions public function Return the options array. Overrides ObjectInterface::getOptions
Base::getParents public function Returns an array with the maps this object is attached on. Overrides ObjectInterface::getParents
Base::getPluginDescription public function Return the description of the object's plugin. Overrides ObjectInterface::getPluginDescription
Base::getProvider public function Return the module that provides this plugin. Overrides ObjectInterface::getProvider
Base::getType public function The type of this object. Overrides ObjectInterface::getType
Base::getWeight public function Get the weight of an object. Overrides ObjectInterface::getWeight
Base::i18nStringsRefresh public function Refresh string translations. Overrides ObjectInterface::i18nStringsRefresh 1
Base::init public function Initializes the object. Overrides ObjectInterface::init 2
Base::initCollection public function Initializes the Collection, Import objects from options, Import the current object. Overrides ObjectInterface::initCollection
Base::optionsForm public function @TODO What is this return? If it is the form, why is form by reference? Overrides ObjectInterface::optionsForm 54
Base::optionsFormSubmit public function Submit callback for the options form. Overrides ObjectInterface::optionsFormSubmit 11
Base::optionsFormValidate public function Validation callback for the options form. Overrides ObjectInterface::optionsFormValidate
Base::postBuild public function Invoked after an objects render array is built. Overrides ObjectInterface::postBuild 13
Base::preBuild public function Invoked before an objects render array is built. Overrides ObjectInterface::preBuild 4
Base::removeObject public function Remove an object from the collection. Overrides ObjectInterface::removeObject
Base::resetCollection public function Reset the object's Collection. Overrides ObjectInterface::resetCollection
Base::setFactoryService public function Set the Factory Service of the object. Overrides ObjectInterface::setFactoryService
Base::setId public function Set the object ID. Overrides ObjectInterface::setId
Base::setOption public function Set an option. Overrides ObjectInterface::setOption
Base::setOptions public function Set the options array. Overrides ObjectInterface::setOptions
Base::setWeight public function Set the weight of an object. Overrides ObjectInterface::setWeight
Map::addComponent public function Overrides MapInterface::addComponent
Map::addControl public function Overrides MapInterface::addControl
Map::addInteraction public function Overrides MapInterface::addInteraction
Map::addLayer public function Overrides MapInterface::addLayer
Map::attached public function Returns a list of attachments for building the render array. Overrides Base::attached 1
Map::build public function Build render array of a map. Overrides MapInterface::build
Map::getJS public function !Attention! This function will remove any option that is named after a plugin type e.g.: layers, controls, styles, interactions, components . Overrides Base::getJS
Map::getSize public function Return the size of the map. Overrides MapInterface::getSize
Map::getTarget public function Get the target ID in which this map is rendered. Overrides MapInterface::getTarget
Map::isAsynchronous public function Whether or not this object has to be processed asynchronously. Overrides Base::isAsynchronous
Map::optionsToObjects public function Return a flat array containing Openlayers Objects from the options array. Overrides Base::optionsToObjects
Map::removeComponent public function Overrides MapInterface::removeComponent
Map::removeControl public function Overrides MapInterface::removeControl
Map::removeInteraction public function Overrides MapInterface::removeInteraction
Map::removeLayer public function Overrides MapInterface::removeLayer
Map::render public function Render a build array into HTML. Overrides MapInterface::render
Map::setSize public function Set the size of the map. Overrides MapInterface::setSize
Map::setTarget public function Set the target element to render this map into. Overrides MapInterface::setTarget