Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

Commit

Permalink
Add default zoom, coordinate settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner committed Aug 23, 2019
1 parent c1944cc commit 4745e45
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.1.9] - 2019-08-02
### Added
- default Zoom, Lat, Long settings.

## [0.1.8] - 2019-08-02
### Fixed
- display or validation errors.
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,21 @@ the `->latitude('lat')` and `->longitude('long')` methods:
```php
MapMarker::make("Location")
->latitude('lat')
->longitude('long'),
->longitude('long')
->defaultZoom(8)
->defaultLatitude(41.823611)
->defaultLongitude(-71.422222),
```

### Default Settings
You can specify default settings for zoom level, and initial map center
coordinates. If not specified, the zoom level will default to 12; the
coordinates will default to (0, 0).
```php
MapMarker::make("Location")
->defaultZoom(8)
->defaultLatitude(41.823611)
->defaultLongitude(-71.422222),
```

### Search Provider
Expand Down
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

18 changes: 5 additions & 13 deletions resources/js/components/DetailField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export default {
},
computed: {
defaultZoom: function () {
return this.field.defaultZoom || 12;
},
locationIsSet: function () {
if (this.value.latitude === undefined) {
this.setInitialValue();
Expand All @@ -67,18 +71,6 @@ export default {
this.value.longitude,
];
},
zoom: function () {
if (this.value.latitude === undefined) {
this.setInitialValue();
}
if (! this.value.latitude) {
return 4;
}
return 16;
}
},
methods: {
Expand Down Expand Up @@ -123,7 +115,7 @@ export default {
ref="map"
:center="mapCenter"
:options="mapOptions"
:zoom="zoom"
:zoom="defaultZoom"
@move="mapMoved"
>
<l-tile-layer
Expand Down
30 changes: 15 additions & 15 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ export default {
},
computed: {
defaultLatitude: function () {
return this.field.defaultLatitude || 0;
},
defaultLongitude: function () {
return this.field.defaultLongitude || 0;
},
defaultZoom: function () {
return this.field.defaultZoom || 12;
},
firstLocationError: function () {
if (this.hasLocationError) {
return (this.errors.first(this.latitudeFieldName)
Expand Down Expand Up @@ -104,22 +116,10 @@ export default {
}
return [
this.value.latitude,
this.value.longitude,
this.value.latitude || this.defaultLatitude,
this.value.longitude || this.defaultLongitude,
];
},
zoom: function () {
if (this.value.latitude === undefined) {
this.setInitialValue();
}
if (! this.value.latitude) {
return 4;
}
return 18;
}
},
methods: {
Expand Down Expand Up @@ -165,7 +165,7 @@ export default {
ref="map"
:center="mapCenter"
:options="mapOptions"
:zoom="zoom"
:zoom="defaultZoom"
@move="mapMoved"
>
<l-tile-layer
Expand Down
33 changes: 33 additions & 0 deletions src/MapMarker.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,39 @@ public function longitude($field)
return $this->withMeta([__FUNCTION__ => $field]);
}

public function defaultLatitude($field)
{
if (! is_array($this->attribute)) {
$this->attribute = [];
}

$this->attribute["default_latitude"] = $field;

return $this->withMeta([__FUNCTION__ => $field]);
}

public function defaultLongitude($field)
{
if (! is_array($this->attribute)) {
$this->attribute = [];
}

$this->attribute["default_longitude"] = $field;

return $this->withMeta([__FUNCTION__ => $field]);
}

public function defaultZoom($field)
{
if (! is_array($this->attribute)) {
$this->attribute = [];
}

$this->attribute["default_zoom"] = $field;

return $this->withMeta([__FUNCTION__ => $field]);
}

// public function markerIcon(string $url)
// {
// return $this->withMeta([__FUNCTION__ => $url]);
Expand Down

0 comments on commit 4745e45

Please sign in to comment.