Skip to content

Commit 45bb6f1

Browse files
committed
Add the possibility to define map center without default lat/lng values
1 parent 06fdaa0 commit 45bb6f1

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

_config/googlemapfield.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ BetterBrief\GoogleMapField:
1616
default_field_values:
1717
Latitude: 30
1818
Longitude: 0
19+
center:
20+
Latitude: 30
21+
Longitude: 0

client/js/GoogleMapField.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
field.data('gmapfield-inited', true);
1616
var settings = JSON.parse(field.attr('data-settings')),
17-
centre = new google.maps.LatLng(settings.coords[0], settings.coords[1]),
17+
centre = new google.maps.LatLng(settings.center[0], settings.center[1]),
1818
mapSettings = {
1919
streetViewControl: false,
2020
zoom: settings.map.zoom * 1,

src/GoogleMapField.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ public function Field($properties = array()) {
155155
$this->recordFieldData('Latitude'),
156156
$this->recordFieldData('Longitude')
157157
),
158+
'center' => array(
159+
$this->getLatData() ?: $this->getOption('center.Latitude'),
160+
$this->getLngData() ?: $this->getOption('center.Longitude'),
161+
),
158162
'map' => array(
159163
'zoom' => $this->recordFieldData('Zoom') ?: $this->getOption('map.zoom'),
160164
'mapTypeId' => 'ROADMAP',
@@ -242,15 +246,15 @@ public function getDefaultValue($name) {
242246
*/
243247
public function getLatData() {
244248
$fieldNames = $this->getOption('field_names');
245-
return $this->data->$fieldNames['Latitude'];
249+
return $this->data->{$fieldNames['Latitude']};
246250
}
247251

248252
/**
249253
* @return string The VALUE of the Longitude field
250254
*/
251255
public function getLngData() {
252256
$fieldNames = $this->getOption('field_names');
253-
return $this->data->$fieldNames['Longitude'];
257+
return $this->data->{$fieldNames['Longitude']};
254258
}
255259

256260
/**

0 commit comments

Comments
 (0)