You are here

function _geofield_formatter_get_info in Geofield 7

Same name and namespace in other branches
  1. 7.2 geofield.formatters.inc \_geofield_formatter_get_info()
2 calls to _geofield_formatter_get_info()
_geofield_def_list_formatter in ./geofield.formatters.inc
_geofield_description_formatter in ./geofield.formatters.inc

File

./geofield.formatters.inc, line 439
Drupal field formatter hooks and helper functions.

Code

function _geofield_formatter_get_info($geometry, $centroid, $address = FALSE, $units = 'degrees') {
  $info = array(
    'latitude' => $centroid
      ->y(),
    'longitude' => $centroid
      ->x(),
  );

  // Get the shape
  if ($geometry
    ->geometryType() == 'Point') {
    $info['shape'] = 'Point';
  }
  if ($geometry
    ->geometryType() == 'LineString') {
    $info['shape'] = 'Line';
  }
  if ($geometry
    ->geometryType() == 'Polygon') {

    //@@TODO: Get more useful information like 'Triangle', 'Square', 'Rectangle', 'Pentagon'
    $info['shape'] = 'Polygon';
  }
  if ($address) {
    $info['address'] = $centroid
      ->out('google_geocode');
  }

  //@@TODO, convert length and area to proper units

  #if ($geometry->geometryType() == 'LineString') {

  #  $info['length'] = $geometry->length();

  #}

  #if ($geometry->geometryType() == 'Polygon') {

  #  $info['area'] = $geometry->area();

  #}
  return $info;
}