|
@@ -4477,22 +4477,25 @@ class TypeConverter
|
4477
|
4477
|
|
4478
|
4478
|
class Feature implements \JsonSerializable
|
4479
|
4479
|
{
|
|
4480
|
+ private $id;
|
4480
|
4481
|
private $properties;
|
4481
|
4482
|
private $geometry;
|
4482
|
4483
|
|
4483
|
|
- public function __construct(array $properties, /*?Geometry*/ $geometry)
|
|
4484
|
+ public function __construct(string $id, array $properties, /*?Geometry*/ $geometry)
|
4484
|
4485
|
{
|
|
4486
|
+ $this->id = $id;
|
4485
|
4487
|
$this->properties = $properties;
|
4486
|
4488
|
$this->geometry = $geometry;
|
4487
|
4489
|
}
|
4488
|
4490
|
|
4489
|
4491
|
public function serialize()
|
4490
|
4492
|
{
|
4491
|
|
- return [
|
|
4493
|
+ return array_filter([
|
4492
|
4494
|
'type' => 'Feature',
|
|
4495
|
+ 'id' => $this->id,
|
4493
|
4496
|
'properties' => $this->properties,
|
4494
|
4497
|
'geometry' => $this->geometry,
|
4495
|
|
- ];
|
|
4498
|
+ ]);
|
4496
|
4499
|
}
|
4497
|
4500
|
|
4498
|
4501
|
public function jsonSerialize()
|
|
@@ -4586,38 +4589,61 @@ class GeoJsonService
|
4586
|
4589
|
}
|
4587
|
4590
|
$params['filter'][] = "$geometryColumnName,sin,POLYGON(($c[0] $c[1],$c[2] $c[1],$c[2] $c[3],$c[0] $c[3],$c[0] $c[1]))";
|
4588
|
4591
|
}
|
4589
|
|
- /*
|
4590
|
4592
|
$tile = isset($params['tile']) ? $params['tile'][0] : '';
|
4591
|
4593
|
if ($tile) {
|
4592
|
|
-
|
4593
|
|
- $n = pow(2, $zoom);
|
4594
|
|
- $lon_deg = $xtile / $n * 360.0 - 180.0;
|
4595
|
|
- $lat_deg = rad2deg(atan(sinh(pi() * (1 - 2 * $ytile / $n))));
|
4596
|
|
-
|
4597
|
|
- calculates upperleft corner
|
|
4594
|
+ $zxy = explode(',', $tile);
|
|
4595
|
+ if (count($zxy) == 3) {
|
|
4596
|
+ list($z, $x, $y) = $zxy;
|
|
4597
|
+ $c = array();
|
|
4598
|
+ $c = array_merge($c, $this->convertTileToLatLonOfUpperLeftCorner($z, $x, $y));
|
|
4599
|
+ $c = array_merge($c, $this->convertTileToLatLonOfUpperLeftCorner($z, $x + 1, $y + 1));
|
|
4600
|
+ $params['filter'][] = "$geometryColumnName,sin,POLYGON(($c[0] $c[1],$c[2] $c[1],$c[2] $c[3],$c[0] $c[3],$c[0] $c[1]))";
|
|
4601
|
+ }
|
|
4602
|
+ }
|
|
4603
|
+ }
|
4598
|
4604
|
|
4599
|
|
- $params['filter'][] = "$geometryColumnName,sin,POLYGON(($c[0] $c[1],$c[2] $c[1],$c[2] $c[3],$c[0] $c[3],$c[0] $c[1]))";
|
4600
|
|
- }*/
|
|
4605
|
+ private function convertTileToLatLonOfUpperLeftCorner($z, $x, $y): array
|
|
4606
|
+ {
|
|
4607
|
+ $n = pow(2, $z);
|
|
4608
|
+ $lon = $x / $n * 360.0 - 180.0;
|
|
4609
|
+ $lat = rad2deg(atan(sinh(pi() * (1 - 2 * $y / $n))));
|
|
4610
|
+ return [$lon, $lat];
|
4601
|
4611
|
}
|
4602
|
4612
|
|
4603
|
|
- private function convertRecordToFeature( /*object*/$record, string $geometryColumnName)
|
|
4613
|
+ private function convertRecordToFeature( /*object*/$record, string $primaryKeyColumnName, string $geometryColumnName)
|
4604
|
4614
|
{
|
|
4615
|
+ $id = '';
|
|
4616
|
+ if ($primaryKeyColumnName) {
|
|
4617
|
+ $id = $record[$primaryKeyColumnName];
|
|
4618
|
+ }
|
4605
|
4619
|
$geometry = null;
|
4606
|
4620
|
if (isset($record[$geometryColumnName])) {
|
4607
|
4621
|
$geometry = Geometry::fromWkt($record[$geometryColumnName]);
|
4608
|
4622
|
}
|
4609
|
|
- $properties = array_diff_key($record, [$geometryColumnName => true]);
|
4610
|
|
- return new Feature($properties, $geometry);
|
|
4623
|
+ $properties = array_diff_key($record, [$primaryKeyColumnName => true, $geometryColumnName => true]);
|
|
4624
|
+ return new Feature($id, $properties, $geometry);
|
|
4625
|
+ }
|
|
4626
|
+
|
|
4627
|
+ private function getPrimaryKeyColumnName(string $tableName, array &$params): string
|
|
4628
|
+ {
|
|
4629
|
+ $primaryKeyColumn = $this->reflection->getTable($tableName)->getPk();
|
|
4630
|
+ if (!$primaryKeyColumn) {
|
|
4631
|
+ return '';
|
|
4632
|
+ }
|
|
4633
|
+ $primaryKeyColumnName = $primaryKeyColumn->getName();
|
|
4634
|
+ $params['mandatory'][] = $tableName . "." . $primaryKeyColumnName;
|
|
4635
|
+ return $primaryKeyColumnName;
|
4611
|
4636
|
}
|
4612
|
4637
|
|
4613
|
4638
|
public function _list(string $tableName, array $params): FeatureCollection
|
4614
|
4639
|
{
|
4615
|
4640
|
$geometryColumnName = $this->getGeometryColumnName($tableName, $params);
|
4616
|
4641
|
$this->setBoudingBoxFilter($geometryColumnName, $params);
|
|
4642
|
+ $primaryKeyColumnName = $this->getPrimaryKeyColumnName($tableName, $params);
|
4617
|
4643
|
$records = $this->records->_list($tableName, $params);
|
4618
|
4644
|
$features = array();
|
4619
|
4645
|
foreach ($records->getRecords() as $record) {
|
4620
|
|
- $features[] = $this->convertRecordToFeature($record, $geometryColumnName);
|
|
4646
|
+ $features[] = $this->convertRecordToFeature($record, $primaryKeyColumnName, $geometryColumnName);
|
4621
|
4647
|
}
|
4622
|
4648
|
return new FeatureCollection($features, $records->getResults());
|
4623
|
4649
|
}
|
|
@@ -4626,8 +4652,9 @@ class GeoJsonService
|
4626
|
4652
|
{
|
4627
|
4653
|
$geometryColumnName = $this->getGeometryColumnName($tableName, $params);
|
4628
|
4654
|
$this->setBoudingBoxFilter($geometryColumnName, $params);
|
|
4655
|
+ $primaryKeyColumnName = $this->getPrimaryKeyColumnName($tableName, $params);
|
4629
|
4656
|
$record = $this->records->read($tableName, $id, $params);
|
4630
|
|
- return $this->convertRecordToFeature($record, $geometryColumnName);
|
|
4657
|
+ return $this->convertRecordToFeature($record, $primaryKeyColumnName, $geometryColumnName);
|
4631
|
4658
|
}
|
4632
|
4659
|
}
|
4633
|
4660
|
|