forked from fillerwriter/geofield
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeofield.module
More file actions
95 lines (83 loc) · 2.84 KB
/
geofield.module
File metadata and controls
95 lines (83 loc) · 2.84 KB
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
<?php
/**
* @TODO: Provide function/method to determine version.
*/
require_once('geofield.elements.inc');
/*require_once('geofield.widgets.inc');
require_once('geofield.formatters.inc');
require_once('geofield.openlayers.inc');
require_once('geofield.feeds.inc');
require_once('geofield.apachesolr.inc');
require_once('geofield.schemaorg.inc');
require_once('geofield.microdata.inc');*/
/* *
* 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_field_info().
*/
function geofield_field_info() {
return array(
'geofield' => array(
'label' => 'Geofield',
'description' => t('This field stores geo information.'),
'default_widget' => 'text_textfield',
'default_formatter' => 'text_plain',
'field item class' => 'Drupal\geofield\Type\GeofieldItem',
'settings' => array(
'backend' => 'default',
),
),
);
}
/**
* Implements hook_field_is_empty().
* @TODO: Handle empty geometries. (i.e., a WKT value of GEOMETRYCOLLECTION EMPTY)
*/
function geofield_field_is_empty($item, $field) {
return !isset($item['value']) || $item['value'] === '';
}
/**
* Implements hook_field_presave().
*/
function geofield_field_presave($entity, $field, $instance, $langcode, &$items) {
$geofield_name = $instance->definition['field_name'];
foreach ($items as $delta => $item) {
// @TODO: There must be a better way to do this. :-(
$f = $entity->get($geofield_name);
$items[$delta]['geo_type'] = $entity->get($geofield_name)->offsetGet($delta)->get('geo_type')->getValue();
$items[$delta]['lat'] = $entity->get($geofield_name)->offsetGet($delta)->get('lat')->getValue();
$items[$delta]['lon'] = $entity->get($geofield_name)->offsetGet($delta)->get('lon')->getValue();
$items[$delta]['left'] = $entity->get($geofield_name)->offsetGet($delta)->get('left')->getValue();
$items[$delta]['top'] = $entity->get($geofield_name)->offsetGet($delta)->get('top')->getValue();
$items[$delta]['right'] = $entity->get($geofield_name)->offsetGet($delta)->get('right')->getValue();
$items[$delta]['bottom'] = $entity->get($geofield_name)->offsetGet($delta)->get('bottom')->getValue();
$items[$delta]['geohash'] = $entity->get($geofield_name)->offsetGet($delta)->get('geohash')->getValue();
}
watchdog('geofield', 'Sanity check - geofield.module line 51');
}