]> git.openstreetmap.org Git - nominatim.git/commitdiff
factor out geocodejson address generation
authorSarah Hoffmann <lonvia@denofr.de>
Wed, 1 Apr 2020 08:27:17 +0000 (10:27 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Wed, 1 Apr 2020 08:27:17 +0000 (10:27 +0200)
Unifies the two implementations currently used for search and address.

lib/AddressDetails.php
lib/template/address-geocodejson.php
lib/template/search-geocodejson.php

index 61823b4ce9dc504010ed33e67aeb575df400d047..3575d155a9dcfd9eb573027b53c174e3fcd7b48f 100644 (file)
@@ -101,6 +101,28 @@ class AddressDetails
         return $aAddress;
     }
 
         return $aAddress;
     }
 
+    public function addGeocodeJsonAddressParts(&$aJson)
+    {
+        $aFieldMappings = array(
+                           'house_number' => 'housenumber',
+                           'road' => 'street',
+                           'locality' => 'locality',
+                           'postcode' => 'postcode',
+                           'city' => 'city',
+                           'district' => 'district',
+                           'county' => 'county',
+                           'state' => 'state',
+                           'country' => 'country'
+                          );
+
+        $aAddrNames = $this->getAddressNames();
+        foreach ($aFieldMappings as $sFrom => $sTo) {
+            if (isset($aAddrNames[$sFrom])) {
+                $aJson[$sTo] = $aAddrNames[$sFrom];
+            }
+        }
+    }
+
     public function getAdminLevels()
     {
         $aAddress = array();
     public function getAdminLevels()
     {
         $aAddress = array();
index 032dcf4347a1046eb684a517af6cebb980aef176..6ccbeb5786b0563737bf647662205107a2b476b5 100644 (file)
@@ -33,24 +33,9 @@ if (empty($aPlace)) {
     $aFilteredPlaces['properties']['geocoding']['name'] = $aPlace['placename'];
 
     if (isset($aPlace['address'])) {
     $aFilteredPlaces['properties']['geocoding']['name'] = $aPlace['placename'];
 
     if (isset($aPlace['address'])) {
-        $aFieldMappings = array(
-                           'house_number' => 'housenumber',
-                           'road' => 'street',
-                           'locality' => 'locality',
-                           'postcode' => 'postcode',
-                           'city' => 'city',
-                           'district' => 'district',
-                           'county' => 'county',
-                           'state' => 'state',
-                           'country' => 'country'
-                          );
-
-        $aAddressNames = $aPlace['address']->getAddressNames();
-        foreach ($aFieldMappings as $sFrom => $sTo) {
-            if (isset($aAddressNames[$sFrom])) {
-                $aFilteredPlaces['properties']['geocoding'][$sTo] = $aAddressNames[$sFrom];
-            }
-        }
+        $aPlace['address']->addGeocodeJsonAddressParts(
+          $aFilteredPlaces['properties']['geocoding']
+        );
 
         $aFilteredPlaces['properties']['geocoding']['admin']
             = $aPlace['address']->getAdminLevels();
 
         $aFilteredPlaces['properties']['geocoding']['admin']
             = $aPlace['address']->getAdminLevels();
index 29bfe0bf58d4fae3be47896c26d64b00e6bfcf03..c046b4affdde1db98be548913c2521bda6947f16 100644 (file)
@@ -23,24 +23,9 @@ foreach ($aSearchResults as $iResNum => $aPointDetails) {
     $aPlace['properties']['geocoding']['name'] = $aPointDetails['placename'];
 
     if (isset($aPointDetails['address'])) {
     $aPlace['properties']['geocoding']['name'] = $aPointDetails['placename'];
 
     if (isset($aPointDetails['address'])) {
-        $aFieldMappings = array(
-                           'house_number' => 'housenumber',
-                           'road' => 'street',
-                           'locality' => 'locality',
-                           'postcode' => 'postcode',
-                           'city' => 'city',
-                           'district' => 'district',
-                           'county' => 'county',
-                           'state' => 'state',
-                           'country' => 'country'
-                          );
-
-        $aAddrNames = $aPointDetails['address']->getAddressNames();
-        foreach ($aFieldMappings as $sFrom => $sTo) {
-            if (isset($aAddrNames[$sFrom])) {
-                $aPlace['properties']['geocoding'][$sTo] = $aAddrNames[$sFrom];
-            }
-        }
+        $aPointDetails['address']->addGeocodeJsonAddressParts(
+          $aPlace['properties']['geocoding']
+        );
 
         $aPlace['properties']['geocoding']['admin']
             = $aPointDetails['address']->getAdminLevels();
 
         $aPlace['properties']['geocoding']['admin']
             = $aPointDetails['address']->getAdminLevels();