diff --git a/backend/src/Entity/CoastalPoint.php b/backend/src/Entity/CoastalPoint.php index b106cdc..f32c82a 100644 --- a/backend/src/Entity/CoastalPoint.php +++ b/backend/src/Entity/CoastalPoint.php @@ -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; } diff --git a/frontend/src/components/Map/SargassesMap.jsx b/frontend/src/components/Map/SargassesMap.jsx index ae8e220..8ba7797 100644 --- a/frontend/src/components/Map/SargassesMap.jsx +++ b/frontend/src/components/Map/SargassesMap.jsx @@ -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 (