openlayers-8.x-4.x-dev/src/Plugin/Interaction/Snap/Snap.php
src/Plugin/Interaction/Snap/Snap.php
<?php
namespace Drupal\openlayers\Plugin\Interaction\Snap;
use Drupal\Core\Form\FormStateInterface;
use Drupal\openlayers\Openlayers;
use Drupal\openlayers\Types\Interaction;
/**
* FIX - Insert short comment here.
*
* @OpenlayersPlugin(
* id = "ol_interaction_snap",
* label = @Translation("Snap"),
* description = @Translation("TODO..."),
* service = "openlayers.Interaction:Snap",
* library = "openlayers-plugin-interaction-snap",
* is_configurable = "true",
* type = "interaction"
* )
*/
class Snap extends Interaction {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['options']['pixelTolerance'] = array(
'#type' => 'textfield',
'#title' => 'Pixel tolerance',
'#description' => 'Pixel tolerance for considering the pointer close enough to a segment or vertex for editing. Default is 10 pixels.',
'#default_value' => $this->getOption('pixelTolerance', 10),
);
$form['options']['source'] = array(
'#type' => 'select',
'#title' => t('Source'),
'#empty_option' => t('- Select a Source -'),
'#default_value' => $this->getOption('source', ''),
'#description' => t('Select the vector source.'),
'#options' => Openlayers::loadAllAsOptions('Source'),
'#required' => TRUE,
);
return $form;
}
/**
* {@inheritdoc}
*/
public function optionsToObjects() {
$import = parent::optionsToObjects();
if ($source = $this->getOption('source')) {
$source = Openlayers::load('source', $source);
// This source is a dependency of the current one,
// we need a lighter weight.
$this->setWeight($source->getWeight() + 1);
$import = array_merge($source->getCollection()->getFlatList(), $import);
}
return $import;
}
}
