Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function preBuild(array &$build, \Drupal\openlayers\Types\ObjectInterface $context = NULL)
 {
     $map_id = $context->getId();
     $layers = $this->getOption('layers', array());
     $items = array();
     $map_layers = $context->getLayers();
     $element_type = $this->getOption('multiselect', FALSE) ? 'checkbox' : 'radio';
     // Only handle layers available in the map and configured in the control.
     // @TODO: use Form API (with form_process_* and stuff)
     $labels = $this->getOption('layer_labels', array());
     foreach ($map_layers as $i => $map_layer) {
         if (isset($layers[$map_layer->machine_name])) {
             $classes = array(drupal_html_class($map_layer->machine_name));
             $checked = '';
             if ($element_type == 'checkbox') {
                 if ($map_layer->getOption('visible', 1)) {
                     $checked = 'checked ';
                     $classes[] = 'active';
                 }
             }
             $label = check_plain($map_layer->name);
             if (isset($labels[$map_layer->machine_name])) {
                 $label = openlayers_i18n_string('openlayers:layerswitcher:' . $this->machine_name . ':' . $map_layer->machine_name . ':label', $labels[$map_layer->machine_name], array('sanitize' => TRUE));
             }
             $items[] = array('data' => '<label><input type="' . $element_type . '" name="layer" ' . $checked . 'value="' . $map_layer->machine_name . '">' . $label . '</label>', 'id' => drupal_html_id($map_id . '-' . $map_layer->machine_name), 'class' => $classes);
         }
     }
     $title = openlayers_i18n_string('openlayers:layerswitcher:' . $this->machine_name . ':title', $this->getOption('label', 'Layers'), array('sanitize' => TRUE));
     $layerswitcher = array('#theme' => 'item_list', '#type' => 'ul', '#title' => $title, '#items' => $items, '#attributes' => array('id' => drupal_html_id($this->machine_name . '-items')));
     $this->setOption('element', '<div id="' . drupal_html_id($this->machine_name) . '" class="' . drupal_html_class($this->machine_name) . ' layerswitcher">' . drupal_render($layerswitcher) . '</div>');
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function preBuild(array &$build, ObjectInterface $context = NULL)
 {
     $layers = $context->getObjects('layer');
     foreach ($layers as $layer) {
         if (!in_array($layer->getFactoryService(), array('openlayers.Layer:Vector', 'openlayers.Layer:Heatmap'))) {
             $layer->setOption('type', 'base');
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Array containing basic information about an OL Object.
  *
  * @param \Drupal\openlayers\Types\ObjectInterface $object
  * @return array
  */
 protected function getInfo(ObjectInterface $object)
 {
     $js = $object->getJS();
     $info = array('mn' => array('#type' => 'item', '#title' => 'Machine name:', '#markup' => $object->machine_name), 'fs' => array('#type' => 'item', '#title' => 'Factory service:', '#markup' => $object->factory_service));
     $plugin_description = $object->getPluginDescription();
     if (!empty($plugin_description)) {
         $info['pd'] = array('#type' => 'item', '#title' => 'Plugin description:', '#markup' => $plugin_description);
     }
     if (isset($js['opt'])) {
         $info['opt'] = array('#type' => 'item', '#title' => 'Options:', 'options' => array('#markup' => $this->toInfoArrayMarkup($js['opt'])));
     }
     return $info;
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function preBuild(array &$build, \Drupal\openlayers\Types\ObjectInterface $context = NULL)
 {
     $layers = $this->getOption('layers', array());
     $map_layers = $context->getLayers();
     // Only handle layers available in the map and configured in the control.
     // Ensures maximum performance on client side while having maximum
     // configuration flexibility.
     $frontend_layers = array();
     foreach ($map_layers as $map_layer) {
         if (isset($layers[$map_layer->machine_name])) {
             $frontend_layers[$map_layer->machine_name] = $map_layer->machine_name;
         }
     }
     $this->setOption('layers', $frontend_layers);
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function addObject(ObjectInterface $object)
 {
     $this->setOption($object->getType() . 's', $this->getOption($object->getType() . 's', array()) + array($object->getMachineName()));
     $object->setWeight(count($this->getOption($object->getType() . 's', array())) + 2);
     $this->getCollection()->import(array($object));
     return $this;
 }
 /**
  * Remove object from this collection.
  *
  * @param \Drupal\openlayers\Types\ObjectInterface $object
  *   Object instance to remove from this collection.
  */
 public function delete(ObjectInterface $object)
 {
     unset($this->objects[$object->getType() . '_' . $object->getMachineName()]);
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function preBuild(array &$build, ObjectInterface $context = NULL)
 {
     $layers = $context->getObjects('layer');
     foreach ($layers as $layer) {
         $layer->setOption('title', $layer->name);
     }
 }
Exemplo n.º 8
0
 /**
  * Save an object in the database.
  *
  * @param ObjectInterface $object
  *   The object to save.
  */
 public static function save(ObjectInterface $object)
 {
     ctools_include('export');
     $configuration = $object->getConfiguration();
     $export = $object->getExport();
     ctools_export_crud_save($configuration['table'], $export);
 }
 /**
  * {@inheritDoc}
  */
 public function postBuild(array &$build, ObjectInterface $context = NULL)
 {
     $build['openlayers']['map-container']['progress-bar'] = array('#type' => 'container', '#attributes' => array('id' => 'progress-' . $context->getId(), 'class' => array('openlayers-progressbar')));
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function postBuild(array &$build, ObjectInterface $context = NULL)
 {
     $component = array('#type' => 'container', '#attributes' => array('id' => 'openlayers-geofield-' . $context->getId()));
     $data_type = $this->getOption('dataType', array('WKT' => 'WKT'));
     if (count($data_type) > 1) {
         $component['dataType'] = array('#type' => 'select', '#title' => 'Data type', '#options' => array_intersect_key(array('WKT' => 'WKT', 'GeoJSON' => 'GeoJSON', 'KML' => 'KML', 'GPX' => 'GPX'), $data_type), '#attributes' => array('class' => array('data-type')), '#default_value' => $data_type);
     } else {
         $component['dataType'] = array('#type' => 'hidden', '#default_value' => reset($data_type), '#value' => reset($data_type), '#attributes' => array('class' => array('data-type')));
     }
     $geom = $this->initialDataToGeomFeatures();
     $wkt = '';
     if (!empty($geom['geom'])) {
         $wkt = $geom['geom']->out('wkt');
     }
     $component['data'] = array('#type' => $this->getOption('showInputField') ? 'textarea' : 'hidden', '#title' => 'Data', '#attributes' => array('class' => array('openlayers-geofield-data')), '#default_value' => $wkt, '#value' => $wkt);
     // Now add the component into the build array. This is a bit complex due
     // the fact that we want to support form nesting.
     $parents = array('geofield', 'component');
     $data_input_field_name = $this->getOption('inputFieldName');
     if (!empty($data_input_field_name)) {
         $data_input_field_name = preg_replace('/(^\\[|\\]$)/', '', $data_input_field_name);
         $levels = explode('][', $data_input_field_name);
         $parents = array_slice(explode('][', $data_input_field_name), 0, count($levels) - 1);
         // Ensure the requested name for the input data field is set.
         $component[end($levels)] = $component['data'];
         unset($component['data']);
     }
     if (!empty($parents)) {
         drupal_array_set_nested_value($build, $parents, $component);
     } else {
         $build += $component;
     }
 }
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function postBuild(array &$build, \Drupal\openlayers\Types\ObjectInterface $map = NULL)
 {
     $map_id = $map->getId();
     $gmap_id = 'gmap-' . $map_id;
     $build['gmap'] = array('#theme' => 'html_tag', '#tag' => 'div', '#value' => '', '#attributes' => array('id' => $gmap_id, 'class' => array('openlayers', 'gmap-map'), 'style' => 'height: 100%; width: 100%;'));
 }
Exemplo n.º 12
0
 /**
  * @inheritDoc
  */
 public function preBuild(array &$build, ObjectInterface $context = NULL)
 {
     $build['spinjs']['#attached']['js'][] = array('data' => array('spinjs' => array($context->getId() => $this->getOptions())), 'type' => 'setting');
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function postBuild(array &$build, \Drupal\openlayers\Types\ObjectInterface $context = NULL)
 {
     $component = array('#type' => 'fieldset', '#title' => 'Geofield component', '#attributes' => array('id' => 'geofield-' . $context->getId()));
     $action_feature = $type_of_feature = $this->getOption('actionFeature');
     if (count($action_feature) > 1) {
         $component['actionFeature'] = array('#type' => 'select', '#title' => 'Type of interaction', '#options' => array_intersect_key(array('draw' => t('Draw'), 'modify' => t('Modify')), $action_feature), '#attributes' => array('class' => array('action-feature')));
     } else {
         $component['actionFeature'] = array('#type' => 'hidden', '#default_value' => reset($action_feature), '#attributes' => array('class' => array('action-feature')));
     }
     $data_type = $this->getOption('dataType');
     if (count($data_type) > 1) {
         $component['dataType'] = array('#type' => 'select', '#title' => 'Data type', '#options' => array_intersect_key(array('GeoJSON' => 'GeoJSON', 'KML' => 'KML', 'GPX' => 'GPX', 'WKT' => 'WKT'), $data_type), '#attributes' => array('class' => array('data-type')));
     } else {
         $component['dataType'] = array('#type' => 'hidden', '#default_value' => reset($data_type), '#value' => reset($data_type), '#attributes' => array('class' => array('data-type')));
     }
     $type_of_feature = $this->getOption('typeOfFeature');
     if (count($type_of_feature) > 1) {
         $component['typeOfFeature'] = array('#type' => 'select', '#title' => 'Geometry type', '#options' => array_intersect_key(array('Point' => t('Point'), 'LineString' => t('LineString'), 'Polygon' => t('Polygon')), $type_of_feature), '#attributes' => array('id' => 'typeOfFeature', 'class' => array('type-of-feature')));
     } else {
         $component['typeOfFeature'] = array('#type' => 'hidden', '#default_value' => reset($type_of_feature), '#value' => reset($type_of_feature), '#attributes' => array('class' => array('type-of-feature')));
     }
     $component['clearmap'] = array('#markup' => '<a href="#" class="clearmap">' . t('Clear the map') . '</a>');
     $component['data'] = array('#type' => $this->getOption('showInputField') ? 'textarea' : 'hidden', '#title' => 'Data', '#attributes' => array('class' => array('openlayers-geofield-data')), '#default_value' => $this->getOption('initialData'), '#value' => $this->getOption('initialData'));
     // Now add the component into the build array. This is a bit complex due
     // the fact that we want to support form nesting.
     $build = array('map' => $build);
     $parents = array('geofield', 'component');
     $data_input_field_name = $this->getOption('inputFieldName');
     if (!empty($data_input_field_name)) {
         $data_input_field_name = preg_replace('/(^\\[|\\]$)/', '', $data_input_field_name);
         $levels = explode('][', $data_input_field_name);
         $parents = array_slice(explode('][', $data_input_field_name), 0, count($levels) - 1);
         // Ensure the requested name for the input data field is set.
         $component[end($levels)] = $component['data'];
         unset($component['data']);
     }
     if (!empty($parents)) {
         drupal_array_set_nested_value($build, $parents, $component);
     } else {
         $build += $component;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function postBuild(array &$build, \Drupal\openlayers\Types\ObjectInterface $map = NULL)
 {
     $build['openlayers']['map-container']['gmap'] = array('#type' => 'container', '#attributes' => array('id' => 'gmap-' . $map->getId(), 'class' => array('openlayers', 'gmap-map'), 'style' => $build['openlayers']['map-container']['#attributes']['style']));
 }
Exemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function preBuild(array &$build, ObjectInterface $context = NULL)
 {
     /** @var LayerInterface $layer */
     foreach ($context->getObjects('layer') as $layer) {
         $layer->setOption('title', $layer->getName());
     }
 }
Exemplo n.º 16
0
 /**
  * Add object to this collection.
  *
  * @param ObjectInterface $object
  *   Object instance to add to this collection.
  */
 public function prepend(ObjectInterface $object)
 {
     $this->objects = array_merge(array($object->getType() . '_' . $object->getMachineName() => $object), $this->objects);
 }