Skip to content

Commit f1cfb3c

Browse files
committed
Some GeoJSON fixes
1 parent 04f78b8 commit f1cfb3c

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ The GeoJSON support is a read-only view on the tables and records in GeoJSON for
621621

622622
The "`/geojson`" endpoint uses the "`/records`" endpoint internally and inherits all functionality, such as joins and filters.
623623
It also supports a "geometry" parameter to indicate the name of the geometry column in case the table has more than one of them.
624+
For map views it supports the "bbox" parameter in which you can specify upper-left and lower-right coordinates (comma separated).
624625
The following Geometry types are supported by the GeoJSON implementation:
625626

626627
- Point

src/Tqdev/PhpCrudApi/GeoJson/GeoJsonService.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private function getGeometryColumnName(string $tableName, array &$params): strin
4747
return $geometryColumnName;
4848
}
4949

50-
private function setBoudingBoxFilter(array &$params)
50+
private function setBoudingBoxFilter(string $geometryColumnName, array &$params)
5151
{
5252
$boundingBox = isset($params['bbox']) ? $params['bbox'][0] : '';
5353
if ($boundingBox) {
@@ -72,7 +72,7 @@ private function convertRecordToFeature( /*object*/$record, string $geometryColu
7272
public function _list(string $tableName, array $params): FeatureCollection
7373
{
7474
$geometryColumnName = $this->getGeometryColumnName($tableName, $params);
75-
$this->setBoudingBoxFilter($params);
75+
$this->setBoudingBoxFilter($geometryColumnName, $params);
7676
$records = $this->records->_list($tableName, $params);
7777
$features = array();
7878
foreach ($records->getRecords() as $record) {
@@ -84,7 +84,7 @@ public function _list(string $tableName, array $params): FeatureCollection
8484
public function read(string $tableName, string $id, array $params): Feature
8585
{
8686
$geometryColumnName = $this->getGeometryColumnName($tableName, $params);
87-
$this->setBoudingBoxFilter($params);
87+
$this->setBoudingBoxFilter($geometryColumnName, $params);
8888
$record = $this->records->read($tableName, $id, $params);
8989
return $this->convertRecordToFeature($record, $geometryColumnName);
9090
}

tests/functional/001_records/083_list_users_as_geojson.log

+8
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,11 @@ Content-Type: application/json
2929
Content-Length: 186
3030

3131
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"id":1,"username":"user1","password":"testtest2"},"geometry":{"type":"Point","coordinates":[30,20]}}],"results":2}
32+
===
33+
GET /geojson/users?bbox=29.99,19.99,30.01,20.01
34+
===
35+
200
36+
Content-Type: application/json
37+
Content-Length: 174
38+
39+
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"id":1,"username":"user1","password":"testtest2"},"geometry":{"type":"Point","coordinates":[30,20]}}]}

0 commit comments

Comments
 (0)