class Group in Openlayers 7.3
Class Group.
Plugin annotation
@OpenlayersPlugin(
id = "Group"
)
Hierarchy
- class \Drupal\openlayers\Types\Base extends \Drupal\Component\Plugin\PluginBase implements ObjectInterface
- class \Drupal\openlayers\Types\Layer implements LayerInterface
- class \Drupal\openlayers\Plugin\Layer\Group\Group
- class \Drupal\openlayers\Types\Layer implements LayerInterface
Expanded class hierarchy of Group
File
- src/
Plugin/ Layer/ Group/ Group.php, line 20 - Layer: Heatmap.
Namespace
Drupal\openlayers\Plugin\Layer\GroupView source
class Group extends Layer {
/**
* {@inheritdoc}
*/
public function optionsForm(array &$form, array &$form_state) {
$form['options']['grouptitle'] = array(
'#type' => 'textfield',
'#title' => 'Layer group title',
'#default_value' => $this
->getOption('grouptitle', 'Base layers'),
);
/** @var LayerInterface[] $all_layers */
$all_layers = Openlayers::loadAll('Layer');
array_walk($all_layers, function ($object) {
$object
->setWeight(0);
$object->enabled = 0;
});
foreach ($this
->getOption('grouplayers', array()) as $weight => $layer) {
$layer = Openlayers::load('layer', $layer);
$all_layers[$layer
->getMachineName()]
->setWeight($weight);
$all_layers[$layer
->getMachineName()]->enabled = 1;
}
uasort($all_layers, function ($a, $b) {
if ($a->enabled > $b->enabled) {
return -1;
}
elseif ($a->enabled < $b->enabled) {
return 1;
}
if ($a
->getWeight() < $b
->getWeight()) {
return -1;
}
elseif ($a
->getWeight() > $b
->getWeight()) {
return 1;
}
if ($a
->getMachineName() < $b
->getMachineName()) {
return -1;
}
elseif ($a
->getMachineName() > $b
->getMachineName()) {
return 1;
}
return 0;
});
$data = array();
$i = 0;
/** @var \Drupal\openlayers\Types\Layer $layer */
foreach ($all_layers as $layer) {
$data[$layer
->getMachineName()] = array(
'name' => $layer
->getName(),
'machine_name' => $layer
->getMachineName(),
'factory_service' => $layer
->getFactoryService(),
'weight' => $i++,
'enabled' => isset($layer->enabled) ? $layer->enabled : 0,
);
}
$rows = array();
$row_elements = array();
foreach ($data as $id => $entry) {
$rows[$id] = array(
'data' => array(
array(
'class',
array(
'entry-cross',
),
),
array(
'data' => array(
'#type' => 'weight',
'#title' => t('Weight'),
'#title_display' => 'invisible',
'#default_value' => $entry['weight'],
'#parents' => array(
'grouplayers',
$id,
'weight',
),
'#attributes' => array(
'class' => array(
'entry-order-weight',
),
),
),
),
array(
'data' => array(
'#type' => 'hidden',
'#default_value' => $entry['machine_name'],
'#parents' => array(
'grouplayers',
$id,
'machine_name',
),
),
),
array(
'data' => array(
'#type' => 'checkbox',
'#title' => t('Enable'),
'#title_display' => 'invisible',
'#default_value' => $entry['enabled'],
'#parents' => array(
'grouplayers',
$id,
'enabled',
),
),
),
check_plain($entry['name']),
check_plain($entry['machine_name']),
check_plain($entry['factory_service']),
l(t('Edit'), 'admin/structure/openlayers/layers/list/' . $entry['machine_name'] . '/edit/options', array(
'query' => array(
'destination' => current_path(),
),
)),
),
'class' => array(
'draggable',
),
);
// Build rows of the form elements in the table.
$row_elements[$id] = array(
'weight' => &$rows[$id]['data'][1]['data'],
'enabled' => &$rows[$id]['data'][2]['data'],
'machine_name' => &$rows[$id]['data'][3]['data'],
);
}
$form['grouplayers'] = array(
'#type' => 'fieldset',
'#title' => 'Layers',
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
// Add the table to the form.
$form['grouplayers']['table_layers'] = array(
'#theme' => 'table',
// The row form elements need to be processed and build,
// therefore pass them as element children.
'elements' => $row_elements,
'#header' => array(
// We need two empty columns for the weigth field and the cross.
array(
'data' => NULL,
'colspan' => 2,
),
array(
'data' => t('Enabled'),
'colspan' => 2,
),
t('Name'),
t('Machine name'),
t('Factory service'),
t('Operations'),
),
'#rows' => $rows,
'#empty' => t('There are no entries available.'),
'#attributes' => array(
'id' => 'entry-order-layers',
),
);
drupal_add_tabledrag('entry-order-layers', 'order', 'sibling', 'entry-order-weight');
}
/**
* {@inheritdoc}
*/
public function optionsFormSubmit(array $form, array &$form_state) {
$layers_enabled = array_filter($form_state['values']['grouplayers'], function ($item) {
return (bool) $item['enabled'];
});
uasort($layers_enabled, function ($a, $b) {
return $a['weight'] - $b['weight'];
});
$this
->setOption('grouplayers', array_keys($layers_enabled));
$form_state['item'] = $this
->getExport();
}
/**
* {@inheritdoc}
*/
public function optionsToObjects() {
$import = array();
foreach ($this
->getOption('grouplayers', array()) as $weight => $object) {
if ($merge_object = Openlayers::load('layer', $object)) {
$merge_object
->setWeight($this
->getWeight() - 1);
$import[] = $merge_object;
}
}
return $import;
}
/**
* {@inheritdoc}
*/
public function preBuild(array &$build, ObjectInterface $context = NULL) {
/** @var LayerInterface $layer */
foreach ($context
->getObjects('layer') as $layer) {
$layer
->setOption('title', $layer
->getName());
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Base:: |
protected | property | Holds all the attachment used by this object. | 6 |
Base:: |
protected | property | Holds the Collection object. | |
Base:: |
protected | property | A unique ID for the object. | |
Base:: |
public | function |
Add an object into the collection of the parent object. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Returns a list of attachments for building the render array. Overrides ObjectInterface:: |
6 |
Base:: |
public | function |
Remove an option. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Defines dependencies. Overrides ObjectInterface:: |
3 |
Base:: |
public | function |
Returns the path to the plugin directory. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Returns the path to the class file. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Return the Collection object linked to the object. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Return the object configuration. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Return all the dependencies objects of the parent object. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Return the description of the object. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Return an object, CTools Exportable. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Return the Factory Service of the object. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Return the object unique ID. Overrides ObjectInterface:: |
|
Base:: |
public | function |
!Attention! This function will remove any option that is named after a
plugin type e.g.: layers, controls, styles, interactions, components . Overrides ObjectInterface:: |
6 |
Base:: |
public | function |
Return the unique machine name of the object. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Return the human name of the object. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Return an array of OL objects indexed by their type. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Returns an option. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Return the options array. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Returns an array with the maps this object is attached on. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Return the description of the object's plugin. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Return the module that provides this plugin. Overrides ObjectInterface:: |
|
Base:: |
public | function |
The type of this object. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Get the weight of an object. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Refresh string translations. Overrides ObjectInterface:: |
1 |
Base:: |
public | function |
Initializes the object. Overrides ObjectInterface:: |
2 |
Base:: |
public | function |
Initializes the Collection,
Import objects from options,
Import the current object. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Whether or not this object has to be processed asynchronously. Overrides ObjectInterface:: |
3 |
Base:: |
public | function |
Validation callback for the options form. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Invoked after an objects render array is built. Overrides ObjectInterface:: |
13 |
Base:: |
public | function |
Remove an object from the collection. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Reset the object's Collection. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Set the Factory Service of the object. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Set the object ID. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Set an option. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Set the options array. Overrides ObjectInterface:: |
|
Base:: |
public | function |
Set the weight of an object. Overrides ObjectInterface:: |
|
Group:: |
public | function |
@TODO What is this return? If it is the form, why is form by reference? Overrides Base:: |
|
Group:: |
public | function |
Submit callback for the options form. Overrides Base:: |
|
Group:: |
public | function |
Return a flat array containing Openlayers Objects from the options array. Overrides Layer:: |
|
Group:: |
public | function |
Invoked before an objects render array is built. Overrides Base:: |
|
Layer:: |
protected | property |
The array containing the options. Overrides Base:: |
|
Layer:: |
public | function |
Return the opacity of the layer (between 0 and 1). Overrides LayerInterface:: |
|
Layer:: |
public | function |
Returns the source of this layer. Overrides LayerInterface:: |
|
Layer:: |
public | function |
Returns the style of this layer. Overrides LayerInterface:: |
|
Layer:: |
public | function |
Return the visibility of the layer. Overrides LayerInterface:: |
|
Layer:: |
public | function |
Return the Z-index of the layer. Overrides LayerInterface:: |
|
Layer:: |
public | function |
Set the opacity of the layer. Overrides LayerInterface:: |
|
Layer:: |
public | function |
Set the source of this layer. Overrides LayerInterface:: |
|
Layer:: |
public | function |
Set the style of this layer. Overrides LayerInterface:: |
|
Layer:: |
public | function |
Set the visibility of the layer. Overrides LayerInterface:: |
|
Layer:: |
public | function |
Set Z-index of the layer, which is used to order layers before rendering. Overrides LayerInterface:: |