From 57ae3d03a1ccfb464216b58e7e70abaf3a3d8c48 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 9 Feb 2020 15:45:38 +0100 Subject: [PATCH 1/4] return place_id link to details when not an OSM object Stop-gap solution to find the right object for Tiger and interpolation objects. --- lib/output.php | 2 +- test/php/Nominatim/OutputTest.php | 57 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 test/php/Nominatim/OutputTest.php diff --git a/lib/output.php b/lib/output.php index 9d4b7502..8715efbc 100644 --- a/lib/output.php +++ b/lib/output.php @@ -48,5 +48,5 @@ function detailsPermaLink($aFeature, $sRefText = false) $sLabel = $sRefText ? $sRefText : $sOSMType.' '.$aFeature['osm_id']; return ''.$sLabel.''; } - return ''; + return detailsLink($aFeature, $sRefText); } diff --git a/test/php/Nominatim/OutputTest.php b/test/php/Nominatim/OutputTest.php new file mode 100644 index 00000000..ce9bfa35 --- /dev/null +++ b/test/php/Nominatim/OutputTest.php @@ -0,0 +1,57 @@ + 'N', 'osm_id'=> 38274, 'class' => 'place'); + $this->assertSame( + detailsPermaLink($aFeature), + 'node 38274' + ); + } + + public function testDetailsPermaLinkWay() + { + $aFeature = array('osm_type' => 'W', 'osm_id'=> 65, 'class' => 'highway'); + $this->assertSame( + detailsPermaLink($aFeature), + 'way 65' + ); + } + + public function testDetailsPermaLinkRelation() + { + $aFeature = array('osm_type' => 'R', 'osm_id'=> 9908, 'class' => 'waterway'); + $this->assertSame( + detailsPermaLink($aFeature), + 'relation 9908' + ); + } + + public function testDetailsPermaLinkTiger() + { + $aFeature = array('osm_type' => 'T', 'osm_id'=> 2, 'place_id' => 334); + $this->assertSame( + detailsPermaLink($aFeature, 'foo'), + 'foo' + ); + } + + public function testDetailsPermaLinkInterpolation() + { + $aFeature = array('osm_type' => 'I', 'osm_id'=> 400, 'place_id' => 3); + $this->assertSame( + detailsPermaLink($aFeature, 'foo'), + 'foo' + ); + } + + + + +} From c36fd72f99ce6489b29fa846ec9af650747ab959 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 9 Feb 2020 16:05:22 +0100 Subject: [PATCH 2/4] use detailsPermaLink function on main website as well --- lib/output.php | 31 +++++++++++++++++++++++++------ lib/template/address-html.php | 2 +- lib/template/search-html.php | 2 +- test/php/Nominatim/OutputTest.php | 19 +++++++++++++++++++ 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/lib/output.php b/lib/output.php index 8715efbc..4a15ecde 100644 --- a/lib/output.php +++ b/lib/output.php @@ -33,20 +33,39 @@ function wikipediaLink($aFeature) return ''; } -function detailsLink($aFeature, $sTitle = false) +function detailsLink($aFeature, $sTitle = false, $sExtraProperties = false) { if (!$aFeature['place_id']) return ''; - return ''.($sTitle?$sTitle:$aFeature['place_id']).''; + $sHtml = ''.($sTitle?$sTitle:$aFeature['place_id']).''; + + return $sHtml; } -function detailsPermaLink($aFeature, $sRefText = false) +function detailsPermaLink($aFeature, $sRefText = false, $sExtraProperties = false) { $sOSMType = formatOSMType($aFeature['osm_type'], false); if ($sOSMType) { - $sLabel = $sRefText ? $sRefText : $sOSMType.' '.$aFeature['osm_id']; - return ''.$sLabel.''; + $sHtml = ''; + + if ($sRefText) { + $sHtml .= $sRefText.''; + } else { + $sHtml .= $sOSMType.' '.$aFeature['osm_id'].''; + } + + return $sHtml; } - return detailsLink($aFeature, $sRefText); + return detailsLink($aFeature, $sRefText, $sExtraProperties); } diff --git a/lib/template/address-html.php b/lib/template/address-html.php index 9b098428..5be714d3 100644 --- a/lib/template/address-html.php +++ b/lib/template/address-html.php @@ -85,7 +85,7 @@ else echo ' ('.ucwords(str_replace('_',' ',$aResult['type'])).')'; echo '

'.$aResult['lat'].','.$aResult['lon'].'

