Skip to content

Commit

Permalink
[Options] Add default zoom and center options
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricewijnia committed Sep 10, 2020
1 parent ce026fe commit 239ffd6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,25 @@ protected $casts = [
The resulting data will have this format:
```
{
street_name: '',
street_number: '',
postal_code: '',
city: '',
country: '',
formatted_address: '',
latitude: '',
longitude: ''
street_name: string,
street_number: string,
postal_code: string,
city: string,
country: string,
formatted_address: string,
latitude: float,
longitude: float
}
```

## Options

You can change the default zoom and center options for the map.
```php
MapsAddress::make(__('Address'), 'address')
->zoom(5)
->center(['lat' => 55.5, 'lng' => 5.5]);
```



2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ export default {
this.map = new google.maps.Map(
document.getElementById('nova-maps-address-container'),
{
zoom: 9,
center: {lat: 52.370216, lng: 4.895168},
zoom: this.field.zoom,
center: {lat: this.field.center.lat, lng: this.field.center.lng},
mapTypeControl: false,
streetViewControl: false,
fullscreenControl: false,
Expand Down
30 changes: 29 additions & 1 deletion src/MapsAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct($name, $attribute = null, callable $resolveCallback
{
parent::__construct($name, $attribute, $resolveCallback);

$this->googleKey();
$this->googleKey()->zoom(10)->center(['lat' => 52.370216, 'lng' => 4.895168]);
}

/**
Expand All @@ -30,6 +30,34 @@ public function googleKey() {
]);
}

/**
* @param int $zoom
* @return MapsAddress
*/
public function zoom(int $zoom)
{
return $this->withMeta(['zoom' => $zoom]);
}

/**
* @param array $center
* @return MapsAddress
*/
public function center(array $center) {
if (isset($this->meta['center'])) {
$center = array_merge($this->meta['center'], $center);
}

return $this->withMeta(['center' => $center]);
}

/**
* @param NovaRequest $request
* @param string $requestAttribute
* @param object $model
* @param string $attribute
* @return mixed|void
*/
public function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute)
{
$model->setAttribute($attribute, json_decode($request->$attribute, true));
Expand Down

0 comments on commit 239ffd6

Please sign in to comment.