/**
  * @inheritdoc
  */
 public function optionsForm($delta, $qt)
 {
     $tab = $this->settings;
     $form = array();
     $form['Openlayers-map']['map'] = array('#type' => 'select', '#title' => t('Openlayers map'), '#options' => \Drupal\openlayers\Openlayers::loadAllAsOptions('Map'), "#empty_option" => t('- Select a map -'), '#default_value' => isset($tab['openlayers_map']) ? $tab['openlayers_map'] : '');
     return $form;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function options_form(&$form_state)
 {
     $form = array();
     // Map objects.
     $form['map'] = array('#type' => 'select', '#title' => t('Openlayers map'), '#description' => t('Map to display.'), '#options' => \Drupal\openlayers\Openlayers::loadAllAsOptions('Map'), "#empty_option" => t('- Select a Map -'), '#default_value' => $this->options['map'] ? $this->options['map'] : variable_get('openlayers_default_map', 'default'));
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function optionsForm(&$form, &$form_state)
 {
     $form['options']['layers'] = array('#type' => 'select', '#title' => t('Layers'), '#empty_option' => t('- Select a Layer -'), '#default_value' => isset($form_state['item']->options['layers']) ? $form_state['item']->options['layers'] : '', '#description' => t('Select the layers.'), '#options' => \Drupal\openlayers\Openlayers::loadAllAsOptions('Layer'), '#required' => TRUE, '#multiple' => TRUE);
     $form['options']['positioning'] = array('#type' => 'select', '#title' => t('Positioning'), '#default_value' => isset($form_state['item']->options['positioning']) ? $form_state['item']->options['positioning'] : 'top-left', '#description' => t('Defines how the overlay is actually positioned. Default is top-left.'), '#options' => openlayers_positioning_options(), '#required' => TRUE);
     $form['options']['autoPan'] = array('#type' => 'checkbox', '#title' => t('Autopan'), '#description' => t('If set to true the map is panned when calling setPosition, so that the overlay is entirely visible in the current viewport. The default is false.'), '#default_value' => $this->getOption('autoPan', FALSE));
     $form['options']['autoPanAnimation'] = array('#type' => 'textfield', '#title' => t('Autopan animation duration'), '#default_value' => $this->getOption('autoPanAnimation', 1000), '#description' => t('The options used to create a ol.animation.pan animation. This animation is only used when autoPan is enabled. By default the default options for ol.animation.pan are used. If set to zero the panning is not animated. The duration of the animation is in milliseconds. Default is 1000.'));
     $form['options']['autoPanMargin'] = array('#type' => 'textfield', '#title' => t('Autopan Animation'), '#default_value' => $this->getOption('autoPanMargin', 20), '#description' => t('The margin (in pixels) between the overlay and the borders of the map when autopanning. The default is 20.'));
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 public function optionsToObjects()
 {
     $import = parent::optionsToObjects();
     if ($layer = $this->getOption('layer')) {
         $layer = Openlayers::load('layer', $layer);
         $import = array_merge($layer->getCollection()->getFlatList(), $import);
     }
     return $import;
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function optionsToObjects()
 {
     $import = parent::optionsToObjects();
     if ($select = $this->getOption('select')) {
         $select = Openlayers::load('interaction', $select);
         $import = array_merge($select->getCollection()->getFlatList(), $import);
     }
     return $import;
 }
 /**
  * {@inheritdoc}
  */
 public function optionsForm(&$form, &$form_state)
 {
     $form['options']['source'] = array('#type' => 'select', '#title' => t('Source'), '#empty_option' => t('- Select a Source -'), '#default_value' => isset($form_state['item']->options['source']) ? $form_state['item']->options['source'] : '', '#description' => t('Select the source.'), '#options' => \Drupal\openlayers\Openlayers::loadAllAsOptions('Source'), '#required' => TRUE);
     $form['options']['zoom'] = array('#type' => 'textfield', '#title' => t('Zoom'), '#default_value' => isset($form_state['item']->options['zoom']) ? $form_state['item']->options['zoom'] : 10, '#description' => t('Integer or <em>auto</em>.'), '#required' => TRUE);
     $form['options']['enableAnimations'] = array('#type' => 'checkbox', '#title' => t('Enable animations'), '#default_value' => isset($form_state['item']->options['enableAnimations']) ? $form_state['item']->options['enableAnimations'] : FALSE, '#description' => t('Enable pan and zoom animation.'));
     $form['options']['animations'] = array('#type' => 'fieldset', '#title' => 'Animations options', '#states' => array('visible' => array('input[name="options[enableAnimations]"' => array('checked' => TRUE))));
     $form['options']['animations']['pan'] = array('#type' => 'textfield', '#title' => t('Pan animation duration'), '#default_value' => isset($form_state['item']->options['animations']['pan']) ? $form_state['item']->options['animations']['pan'] : '500', '#description' => t('Duration of the pan animation.'));
     $form['options']['animations']['zoom'] = array('#type' => 'textfield', '#title' => t('Zoom animation duration'), '#default_value' => isset($form_state['item']->options['animations']['zoom']) ? $form_state['item']->options['animations']['zoom'] : '500', '#description' => t('Duration of the zoom animation.'));
     $form['options']['positioning'] = array('#type' => 'select', '#title' => t('Positioning'), '#default_value' => isset($form_state['item']->options['positioning']) ? $form_state['item']->options['positioning'] : 'top-left', '#description' => t('Defines how the overlay is actually positioned. Default is top-left.'), '#options' => openlayers_positioning_options(), '#required' => TRUE);
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function optionsToObjects()
 {
     $import = parent::optionsToObjects();
     if ($style = $this->getOption('style')) {
         $import = array_merge($import, Openlayers::load('style', $style)->getCollection()->getFlatList());
     }
     if ($source = $this->getOption('source')) {
         $import = array_merge($import, Openlayers::load('source', $source)->getCollection()->getFlatList());
     }
     return $import;
 }
 /**
  * {@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;
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function optionsForm(&$form, &$form_state)
 {
     $form['options']['source'] = array('#type' => 'select', '#title' => t('Source'), '#empty_option' => t('- Select a Source -'), '#default_value' => isset($form_state['item']->options['source']) ? $form_state['item']->options['source'] : '', '#description' => t('Select the source.'), '#options' => \Drupal\openlayers\Openlayers::loadAllAsOptions('Source'), '#required' => TRUE, '#multiple' => TRUE);
     $form['options']['zoom'] = array('#type' => 'textfield', '#title' => t('Zoom'), '#default_value' => isset($form_state['item']->options['zoom']) ? $form_state['item']->options['zoom'] : 10, '#description' => t('Integer or <em>auto</em> or <em>disabled</em>.'), '#required' => TRUE);
     $form['options']['max_zoom'] = array('#type' => 'textfield', '#title' => t('Max Zoom'), '#default_value' => isset($form_state['item']->options['max_zoom']) ? $form_state['item']->options['max_zoom'] : 0, '#description' => t('Define the max zoom for the autozoom. Disabled when <em>0</em>.'), '#states' => array('visible' => array('input[name="options[zoom]"' => array('value' => 'auto'))));
     $form['options']['process_once'] = array('#type' => 'checkbox', '#title' => t('Zoom just on map build'), '#default_value' => !empty($form_state['item']->options['process_once']), '#description' => t('If enabled the zoom to source only will fire once at map build. And ignore change events on the source.'));
     $form['options']['enableAnimations'] = array('#type' => 'checkbox', '#title' => t('Enable animations'), '#default_value' => isset($form_state['item']->options['enableAnimations']) ? $form_state['item']->options['enableAnimations'] : FALSE, '#description' => t('Enable pan and zoom animation.'));
     $form['options']['animations'] = array('#type' => 'fieldset', '#title' => 'Animations options', '#states' => array('visible' => array('input[name="options[enableAnimations]"' => array('checked' => TRUE))));
     $form['options']['animations']['pan'] = array('#type' => 'textfield', '#title' => t('Pan animation duration'), '#default_value' => isset($form_state['item']->options['animations']['pan']) ? $form_state['item']->options['animations']['pan'] : '500', '#description' => t('Duration of the pan animation.'));
     $form['options']['animations']['zoom'] = array('#type' => 'textfield', '#title' => t('Zoom animation duration'), '#default_value' => isset($form_state['item']->options['animations']['zoom']) ? $form_state['item']->options['animations']['zoom'] : '500', '#description' => t('Duration of the zoom animation.'));
 }
Example #10
0
 /**
  * Build a row based on the item.
  *
  * By default all of the rows are placed into a table by the render
  * method, so this is building up a row suitable for theme('table').
  * This doesn't have to be true if you override both.
  */
 public function list_build_row($item, &$form_state, $operations)
 {
     // Set up sorting.
     $name = $item->{$this->plugin['export']['key']};
     $schema = ctools_export_get_schema($this->plugin['schema']);
     list($plugin_manager, $plugin_id) = explode(':', $item->factory_service);
     list($module, $plugin_type) = explode('.', $plugin_manager);
     $object = \Drupal\openlayers\Openlayers::load($plugin_type, $item->machine_name);
     // Note: $item->{$schema['export']['export type string']} should have
     // already been set up by export.inc so we can use it safely.
     switch ($form_state['values']['order']) {
         case 'disabled':
             $this->sorts[$name] = empty($item->disabled) . $name;
             break;
         case 'title':
             $this->sorts[$name] = $item->{$this->plugin['export']['admin_title']};
             break;
         case 'name':
             $this->sorts[$name] = $name;
             break;
         case 'class':
             $this->sorts[$name] = $name;
             break;
         case 'storage':
             $this->sorts[$name] = $item->{$schema['export']['export type string']} . $name;
             break;
     }
     // Generate a map and use the style on it to make a preview.
     $map = Openlayers::load('map', 'openlayers_ui_map_style_demo');
     foreach ($map->getCollection()->getFlatList(array('layer')) as $layer) {
         $layer->setStyle($object);
         $map->getCollection()->import(array($layer));
     }
     $map_build = $map->build();
     $map_render = drupal_render($map_build);
     $this->rows[$name]['data'] = array();
     $this->rows[$name]['class'] = !empty($item->disabled) ? array('ctools-export-ui-disabled') : array('ctools-export-ui-enabled');
     $this->rows[$name]['data'][] = array('data' => $map_render, 'class' => array('ctools-export-ui-title'));
     // If we have an admin title, make it the first row.
     if (!empty($this->plugin['export']['admin_title'])) {
         $this->rows[$name]['data'][] = array('data' => check_plain($item->{$this->plugin['export']['admin_title']}), 'class' => array('ctools-export-ui-title'));
     }
     $this->rows[$name]['data'][] = array('data' => check_plain($name), 'class' => array('ctools-export-ui-name'));
     $this->rows[$name]['data'][] = array('data' => check_plain($item->factory_service), 'class' => array('ctools-export-ui-service'));
     $this->rows[$name]['data'][] = array('data' => check_plain($item->{$schema['export']['export type string']}), 'class' => array('ctools-export-ui-storage'));
     $ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
     $this->rows[$name]['data'][] = array('data' => $ops, 'class' => array('ctools-export-ui-operations'));
     // Add an automatic mouseover of the description if one exists.
     if (!empty($this->plugin['export']['admin_description'])) {
         $this->rows[$name]['title'] = $item->{$this->plugin['export']['admin_description']};
     }
 }
Example #11
0
 /**
  * {@inheritdoc}
  */
 public function optionsFormSubmit($form, &$form_state)
 {
     parent::optionsFormSubmit($form, $form_state);
     $options = $this->getOptions();
     foreach (Openlayers::getGeometryTypes() as $geometry_type => $geometry) {
         if ((bool) $options[$geometry_type]['enabled'] === FALSE) {
             unset($options[$geometry_type]);
         }
     }
     $this->setOptions($options);
     $form_state['values']['options'] = $options;
     parent::optionsFormSubmit($form, $form_state);
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function optionsToObjects()
 {
     $import = parent::optionsToObjects();
     foreach (array('style', 'source') as $option) {
         if ($option_value = $this->getOption($option, FALSE)) {
             if ($object = $this->getCollection()->getObjectById($option, $option_value)) {
                 $import = array_merge($import, $object->getCollection()->getFlatList());
             } else {
                 $import = array_merge($import, Openlayers::load($option, $option_value)->getCollection()->getFlatList());
             }
         }
     }
     return $import;
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 public function optionsToObjects()
 {
     $import = parent::optionsToObjects();
     foreach ($this->getOptions() as $geometry_type => $data) {
         if ($styles = $this->getOption(array($geometry_type, 'styles'), array())) {
             foreach ($styles as $style) {
                 $style = Openlayers::load('style', $style);
                 // This source is a dependency of the current one,
                 // we need a lighter weight.
                 $this->setWeight($style->getWeight() + 1);
                 $import = array_merge($style->getCollection()->getFlatList(), $import);
             }
         }
     }
     return $import;
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function postBuild(array &$build, ObjectInterface $context = NULL)
 {
     parent::postBuild($build, $context);
     $options = array();
     foreach (\Drupal\openlayers\Openlayers::loadAllExportable('Map') as $machine_name => $data) {
         if (!is_object($data) || property_exists($data, 'disabled') && ($data->disabled == 1 || $data->disabled == TRUE)) {
             continue;
         }
         $options[$machine_name] = $data->name;
     }
     $wrapper = 'wrapper-' . $context->getId();
     $build['openlayers_default_map'] = array('#type' => 'select', '#title' => 'Chose a map', '#multiple' => FALSE, '#options' => $options, '#ajax' => array('callback' => '_openlayers_ajax_reload_default_map', 'method' => 'replace', 'wrapper' => $wrapper, 'effect' => 'fade'));
     $build['form'] = array('#type' => 'container', '#attributes' => array('id' => $wrapper));
     $build['form'][$context->getId()]['map'] = $build['openlayers'];
     unset($build['openlayers']);
 }
 /**
  * Build a row based on the item.
  *
  * By default all of the rows are placed into a table by the render
  * method, so this is building up a row suitable for theme('table').
  * This doesn't have to be true if you override both.
  */
 public function list_build_row($item, &$form_state, $operations)
 {
     // Set up sorting.
     $name = $item->{$this->plugin['export']['key']};
     $schema = ctools_export_get_schema($this->plugin['schema']);
     list($plugin_manager, $plugin_id) = explode(':', $item->factory_service);
     list($module, $plugin_type) = explode('.', $plugin_manager);
     $count_parents = 0;
     if ($object = \Drupal\openlayers\Openlayers::load($plugin_type, $item->machine_name)) {
         $count_parents = count($object->getParents());
     }
     // Note: $item->{$schema['export']['export type string']} should have
     // already been set up by export.inc so we can use it safely.
     switch ($form_state['values']['order']) {
         case 'disabled':
             $this->sorts[$name] = empty($item->disabled) . $name;
             break;
         case 'title':
             $this->sorts[$name] = $item->{$this->plugin['export']['admin_title']};
             break;
         case 'name':
             $this->sorts[$name] = $name;
             break;
         case 'class':
             $this->sorts[$name] = $name;
             break;
         case 'storage':
             $this->sorts[$name] = $item->{$schema['export']['export type string']} . $name;
             break;
     }
     $this->rows[$name]['data'] = array();
     $this->rows[$name]['class'] = !empty($item->disabled) ? array('ctools-export-ui-disabled') : array('ctools-export-ui-enabled');
     // If we have an admin title, make it the first row.
     if (!empty($this->plugin['export']['admin_title'])) {
         $this->rows[$name]['data'][] = array('data' => check_plain($item->{$this->plugin['export']['admin_title']}), 'class' => array('ctools-export-ui-title'));
     }
     $this->rows[$name]['data'][] = array('data' => check_plain($name), 'class' => array('ctools-export-ui-name'));
     $this->rows[$name]['data'][] = array('data' => check_plain($item->factory_service), 'class' => array('ctools-export-ui-service'));
     $this->rows[$name]['data'][] = array('data' => check_plain($count_parents), 'class' => array('ctools-export-ui-parents'));
     $this->rows[$name]['data'][] = array('data' => check_plain($item->{$schema['export']['export type string']}), 'class' => array('ctools-export-ui-storage'));
     $ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
     $this->rows[$name]['data'][] = array('data' => $ops, 'class' => array('ctools-export-ui-operations'));
     // Add an automatic mouseover of the description if one exists.
     if (!empty($this->plugin['export']['admin_description'])) {
         $this->rows[$name]['title'] = $item->{$this->plugin['export']['admin_description']};
     }
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function optionsToObjects()
 {
     $import = parent::optionsToObjects();
     if ($style = $this->getOption('editStyle')) {
         $style = Openlayers::load('style', $style);
         $this->setWeight($style->getWeight() + 1);
         $import = array_merge($style->getCollection()->getFlatList(), $import);
     }
     if ($layer = $this->getOption('editLayer')) {
         $layer = Openlayers::load('layer', $layer);
         $import = array_merge($layer->getCollection()->getFlatList(), $import);
     }
     if ($control = $this->getOption('editControl')) {
         $control = Openlayers::load('control', $control);
         $import = array_merge($control->getCollection()->getFlatList(), $import);
     }
     return $import;
 }
Example #17
0
 /**
  * {@inheritdoc}
  */
 public function optionsForm(&$form, &$form_state)
 {
     $form['options']['label'] = array('#type' => 'textfield', '#title' => t('Title of the control'), '#default_value' => $this->getOption('label', 'Layers'));
     $form['options']['layers'] = array('#type' => 'select', '#title' => t('Layers'), '#empty_option' => t('- Select a Layer -'), '#multiple' => TRUE, '#default_value' => $this->getOption('layers'), '#options' => Openlayers::loadAllAsOptions('Layer'));
     $form['options']['multiselect'] = array('#type' => 'checkbox', '#title' => t('Allow selecting multiple layers'), '#default_value' => $this->getOption('multiselect', FALSE));
     $form['options']['layer_labels_hint'] = array('#markup' => t('You need to save the configuration before being able to set custom layer labels.'));
     $labels = $this->getOption('layer_labels', array());
     foreach ((array) $this->getOption('layers') as $i => $machine_name) {
         if (($map_layer = Openlayers::load('Layer', $machine_name)) == TRUE) {
             $label = check_plain($map_layer->getName());
             if (isset($labels[$machine_name])) {
                 $label = $labels[$machine_name];
             }
             $form['options']['layer_labels'][$machine_name] = array('#type' => 'textfield', '#title' => t('Label for layer @label:', array('@label' => $map_layer->getName())), '#default_value' => $label);
         }
     }
     // @TODO Add configuration for initial visibility. (Adjust JS accordingly)
     // @TODO Add configuration for ordering?
 }
Example #18
0
 /**
  * {@inheritdoc}
  *
  * !Attention! This function will remove any option that is named after a
  * plugin type e.g.: layers, controls, styles, interactions, components .
  */
 public function getJS()
 {
     $export = $this->getExport();
     array_map(function ($type) use($export) {
         unset($export->options[$type . 's']);
     }, Openlayers::getPluginTypes());
     $js = array('mn' => $export->machine_name, 'fs' => $export->factory_service);
     if (!empty($export->options)) {
         $js['opt'] = $export->options;
     }
     return $js;
 }
 /**
  * {@inheritdoc}
  */
 public function optionsForm(&$form, &$form_state)
 {
     $form['options']['ui'] = array('#type' => 'fieldset', '#title' => t('User interface'), 'width' => array('#type' => 'textfield', '#title' => 'Width of the map', '#default_value' => $this->getOption('width', 'auto'), '#parents' => array('options', 'width')), 'height' => array('#type' => 'textfield', '#title' => t('Height of the map'), '#default_value' => $this->getOption('height', '300px'), '#parents' => array('options', 'height')));
     $form['options']['view'] = array('#type' => 'fieldset', '#title' => t('Center and rotation'), '#tree' => TRUE);
     if ($this->machine_name != Config::get('openlayers.edit_view_map')) {
         if (($map = Openlayers::load('Map', Config::get('openlayers.edit_view_map'))) == TRUE) {
             $map_configuration = $map->getConfiguration();
             if ($view = $this->getOption('view')) {
                 // Don't apply min / max zoom settings to this map to avoid lock-in.
                 $view['minZoom'] = 0;
                 $view['maxZoom'] = 0;
                 $map->setOption('view', $view);
             }
             $form['options']['view']['map'] = array('#type' => 'openlayers', '#description' => $map->getPluginDescription(), '#map' => $map);
         }
     }
     $form['options']['view']['center'] = array('#tree' => TRUE, 'lat' => array('#type' => 'textfield', '#title' => t('Latitude'), '#default_value' => $this->getOption(array('view', 'center', 'lat'), 0)), 'lon' => array('#type' => 'textfield', '#title' => t('Longitude'), '#default_value' => $this->getOption(array('view', 'center', 'lat'), 0)));
     $form['options']['view']['rotation'] = array('#type' => 'textfield', '#title' => t('Rotation'), '#default_value' => $this->getOption(array('view', 'rotation'), 0));
     $form['options']['view']['zoom'] = array('#type' => 'textfield', '#title' => t('Zoom'), '#default_value' => $this->getOption(array('view', 'zoom'), 0));
     $form['options']['view']['minZoom'] = array('#type' => 'textfield', '#title' => t('Min zoom'), '#default_value' => $this->getOption(array('view', 'minZoom'), 0));
     $form['options']['view']['maxZoom'] = array('#type' => 'textfield', '#title' => t('Max zoom'), '#default_value' => $this->getOption(array('view', 'maxZoom'), 0));
     $form['options']['view']['limit_extent'] = array('#type' => 'select', '#title' => t('Limit to extent'), '#empty_option' => t('Disabled'), '#empty_value' => '', '#options' => array('custom' => 'Custom extent', 'projection' => 'Map projection'), '#description' => t('If enabled navigation on the map is limited to the give extent.'), '#default_value' => $this->getOption(array('view', 'limit_extent'), FALSE));
     $form['options']['view']['extent'] = array('#type' => 'textfield', '#title' => t('Extent [minx, miny, maxx, maxy]'), '#default_value' => $this->getOption(array('view', 'extent'), ''), '#states' => array('visible' => array(':input[name="options[view][limit_extent]"]' => array('value' => 'custom'))));
     $form['options']['misc'] = array('#type' => 'fieldset', '#title' => t('Miscellaneous options'));
     $form['options']['misc']['renderer'] = array('#type' => 'radios', '#title' => t('Renderer'), '#description' => t('Renderer by default. Canvas, DOM and WebGL renderers are tested for support in that order. Note that at present only the Canvas renderer support vector data.'), '#options' => array('canvas' => t('Canvas'), 'dom' => t('DOM'), 'webgl' => t('WebGL')), '#default_value' => $this->getOption('renderer', 'canvas'), '#parents' => array('options', 'renderer'));
     $i = 0;
     $data = array();
     $map_options = $this->getOptions();
     /* @var \Drupal\openlayers\Types\Object $object */
     foreach ($this->getCollection()->getFlatList() as $object) {
         $weight = 0;
         if (isset($map_options['capabilities']['options']['table'][$object->getMachineName()])) {
             $weight = array_search($object->getMachineName(), array_keys($map_options['capabilities']['options']['table']));
         }
         $data[$object->machine_name] = array('name' => $object->name, 'machine_name' => $object->machine_name, 'text' => isset($map_options['capabilities']['options']['table'][$object->getMachineName()]) ? $map_options['capabilities']['options']['table'][$object->getMachineName()] : $object->getPluginDescription(), 'weight' => $weight, 'enabled' => isset($map_options['capabilities']['options']['table'][$object->getMachineName()]) ? TRUE : FALSE, 'default' => 1);
     }
     uasort($data, function ($a, $b) {
         if ($a['enabled'] > $b['enabled']) {
             return -1;
         } else {
             if ($a['enabled'] < $b['enabled']) {
                 return 1;
             }
         }
         if ($a['weight'] < $b['weight']) {
             return -1;
         } else {
             if ($a['weight'] > $b['weight']) {
                 return 1;
             }
         }
         return 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'], '#attributes' => array('class' => array('entry-order-weight')))), array('data' => array('#type' => 'hidden', '#default_value' => $entry['machine_name'])), array('data' => array('#type' => 'checkbox', '#title' => t('Enable'), '#title_display' => 'invisible', '#default_value' => $entry['enabled'])), array('data' => array('#type' => 'textfield', '#title' => t('Text'), '#title_display' => 'invisible', '#default_value' => $entry['text'], '#maxlength' => 256)), check_plain($entry['name']), check_plain($entry['machine_name'])), 'class' => array('draggable'));
         // Build rows of the form elements in the table.
         $row_elements[$id] = array('weight' => &$rows[$id]['data'][1]['data'], 'machine_name' => &$rows[$id]['data'][2]['data'], 'enabled' => &$rows[$id]['data'][3]['data'], 'text' => &$rows[$id]['data'][4]['data']);
     }
     $form['options']['capabilities'] = array('#type' => 'fieldset', '#title' => 'Map description and capabilities', '#collapsible' => FALSE, '#collapsed' => FALSE, 'enabled' => array('#type' => 'checkbox', '#title' => t('Enable map capabilities ?'), '#default_value' => (bool) $this->getOption(array('capabilities'), FALSE)), 'options' => array('#type' => 'container', '#states' => array('visible' => array(':input[name="options[capabilities][enabled]"]' => array('checked' => TRUE))), 'container_type' => array('#type' => 'select', '#title' => t('Container type'), '#options' => array('fieldset' => 'Fieldset', 'container' => 'Simple div'), '#default_value' => $this->getOption(array('capabilities', 'options', 'container_type'), 'fieldset')), 'title' => array('#type' => 'textfield', '#title' => t('Title'), '#description' => t('Show a title ? Empty to disable.'), '#default_value' => $this->getOption(array('capabilities', 'options', 'title'), t('Map capabilities')), '#states' => array('visible' => array(':input[name="options[capabilities][options][container_type]"]' => array('value' => 'fieldset')))), 'description' => array('#type' => 'textfield', '#title' => t('Description'), '#description' => t('Show a description ? Empty to disable.'), '#default_value' => $this->getOption(array('capabilities', 'options', 'description'), t('Description')), '#states' => array('visible' => array(':input[name="options[capabilities][options][container_type]"]' => array('value' => 'fieldset')))), 'collapsible' => array('#type' => 'checkbox', '#title' => t('Collapsible'), '#default_value' => (bool) $this->getOption(array('capabilities', 'options', 'collapsible'), TRUE), '#states' => array('visible' => array(':input[name="options[capabilities][options][container_type]"]' => array('value' => 'fieldset')))), 'collapsed' => array('#type' => 'checkbox', '#title' => t('Collapsed'), '#default_value' => (bool) $this->getOption(array('capabilities', 'options', 'collapsed'), TRUE), '#states' => array('visible' => array(':input[name="options[capabilities][options][container_type]"]' => array('value' => 'fieldset'))))));
     // Add the table to the form.
     $form['options']['capabilities']['options']['table'] = array('#theme' => 'table', 'elements' => $row_elements, '#header' => array(array('data' => NULL, 'colspan' => 2), array('data' => t('Enabled'), 'colspan' => 2), array('data' => t('Description'), 'colspan' => 1), t('Name'), t('Machine name')), '#rows' => $rows, '#empty' => t('There are no entries available.'), '#attributes' => array('id' => 'entry-order-objects'));
     drupal_add_tabledrag('entry-order-objects', 'order', 'sibling', 'entry-order-weight');
 }
Example #20
0
 /**
  * {@inheritdoc}
  */
 public function attached()
 {
     return array_merge_recursive(parent::attached(), Openlayers::getAttached());
 }
Example #21
0
 /**
  * {@inheritdoc}
  */
 public function optionsForm(&$form, &$form_state)
 {
     $form['options']['source'] = array('#type' => 'select', '#title' => t('Source'), '#empty_option' => t('- Select a Source -'), '#default_value' => isset($form_state['item']->options['source']) ? $form_state['item']->options['source'] : '', '#description' => t('Select the source.'), '#options' => Openlayers::loadAllAsOptions('Source'), '#required' => TRUE);
 }
Example #22
0
 /**
  * {@inheritdoc}
  */
 public function optionsForm(&$form, &$form_state)
 {
     $form['options']['layer'] = array('#type' => 'select', '#title' => t('Layer'), '#empty_option' => t('- Select a Layer -'), '#default_value' => isset($form_state['item']->options['layer']) ? $form_state['item']->options['layer'] : '', '#description' => t('Select the layer.'), '#options' => Openlayers::loadAllAsOptions('Layer'), '#required' => TRUE);
     $form['options']['positioning'] = array('#type' => 'select', '#title' => t('Positioning'), '#default_value' => isset($form_state['item']->options['positioning']) ? $form_state['item']->options['positioning'] : 'top-left', '#description' => t('Defines how the overlay is actually positioned. Default is top-left.'), '#options' => Openlayers::positioningOptions(), '#required' => TRUE);
 }
Example #23
0
 /**
  * {@inheritdoc}
  */
 public function optionsToObjects()
 {
     $import = array();
     foreach ($this->getOption('grouplayers', array()) as $weight => $object) {
         if ($merge_object = Openlayers::load('layer', $object)) {
             $merge_object->setWeight($weight);
             $import[] = $merge_object;
         }
     }
     return $import;
 }
Example #24
0
 /**
  * Create an object instance for an export.
  *
  * @param string $object_type
  *   The object type to look up. See openlayers_object_types() for a list of
  *   available object types.
  * @param array|string|object $export
  *   The exported object.
  *
  * @return ObjectInterface|Error
  *   Returns the instance of the requested object or an instance of
  *   Error on error.
  */
 public static function load($object_type = NULL, $export)
 {
     /** @var \Drupal\openlayers\Types\ObjectInterface $object */
     $object = NULL;
     $configuration = array();
     $object_type = drupal_ucfirst(drupal_strtolower(check_plain($object_type)));
     if (is_array($export)) {
         $configuration = $export;
     }
     if (is_object($export) && $export instanceof \StdClass) {
         $array_object = new \ArrayObject($export);
         $configuration = $array_object->getArrayCopy();
     }
     if (is_object($export) && $export instanceof ObjectInterface) {
         return $export;
     }
     if (is_string($export)) {
         $configuration = (array) Openlayers::loadExportable($object_type, $export);
     }
     if (is_array($configuration) && isset($configuration['factory_service'])) {
         // Bail out if the base service can't be found - likely due a registry
         // rebuild.
         if (!\Drupal::hasService('openlayers.Types')) {
             return NULL;
         }
         list($plugin_manager_id, $plugin_id) = explode(':', $configuration['factory_service'], 2);
         if (\Drupal::hasService($plugin_manager_id)) {
             $plugin_manager = \Drupal::service($plugin_manager_id);
             if ($plugin_manager->hasDefinition($plugin_id)) {
                 $object = $plugin_manager->createInstance($plugin_id, $configuration);
             } else {
                 $configuration += array('type' => $object_type, 'errorMessage' => 'Unable to load @type @machine_name');
                 $object = \Drupal::service('openlayers.Types')->createInstance('Error', $configuration);
             }
         } else {
             $configuration += array('type' => $object_type, 'errorMessage' => 'Service <em>@service</em> doesn\'t exists, unable to load @type @machine_name');
             $object = \Drupal::service('openlayers.Types')->createInstance('Error', $configuration);
         }
     } else {
         $configuration += array('type' => $object_type, 'name' => 'Error', 'description' => 'Error', 'factory_service' => '', 'machine_name' => $export, 'errorMessage' => 'Unable to load CTools exportable @type @machine_name.');
         $object = \Drupal::service('openlayers.Types')->createInstance('Error', $configuration);
     }
     if (isset($configuration['disabled']) && (bool) $configuration['disabled'] == 1) {
         $object->disabled = 1;
     }
     return $object->init();
 }
 /**
  * Load all objects.
  *
  * @param null $type
  *   Type of object to load: map|layer|source|control|interaction|style|component
  * @return \Drupal\openlayers\Types\Object[]
  */
 public static function loadAll($object_type = NULL)
 {
     $objects = array();
     foreach (Openlayers::loadAllExportable($object_type) as $exportable) {
         if (is_object($exportable)) {
             $objects[$exportable->machine_name] = Openlayers::load($object_type, $exportable);
         }
     }
     return $objects;
 }
Example #26
0
 /**
  * {@inheritdoc}
  */
 public function optionsToObjects()
 {
     $import = array();
     foreach (Openlayers::getPluginTypes(array('map')) as $type) {
         foreach ($this->getOption($type . 's', array()) as $weight => $object) {
             if ($merge_object = Openlayers::load($type, $object)) {
                 $merge_object->setWeight($weight);
                 $import[] = $merge_object;
             }
         }
     }
     return $import;
 }
Example #27
0
 /**
  * {@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 ($col_object = $this->getCollection()->getObjectById($type, $object)) {
                 //$col_object->setWeight($weight_type . '.' . $weight);
                 //$import[] = $col_object;
             } else {
                 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;
 }