<?php
define(GEO_SRID_DEFAULT, 4326);
define(GEO_DEGREE_M, 111206);
function geo($op = NULL) {
static $backend;
module_load_include('inc', 'geo');
if (!isset($backend)) {
$backend = geo_backend_type();
module_load_include('inc', 'geo', 'db/'. $backend);
}
$args = func_get_args();
if($args) {
$op = array_shift($args);
if (!function_exists($func = 'geo_'. $backend .'_'. $op)) {
$func = 'geo_'. $op;
}
if (!function_exists($func)) {
drupal_set_message(t('Call to undefined geo operation %op', array('%op' => $op)), 'error');
return FALSE;
}
return call_user_func_array($func, $args);
}
}
function geo_theme() {
$file_path = drupal_get_path('module', 'geo') .'/includes';
return array(
'geo_formatter_default' => array(
'arguments' => array('element' => NULL),
'file' => 'geo.formatters.inc',
'path' => $file_path,
),
'geo_formatter_lat' => array(
'arguments' => array('element' => NULL),
'file' => 'geo.formatters.inc',
'path' => $file_path,
),
'geo_formatter_lon' => array(
'arguments' => array('element' => NULL),
'file' => 'geo.formatters.inc',
'path' => $file_path,
),
'geo_formatter_georss' => array(
'arguments' => array('element' => NULL),
'file' => 'geo.formatters.inc',
'path' => $file_path,
),
'geo_formatter_svg' => array(
'arguments' => array('element' => NULL),
'file' => 'geo.formatters.inc',
'path' => $file_path,
),
);
}
function geo_field_formatter_info() {
return array(
'default' => array(
'label' => t('Well Known Text'),
'field types' => geo_field_types(),
),
'lat' => array(
'label' => t('Latitude'),
'field types' => geo_field_types(),
),
'lon' => array(
'label' => t('Longitude'),
'field types' => geo_field_types(),
),
'georss' => array(
'label' => t('GeoRSS'),
'field types' => geo_field_types(),
),
);
}
function geo_field_types() {
static $field_types;
if (!isset($field_types)) {
$field_types = array('geo', 'geo_data');
drupal_alter('geo_field_types', $field_types);
}
return $field_types;
}
function geo_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'geo') .'/includes/views',
);
}
function geo_wkb_get_data($wkb = NULL, $format = 'text', $fp = NULL, $type = NULL) {
module_load_include('inc', 'geo', 'includes/geo.wkb');
return _geo_wkb_get_data($wkb, $format, $fp, $type);
}
function geo_units($unit = NULL) {
$units = array(
'mi' => t('Miles'),
'km' => t('Kilometers'),
'm' => t('Meters'),
);
return $unit ? $units[$unit] : $units;
}
function geo_unit_convert($val, $from_unit, $to_unit) {
switch ($from_unit) {
case 'm': switch ($to_unit) {
case 'km':
$val = $val / 1000;
break;
case 'mi':
$val = $val / 1609.344;
break;
}
break;
case 'km': switch ($to_unit) {
case 'm':
$val = $val * 1000;
break;
case 'mi':
$val = $val * 0.62137;
break;
}
break;
case 'mi': switch ($to_unit) {
case 'm':
$val = $val * 1609.344;
break;
case 'km':
$val = $val * 1.60934;
break;
}
break;
}
return $val;
}