/** * {@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; }
/** * {@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']); }
/** * {@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; }
/** * {@inheritdoc} */ public function preBuild(array &$build, ObjectInterface $context = NULL) { parent::preBuild($build, $context); $layers = $this->getOption('layers', array()); $map_layers = $context->getObjects('layer'); // 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->getMachineName()])) { $frontend_layers[$map_layer->getMachineName()] = $map_layer->getMachineName(); } } // Don't name these "layers" otherwise Object::getJS() will delete the // option from the JS array. $this->setOption('frontend_layers', $frontend_layers); }
/** * {@inheritdoc} */ public function attached() { $attached = parent::attached(); $attached['libraries_load'][] = array('bootstrap'); return $attached; }
/** * {@inheritdoc} */ public function getJS() { $js = parent::getJS(); $js['opt']['url'] = file_create_url(drupal_get_path('module', 'openlayers_examples') . '/assets/Butterfly.png'); return $js; }
/** * {@inheritDoc} */ public function optionsFormSubmit($form, &$form_state) { $form_state['values']['options']['shadow'] = (bool) $form_state['values']['options']['shadow']; $form_state['values']['options']['hwaccel'] = (bool) $form_state['values']['options']['hwaccel']; parent::optionsFormSubmit($form, $form_state); }
/** * {@inheritdoc} */ public function getJS() { // Ensure the options are properly set and clean. $this->options['dataType'] = array_filter($this->options['dataType']); $this->options['typeOfFeature'] = array_filter($this->options['typeOfFeature']); $this->options['actionFeature'] = array_filter($this->options['actionFeature']); // Process initial data. Ensure it's WKT. if (isset($this->options['initialData'])) { // Process strings and arrays likewise. geophp_load(); if (!is_array($this->options['initialData'])) { $this->options['initialData'] = array($this->options['initialData']); } $geoms = array(); foreach ($this->options['initialData'] as $delta => $item) { if (is_array($item) && array_key_exists('geom', $item)) { $geoms[] = geoPHP::load($item['geom']); } else { // Is this really necessary ? Commented for now. // $geoms[] = geoPHP::load(''); } } $combined_geom = geoPHP::geometryReduce($geoms); // If we could parse the geom process further. if ($combined_geom && !$combined_geom->isEmpty()) { // We want to force the combined_geom into a geometryCollection. $geom_type = $combined_geom->geometryType(); if ($geom_type == 'MultiPolygon' || $geom_type == 'MultiLineString' || $geom_type == 'MultiPoint') { $combined_geom = new \GeometryCollection($combined_geom->getComponents()); } // Ensure proper initial data in the textarea / hidden field. $this->options['initialData'] = $combined_geom->out(strtolower(key($this->options['dataType']))); $this->options['initialDataType'] = key($this->options['dataType']); } else { // Set initial data to NULL if the data couldn't be evaluated. $this->options['initialData'] = NULL; $this->options['initialDataType'] = key($this->options['dataType']); } } return parent::getJS(); }