1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class LatLongField extends FieldGroup |
4
|
|
|
{ |
5
|
|
|
protected $latField; |
6
|
|
|
|
7
|
|
|
protected $longField; |
8
|
|
|
|
9
|
|
|
protected $zoomField; |
10
|
|
|
|
11
|
|
|
protected $buttonText; |
12
|
|
|
|
13
|
|
|
private $guidePoints = null; |
14
|
|
|
|
15
|
|
|
private static $ctr = 0; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param string[] $buttonText |
19
|
|
|
*/ |
20
|
8 |
|
public function __construct($children = array(), $buttonText = null) |
21
|
|
|
{ |
22
|
8 |
|
++self::$ctr; |
23
|
|
|
|
24
|
8 |
|
if ((sizeof($children) < 2) || (sizeof($children) > 3) || |
25
|
7 |
|
(!$children[0] instanceof FormField) || |
26
|
7 |
|
(!$children[1] instanceof FormField) |
27
|
8 |
|
) { |
28
|
1 |
|
user_error('LatLongField argument 1 must be an array containing at least two FormField '. |
29
|
1 |
|
'objects for Lat/Long values, respectively.', E_USER_ERROR); |
30
|
|
|
} |
31
|
|
|
|
32
|
7 |
|
parent::__construct($children); |
33
|
|
|
|
34
|
7 |
|
$this->buttonText = $buttonText ? $buttonText : _t('LatLongField.LOOKUP', 'Search'); |
35
|
7 |
|
$this->latField = $children[0]->getName(); |
36
|
7 |
|
$this->longField = $children[1]->getName(); |
37
|
|
|
|
38
|
7 |
|
if (sizeof($children) == 3) { |
39
|
6 |
|
$this->zoomField = $children[2]->getName(); |
40
|
6 |
|
} |
41
|
7 |
|
$name = ''; |
42
|
7 |
|
foreach ($children as $field) { |
43
|
7 |
|
$name .= $field->getName(); |
44
|
7 |
|
} |
45
|
|
|
|
46
|
|
|
// hide the lat long and zoom fields from the interface |
47
|
7 |
|
foreach ($this->FieldList() as $fieldToHide) { |
48
|
7 |
|
$fieldToHide->addExtraClass('hide'); |
49
|
7 |
|
} |
50
|
|
|
|
51
|
7 |
|
$this->name = $name; |
52
|
7 |
|
} |
53
|
|
|
|
54
|
3 |
|
public function FieldHolder($properties = array()) |
|
|
|
|
55
|
|
|
{ |
56
|
3 |
|
Requirements::javascript(THIRDPARTY_DIR.'/jquery/jquery.js'); |
57
|
3 |
|
Requirements::javascript(THIRDPARTY_DIR.'/jquery-livequery/jquery.livequery.js'); |
58
|
3 |
|
Requirements::javascript(THIRDPARTY_DIR.'/jquery-metadata/jquery.metadata.js'); |
59
|
3 |
|
Requirements::javascript(MAPPABLE_MODULE_PATH.'/javascript/mapField.js'); |
60
|
|
|
|
61
|
|
|
$attributes = array( |
62
|
3 |
|
'class' => 'editableMap', |
63
|
3 |
|
'id' => 'GoogleMap', |
64
|
3 |
|
'data-LatFieldName' => $this->latField, |
65
|
3 |
|
'data-LonFieldName' => $this->longField, |
66
|
3 |
|
'data-ZoomFieldName' => $this->zoomField, |
67
|
3 |
|
'data-UseMapBounds' => false, |
68
|
3 |
|
); |
69
|
|
|
|
70
|
3 |
|
Requirements::css('mappable/css/mapField.css'); |
71
|
|
|
|
72
|
|
|
// check for and if required add guide points |
73
|
3 |
|
if (!empty($this->guidePoints)) { |
74
|
1 |
|
$latlongps = array(); |
75
|
|
|
|
76
|
1 |
|
foreach ($this->guidePoints as $guidepoint) { |
77
|
1 |
|
array_push($latlongps, $guidepoint); |
78
|
1 |
|
} |
79
|
|
|
|
80
|
1 |
|
$guidePointsJSON = json_encode($latlongps); |
81
|
|
|
// convert the mappable guidepoints to lat lon |
82
|
|
|
|
83
|
1 |
|
$attributes['data-GuidePoints'] = $guidePointsJSON; |
84
|
|
|
|
85
|
|
|
// we only wish to change the bounds to those of all the points iff |
86
|
|
|
// the item currently has no location |
87
|
1 |
|
$attributes['data-useMapBounds'] = true; |
88
|
1 |
|
} |
89
|
3 |
|
$content = '<div class="editableMapWrapper">'.$this->create_tag( |
90
|
3 |
|
'div', |
91
|
|
|
$attributes |
92
|
3 |
|
).'</div>'; |
93
|
|
|
|
94
|
3 |
|
$this->FieldList()->push(new LiteralField('locationEditor', $content)); |
95
|
|
|
|
96
|
|
|
$content2 = <<<HTML |
97
|
|
|
<div id="mapSearch"> |
98
|
|
|
<input name="location_search" id="location_search" size=80/> |
99
|
|
|
<button class="action" id="searchLocationButton">Search Location Name</button> |
100
|
|
|
<div id="mapSearchResults"> |
101
|
|
|
</div> |
102
|
|
|
</div> |
103
|
3 |
|
HTML; |
104
|
|
|
|
105
|
3 |
|
$this->FieldList()->push(new LiteralField('mapSearch', $content2)); |
106
|
|
|
|
107
|
3 |
|
return parent::FieldHolder(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/* |
111
|
|
|
Set guidance points for the map being edited. For example in a photographic set show the map |
112
|
|
|
position of some other images so that subsequent photo edits do not start with a map centred |
113
|
|
|
at the origin |
114
|
|
|
|
115
|
|
|
@var newGuidePoints array of points expressed as associative arrays containing keys latitude |
116
|
|
|
and longitude mapping to geographical locations |
117
|
|
|
*/ |
118
|
1 |
|
public function setGuidePoints($newGuidePoints) |
119
|
|
|
{ |
120
|
1 |
|
$this->guidePoints = $newGuidePoints; |
121
|
1 |
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Accessor to guidepoints. For testing purposes. |
125
|
|
|
* |
126
|
|
|
* @return array guidepoints |
127
|
|
|
*/ |
128
|
|
|
public function getGuidePoints() |
129
|
|
|
{ |
130
|
|
|
return $this->guidePoints; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|