]> git.openstreetmap.org Git - nominatim.git/commitdiff
encapsulate icon URL in a function
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 17 May 2020 14:45:46 +0000 (16:45 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 17 May 2020 14:46:45 +0000 (16:46 +0200)
lib/ClassTypes.php
lib/Geocode.php
lib/template/details-html.php
lib/template/details-json.php
website/details.php

index 971f5b93147a5fc35f753d8fb8c9985096c2f19e..5a69d1ded8e9db631108ab9e09b9072d678d4d6a 100644 (file)
@@ -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.
  *
index 253b9798950d2cda202c86fdda1636a28aca049c..0c93e0a96e429945d4a795fe32179fcc573f0544 100644 (file)
@@ -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);
index 4ea5a258d5de6a58e832b59f91194957fb17e41c..c15e74c89ab928739942e599e4fc9a786ac5efae 100644 (file)
         return $sHTML;
     }
 
-    function map_icon($sIcon)
+    function map_icon($aPlace)
     {
+        $sIcon = Nominatim\ClassTypes\getIconFile($aPlace);
         if (isset($sIcon)) {
-            echo '<img id="mapicon" src="'.CONST_Website_BaseURL.'images/mapicons/'.$sIcon.'.n.32.png'.'" alt="'.$sIcon.'" />';
+            $sLabel = Nominatim\ClassTypes\getIcon($aPlace);
+            echo '<img id="mapicon" src="'.$sIcon.'" alt="'.$sLabel.'" />';
         }
     }
 
                 </h1>
             </div>
             <div class="col-sm-2 text-right">
-                <?php map_icon($aPointDetails['icon']) ?>
+                <?php map_icon($aPointDetails) ?>
             </div>
         </div>
         <div class="row">
index 4dc65a5b0d3637e7c27294c0414ab37a2e9b261a..0449dbb94f20916c26b1f68562e0ea185d7d3807 100644 (file)
@@ -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'];
index 73c07ba7fff3274bd7216fa4614c4c80afcf13c7..ff6ddaca8d17bd1d7380a37deb4c5b2e250587e5 100644 (file)
@@ -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)