Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from Ercogx/feature/add-possibility-to-change-s…
Browse files Browse the repository at this point in the history
…rid-for-point

Add possibility to change srid for Point type
  • Loading branch information
Traineratwot authored Jun 17, 2024
2 parents 9ac91cf + 47b8ca1 commit 3b43a88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class MapPointResource extends Resource
->schema([
MapInput::make('point')
->saveAsPoint() // Important for Point type
->srid(4326) // Change srid for Point
->placeholder('Choose your location')
->coordinates(37.619, 55.7527) // start coordinates
->rows(10) // height of map
Expand Down
11 changes: 10 additions & 1 deletion src/Forms/Components/MapInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class MapInput extends Textarea
*/
public string $saveAs = 'String';

private int $srid = 0;

private Closure|int|float $zoom = 10;

/**
Expand Down Expand Up @@ -54,7 +56,7 @@ protected function setUp(): void
$value = $component->parseInput($state);
switch ($component->saveAs) {
case 'Point':
return new Point($value['latitude'], $value['longitude']);
return new Point($value['latitude'], $value['longitude'], $component->srid);
break;
case 'Array':
return [$value['latitude'], $value['longitude']];
Expand Down Expand Up @@ -90,6 +92,13 @@ public function saveAsArray(): static
return $this;
}

public function srid(int $srid): static
{
$this->srid = $srid;

return $this;
}

protected function parseInput(mixed $state): array
{
$validator = Validator::make([
Expand Down

0 comments on commit 3b43a88

Please sign in to comment.