You are here

function theme_openlayers_cck_formatter_map in Openlayers 6

Same name and namespace in other branches
  1. 6.2 modules/openlayers_cck/includes/openlayers_cck.theme.inc \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/openlayers_cck.module, line 574
This file holds the main Drupal hook functions and private functions for the openlayers_cck module.

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['openlayers_cck_vector_feature_' . $delta] = array(
      // First look for geo_field data, then for openlayers wkt data
      'wkt' => $element[$delta]['#item']['wkt'] ? $element[$delta]['#item']['wkt'] : $element[$delta]['#item']['openlayers_wkt'],
      'projection' => $element[$delta]['#item']['srid'] ? $element[$delta]['#item']['srid'] : '4326',
    );
  }

  // Check for features and if field wants to display empty map
  if ((count($features) == 0 || empty($features['openlayers_cck_vector_feature_0']['wkt'])) && $widget['openlayers_cck_show_empty_map'] == FALSE) {

    // Display nothing
    return '';
  }

  // Get preset name from formatter. Strip off
  // 'openlayers_cck_formatter_' and 'openlayers_map_' from the begginging.
  if (drupal_substr($element['#formatter'], 25) == 'openlayers_cck_formatter_') {
    $preset_name = drupal_substr($element['#formatter'], 25);
  }
  if (drupal_substr($element['#formatter'], 0, 15) == 'openlayers_map_') {
    $preset_name = drupal_substr($element['#formatter'], 15);
  }

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

  // Set map ID
  static $formatter_count = array();
  if (isset($formatter_count[$field['field_name']])) {
    $formatter_count[$field['field_name']]++;
  }
  else {
    $formatter_count[$field['field_name']] = 0;
  }
  $map['id'] = OPENLAYERS_CCK_FORMATTER_MAP_ID_PREFIX . '-' . str_replace('_', '-', $field['field_name']) . '-' . $formatter_count[$field['field_name']];
  $formatter_count++;

  // Add features and vector layer
  if (count($features) > 0) {
    $map['layers']['openlayers_cck_vector'] = array(
      'id' => 'openlayers_cck_vector',
      'name' => $field['widget']['label'],
      'type' => 'Vector',
      'options' => array(),
      'features' => $features,
    );
    $map['options']['displayProjection'] = $field['srid'] != 0 ? $field['srid'] : '4326';

    // Zoom to layer
    if ($widget['openlayers_cck_zoom_to_layer']) {
      $map['behaviors']['cck_zoom_to_layer'] = array(
        'id' => 'cck_zoom_to_layer',
        'type' => 'openlayers_behaviors_zoom_to_layer',
        'layer' => 'openlayers_cck_vector',
        'pointzoom' => $widget['openlayers_cck_zoom_to_layer_level'],
      );
    }
  }

  // Render map
  $rendered = openlayers_render_map($map);

  // Check for output
  if (!$map['errors'] && !empty($map['width'])) {
    return $rendered['themed'];
  }
  else {
    return '';
  }
}