Skip to content

Commit 6577aa3

Browse files
committed
support tiles in GeoJSON
1 parent 573be5f commit 6577aa3

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

src/Tqdev/PhpCrudApi/GeoJson/Feature.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Feature implements \JsonSerializable
77
private $properties;
88
private $geometry;
99

10-
public function __construct(string $id, array $properties, /*?Geometry*/ $geometry)
10+
public function __construct($id, array $properties, /*?Geometry*/ $geometry)
1111
{
1212
$this->id = $id;
1313
$this->properties = $properties;
@@ -16,12 +16,12 @@ public function __construct(string $id, array $properties, /*?Geometry*/ $geomet
1616

1717
public function serialize()
1818
{
19-
return array_filter([
19+
return [
2020
'type' => 'Feature',
2121
'id' => $this->id,
2222
'properties' => $this->properties,
2323
'geometry' => $this->geometry,
24-
]);
24+
];
2525
}
2626

2727
public function jsonSerialize()

src/Tqdev/PhpCrudApi/GeoJson/GeoJsonService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private function convertTileToLatLonOfUpperLeftCorner($z, $x, $y): array
8080

8181
private function convertRecordToFeature( /*object*/$record, string $primaryKeyColumnName, string $geometryColumnName)
8282
{
83-
$id = '';
83+
$id = null;
8484
if ($primaryKeyColumnName) {
8585
$id = $record[$primaryKeyColumnName];
8686
}

tests/functional/001_records/081_read_countries_as_geojson.log

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,63 @@ GET /geojson/countries/3
44
Content-Type: application/json
55
Content-Length: 105
66

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]}}
88
===
99
GET /geojson/countries/4
1010
===
1111
200
1212
Content-Type: application/json
1313
Content-Length: 127
1414

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]]}}
1616
===
1717
GET /geojson/countries/5
1818
===
1919
200
2020
Content-Type: application/json
2121
Content-Length: 143
2222

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]]]}}
2424
===
2525
GET /geojson/countries/6
2626
===
2727
200
2828
Content-Type: application/json
2929
Content-Length: 177
3030

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]]]}}
3232
===
3333
GET /geojson/countries/7
3434
===
3535
200
3636
Content-Type: application/json
3737
Content-Length: 137
3838

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]]}}
4040
===
4141
GET /geojson/countries/8
4242
===
4343
200
4444
Content-Type: application/json
4545
Content-Length: 169
4646

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]]]}}
4848
===
4949
GET /geojson/countries/9
5050
===
5151
200
5252
Content-Type: application/json
5353
Content-Length: 184
5454

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]]]]}}
5656
===
5757
GET /geojson/countries/10
5858
===
5959
200
6060
Content-Type: application/json
6161
Content-Length: 229
6262

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]]]]}}
6464
===
6565
GET /geojson/countries/11
6666
===

tests/functional/001_records/082_read_users_as_geojson.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ GET /geojson/users/1
44
Content-Type: application/json
55
Content-Length: 132
66

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]}}
88
===
99
GET /geojson/users/2
1010
===
1111
200
1212
Content-Type: application/json
1313
Content-Length: 94
1414

15-
{"type":"Feature","properties":{"id":2,"username":"user2","password":"pass2"},"geometry":null}
15+
{"type":"Feature","id":2,"properties":{"username":"user2","password":"pass2"},"geometry":null}

tests/functional/001_records/083_list_users_as_geojson.log

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,36 @@ GET /geojson/users
44
Content-Type: application/json
55
Content-Length: 269
66

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}]}
88
===
99
GET /geojson/users?geometry=location&include=username
1010
===
1111
200
1212
Content-Type: application/json
13-
Content-Length: 213
13+
Content-Length: 227
1414

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}]}
1616
===
1717
GET /geojson/users?geometry=notlocation
1818
===
1919
200
2020
Content-Type: application/json
2121
Content-Length: 277
2222

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}]}
2424
===
2525
GET /geojson/users?page=1,1
2626
===
2727
200
2828
Content-Type: application/json
2929
Content-Length: 186
3030

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}
3232
===
3333
GET /geojson/users?bbox=29.99,19.99,30.01,20.01
3434
===
3535
200
3636
Content-Type: application/json
3737
Content-Length: 174
3838

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]}}]}

0 commit comments

Comments
 (0)