t('Openlayers Map'), 'field types' => array('geofield'), ); } $widgets['geofield_wkt'] = array( 'label' => t('Well Known Text (WKT)'), 'field types' => array('geofield'), ); $widgets['geofield_geojson'] = array( 'label' => t('GeoJSON'), 'field types' => array('geofield'), ); $widgets['geofield_latlon'] = array( 'label' => t('Latitude / Longitude'), 'field types' => array('geofield'), ); $widgets['geofield_bounds'] = array( 'label' => t('Bounds'), 'field types' => array('geofield'), ); $widgets['geofield_textfields'] = array( 'label' => t('All Textfields'), 'field types' => array('geofield'), ); $widgets['geofield_geolocation'] = array( 'label' => 'HTML5 Geolocation', 'field types' => array('geofield'), ); return $widgets; } /** * Implements hook_field_widget_settings_form(). */ function geofield_field_widget_settings_form($field, $instance) { $widget = $instance['widget']; $settings = $widget['settings']; $form = array(); //TODO: Allow more fine-grained control if ($widget['type'] == 'geofield_openlayers') { // Get preset options, filtered to those which have the GeoField behavior and *don't* have the draw features behavior, which is incompatible $maps = openlayers_maps(); $map_options = array(); foreach ($maps as $map) { if (array_key_exists('openlayers_behavior_geofield', $map->data['behaviors']) && !array_key_exists('openlayers_behavior_drawfeatures', $map->data['behaviors'])) { $map_options[$map->name] = $map->title; } } if (empty($map_options)) { form_set_error('openlayers_map', "Error: You have no compatible openlayers maps. Make sure that at least one preset has the 'GeoField' behavior enabled and that it does not have the 'Draw Features' behavior enabled (which is incompatible)."); } $form['openlayers_map'] = array( '#type' => 'select', '#title' => t('OpenLayers Map'), '#default_value' => isset($settings['openlayers_map']) ? $settings['openlayers_map'] : 'geofield_widget_map', '#options' => $map_options, '#description' => t('Select which OpenLayers map you would like to use. Only maps which have the GeoField behavior may be selected. If your preferred map is not here, add the GeoField behavior to it first. The "Draw Features" bahavior is incompatible - presets with this behavior are not shown.'), ); $form['data_storage'] = array( '#type' => 'radios', '#title' => t('Storage Options'), '#description' => t('Should the widget only allow simple features (points, lines, or polygons), or should the widget allow for complex features? Note that changing this setting from complex to simple after data has been entered can lead to data loss.'), '#options' => array( 'collection' => 'Store as a single collection.', 'single' => 'Store each simple feature as a separate field.', ), '#default_value' => (isset($settings['data_storage'])) ? $settings['data_storage'] : 'collection', ); } return $form; } /** * Implements hook_field_widget_form(). */ function geofield_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $base) { $widget = $instance['widget']; $settings = $widget['settings']; $element = geofield_get_base_element($base, $items, $delta); if ($widget['type'] == 'geofield_wkt') { $element['wkt']['#title'] = 'Well Known Text'; $element['wkt']['#type'] = 'textarea'; $element['master_column']['#value'] = 'wkt'; } if ($widget['type'] == 'geofield_geojson') { $element['wkt']['#title'] = 'GeoJSON'; $element['wkt']['#type'] = 'textarea'; // We're actually displaying as GeoJSON, not wkt. This is confusing. geofield_load_geophp(); $default_value = ''; try { $wkt = isset($items[$delta]['wkt']) ? $items[$delta]['wkt'] : NULL; $geometry = geoPHP::load($wkt, 'wkt'); if ($geometry) { $default_value = $geometry->out('json'); } } catch (Exception $e) { // @TODO: Not sure if we should do validation here or not... } $element['wkt']['#default_value'] = $default_value; $element['master_column']['#value'] = 'wkt'; $element['input_format']['#value'] = 'geojson'; } if ($widget['type'] == 'geofield_latlon') { $element['lat']['#title'] = 'Latitude'; $element['lat']['#type'] = 'textfield'; $element['lon']['#title'] = 'Longitude'; $element['lon']['#type'] = 'textfield'; $element['master_column']['#value'] = 'latlon'; } if ($widget['type'] == 'geofield_bounds') { $element['left']['#title'] = 'Left Longitude'; $element['left']['#type'] = 'textfield'; $element['top']['#title'] = 'Top Latitude'; $element['top']['#type'] = 'textfield'; $element['right']['#title'] = 'Right Longitude'; $element['right']['#type'] = 'textfield'; $element['bottom']['#title'] = 'Bottom Latitude'; $element['bottom']['#type'] = 'textfield'; $element['master_column']['#value'] = 'bounds'; } if ($widget['type'] == 'geofield_textfields') { $element['wkt']['#title'] = 'Well Known Text'; $element['wkt']['#type'] = 'textarea'; $element['geo_type']['#title'] = 'Geometry Type'; $element['geo_type']['#type'] = 'textfield'; $element['lat']['#title'] = 'Latitude'; $element['lat']['#type'] = 'textfield'; $element['lon']['#title'] = 'Longitude'; $element['lon']['#type'] = 'textfield'; $element['left']['#title'] = 'Left Longitude'; $element['left']['#type'] = 'textfield'; $element['top']['#title'] = 'Top Latitude'; $element['top']['#type'] = 'textfield'; $element['right']['#title'] = 'Right Longitude'; $element['right']['#type'] = 'textfield'; $element['bottom']['#title'] = 'Bottom Latitude'; $element['bottom']['#type'] = 'textfield'; } if ($widget['type'] == 'geofield_geolocation') { $element['#attached']['js'][] = drupal_get_path('module', 'geofield') . '/js/geolocation.js'; $element['lat']['#title'] = 'Latitude'; $element['lat']['#type'] = 'textfield'; $element['lon']['#title'] = 'Longitude'; $element['lon']['#type'] = 'textfield'; $element['master_column']['#value'] = 'latlon'; } if ($widget['type'] == 'geofield_openlayers') { drupal_add_js( array('geofield' => array( 'data_storage' => (!empty($settings['data_storage'])) ? $settings['data_storage'] : 'collection', ), ), 'setting'); $field_class = '.field-name-' . str_replace('_', '-', $field['field_name']); $defaults = array(); $element['helpmap'] = array( '#markup' => '