]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/PlaceLookup.php
use PlaceLookup::loadParamArray in search and lookup
[nominatim.git] / lib / PlaceLookup.php
index f7617d827e00439e89d223d4c9fe0e0f47fe4b33..a48f5597e66c2218cd1d79891e382b281a20756d 100644 (file)
@@ -32,75 +32,104 @@ class PlaceLookup
         $this->oDB =& $oDB;
     }
 
-    public function setAnchorSql($sPoint)
+    public function doDeDupe()
     {
-        $this->sAnchorSql = $sPoint;
+        return $this->bDeDupe;
     }
 
-    public function setDeDupe($bDeDupe)
+    public function setIncludePolygonAsPoints($b = true)
     {
-        $this->bDeDupe = $bDeDupe;
+        $this->bIncludePolygonAsPoints = $b;
     }
 
-    public function setAddressRankList($aList)
+    public function loadParamArray($oParams, $sGeomType = null)
     {
-        $this->sAddressRankListSql = '('.join(',', $aList).')';
-    }
+        $aLangs = $oParams->getPreferredLanguages();
+        $this->aLangPrefOrderSql =
+            'ARRAY['.join(',', array_map('getDBQuoted', $aLangs)).']';
 
-    public function setAllowedTypesSQLList($sSql)
-    {
-        $this->sAllowedTypesSQLList = $sSql;
-    }
+        $this->bAddressDetails = $oParams->getBool('addressdetails', true);
+        $this->bExtraTags = $oParams->getBool('extratags', false);
+        $this->bNameDetails = $oParams->getBool('namedetails', false);
 
-    public function setLanguagePreference($aLangPrefOrder)
-    {
-        $this->aLangPrefOrderSql =
-            'ARRAY['.join(',', array_map('getDBQuoted', $aLangPrefOrder)).']';
-    }
+        $this->bDeDupe = $oParams->getBool('dedupe', $this->bDeDupe);
 
-    public function setIncludeAddressDetails($bAddressDetails = true)
-    {
-        $this->bAddressDetails = $bAddressDetails;
+        if ($sGeomType === null || $sGeomType == 'text') {
+            $this->bIncludePolygonAsText = $oParams->getBool('polygon_text');
+        }
+        if ($sGeomType === null || $sGeomType == 'geojson') {
+            $this->bIncludePolygonAsGeoJSON = $oParams->getBool('polygon_geojson');
+        }
+        if ($sGeomType === null || $sGeomType == 'kml') {
+            $this->bIncludePolygonAsKML = $oParams->getBool('polygon_kml');
+        }
+        if ($sGeomType === null || $sGeomType == 'svg') {
+            $this->bIncludePolygonAsSVG = $oParams->getBool('polygon_svg');
+        }
+        $this->fPolygonSimplificationThreshold
+            = $oParams->getFloat('polygon_threshold', 0.0);
+
+        $iWantedTypes =
+            ($this->bIncludePolygonAsText ? 1 : 0) +
+            ($this->bIncludePolygonAsGeoJSON ? 1 : 0) +
+            ($this->bIncludePolygonAsKML ? 1 : 0) +
+            ($this->bIncludePolygonAsSVG ? 1 : 0);
+        if ($iWantedTypes > CONST_PolygonOutput_MaximumTypes) {
+            if (CONST_PolygonOutput_MaximumTypes) {
+                userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
+            } else {
+                userError("Polygon output is disabled");
+            }
+        }
     }
 
-    public function setIncludeExtraTags($bExtraTags = false)
+    public function getMoreUrlParams()
     {
-        $this->bExtraTags = $bExtraTags;
-    }
+        $aParams = array();
 
-    public function setIncludeNameDetails($bNameDetails = false)
-    {
-        $this->bNameDetails = $bNameDetails;
-    }
+        if ($this->bAddressDetails) $aParams['addressdetails'] = '1';
+        if ($this->bExtraTags) $aParams['extratags'] = '1';
+        if ($this->bNameDetails) $aParams['namedetails'] = '1';
 
-    public function setIncludePolygonAsPoints($b = true)
-    {
-        $this->bIncludePolygonAsPoints = $b;
+        if ($this->bIncludePolygonAsPoints) $aParams['polygon'] = '1';
+        if ($this->bIncludePolygonAsText) $aParams['polygon_text'] = '1';
+        if ($this->bIncludePolygonAsGeoJSON) $aParams['polygon_geojson'] = '1';
+        if ($this->bIncludePolygonAsKML) $aParams['polygon_kml'] = '1';
+        if ($this->bIncludePolygonAsSVG) $aParams['polygon_svg'] = '1';
+
+        if ($this->fPolygonSimplificationThreshold > 0.0) {
+            $aParams['polygon_threshold'] = $this->fPolygonSimplificationThreshold;
+        }
+
+        if (!$this->bDeDupe) $aParams['dedupe'] = '0';
+
+        return $aParams;
     }
 
-    public function setIncludePolygonAsText($b = true)
+    public function setAnchorSql($sPoint)
     {
-        $this->bIncludePolygonAsText = $b;
+        $this->sAnchorSql = $sPoint;
     }
 
-    public function setIncludePolygonAsGeoJSON($b = true)
+    public function setAddressRankList($aList)
     {
-        $this->bIncludePolygonAsGeoJSON = $b;
+        $this->sAddressRankListSql = '('.join(',', $aList).')';
     }
 
-    public function setIncludePolygonAsKML($b = true)
+    public function setAllowedTypesSQLList($sSql)
     {
-        $this->bIncludePolygonAsKML = $b;
+        $this->sAllowedTypesSQLList = $sSql;
     }
 
-    public function setIncludePolygonAsSVG($b = true)
+    public function setLanguagePreference($aLangPrefOrder)
     {
-        $this->bIncludePolygonAsSVG = $b;
+        $this->aLangPrefOrderSql =
+            'ARRAY['.join(',', array_map('getDBQuoted', $aLangPrefOrder)).']';
     }
 
-    public function setPolygonSimplificationThreshold($f)
+    public function setIncludeAddressDetails($bAddressDetails = true)
     {
-        $this->fPolygonSimplificationThreshold = $f;
+        $this->bAddressDetails = $bAddressDetails;
     }
 
     private function addressImportanceSql($sGeometry, $sPlaceId)