-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeofield.module
145 lines (119 loc) · 3.08 KB
/
geofield.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* @TODO: Provide function/method to determine version.
*/
use Drupal\Core\Template\Attribute;
/**
* Point feature constant.
*
* @var string
*/
define('GEOFIELD_TYPE_POINT', 'POINT');
/**
* Multipoint feature constant.
*
* @var string
*/
define('GEOFIELD_TYPE_MULTIPOINT', 'MULTIPOINT');
/**
* Linestring feature constant.
*
* @var string
*/
define('GEOFIELD_TYPE_LINESTRING', 'LINESTRING');
/**
* Multilinestring feature constant.
*
* @var string
*/
define('GEOFIELD_TYPE_MULTILINESTRING' , 'MULTILINESTRING');
/**
* Polygon feature constant.
*
* @var string
*/
define('GEOFIELD_TYPE_POLYGON', 'POLYGON');
/**
* Multipolygon feature constant.
*
* @var string
*/
define('GEOFIELD_TYPE_MULTIPOLYGON', 'MULTIPOLYGON');
/* *
* Max length of geohashes (imposed by database column length).
*/
define('GEOFIELD_GEOHASH_LENGTH', 16);
/**
* Diameter of the Earth in kilometers.
*/
define('GEOFIELD_KILOMETERS', 6371);
/**
* Diameter of the Earth in meters.
*/
define('GEOFIELD_METERS', 6371000);
/**
* Diameter of the Earth in miles.
*/
define('GEOFIELD_MILES', 3959);
/**
* Diameter of the Earth in yards.
*/
define('GEOFIELD_YARDS', 6975175);
/**
* Diameter of the Earth in feet.
*/
define('GEOFIELD_FEET', 20925525);
/**
* Diameter of the Earth in nautical miles.
*/
define('GEOFIELD_NAUTICAL_MILES', 3444);
/**
* Implements hook_theme().
*/
function geofield_theme() {
return array(
'geofield_proximity' => array(
'render element' => 'element',
),
);
}
/**
* Returns options for radius of the Earth.
*/
function geofield_radius_options() {
return array(
GEOFIELD_KILOMETERS => t('Kilometers'),
GEOFIELD_METERS => t('Meters'),
GEOFIELD_MILES => t('Miles'),
GEOFIELD_YARDS => t('Yards'),
GEOFIELD_FEET => t('Feet'),
GEOFIELD_NAUTICAL_MILES => t('Nautical Miles'),
);
}
function geofield_haversine($options = array()) {
$formula = '( :earth_radius * ACOS( COS( RADIANS(:origin_latitude) ) * COS( RADIANS(:destination_latitude) ) * COS( RADIANS(:destination_longitude) - RADIANS(:origin_longitude) ) + SIN( RADIANS(:origin_latitude) ) * SIN( RADIANS(:destination_latitude) ) ) )';
foreach ($options as $key => $option) {
if (is_numeric($option)) {
$formula = str_replace(':' . $key, $option, $formula);
}
else {
$formula = str_replace(':' . $key, db_escape_field($option), $formula);
}
}
return $formula;
}
/**
* Theme wrapper for form item
*/
function theme_geofield_proximity($vars) {
$element = $vars['element'];
$attributes = !empty($element['#wrapper_attributes']) ? $element['#wrapper_attributes'] : array('class' => array());
$attributes['class'][] = 'geofield-proximity-field-wrapper';
$attributes['class'][] = 'clearfix';
$wrapper_attributes = array();
$wrapper_attributes['class'][] = 'clearfix';
if (isset($element['#children']))
$element['#children'] = '<div id="' . $element['#id'] . '" ' . new Attribute($wrapper_attributes) . '>' . $element['#children'] . '</div>';
$output = '<div ' . new Attribute($attributes) . '>' . render($vars) . '</div>';
return $output;
}