'; - echo ' details'; + echo detailsPermaLink($aResult, 'details', 'class="btn btn-default btn-xs details"'); echo ''; ?> diff --git a/lib/template/search-html.php b/lib/template/search-html.php index c42476bf..2b8c1495 100644 --- a/lib/template/search-html.php +++ b/lib/template/search-html.php @@ -53,7 +53,7 @@ echo ' ('.ucwords(str_replace('_',' ',$aResult['class'])).')'; else echo ' ('.ucwords(str_replace('_',' ',$aResult['type'])).')'; - echo ' details'; + echo detailsPermaLink($aResult, 'details', 'class="btn btn-default btn-xs details"'); echo ''; $i = $i+1; } diff --git a/test/php/Nominatim/OutputTest.php b/test/php/Nominatim/OutputTest.php index ce9bfa35..48644845 100644 --- a/test/php/Nominatim/OutputTest.php +++ b/test/php/Nominatim/OutputTest.php @@ -51,6 +51,25 @@ class OutputTest extends \PHPUnit\Framework\TestCase ); } + public function testDetailsPermaLinkWithExtraPropertiesNode() + { + $aFeature = array('osm_type' => 'N', 'osm_id'=> 2, 'class' => 'amenity'); + $this->assertSame( + detailsPermaLink($aFeature, 'something', 'class="xtype"'), + 'something' + ); + } + + public function testDetailsPermaLinkWithExtraPropertiesTiger() + { + $aFeature = array('osm_type' => 'T', 'osm_id'=> 5, 'place_id' => 46); + $this->assertSame( + detailsPermaLink($aFeature, 'something', 'class="xtype"'), + 'something' + ); + } + + From 97d87895bff0e23ace74b616333b6b347c57f5b3 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 9 Feb 2020 16:50:04 +0100 Subject: [PATCH 3/4] details: also look for interpolations when way id is given --- lib/output.php | 2 ++ website/details.php | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/output.php b/lib/output.php index 4a15ecde..823a6631 100644 --- a/lib/output.php +++ b/lib/output.php @@ -12,6 +12,8 @@ function formatOSMType($sType, $bIncludeExternal = true) if ($sType == 'T') return 'way'; if ($sType == 'I') return 'way'; + // not handled: P, L + return ''; } diff --git a/website/details.php b/website/details.php index 44d4956b..39fa0afa 100644 --- a/website/details.php +++ b/website/details.php @@ -44,6 +44,16 @@ if ($sOsmType && $iOsmId > 0) { $sSQL .= ' ORDER BY class ASC'; $sPlaceId = $oDB->getOne($sSQL, array(':type' => $sOsmType, ':id' => $iOsmId)); + + // Nothing? Maybe it's an interpolation. + // XXX Simply returns the first parent street it finds. It should + // get a house number and get the right interpolation. + if (!$sPlaceId && $sOsmType == 'W' && (!$sClass || $sClass == 'place')) { + $sSQL = 'SELECT place_id FROM location_property_osmline' + .' WHERE osm_id = :id LIMIT 1'; + $sPlaceId = $oDB->getOne($sSQL, array(':id' => $iOsmId)); + } + // Be nice about our error messages for broken geometry if (!$sPlaceId) { From 3a3f9b34960ccfc0d5f87d05dfe521b1527826b6 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 9 Feb 2020 16:57:55 +0100 Subject: [PATCH 4/4] fix formatting --- test/php/Nominatim/OutputTest.php | 47 ++++++++++++++----------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/test/php/Nominatim/OutputTest.php b/test/php/Nominatim/OutputTest.php index 48644845..b243ba47 100644 --- a/test/php/Nominatim/OutputTest.php +++ b/test/php/Nominatim/OutputTest.php @@ -10,67 +10,62 @@ class OutputTest extends \PHPUnit\Framework\TestCase { $aFeature = array('osm_type' => 'N', 'osm_id'=> 38274, 'class' => 'place'); $this->assertSame( - detailsPermaLink($aFeature), - 'node 38274' - ); + detailsPermaLink($aFeature), + 'node 38274' + ); } public function testDetailsPermaLinkWay() { $aFeature = array('osm_type' => 'W', 'osm_id'=> 65, 'class' => 'highway'); $this->assertSame( - detailsPermaLink($aFeature), - 'way 65' - ); + detailsPermaLink($aFeature), + 'way 65' + ); } public function testDetailsPermaLinkRelation() { $aFeature = array('osm_type' => 'R', 'osm_id'=> 9908, 'class' => 'waterway'); $this->assertSame( - detailsPermaLink($aFeature), - 'relation 9908' - ); + detailsPermaLink($aFeature), + 'relation 9908' + ); } public function testDetailsPermaLinkTiger() { $aFeature = array('osm_type' => 'T', 'osm_id'=> 2, 'place_id' => 334); $this->assertSame( - detailsPermaLink($aFeature, 'foo'), - 'foo' - ); + detailsPermaLink($aFeature, 'foo'), + 'foo' + ); } public function testDetailsPermaLinkInterpolation() { $aFeature = array('osm_type' => 'I', 'osm_id'=> 400, 'place_id' => 3); $this->assertSame( - detailsPermaLink($aFeature, 'foo'), - 'foo' - ); + detailsPermaLink($aFeature, 'foo'), + 'foo' + ); } public function testDetailsPermaLinkWithExtraPropertiesNode() { $aFeature = array('osm_type' => 'N', 'osm_id'=> 2, 'class' => 'amenity'); $this->assertSame( - detailsPermaLink($aFeature, 'something', 'class="xtype"'), - 'something' - ); + detailsPermaLink($aFeature, 'something', 'class="xtype"'), + 'something' + ); } public function testDetailsPermaLinkWithExtraPropertiesTiger() { $aFeature = array('osm_type' => 'T', 'osm_id'=> 5, 'place_id' => 46); $this->assertSame( - detailsPermaLink($aFeature, 'something', 'class="xtype"'), - 'something' - ); + detailsPermaLink($aFeature, 'something', 'class="xtype"'), + 'something' + ); } - - - - - }