You are here

function theme_gm3_view_gm3 in Google Maps API V3 7

Theme a GM3 view.

File

./gm3.theme.inc, line 176

Code

function theme_gm3_view_gm3($variables) {
  $geo_fields = array();
  $none_geo_fields = array();
  foreach ($variables['view']->field as $field_key => $field) {
    if (isset($field->field_info['type']) && substr($field->field_info['type'], 0, 4) == 'gm3_') {
      $geo_fields[$field_key] = $field->field_info['type'];
    }
    else {
      $none_geo_fields[] = $field_key;
    }
  }
  $map = array(
    'libraries' => array(),
  );

  //foreach($variables['view']->result as $index => $row){
  foreach ($variables['rows'] as $index => $row) {
    $content = '';
    foreach ($none_geo_fields as $key) {
      if ($key == 'title') {

        // Need a way of setting the title on all entity types.
      }
      else {
        if (isset($row->{"field_{$key}"})) {
          foreach ($row->{"field_{$key}"} as $key => $value) {
            if (is_array($value['rendered'])) {
              $content .= drupal_render($value['rendered']);
            }
            else {
              $content .= $value['rendered'];
            }
          }
        }
      }
    }
    foreach ($geo_fields as $key => $type) {
      switch ($type) {
        case 'gm3_rectangle':
        case 'gm3_polygon':
        case 'gm3_polyline':
          foreach ($row->{"field_{$key}"} as $item) {
            module_load_include('functions.inc', 'gm3');
            if (!isset($map['libraries'][substr($type, 4)])) {
              $map['libraries'][substr($type, 4)] = array(
                substr($type, 4) . 's' => array(),
              );
            }
            $map['libraries'][substr($type, 4)][substr($type, 4) . 's'][] = array(
              substr($type, 4) => array_pop(gm3_convert_polygon_string($item['raw'][substr($type, 4)])),
              'editable' => FALSE,
              'content' => $content,
            );
          }
          break;
        case 'gm3_point':
          if (!isset($map['libraries']['point'])) {
            $map['libraries']['point'] = array(
              'points' => array(),
            );
          }
          foreach ($row->{"field_{$key}"} as $item) {
            $point = $item['raw'];
            $point['content'] = $content;
            $map['libraries']['point']['points'][] = $point;
          }
          break;
        case 'gm3_combination':
          foreach ($row->{"field_{$key}"} as $item) {
            switch ($item['raw']['gm3_type']) {
              case 'point':
                if (!isset($map['libraries']['point'])) {
                  $map['libraries']['point'] = array(
                    'points' => array(),
                  );
                }
                $map['libraries']['point']['points'][] = array(
                  'latitude' => $item['raw']['latitude'],
                  'longitude' => $item['raw']['longitude'],
                  'content' => $content,
                );
                break;
              case 'rectangle':
              case 'polyline':
              case 'polygon':
                module_load_include('functions.inc', 'gm3');
                if (!isset($map['libraries'][$item['raw']['gm3_type']])) {
                  $map['libraries'][$item['raw']['gm3_type']] = array(
                    $item['raw']['gm3_type'] . 's' => array(),
                  );
                }
                $map['libraries'][$item['raw']['gm3_type']][$item['raw']['gm3_type'] . 's'][] = array(
                  $item['raw']['gm3_type'] => array_pop(gm3_convert_polygon_string($item['raw'][$item['raw']['gm3_type']])),
                  'editable' => FALSE,
                  'content' => $content,
                );
                break;
              default:

                // The default - This field type is not defined by the gm3 module,
                // we therefore append call the map_alter function for this
                // field
                $function = "{$item['raw']['gm3_type']}_map_alter";
                if (function_exists($function)) {
                  $function($map, $item['raw']);
                }
                break;
            }
          }
          break;
        default:

          // The default - This field type is not defined by the gm3 module,
          // we therefore append call the map_alter function for this
          // field
          foreach ($row->{"field_{$key}"} as $item) {
            $function = "{$item['raw']['gm3_type']}_map_alter";
            if (function_exists($function)) {
              $function($map, $item['raw']);
            }
          }
          break;
      }
    }
  }
  return theme('gm3_map', array(
    'map' => $map,
  ));
}