Browse Source

support tiles in GeoJSON

Maurits van der Schee 6 years ago
parent
commit
6577aa3d0f

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

@@ -7,7 +7,7 @@ class Feature implements \JsonSerializable
7 7
     private $properties;
8 8
     private $geometry;
9 9
 
10
-    public function __construct(string $id, array $properties, /*?Geometry*/ $geometry)
10
+    public function __construct($id, array $properties, /*?Geometry*/ $geometry)
11 11
     {
12 12
         $this->id = $id;
13 13
         $this->properties = $properties;
@@ -16,12 +16,12 @@ class Feature implements \JsonSerializable
16 16
 
17 17
     public function serialize()
18 18
     {
19
-        return array_filter([
19
+        return [
20 20
             'type' => 'Feature',
21 21
             'id' => $this->id,
22 22
             'properties' => $this->properties,
23 23
             'geometry' => $this->geometry,
24
-        ]);
24
+        ];
25 25
     }
26 26
 
27 27
     public function jsonSerialize()

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

@@ -80,7 +80,7 @@ class GeoJsonService
80 80
 
81 81
     private function convertRecordToFeature( /*object*/$record, string $primaryKeyColumnName, string $geometryColumnName)
82 82
     {
83
-        $id = '';
83
+        $id = null;
84 84
         if ($primaryKeyColumnName) {
85 85
             $id = $record[$primaryKeyColumnName];
86 86
         }

+ 8
- 8
tests/functional/001_records/081_read_countries_as_geojson.log View File

@@ -4,7 +4,7 @@ GET /geojson/countries/3
4 4
 Content-Type: application/json
5 5
 Content-Length: 105
6 6
 
7
-{"type":"Feature","properties":{"id":3,"name":"Point"},"geometry":{"type":"Point","coordinates":[30,10]}}
7
+{"type":"Feature","id":3,"properties":{"name":"Point"},"geometry":{"type":"Point","coordinates":[30,10]}}
8 8
 ===
9 9
 GET /geojson/countries/4
10 10
 ===
@@ -12,7 +12,7 @@ GET /geojson/countries/4
12 12
 Content-Type: application/json
13 13
 Content-Length: 127
14 14
 
15
-{"type":"Feature","properties":{"id":4,"name":"Line"},"geometry":{"type":"LineString","coordinates":[[30,10],[10,30],[40,40]]}}
15
+{"type":"Feature","id":4,"properties":{"name":"Line"},"geometry":{"type":"LineString","coordinates":[[30,10],[10,30],[40,40]]}}
16 16
 ===
17 17
 GET /geojson/countries/5
18 18
 ===
@@ -20,7 +20,7 @@ GET /geojson/countries/5
20 20
 Content-Type: application/json
21 21
 Content-Length: 143
22 22
 
23
-{"type":"Feature","properties":{"id":5,"name":"Poly1"},"geometry":{"type":"Polygon","coordinates":[[[30,10],[40,40],[20,40],[10,20],[30,10]]]}}
23
+{"type":"Feature","id":5,"properties":{"name":"Poly1"},"geometry":{"type":"Polygon","coordinates":[[[30,10],[40,40],[20,40],[10,20],[30,10]]]}}
24 24
 ===
25 25
 GET /geojson/countries/6
26 26
 ===
@@ -28,7 +28,7 @@ GET /geojson/countries/6
28 28
 Content-Type: application/json
29 29
 Content-Length: 177
30 30
 
31
-{"type":"Feature","properties":{"id":6,"name":"Poly2"},"geometry":{"type":"Polygon","coordinates":[[[35,10],[45,45],[15,40],[10,20],[35,10]],[[20,30],[35,35],[30,20],[20,30]]]}}
31
+{"type":"Feature","id":6,"properties":{"name":"Poly2"},"geometry":{"type":"Polygon","coordinates":[[[35,10],[45,45],[15,40],[10,20],[35,10]],[[20,30],[35,35],[30,20],[20,30]]]}}
32 32
 ===
33 33
 GET /geojson/countries/7
34 34
 ===
@@ -36,7 +36,7 @@ GET /geojson/countries/7
36 36
 Content-Type: application/json
37 37
 Content-Length: 137
38 38
 
39
-{"type":"Feature","properties":{"id":7,"name":"Mpoint"},"geometry":{"type":"MultiPoint","coordinates":[[10,40],[40,30],[20,20],[30,10]]}}
39
+{"type":"Feature","id":7,"properties":{"name":"Mpoint"},"geometry":{"type":"MultiPoint","coordinates":[[10,40],[40,30],[20,20],[30,10]]}}
40 40
 ===
41 41
 GET /geojson/countries/8
42 42
 ===
@@ -44,7 +44,7 @@ GET /geojson/countries/8
44 44
 Content-Type: application/json
45 45
 Content-Length: 169
46 46
 
47
-{"type":"Feature","properties":{"id":8,"name":"Mline"},"geometry":{"type":"MultiLineString","coordinates":[[[10,10],[20,20],[10,40]],[[40,40],[30,30],[40,20],[30,10]]]}}
47
+{"type":"Feature","id":8,"properties":{"name":"Mline"},"geometry":{"type":"MultiLineString","coordinates":[[[10,10],[20,20],[10,40]],[[40,40],[30,30],[40,20],[30,10]]]}}
48 48
 ===
49 49
 GET /geojson/countries/9
50 50
 ===
@@ -52,7 +52,7 @@ GET /geojson/countries/9
52 52
 Content-Type: application/json
53 53
 Content-Length: 184
54 54
 
55
-{"type":"Feature","properties":{"id":9,"name":"Mpoly1"},"geometry":{"type":"MultiPolygon","coordinates":[[[[30,20],[45,40],[10,40],[30,20]]],[[[15,5],[40,10],[10,20],[5,10],[15,5]]]]}}
55
+{"type":"Feature","id":9,"properties":{"name":"Mpoly1"},"geometry":{"type":"MultiPolygon","coordinates":[[[[30,20],[45,40],[10,40],[30,20]]],[[[15,5],[40,10],[10,20],[5,10],[15,5]]]]}}
56 56
 ===
57 57
 GET /geojson/countries/10
58 58
 ===
@@ -60,7 +60,7 @@ GET /geojson/countries/10
60 60
 Content-Type: application/json
61 61
 Content-Length: 229
62 62
 
63
-{"type":"Feature","properties":{"id":10,"name":"Mpoly2"},"geometry":{"type":"MultiPolygon","coordinates":[[[[40,40],[20,45],[45,30],[40,40]]],[[[20,35],[10,30],[10,10],[30,5],[45,20],[20,35]],[[30,20],[20,15],[20,25],[30,20]]]]}}
63
+{"type":"Feature","id":10,"properties":{"name":"Mpoly2"},"geometry":{"type":"MultiPolygon","coordinates":[[[[40,40],[20,45],[45,30],[40,40]]],[[[20,35],[10,30],[10,10],[30,5],[45,20],[20,35]],[[30,20],[20,15],[20,25],[30,20]]]]}}
64 64
 ===
65 65
 GET /geojson/countries/11
66 66
 ===

+ 2
- 2
tests/functional/001_records/082_read_users_as_geojson.log View File

@@ -4,7 +4,7 @@ GET /geojson/users/1
4 4
 Content-Type: application/json
5 5
 Content-Length: 132
6 6
 
7
-{"type":"Feature","properties":{"id":1,"username":"user1","password":"testtest2"},"geometry":{"type":"Point","coordinates":[30,20]}}
7
+{"type":"Feature","id":1,"properties":{"username":"user1","password":"testtest2"},"geometry":{"type":"Point","coordinates":[30,20]}}
8 8
 ===
9 9
 GET /geojson/users/2
10 10
 ===
@@ -12,4 +12,4 @@ GET /geojson/users/2
12 12
 Content-Type: application/json
13 13
 Content-Length: 94
14 14
 
15
-{"type":"Feature","properties":{"id":2,"username":"user2","password":"pass2"},"geometry":null}
15
+{"type":"Feature","id":2,"properties":{"username":"user2","password":"pass2"},"geometry":null}

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

@@ -4,15 +4,15 @@ GET /geojson/users
4 4
 Content-Type: application/json
5 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","id":1,"properties":{"username":"user1","password":"testtest2"},"geometry":{"type":"Point","coordinates":[30,20]}},{"type":"Feature","id":2,"properties":{"username":"user2","password":"pass2"},"geometry":null}]}
8 8
 ===
9 9
 GET /geojson/users?geometry=location&include=username
10 10
 ===
11 11
 200
12 12
 Content-Type: application/json
13
-Content-Length: 213
13
+Content-Length: 227
14 14
 
15
-{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"username":"user1"},"geometry":{"type":"Point","coordinates":[30,20]}},{"type":"Feature","properties":{"username":"user2"},"geometry":null}]}
15
+{"type":"FeatureCollection","features":[{"type":"Feature","id":1,"properties":{"username":"user1"},"geometry":{"type":"Point","coordinates":[30,20]}},{"type":"Feature","id":2,"properties":{"username":"user2"},"geometry":null}]}
16 16
 ===
