From: Sarah Hoffmann Date: Sun, 9 Feb 2020 20:07:19 +0000 (+0100) Subject: Merge pull request #1670 from lonvia/permalinks-for-tiger-and-interpolation X-Git-Tag: v3.5.0~86 X-Git-Url: https://git.openstreetmap.org/nominatim.git/commitdiff_plain/0698757e6e04e2a875ebd345b07d19f263fa4084?hp=3737712044b50ec1319afeebcd24d0ca2d0b181d Merge pull request #1670 from lonvia/permalinks-for-tiger-and-interpolation Enable Permalinks to dtails for tiger and interpolation --- diff --git a/lib/output.php b/lib/output.php index 9d4b7502..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 ''; } @@ -33,20 +35,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 ''; + 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 new file mode 100644 index 00000000..b243ba47 --- /dev/null +++ b/test/php/Nominatim/OutputTest.php @@ -0,0 +1,71 @@ + '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' + ); + } + + 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' + ); + } +} 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) {