Browse Source

Some GeoJSON fixes

Maurits van der Schee 5 years ago
parent
commit
f1cfb3c291

+ 1
- 0
README.md View File

@@ -621,6 +621,7 @@ The GeoJSON support is a read-only view on the tables and records in GeoJSON for
621 621
 
622 622
 The "`/geojson`" endpoint uses the "`/records`" endpoint internally and inherits all functionality, such as joins and filters.
623 623
 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).
624 625
 The following Geometry types are supported by the GeoJSON implementation:
625 626
 
626 627
   - Point

+ 3
- 3
src/Tqdev/PhpCrudApi/GeoJson/GeoJsonService.php View File

@@ -47,7 +47,7 @@ class GeoJsonService
47 47
         return $geometryColumnName;
48 48
     }
49 49
 
50
-    private function setBoudingBoxFilter(array &$params)
50
+    private function setBoudingBoxFilter(string $geometryColumnName, array &$params)
51 51
     {
52 52
         $boundingBox = isset($params['bbox']) ? $params['bbox'][0] : '';
53 53
         if ($boundingBox) {
@@ -72,7 +72,7 @@ class GeoJsonService
72 72
     public function _list(string $tableName, array $params): FeatureCollection
73 73
     {
74 74
         $geometryColumnName = $this->getGeometryColumnName($tableName, $params);
75
-        $this->setBoudingBoxFilter($params);
75
+        $this->setBoudingBoxFilter($geometryColumnName, $params);
76 76
         $records = $this->records->_list($tableName, $params);
77 77
         $features = array();
78 78
         foreach ($records->getRecords() as $record) {
@@ -84,7 +84,7 @@ class GeoJsonService
84 84
     public function read(string $tableName, string $id, array $params): Feature
85 85
     {
86 86
         $geometryColumnName = $this->getGeometryColumnName($tableName, $params);
87
-        $this->setBoudingBoxFilter($params);
87
+        $this->setBoudingBoxFilter($geometryColumnName, $params);
88 88
         $record = $this->records->read($tableName, $id, $params);
89 89
         return $this->convertRecordToFeature($record, $geometryColumnName);
90 90
     }

+ 8
- 0
tests/functional/001_records/083_list_users_as_geojson.log View File

@@ -29,3 +29,11 @@ Content-Type: application/json
29 29
 Content-Length: 186
30 30
 
31 31
 {"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]}}]}

Loading…
Cancel
Save