Skip to content

Commit

Permalink
Altered way data is sent to Nova - fix
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpiesse committed Sep 26, 2018
1 parent 82ca1b8 commit 399d844
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
10 changes: 2 additions & 8 deletions dist/js/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,16 +779,10 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });

computed: {
geojson: function geojson() {
if (this.type == "LatLon") {
if (this.type == "LatLon" || this.type == "LatLonField") {
return {
type: 'Point',
coordinates: [this.value[this.longitude_field], this.value[this.latitude_field]]
};
} else if (this.type == "LatLonField") {
var coords = this.value.split(/[ ,]+/).filter(Boolean);
return {
type: 'Point',
coordinates: [coords[1], coords[0]]
coordinates: [this.value.lon, this.value.lat]
};
} else if (this.type == "GeoJSON") {
return JSON.parse(this.value);
Expand Down
15 changes: 3 additions & 12 deletions resources/js/components/MapDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,12 @@ export default {
},
computed: {
geojson(){
if(this.type == "LatLon"){
if(this.type == "LatLon" || this.type == "LatLonField"){
return {
type: 'Point',
coordinates: [
this.value[this.longitude_field],
this.value[this.latitude_field],
]
}
}else if(this.type == "LatLonField"){
let coords = this.value.split(/[ ,]+/).filter(Boolean);
return {
type: 'Point',
coordinates: [
coords[1],
coords[0]
this.value.lon,
this.value.lat,
]
}
}else if(this.type == "GeoJSON"){
Expand Down
30 changes: 28 additions & 2 deletions src/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public function spatialType($type){
}

public function latitude($latitude_field){

$this->attribute = null;

return $this->withMeta([
Expand All @@ -37,7 +36,7 @@ public function latitude($latitude_field){

public function longitude($longitude_field){
$this->attribute = null;

return $this->withMeta([
'longitude_field' => $longitude_field
]);
Expand All @@ -51,6 +50,33 @@ public function geojson($geojson_field){
]);
}

public function resolveAttribute($resource, $attribute = null){
switch($this->meta['spatialType']){
case 'LatLon':
return [
'lat' => $resource->{$this->meta['latitude_field']},
'lon' => $resource->{$this->meta['longitude_field']},
];
break;
case 'LatLonField':
$parts = collect(explode(',',$resource->{$attribute}))->map(function($item){
return trim($item);
});

return [
'lat' => $parts[0],
'lon' => $parts[1],
];
break;
case 'GeoJSON':
return $resource->{$attribute};
break;
default:
return $resource->{$attribute};
break;
}
}

// protected function fillAttributeFromRequest(NovaRequest $request,
// $requestAttribute,
// $model,
Expand Down

0 comments on commit 399d844

Please sign in to comment.