Skip to content

Commit 399d844

Browse files
committed
Altered way data is sent to Nova - fix
1 parent 82ca1b8 commit 399d844

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

dist/js/field.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -779,16 +779,10 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
779779

780780
computed: {
781781
geojson: function geojson() {
782-
if (this.type == "LatLon") {
782+
if (this.type == "LatLon" || this.type == "LatLonField") {
783783
return {
784784
type: 'Point',
785-
coordinates: [this.value[this.longitude_field], this.value[this.latitude_field]]
786-
};
787-
} else if (this.type == "LatLonField") {
788-
var coords = this.value.split(/[ ,]+/).filter(Boolean);
789-
return {
790-
type: 'Point',
791-
coordinates: [coords[1], coords[0]]
785+
coordinates: [this.value.lon, this.value.lat]
792786
};
793787
} else if (this.type == "GeoJSON") {
794788
return JSON.parse(this.value);

resources/js/components/MapDetail.vue

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,12 @@ export default {
8989
},
9090
computed: {
9191
geojson(){
92-
if(this.type == "LatLon"){
92+
if(this.type == "LatLon" || this.type == "LatLonField"){
9393
return {
9494
type: 'Point',
9595
coordinates: [
96-
this.value[this.longitude_field],
97-
this.value[this.latitude_field],
98-
]
99-
}
100-
}else if(this.type == "LatLonField"){
101-
let coords = this.value.split(/[ ,]+/).filter(Boolean);
102-
return {
103-
type: 'Point',
104-
coordinates: [
105-
coords[1],
106-
coords[0]
96+
this.value.lon,
97+
this.value.lat,
10798
]
10899
}
109100
}else if(this.type == "GeoJSON"){

src/Map.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function spatialType($type){
2727
}
2828

2929
public function latitude($latitude_field){
30-
3130
$this->attribute = null;
3231

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

3837
public function longitude($longitude_field){
3938
$this->attribute = null;
40-
39+
4140
return $this->withMeta([
4241
'longitude_field' => $longitude_field
4342
]);
@@ -51,6 +50,33 @@ public function geojson($geojson_field){
5150
]);
5251
}
5352

53+
public function resolveAttribute($resource, $attribute = null){
54+
switch($this->meta['spatialType']){
55+
case 'LatLon':
56+
return [
57+
'lat' => $resource->{$this->meta['latitude_field']},
58+
'lon' => $resource->{$this->meta['longitude_field']},
59+
];
60+
break;
61+
case 'LatLonField':
62+
$parts = collect(explode(',',$resource->{$attribute}))->map(function($item){
63+
return trim($item);
64+
});
65+
66+
return [
67+
'lat' => $parts[0],
68+
'lon' => $parts[1],
69+
];
70+
break;
71+
case 'GeoJSON':
72+
return $resource->{$attribute};
73+
break;
74+
default:
75+
return $resource->{$attribute};
76+
break;
77+
}
78+
}
79+
5480
// protected function fillAttributeFromRequest(NovaRequest $request,
5581
// $requestAttribute,
5682
// $model,

0 commit comments

Comments
 (0)