function openlayers_views_style_map::options_form in Openlayers 6
Same name and namespace in other branches
- 6.2 modules/openlayers_views/views/openlayers_views_style_map.inc \openlayers_views_style_map::options_form()
- 7.2 modules/openlayers_views/views/openlayers_views_style_map.inc \openlayers_views_style_map::options_form()
Options form
File
- modules/
openlayers_views/ views/ openlayers_views_style_map.inc, line 32 - This file holds style plugin for OpenLayers Views
Class
- openlayers_views_style_map
- @class Extension of the Views Plugin Syle for OpenLayers
Code
function options_form(&$form, &$form_state) {
$fields = array();
$geo_field_options = array();
$location_field_options = array();
$data_source_options = array();
// Get list of fields in this view & flag available geodata fields
$handlers = $this->display->handler
->get_handlers('field');
// Check for any fields, as the view needs them
if (empty($handlers)) {
$form['error_markup'] = array(
'#value' => t('You need to enable at least one field before you can configure your field settings'),
'#prefix' => '<div class="error form-item description">',
'#suffix' => '</div>',
);
parent::options_form($form, $form_state);
return;
}
// Go through fields
foreach ($handlers as $field_id => $handler) {
// Collect fields per types
switch ($handler->content_field['type']) {
case 'geo':
$geo_field_options[$handler->content_field['field_name']] = $handler->content_field['widget']['label'];
break;
case 'location':
$location_field_options[$handler->content_field['field_name']] = $handler->content_field['widget']['label'];
break;
default:
$fields[$field_id] = $handler
->label() ? $handler
->label() : $handler
->ui_name();
break;
}
}
// Check Geo fields found
if (count($geo_field_options) > 0) {
$data_source_options['geo'] = t('Geo Module');
}
// Check Node Location found
if (module_exists('location_node')) {
$data_source_options['node_locations'] = t('Node Locations');
}
// Default data source
$data_source_options['other_latlon'] = t('Other: Lat/Lon Point');
$data_source_options['other_wkt'] = t('Other: Well Known Text');
// Data Source options
$form['data_source'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => t('Data Source'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['data_source']['value'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Map Data Sources'),
'#description' => t('Choose which sources of data that the map will provide features for.'),
'#options' => $data_source_options,
'#default_value' => $this->options['data_source']['value'],
);
// Geo Data source options
if ($data_source_options['geo']) {
$form['data_source']['geo_fields'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Geo Module Fields'),
'#description' => t('Choose the fields provide by the Geo Module that will be used for feature data.'),
'#options' => $geo_field_options,
'#default_value' => $this->options['data_source']['geo_fields'],
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
'edit-style-options-data-source-value' => array(
'geo',
),
),
);
}
// Location data source options
if ($data_source_options['location']) {
$form['data_source']['location_fields'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Location Fields'),
'#description' => t('Choose the fields provided by the Location module that will be used for feature data.'),
'#options' => $location_field_options,
'#default_value' => $this->options['data_source']['location_fields'],
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
'edit-style-options-data-source-value' => array(
'location',
),
),
);
}
// Other Lat and Lon data sources
if (count($fields > 0)) {
$form['data_source']['other_lat'] = array(
'#type' => 'select',
'#title' => t('Latitude Field'),
'#description' => t('Choose a field for Latitude. This should be a field that is a decimal or float value.'),
'#options' => $fields,
'#default_value' => $this->options['data_source']['other_lat'],
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
'edit-style-options-data-source-value' => array(
'other_latlon',
),
),
);
$form['data_source']['other_lon'] = array(
'#type' => 'select',
'#title' => t('Longitude Field'),
'#description' => t('Choose a field for Longitude. This should be a field that is a decimal or float value.'),
'#options' => $fields,
'#default_value' => $this->options['data_source']['other_lon'],
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
'edit-style-options-data-source-value' => array(
'other_latlon',
),
),
);
}
// Other Well Known Text
if (count($fields > 0)) {
$form['data_source']['other_wkt'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('WKT Field'),
'#description' => t('Choose the fields for Well Known Text data.'),
'#options' => $fields,
'#default_value' => $this->options['data_source']['other_wkt'],
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
'edit-style-options-data-source-value' => array(
'other_wkt',
),
),
);
}
// Map Preset
$form['presets'] = array(
'#type' => 'fieldset',
'#title' => t('Map Presets'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['presets']['map_preset'] = array(
'#type' => 'select',
'#title' => t('Map Preset'),
'#description' => t('This is map that will be used to render the view.'),
'#options' => openlayers_get_presets(),
'#default_value' => $this->options['presets']['map_preset'] ? $this->options['presets']['map_preset'] : variable_get('openlayers_default_preset', 'default'),
);
$form['presets']['not_display_empty_map'] = array(
'#type' => 'checkbox',
'#title' => t('Do Not Display Empty Map'),
'#description' => t('Check this is you do not want a map to show if there is no data available in the view.'),
'#default_value' => $this->options['presets']['not_display_empty_map'],
);
// Behavior options
if (module_exists('openlayers_behaviors')) {
$form['behaviors'] = array(
'#type' => 'fieldset',
'#title' => t('Map Behaviors Options'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
// Tooltip and Pop-up options if fields
if (count($fields) > 0) {
$tooltip_popup_options = array_merge(array(
'0' => t('<none>'),
'#all_fields' => t('<all> (render entire row)'),
), $fields);
$form['behaviors']['tooltip'] = array(
'#type' => 'select',
'#title' => t('Tooltip Field'),
'#title' => t('Select the field you would like to use as a tooltip'),
'#options' => $tooltip_popup_options,
'#default_value' => $this->options['behaviors']['tooltip'],
);
$form['behaviors']['popup'] = array(
'#type' => 'select',
'#title' => t('Pop-up Field'),
'#title' => t('Select the field you would like to use as a popup'),
'#options' => $tooltip_popup_options,
'#default_value' => $this->options['behaviors']['popup'],
);
}
$form['behaviors']['zoom_to_layer'] = array(
'#type' => 'checkbox',
'#title' => t('Zoom to Features'),
'#description' => t('Automatically zoom to encompass views data (overrides map settings)'),
'#default_value' => $this->options['behaviors']['zoom_to_layer'],
);
$form['behaviors']['fullscreen'] = array(
'#type' => 'checkbox',
'#title' => t('Fullscreen'),
'#description' => t('Allow map to be viewed fullscreen'),
'#default_value' => $this->options['behaviors']['fullscreen'],
);
$form['behaviors']['declutter'] = array(
'#type' => 'checkbox',
'#title' => t('Declutter'),
'#description' => t('Automagically space points so they do not overlap.'),
'#default_value' => $this->options['behaviors']['declutter'],
);
$form['behaviors']['declutter_adjustment'] = array(
'#type' => 'textfield',
'#title' => t('Declutter Distance Adjustment'),
'#description' => t('Set to a negative number to have icons cluster closer together. Set to a positive number to have them furthur apart. Leave blank for default.'),
'#default_value' => $this->options['behaviors']['declutter_adjustment'],
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
'edit-style-options-behaviors-declutter' => array(
'1',
),
),
);
$form['behaviors']['cluster'] = array(
'#type' => 'checkbox',
'#title' => t('Cluster'),
'#description' => t('Cluster nodes that are close together into a single node.'),
'#default_value' => $this->options['behaviors']['cluster'],
);
$form['behaviors']['cluster_distance'] = array(
'#type' => 'textfield',
'#title' => t('Cluster distance'),
'#description' => t('Pixel distance between features that should be considered a single cluster. Default is 20 pixels.'),
'#default_value' => $this->options['behaviors']['cluster_distance'],
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
'edit-style-options-behaviors-cluster' => array(
'1',
),
),
);
$form['behaviors']['cluster_threshold'] = array(
'#type' => 'textfield',
'#title' => t('Cluster threshold'),
'#description' => t('Optional threshold below which original features will be added to the layer instead of clusters. For example, a threshold of 3 would mean that any time there are 2 or fewer features in a cluster, those features will be added directly to the layer instead of a cluster representing those features. Default is 2 (meaning that clusters must contain at least two features).'),
'#default_value' => $this->options['behaviors']['cluster_threshold'] ? $this->options['behaviors']['cluster_threshold'] : 2,
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
'edit-style-options-behaviors-cluster' => array(
'1',
),
),
);
$form['behaviors']['cluster_popup'] = array(
'#type' => 'checkbox',
'#title' => t('Popups on clusters'),
'#description' => t('Should clustered features permit popups?'),
'#default_value' => $this->options['behaviors']['cluster_popup'],
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
'edit-style-options-behaviors-cluster' => array(
'1',
),
),
);
$form['behaviors']['cluster_popup_callback'] = array(
'#type' => 'textfield',
'#title' => t('Callback for popup contents when clustering'),
'#description' => t('Enter the name of a JavaScript callback that returns the contents of popups (a string) attached to clustered features. The callback takes one argument: \'feature\'. <em>feature.cluster</em> contains the features being clustered together.'),
'#default_value' => $this->options['behaviors']['cluster_popup_callback'],
'#process' => array(
'views_process_dependency',
),
'#dependency_count' => 2,
'#dependency' => array(
'edit-style-options-behaviors-cluster' => array(
'1',
),
'edit-style-options-behaviors-cluster-popup' => array(
'1',
),
),
);
$form['behaviors']['cluster_tooltip'] = array(
'#type' => 'checkbox',
'#title' => t('Tooltips on clusters'),
'#description' => t('Should clustered features permit tooltips?'),
'#default_value' => $this->options['behaviors']['cluster_tooltip'],
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
'edit-style-options-behaviors-cluster' => array(
'1',
),
),
);
$form['behaviors']['cluster_tooltip_callback'] = array(
'#type' => 'textfield',
'#title' => t('Callback for tooltip contents when clustering'),
'#description' => t('Enter the name of a JavaScript callback that returns the contents of tolltips (a string) attached to clustered features. The callback takes one argument: \'feature\'. <em>feature.cluster</em> contains the features being clustered together.'),
'#default_value' => $this->options['behaviors']['cluster_tooltip_callback'],
'#process' => array(
'views_process_dependency',
),
'#dependency_count' => 2,
'#dependency' => array(
'edit-style-options-behaviors-cluster' => array(
'1',
),
'edit-style-options-behaviors-cluster-tooltip' => array(
'1',
),
),
);
}
// Grouping
$form['grouping_set'] = array(
'#type' => 'fieldset',
'#title' => t('Grouping'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$grouping_options = array_merge(array(
'0' => t('<none>'),
), $fields);
$form['grouping_set']['grouping'] = array(
'#type' => 'select',
'#title' => t('Grouping Field'),
'#options' => $grouping_options,
'#default_value' => $this->options['grouping_set']['grouping'],
'#description' => t('You can group features by field. This means that each group will be a separate layer with those specific features.'),
);
// Variable Styles
$form['style'] = array(
'#type' => 'fieldset',
'#title' => t('Feature Styles'),
'#description' => t('For advanced users only'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['style']['style_context_callback'] = array(
'#type' => 'textfield',
'#title' => t('Style-context callback'),
'#description' => t('If you want to be able to theme features on the fly with JavaScript, write a JS function that returns an associative array of functions and variables (a style context) and enter its name here. You can then use these callbacks anywhere you define a style array (for example, in theme_openlayers_vector_styles) with "${func_name}". For example: "pointRadius" => "${get_cluster_size}". This is particularly useful when you have clustering enabled, as the clustering algorithm creates new features on the fly and it\'s difficult to theme them before runtime. One caveat: if you define a style context, you cannot access feature.attributes with the ${} notation (although you can access feature.attributes directly from within your context\'s functions). <br /> The function takes the parameters func(map_id, layer_id, render_intent) and so can return different contexts based on the map, layer, and render intent.'),
'#default_value' => $this->options['style']['style_context_callback'],
);
$form['style']['snippet'] = array(
'#type' => 'textarea',
'#title' => t('Feature Styles function'),
'#description' => t('Enter PHP code that returns a style array for each feature. This will overrirde theme feature styling functions. <br/> $fields contains your defined fields, $record contains instances of those fields along with geometries. Array should be of the form \'styleProperty\' => \'styleValue\'. You may return false to use defaults. See documentation for available style Properties.'),
'#default_value' => $this->options['style']['snippet'],
);
}