From 0eb71cdce8c4340690ba5f12cc839913512b65c8 Mon Sep 17 00:00:00 2001 From: Marc Tobias Metten Date: Mon, 19 Mar 2018 01:34:48 +0100 Subject: [PATCH] only return polygon if &polygon_geojson=1 is set --- lib/template/details-json.php | 16 ++++---- test/bdd/api/details/params.feature | 43 ++++++++++++++++++++ test/bdd/api/details/simple.feature | 61 +++++++++++------------------ website/details.php | 22 +++++++---- 4 files changed, 87 insertions(+), 55 deletions(-) create mode 100644 test/bdd/api/details/params.feature diff --git a/lib/template/details-json.php b/lib/template/details-json.php index 44b6bff5..2ea393d8 100644 --- a/lib/template/details-json.php +++ b/lib/template/details-json.php @@ -38,7 +38,7 @@ $aPlaceDetails['lon'] = (float) $aPointDetails['lon']; $aPlaceDetails['geometry'] = json_decode($aPointDetails['asgeojson']); -$funcMapAddressLines = function($aFull) { +$funcMapAddressLines = function ($aFull) { $aMapped = [ 'localname' => $aFull['localname'], 'place_id' => (int) $aFull['place_id'], @@ -53,7 +53,7 @@ $funcMapAddressLines = function($aFull) { return $aMapped; }; -$funcMapKeywords = function($aFull) { +$funcMapKeywords = function ($aFull) { $aMapped = [ 'id' => (int) $aFull['word_id'], 'token' => $aFull['word_token'] @@ -62,29 +62,29 @@ $funcMapKeywords = function($aFull) { }; if ($aAddressLines) { - $aPlaceDetails['address'] = array_map($funcLines, $aAddressLines); + $aPlaceDetails['address'] = array_map($funcMapAddressLines, $aAddressLines); } if ($aLinkedLines) { - $aPlaceDetails['linked_places'] = array_map($funcLines, $aLinkedLines); + $aPlaceDetails['linked_places'] = array_map($funcMapAddressLines, $aLinkedLines); } if ($bIncludeKeywords) { $aPlaceDetails['keywords'] = array(); if ($aPlaceSearchNameKeywords) { - $aPlaceDetails['keywords']['name'] = array_map($funcKeywords, $aPlaceSearchNameKeywords); + $aPlaceDetails['keywords']['name'] = array_map($funcMapKeywords, $aPlaceSearchNameKeywords); } if ($aPlaceSearchAddressKeywords) { - $aPlaceDetails['keywords']['address'] = array_map($funcKeywords, $aPlaceSearchAddressKeywords); + $aPlaceDetails['keywords']['address'] = array_map($funcMapKeywords, $aPlaceSearchAddressKeywords); } } if ($bIncludeChildPlaces) { - $aPlaceDetails['parentof'] = array_map($funcLines, $aParentOfLines); + $aPlaceDetails['parentof'] = array_map($funcMapAddressLines, $aParentOfLines); - if ($bGroupParents) { + if ($bGroupChildPlaces) { $aGroupedAddressLines = []; foreach ($aParentOfLines as $aAddressLine) { if ($aAddressLine['type'] == 'yes') $sType = $aAddressLine['class']; diff --git a/test/bdd/api/details/params.feature b/test/bdd/api/details/params.feature new file mode 100644 index 00000000..b0a80f5b --- /dev/null +++ b/test/bdd/api/details/params.feature @@ -0,0 +1,43 @@ +@APIDB +Feature: Object details + Testing different parameter options for details API. + + Scenario: JSON Details + When sending json details query for W78099902 + Then the result is valid json + And result has attributes geometry + And result has not attributes keywords,address,linked_places,parentof + + Scenario: JSON Details with keywords + When sending json details query for W78099902 + | keywords | + | 1 | + Then the result is valid json + And result has attributes keywords + + Scenario: JSON Details with addressdetails + When sending json details query for W78099902 + | addressdetails | + | 1 | + Then the result is valid json + And result has attributes address + + Scenario: JSON Details with linkedplaces + When sending json details query for R123924 + | linkedplaces | + | 1 | + Then the result is valid json + And result has attributes linked_places + + Scenario: JSON Details with childplaces + When sending json details query for W78099902 + | childplaces | + | 1 | + Then the result is valid json + And result has attributes parentof + + Scenario: JSON Details with linkedplaces + When sending json details query for R123924 + | linkedplaces | + | 1 | + Then the result is valid json diff --git a/test/bdd/api/details/simple.feature b/test/bdd/api/details/simple.feature index 19ef1bfc..a50e53cf 100644 --- a/test/bdd/api/details/simple.feature +++ b/test/bdd/api/details/simple.feature @@ -3,15 +3,30 @@ Feature: Object details Check details page for correctness Scenario Outline: Details via OSM id - When sending details query for - Then the result is valid html + When sending details query for + Then the result is valid + + Examples: + | format | object | + | html | 492887 | + | json | 492887 | + | html | N4267356889 | + | json | N4267356889 | + | html | W230804120 | + | json | W230804120 | + | html | R123924 | + | json | R123924 | + + Scenario Outline: Details via unknown OSM id + When sending details query for + Then a HTTP 400 is returned Examples: - | object | - | 492887 | - | N4267356889 | - | W230804120 | - | R123924 | + | format | object | + | html | 1 | + | json | 1 | + | html | R1 | + | json | R1 | Scenario: Details with keywords When sending details query for W78099902 @@ -19,35 +34,3 @@ Feature: Object details | 1 | Then the result is valid html - Scenario: JSON Details - When sending json details query for W78099902 - Then the result is valid json - And result has not attributes place_search_name_keywords,place_search_address_keywords,address_lines,linked_lines,parentof_lines - - Scenario: JSON Details with keywords - When sending json details query for W78099902 - | keywords | - | 1 | - Then the result is valid json - And result has attributes place_search_name_keywords,place_search_address_keywords - - Scenario: JSON Details with addressdetails - When sending json details query for W78099902 - | addressdetails | - | 1 | - Then the result is valid json - And result has attributes address_lines - - Scenario: JSON Details with linkedplaces - When sending json details query for R123924 - | linkedplaces | - | 1 | - Then the result is valid json - And result has attributes linked_lines - - Scenario: JSON Details with childplaces - When sending json details query for W78099902 - | childplaces | - | 1 | - Then the result is valid json - And result has attributes parentof_lines diff --git a/website/details.php b/website/details.php index 7f26c6ee..11f23cbd 100755 --- a/website/details.php +++ b/website/details.php @@ -23,7 +23,8 @@ $bIncludeKeywords = $oParams->getBool('keywords'); $bIncludeAddressDetails = $oParams->getBool('addressdetails', $sOutputFormat == 'html'); $bIncludeLinkedPlaces = $oParams->getBool('linkedplaces', $sOutputFormat == 'html'); $bIncludeChildPlaces = $oParams->getBool('childplaces', $sOutputFormat == 'html'); -$bGroupParents = $oParams->getBool('group_parents', false); +$bGroupChildPlaces = $oParams->getBool('group_childplaces', false); +$bIncludePolygonAsGeoJSON = $oParams->getBool('polygon_geojson', $sOutputFormat == 'html'); $oDB =& getDB(); @@ -108,17 +109,22 @@ $sSQL .= ' rank_search, '; $sSQL .= ' get_searchrank_label(rank_search) AS rank_search_label,'; $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) AS localname, "; $sSQL .= " ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') AS isarea, "; -//$sSQL .= " ST_Area(geometry::geography) AS area, "; $sSQL .= ' ST_y(centroid) AS lat, '; -$sSQL .= ' ST_x(centroid) AS lon,'; +$sSQL .= ' ST_x(centroid) AS lon, '; $sSQL .= ' CASE '; -$sSQL .= ' WHEN importance = 0 OR importance IS NULL THEN 0.75-(rank_search::float/40) '; +$sSQL .= ' WHEN importance = 0 OR importance IS NULL '; +$sSQL .= ' THEN 0.75-(rank_search::float/40) '; $sSQL .= ' ELSE importance '; $sSQL .= ' END as calculated_importance, '; -$sSQL .= ' ST_AsGeoJSON(CASE '; -$sSQL .= ' WHEN ST_NPoints(geometry) > 5000 THEN ST_SimplifyPreserveTopology(geometry, 0.0001) '; -$sSQL .= ' ELSE geometry '; -$sSQL .= ' END) as asgeojson'; +if ($bIncludePolygonAsGeoJSON) { + $sSQL .= ' ST_AsGeoJSON(CASE '; + $sSQL .= ' WHEN ST_NPoints(geometry) > 5000 '; + $sSQL .= ' THEN ST_SimplifyPreserveTopology(geometry, 0.0001) '; + $sSQL .= ' ELSE geometry '; + $sSQL .= ' END) as asgeojson'; +} else { + $sSQL .= ' ST_AsGeoJSON(centroid) as asgeojson'; +} $sSQL .= ' FROM placex '; $sSQL .= " WHERE place_id = $iPlaceID"; -- 2.39.5