Skip to content

Commit e8eb218

Browse files
committed
Merge pull request BetterBrief#14 from jedateach/master
New google maps endpoint, optional API key, allow frontend usage, make search box optional, add installer name
2 parents 50683c2 + 4c6297c commit e8eb218

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

code/GoogleMapField.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class GoogleMapField extends FormField {
1414
'lat' => 'Lat',
1515
'lng' => 'Lng',
1616
),
17+
'showSearchBox' => true,
18+
'apikey' => null,
1719
),
1820
$js_inserted = false;
1921

@@ -46,8 +48,9 @@ public function __construct(DataObject $data, $title, $options = array()) {
4648
}
4749

4850
public function Field($properties = array()) {
51+
$key = $this->options['apikey'] ? "&key=".$this->options['apikey'] : "";
4952
Requirements::javascript(GOOGLEMAPFIELD_BASE .'/javascript/GoogleMapField.js');
50-
Requirements::javascript('//google.com/maps/api/js?sensor=false&callback=googlemapfieldInit');
53+
Requirements::javascript("//maps.googleapis.com/maps/api/js?callback=googlemapfieldInit".$key);
5154
Requirements::css(GOOGLEMAPFIELD_BASE .'/css/GoogleMapField.css');
5255
$jsOptions = array(
5356
'coords' => array($this->getLatData(), $this->getLngData()),
@@ -56,9 +59,12 @@ public function Field($properties = array()) {
5659
'mapTypeId' => 'ROADMAP',
5760
),
5861
);
59-
62+
if(!$this->options['showSearchBox']){
63+
$this->children->removeByName("Search");
64+
}
6065
$jsOptions = array_replace_recursive($jsOptions, $this->options);
6166
$this->setAttribute('data-settings', Convert::array2json($jsOptions));
67+
6268
return parent::Field($properties);
6369
}
6470

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
}
1414
],
1515
"require": {
16-
"php": ">=5.3.0"
16+
"php": ">=5.3.0",
17+
"composer/installers": "~1.0"
18+
},
19+
"extra" : {
20+
"installer-name": "googlemapfield"
1721
}
1822
}

javascript/GoogleMapField.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,16 @@
107107
}
108108

109109
// Set the init method to re-run if the page is saved or pjaxed
110-
$.entwine('ss', function($) {
111-
$('.googlemapfield').entwine({
112-
onmatch: function() {
113-
if(gmapsAPILoaded) {
114-
init();
110+
if($.entwine){
111+
$.entwine('ss', function($) {
112+
$('.googlemapfield').entwine({
113+
onmatch: function() {
114+
if(gmapsAPILoaded) {
115+
init();
116+
}
115117
}
116-
}
118+
});
117119
});
118-
});
120+
}
119121

120122
}(jQuery));

0 commit comments

Comments
 (0)