Skip to content

Commit d4c08f9

Browse files
committed
Some GeoJSON fixes
1 parent 7ee0a96 commit d4c08f9

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/Tqdev/PhpCrudApi/GeoJson/Feature.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Feature implements \JsonSerializable
66
private $properties;
77
private $geometry;
88

9-
public function __construct(array $properties, Geometry $geometry)
9+
public function __construct(array $properties, /*?Geometry*/ $geometry)
1010
{
1111
$this->properties = $properties;
1212
$this->geometry = $geometry;

src/Tqdev/PhpCrudApi/GeoJson/GeoJsonService.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ private function getGeometryColumnName(string $tableName, string $geometryParam)
4343

4444
private function convertRecordToFeature( /*object*/$record, string $geometryColumnName)
4545
{
46-
$geometry = Geometry::fromWkt($record[$geometryColumnName]);
47-
unset($record[$geometryColumnName]);
48-
return new Feature($record, $geometry);
46+
$geometry = null;
47+
if (isset($record[$geometryColumnName])) {
48+
$geometry = Geometry::fromWkt($record[$geometryColumnName]);
49+
}
50+
$properties = array_diff_key($record, [$geometryColumnName => true]);
51+
return new Feature($properties, $geometry);
4952
}
5053

5154
public function _list(string $tableName, array $params): FeatureCollection
@@ -63,15 +66,11 @@ public function _list(string $tableName, array $params): FeatureCollection
6366
return new FeatureCollection($features);
6467
}
6568

66-
public function read(string $tableName, string $id, array $params) /*: ?Feature*/
69+
public function read(string $tableName, string $id, array $params): Feature
6770
{
6871
$geometryParam = isset($params['geometry']) ? $params['geometry'] : '';
6972
$geometryColumnName = $this->getGeometryColumnName($tableName, $geometryParam);
7073
$record = $this->records->read($tableName, $id, $params);
71-
if (!isset($record[$geometryColumnName])) {
72-
print_r($record);
73-
return null;
74-
}
7574
return $this->convertRecordToFeature($record, $geometryColumnName);
7675
}
7776
}

0 commit comments

Comments
 (0)