You are here

function theme_openlayers_cck_formatter_map in Openlayers 6.2

Same name and namespace in other branches
  1. 6 modules/openlayers_cck/openlayers_cck.module \theme_openlayers_cck_formatter_map()

Theme function for openlayers cck formatters

1 string reference to 'theme_openlayers_cck_formatter_map'
openlayers_cck_theme in modules/openlayers_cck/openlayers_cck.module
Implementation of hook_theme().

File

modules/openlayers_cck/includes/openlayers_cck.theme.inc, line 34
Theme functions for openlayers_cck

Code

function theme_openlayers_cck_formatter_map($element) {
  $features = array();
  $field = content_fields($element['#field_name'], $element['#type_name']);
  $widget = $field['widget'];

  // Create array of $features
  foreach (element_children($element) as $delta) {
    $features[] = array(
      // First look for geo_field data, then for openlayers wkt data
      'wkt' => $element[$delta]['#item']['openlayers_wkt'],
      'projection' => '4326',
    );
  }

  // Get preset name from formatter. Strip off 'openlayers_cck_formatter_'
  // and 'openlayers_map_' from the beginning.
  // If none found, use default map.
  // TODO: Better way to do this?
  if (drupal_substr($element['#formatter'], 25) == 'openlayers_cck_formatter_') {
    $preset_name = drupal_substr($element['#formatter'], 25);
  }
  elseif (drupal_substr($element['#formatter'], 0, 15) == 'openlayers_map_') {
    $preset_name = drupal_substr($element['#formatter'], 15);
  }
  else {
    $preset_name = variable_get('openlayers_default_preset', 'default');
  }

  // Get map preset
  $preset = openlayers_preset_load($preset_name);

  // Add vector layer behavior
  $preset->data['behaviors']['openlayers_cck_vector_layer'] = array(
    'features' => $features,
  );

  // Add widget/formatter behaviors
  if (isset($widget['openlayers_behaviors']) && is_array($widget['openlayers_behaviors'])) {
    foreach ($widget['openlayers_behaviors'] as $key => $behavior) {
      if ($behavior['enabled']) {
        $preset->data['behaviors'][$key] = $behavior['options'];
      }
    }
  }

  // Render map
  return openlayers_render_map($preset->data, $preset->name);
}