瀏覽代碼

Some GeoJSON fixes

Maurits van der Schee 5 年之前
父節點
當前提交
5bd37a0a16
共有 1 個檔案被更改,包括 25 行新增10 行删除
  1. 25
    10
      api.php

+ 25
- 10
api.php 查看文件

@@ -4554,19 +4554,37 @@ class GeoJsonService
4554 4554
         return $this->reflection->getType($table);
4555 4555
     }
4556 4556
 
4557
-    private function getGeometryColumnName(string $tableName, string $geometryParam): string
4557
+    private function getGeometryColumnName(string $tableName, array &$params): string
4558 4558
     {
4559
+        $geometryParam = isset($params['geometry']) ? $params['geometry'][0] : '';
4559 4560
         $table = $this->reflection->getTable($tableName);
4561
+        $geometryColumnName = '';
4560 4562
         foreach ($table->getColumnNames() as $columnName) {
4561 4563
             if ($geometryParam && $geometryParam != $columnName) {
4562 4564
                 continue;
4563 4565
             }
4564 4566
             $column = $table->getColumn($columnName);
4565 4567
             if ($column->isGeometry()) {
4566
-                return $columnName;
4568
+                $geometryColumnName = $columnName;
4569
+                break;
4567 4570
             }
4568 4571
         }
4569
-        return "";
4572
+        if ($geometryColumnName) {
4573
+            $params['mandatory'][] = $tableName . "." . $geometryColumnName;
4574
+        }
4575
+        return $geometryColumnName;
4576
+    }
4577
+
4578
+    private function setBoudingBoxFilter(string $geometryColumnName, array &$params)
4579
+    {
4580
+        $boundingBox = isset($params['bbox']) ? $params['bbox'][0] : '';
4581
+        if ($boundingBox) {
4582
+            $c = explode(',', $boundingBox);
4583
+            if (!isset($params['filter'])) {
4584
+                $params['filter'] = array();
4585
+            }
4586
+            $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]))";
4587
+        }
4570 4588
     }
4571 4589
 
4572 4590
     private function convertRecordToFeature( /*object*/$record, string $geometryColumnName)
@@ -4581,11 +4599,9 @@ class GeoJsonService
4581 4599
 
4582 4600
     public function _list(string $tableName, array $params): FeatureCollection
4583 4601
     {
4584
-        $geometryParam = isset($params['geometry']) ? $params['geometry'][0] : '';
4585
-        $geometryColumnName = $this->getGeometryColumnName($tableName, $geometryParam);
4586
-        $params['mandatory'][] = $tableName . "." . $geometryColumnName;
4602
+        $geometryColumnName = $this->getGeometryColumnName($tableName, $params);
4603
+        $this->setBoudingBoxFilter($geometryColumnName, $params);
4587 4604
         $records = $this->records->_list($tableName, $params);
4588
-
4589 4605
         $features = array();
4590 4606
         foreach ($records->getRecords() as $record) {
4591 4607
             $features[] = $this->convertRecordToFeature($record, $geometryColumnName);
@@ -4595,9 +4611,8 @@ class GeoJsonService
4595 4611
 
4596 4612
     public function read(string $tableName, string $id, array $params): Feature
4597 4613
     {
4598
-        $geometryParam = isset($params['geometry']) ? $params['geometry'][0] : '';
4599
-        $geometryColumnName = $this->getGeometryColumnName($tableName, $geometryParam);
4600
-        $params['mandatory'][] = $tableName . "." . $geometryColumnName;
4614
+        $geometryColumnName = $this->getGeometryColumnName($tableName, $params);
4615
+        $this->setBoudingBoxFilter($geometryColumnName, $params);
4601 4616
         $record = $this->records->read($tableName, $id, $params);
4602 4617
         return $this->convertRecordToFeature($record, $geometryColumnName);
4603 4618
     }

Loading…
取消
儲存