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

Commit

Permalink
Merge pull request #55 from GeneaLabs/revert-53-support-for-storging-…
Browse files Browse the repository at this point in the history
…point-in-geo-point-field

Revert "Support for storing point in geo point field"
  • Loading branch information
mikebronner committed May 31, 2021
2 parents a660691 + 112aed2 commit 4b95873
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 117 deletions.
19 changes: 0 additions & 19 deletions README.md
Expand Up @@ -43,25 +43,6 @@ MapMarker::make("Location")
->longitude('long'),
```

### Coordinate Field Types
By default the field will look for `latitude` and `longitude` fields on the
model. However, if your model uses a spatial field, you may identify the column type
and column name with `->fieldType('point')` and `->pointField('column_name')` methods:

```php
MapMarker::make("Location")
->fieldType('point')
->pointField('location'),
```
In order to use spatial columns in Laravel Nova, you must implement a Nova Action Resource Class in config/nova.php
```
'actions' => [
'resource' => \GeneaLabs\NovaMapMarkerField\Nova\Actions\ActionResource::class,
],
```



### 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
Expand Down
48 changes: 7 additions & 41 deletions src/MapMarker.php
@@ -1,6 +1,5 @@
<?php namespace GeneaLabs\NovaMapMarkerField;

use Illuminate\Support\Facades\DB;
use Laravel\Nova\Fields\Field;
use Laravel\Nova\Http\Requests\NovaRequest;

Expand All @@ -12,31 +11,14 @@ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttrib
{
if ($request->exists($requestAttribute)) {
$result = json_decode($request->{$requestAttribute}, false);
$fieldType = $this->meta['fieldType'] ?? 'coordinates';
switch ($fieldType) {
case 'point':
$model->{$this->getPointField()} = DB::raw(utf8_encode('ST_POINTFROMTEXT("POINT(' . $result->longitude . ' ' . $result->latitude . ')", ' . $this->getSrid() . ')'));
break;
default:
$model->{$result->latitude_field} = $this->isNullValue($result->latitude)
? null
: $result->latitude;
$model->{$result->longitude_field} = $this->isNullValue($result->longitude)
? null
: $result->longitude;
break;
}
}
}

public function getSrid()
{
return $this->meta["srid"] ?? "4326";
}

public function getPointField()
{
return $this->meta["pointField"] ?? "location";
$model->{$result->latitude_field} = $this->isNullValue($result->latitude)
? null
: $result->latitude;
$model->{$result->longitude_field} = $this->isNullValue($result->longitude)
? null
: $result->longitude;
}
}

public function getRules(NovaRequest $request)
Expand Down Expand Up @@ -106,22 +88,6 @@ public function latitude($field)
return $this->withMeta([__FUNCTION__ => $field]);
}

public function fieldType($field)
{
return $this->withMeta([__FUNCTION__ => $field]);
}


public function srid($srid)
{
return $this->withMeta([__FUNCTION__ => $srid]);
}

public function pointField($field)
{
return $this->withMeta([__FUNCTION__ => $field]);
}

public function longitude($field)
{
return $this->withMeta([__FUNCTION__ => $field]);
Expand Down
47 changes: 0 additions & 47 deletions src/Models/ActionEvent.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Nova/Actions/ActionResource.php

This file was deleted.

0 comments on commit 4b95873

Please sign in to comment.