From: Sarah Hoffmann Date: Sun, 17 May 2020 14:45:46 +0000 (+0200) Subject: encapsulate icon URL in a function X-Git-Tag: v3.5.0~8^2~2 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/3a2ddbe2e0f3320b9f21ae6f299d10477553d13d encapsulate icon URL in a function --- diff --git a/lib/ClassTypes.php b/lib/ClassTypes.php index 971f5b93..5a69d1de 100644 --- a/lib/ClassTypes.php +++ b/lib/ClassTypes.php @@ -236,6 +236,20 @@ function getIcon($aPlace) return $aIcons[$sClassPlace] ?? null; } +/** + * Get an icon for the given object with its full URL. + */ +function getIconFile($aPlace) +{ + $sIcon = getIcon($aPlace); + + if (!isset($sIcon)) { + return null; + } + + return CONST_Website_BaseURL.'images/mapicons/'.$sIcon.'.p.20.png'; +} + /** * Return a class importance value for the given place. * diff --git a/lib/Geocode.php b/lib/Geocode.php index 253b9798..0c93e0a9 100644 --- a/lib/Geocode.php +++ b/lib/Geocode.php @@ -903,9 +903,9 @@ class Geocode } // Is there an icon set for this type of result? - $sIcon = ClassTypes\getIcon($aResult); + $sIcon = ClassTypes\getIconFile($aResult); if (isset($sIcon)) { - $aResult['icon'] = CONST_Website_BaseURL.'images/mapicons/'.$sIcon.'.p.20.png'; + $aResult['icon'] = $sIcon; } $sLabel = ClassTypes\getLabel($aResult); diff --git a/lib/template/details-html.php b/lib/template/details-html.php index 4ea5a258..c15e74c8 100644 --- a/lib/template/details-html.php +++ b/lib/template/details-html.php @@ -57,10 +57,12 @@ return $sHTML; } - function map_icon($sIcon) + function map_icon($aPlace) { + $sIcon = Nominatim\ClassTypes\getIconFile($aPlace); if (isset($sIcon)) { - echo ''.$sIcon.''; + $sLabel = Nominatim\ClassTypes\getIcon($aPlace); + echo ''.$sLabel.''; } } @@ -112,7 +114,7 @@
- +
diff --git a/lib/template/details-json.php b/lib/template/details-json.php index 4dc65a5b..0449dbb9 100644 --- a/lib/template/details-json.php +++ b/lib/template/details-json.php @@ -26,8 +26,9 @@ $aPlaceDetails['calculated_importance'] = (float) $aPointDetails['calculated_imp $aPlaceDetails['extratags'] = $aPointDetails['aExtraTags']; $aPlaceDetails['calculated_wikipedia'] = $aPointDetails['wikipedia']; -if (isset($aPointDetails['icon'])) { - $aPlaceDetails['icon'] = CONST_Website_BaseURL.'images/mapicons/'.$aPointDetails['icon'].'.n.32.png'; +$sIcon = Nominatim\ClassTypes\getIconFile($aPointDetails); +if (isset($sIcon)) { + $aPlaceDetails['icon'] = $sIcon; } $aPlaceDetails['rank_address'] = (int) $aPointDetails['rank_address']; diff --git a/website/details.php b/website/details.php index 73c07ba7..ff6ddaca 100644 --- a/website/details.php +++ b/website/details.php @@ -149,7 +149,6 @@ if (!$aPointDetails) { } $aPointDetails['localname'] = $aPointDetails['localname']?$aPointDetails['localname']:$aPointDetails['housenumber']; -$aPointDetails['icon'] = Nominatim\ClassTypes\getIcon($aPointDetails); $aPointDetails['rank_search_label'] = getSearchRankLabel($aPointDetails['rank_search']); // only used in HTML format // Get all alternative names (languages, etc)