openlayers_layers_process_geo_data_layers

openlayers/modules/openlayers_layers/includes/openlayers_layers.layers.inc, line 320

Versions
6
openlayers_layers_process_geo_data_layers($layer = NULL)

Speicifc Layer Callback for Geo Table Layers

This function handles the speicifc layer handling of layers enabled for Geo tables

Parameters

$layer Array of data passed by rendering

Return value

Layer data

Code

<?php
function openlayers_layers_process_geo_data_layers($layer = NULL) {
  // Get table description
  $table_desc = geo('table_desc', $layer);
  $attribute_cols = array();
  // Go through columns
  foreach ($table_desc as $cname => $cinfo){
    if ($cinfo['type'] == 'geometry'){
      $geometry_col = $cname;
      $srid = $cinfo['srid'];
    }
    else {
      $attribute_cols[] = $cname;
    }
  }
  
  // Get geometry text
  $query = "SELECT asText(%s) as %s, ". implode(',', $attribute_cols) ." from {%s}";
  $res = db_query($query, $geometry_col, $geometry_col, $layer);
  $features = array();
  // Go through results
  while ($row = db_fetch_array($res)){
    $attributes = array();
    foreach ($attribute_cols as $attr_name){
      $attr_val = $row[$attr_name];
      $attributes[$attr_name] = $attr_val;
    }
    // Put together features
    $features[] = array(
      'wkt' => $row[$geometry_col],
      'attributes' => $attributes,
      'projection' => $srid,
    );
  }
  
  // Create layer data array
  $layer_data = array(
    'id' => $layer,
    'type' => 'Vector',
    'name' => $layer,
    'features' => $features,
  );
  return $layer_data;
}
?>