Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function attached()
 {
     $attached = parent::attached();
     $variant = NULL;
     if (Config::get('openlayers.debug', FALSE) == TRUE) {
         $variant = 'debug';
     }
     $attached['libraries_load']['openlayers3'] = array('openlayers3', $variant);
     return $attached;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function attached()
 {
     $attached = parent::attached();
     $plugin = $this->getPluginDefinition();
     $plugin['path'] = $this->getClassDirectory();
     if ($this->getOption('devMode')) {
         // @TODO Find a way how to do this just once per map / collection.
         $attached['library']['system.ui.dialog'] = array('system', 'ui.dialog');
         $attached['library']['system.jquery.cookie'] = array('system', 'jquery.cookie');
         $attached['js'][$plugin['path'] . '/js/geojson_dev.js']['weight'] = Config::get('openlayers.js_css.weight') + 1;
     } else {
         unset($attached['js'][$plugin['path'] . '/js/geojson_dev.js']);
         unset($attached['css'][$plugin['path'] . '/css/geojson_dev.css']);
     }
     return $attached;
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function attached()
 {
     if ($plugin = $this->getPluginDefinition()) {
         $path = $this->getClassDirectory();
         $jsdir = $path . '/js';
         $cssdir = $path . '/css';
         if (file_exists($jsdir)) {
             foreach (file_scan_directory($jsdir, '/.*\\.js$/') as $file) {
                 $this->attached['js'][$file->uri] = array('data' => $file->uri, 'type' => 'file', 'group' => Config::get('openlayers.js_css.group'), 'weight' => Config::get('openlayers.js_css.weight'));
             }
         }
         if (file_exists($cssdir)) {
             foreach (file_scan_directory($cssdir, '/.*\\.css$/') as $file) {
                 $this->attached['css'][$file->uri] = array('data' => $file->uri, 'type' => 'file', 'group' => Config::get('openlayers.js_css.group'), 'weight' => Config::get('openlayers.js_css.weight'), 'media' => Config::get('openlayers.js_css.media'));
             }
         }
     }
     return $this->attached;
 }
Пример #4
0
 /**
  * {@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->getMachineName() != 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->getMachineName()] = array('name' => $object->getName(), 'machine_name' => $object->getMachineName(), '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;
         } elseif ($a['enabled'] < $b['enabled']) {
             return 1;
         }
         if ($a['weight'] < $b['weight']) {
             return -1;
         } elseif ($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');
 }
Пример #5
0
 /**
  * Returns the list of files libraries or js/css files needed according to
  * the settings.
  *
  * @return array
  */
 public static function getAttached()
 {
     $attached = array();
     $attached['libraries_load'] = array('openlayers3' => array('openlayers3', Config::get('openlayers.variant', NULL)));
     if (Config::get('openlayers.debug', FALSE)) {
         $attached['libraries_load']['openlayers3_integration'] = array('openlayers3_integration', 'debug');
     }
     return $attached;
 }
Пример #6
0
 /**
  * Return the version of the Openlayers library in use.
  *
  * @return string
  *   Return the version of the Openlayers library set in the configuration.
  */
 public static function getLibraryVersion()
 {
     $variant = \Drupal\openlayers\Config::get('openlayers.variant');
     if (strpos($variant, 'local-') !== FALSE) {
         $version = self::getLocalLibraryVersion();
     } else {
         $version = \Drupal\openlayers\Config::get('openlayers.variant', NULL);
     }
     return $version;
 }