17 17
 GET /geojson/users?geometry=notlocation
18 18
 ===
@@ -20,7 +20,7 @@ GET /geojson/users?geometry=notlocation
20 20
 Content-Type: application/json
21 21
 Content-Length: 277
22 22
 
23
-{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"id":1,"username":"user1","password":"testtest2","location":"POINT(30 20)"},"geometry":null},{"type":"Feature","properties":{"id":2,"username":"user2","password":"pass2","location":null},"geometry":null}]}
23
+{"type":"FeatureCollection","features":[{"type":"Feature","id":1,"properties":{"username":"user1","password":"testtest2","location":"POINT(30 20)"},"geometry":null},{"type":"Feature","id":2,"properties":{"username":"user2","password":"pass2","location":null},"geometry":null}]}
24 24
 ===
25 25
 GET /geojson/users?page=1,1
26 26
 ===
@@ -28,7 +28,7 @@ GET /geojson/users?page=1,1
28 28
 Content-Type: application/json
29 29
 Content-Length: 186
30 30
 
31
-{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"id":1,"username":"user1","password":"testtest2"},"geometry":{"type":"Point","coordinates":[30,20]}}],"results":2}
31
+{"type":"FeatureCollection","features":[{"type":"Feature","id":1,"properties":{"username":"user1","password":"testtest2"},"geometry":{"type":"Point","coordinates":[30,20]}}],"results":2}
32 32
 ===
33 33
 GET /geojson/users?bbox=29.99,19.99,30.01,20.01
34 34
 ===
@@ -36,4 +36,4 @@ GET /geojson/users?bbox=29.99,19.99,30.01,20.01
36 36
 Content-Type: application/json
37 37
 Content-Length: 174
38 38
 
39
-{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"id":1,"username":"user1","password":"testtest2"},"geometry":{"type":"Point","coordinates":[30,20]}}]}
39
+{"type":"FeatureCollection","features":[{"type":"Feature","id":1,"properties":{"username":"user1","password":"testtest2"},"geometry":{"type":"Point","coordinates":[30,20]}}]}

Loading…
Cancel
Save