fix: expose lat/lng from CoastalPoint, fix getCoords in map

This commit is contained in:
Gwadaking
2026-04-01 22:37:14 -04:00
parent 15079ea7b4
commit 1485339aec
2 changed files with 22 additions and 4 deletions

View File

@@ -31,6 +31,7 @@ class CoastalPoint
#[ORM\Column(type: UuidType::NAME, unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
#[Groups(['spot:read'])]
private ?Uuid $id = null;
#[ORM\Column(length: 150)]
@@ -38,7 +39,6 @@ class CoastalPoint
private ?string $name = null;
#[ORM\Column(type: 'geometry', options: ['geometry_type' => 'POINT', 'srid' => 4326])]
#[Groups(['spot:read'])]
private mixed $geometry = null;
#[ORM\Column(length: 30)]
@@ -66,6 +66,22 @@ class CoastalPoint
public function setName(string $name): static { $this->name = $name; return $this; }
public function getGeometry(): mixed { return $this->geometry; }
public function setGeometry(mixed $geometry): static { $this->geometry = $geometry; return $this; }
#[Groups(['spot:read'])]
public function getLongitude(): ?float
{
if ($this->geometry === null) return null;
preg_match('/POINT\(([^ ]+) /', (string) $this->geometry, $m);
return isset($m[1]) ? (float) $m[1] : null;
}
#[Groups(['spot:read'])]
public function getLatitude(): ?float
{
if ($this->geometry === null) return null;
preg_match('/POINT\([^ ]+ ([^)]+)\)/', (string) $this->geometry, $m);
return isset($m[1]) ? (float) $m[1] : null;
}
public function getType(): ?string { return $this->type; }
public function setType(string $type): static { $this->type = $type; return $this; }
public function getRegion(): ?string { return $this->region; }

View File

@@ -43,7 +43,7 @@ export default function SargassesMap({ onSpotSelect, selectedSpotId, activeStep
// Spots côtiers : chargement unique
useEffect(() => {
api.spots.list()
.then(data => setSpots(data['hydra:member'] ?? data.member ?? []))
.then(data => setSpots(Array.isArray(data) ? data : (data['hydra:member'] ?? data.member ?? [])))
.catch(console.error);
}, []);
@@ -83,8 +83,10 @@ export default function SargassesMap({ onSpotSelect, selectedSpotId, activeStep
};
const getCoords = (spot) => {
const c = spot.geometry?.coordinates;
return c ? { lng: c[0], lat: c[1] } : null;
if (spot.longitude != null && spot.latitude != null) {
return { lng: spot.longitude, lat: spot.latitude };
}
return null;
};
return (