theme_openlayers_cck_formatter_openlayersmapformatter_grouped

openlayers/modules/openlayers_cck/openlayers_cck.module, line 326

Versions
6
theme_openlayers_cck_formatter_openlayersmapformatter_grouped($element)

Theme a group of fields using just one map. Each field is given one layer.

Code

<?php
function theme_openlayers_cck_formatter_openlayersmapformatter_grouped($element) {
  // @@TODO: We may want to use nodeapi to do this instead of using a field formatter
  // Since we are grouping all fields, we only ever want to process this function once.
  
  static $processed = FALSE;
  if (!$processed){
    $node = $element['#node'];
    
    $mapid = "openlayers-cck-field-". $node->nid ."-grouped";
    
    // @@TODO: Put in a map form somewhere to configure the rest of the map properties.
    // @@TODO: Should we be using the hook_nodeapi for this?  Given that it is currently displaying under the header of the first field?

    // Go through the layers. Each field get it's own layer.
    $layers = array();
    foreach ($node->geo_fields as $geofield_key){
      // Check to make sure this field is using the grouped formatter
      $formatter = $node->content[$geofield_key]['field']['items']['#formatter'];
      if ($formatter == 'openlayersmapformatter_grouped'){
        
        // Add basic information to the layer in the map array
        $field_info = $node->content[$geofield_key]['field'];
        $layers[$geofield_key] = array(
          'id' => $geofield_key,
          'type' => 'Vector',
          'name' => $field_info['#title'],
        );
        
        // Add features to the map
        $layers[$geofield_key]['features'] = array();
        foreach ($node->$geofield_key as $feature){
          $layers[$geofield_key]['features'][] = array(
            'wkt' => $feature['wkt'],
            'projection' => $feature[$geofield_key."_srid"] ? $feature[$geofield_key."_srid"] : '4326',
            'attributes' => array(
              'name' => $node->node_title, 
              'nid' => $node->nid, 
            ),
          );
        }
      }
    }
    
    // Build our map array
    $map_def = array(
      'id' => $mapid,
      'layers' => $layers,
    );

    
    $map = openlayers_render_map($map_def);
        
    $processed = TRUE;
    return $map['themed'];
  }
  else{
    return false;
  }
}
?>