Browse Source

Some GeoJSON fixes

Maurits van der Schee 6 years ago
parent
commit
665d1bf979

+ 8
- 2
src/Tqdev/PhpCrudApi/GeoJson/FeatureCollection.php View File

5
 {
5
 {
6
     private $features;
6
     private $features;
7
 
7
 
8
-    public function __construct(array $features)
8
+    private $results;
9
+
10
+    public function __construct(array $features, int $results)
9
     {
11
     {
10
         $this->features = $features;
12
         $this->features = $features;
13
+        $this->results = $results;
11
     }
14
     }
12
 
15
 
13
     public function serialize()
16
     public function serialize()
15
         return [
18
         return [
16
             'type' => 'FeatureCollection',
19
             'type' => 'FeatureCollection',
17
             'features' => $this->features,
20
             'features' => $this->features,
21
+            'results' => $this->results,
18
         ];
22
         ];
19
     }
23
     }
20
 
24
 
21
     public function jsonSerialize()
25
     public function jsonSerialize()
22
     {
26
     {
23
-        return $this->serialize();
27
+        return array_filter($this->serialize(), function ($v) {
28
+            return $v !== 0;
29
+        });
24
     }
30
     }
25
 }
31
 }

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

61
         foreach ($records->getRecords() as $record) {
61
         foreach ($records->getRecords() as $record) {
62
             $features[] = $this->convertRecordToFeature($record, $geometryColumnName);
62
             $features[] = $this->convertRecordToFeature($record, $geometryColumnName);
63
         }
63
         }
64
-        return new FeatureCollection($features);
64
+        return new FeatureCollection($features, $records->getResults());
65
     }
65
     }
66
 
66
 
67
     public function read(string $tableName, string $id, array $params): Feature
67
     public function read(string $tableName, string $id, array $params): Feature

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

5
 Content-Length: 269
5
 Content-Length: 269
6
 
6
 
7
 {"type":"FeatureCollection","features":[{"type":"Feature","properties":{"id":1,"username":"user1","password":"testtest2"},"geometry":{"type":"Point","coordinates":[30,20]}},{"type":"Feature","properties":{"id":2,"username":"user2","password":"pass2"},"geometry":null}]}
7
 {"type":"FeatureCollection","features":[{"type":"Feature","properties":{"id":1,"username":"user1","password":"testtest2"},"geometry":{"type":"Point","coordinates":[30,20]}},{"type":"Feature","properties":{"id":2,"username":"user2","password":"pass2"},"geometry":null}]}
8
+===
9
+GET /geojson/users?page=1,1
10
+===
11
+200
12
+Content-Type: application/json
13
+Content-Length: 186
14
+
15
+{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"id":1,"username":"user1","password":"testtest2"},"geometry":{"type":"Point","coordinates":[30,20]}}],"results":2}

Loading…
Cancel
Save