X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/28a5ef899ed824fa857427708607271926a20ef3..eda837a9e5dae51fbe39fbbde3c7f415af5b2a1c:/website/hierarchy.php
diff --git a/website/hierarchy.php b/website/hierarchy.php
index 8562de33..de83ca44 100755
--- a/website/hierarchy.php
+++ b/website/hierarchy.php
@@ -6,14 +6,11 @@
require_once(CONST_BasePath.'/lib/PlaceLookup.php');
$sOutputFormat = 'html';
- /*
- $fLoadAvg = getLoadAverage();
- if ($fLoadAvg > 3)
- {
- echo "Page temporarily blocked due to high server load\n";
- exit;
- }
- */
+ if (isset($_GET['format']) && ($_GET['format'] == 'html' || $_GET['format'] == 'xml' || $_GET['format'] == 'json' || $_GET['format'] == 'jsonv2'))
+ {
+ $sOutputFormat = $_GET['format'];
+ }
+
ini_set('memory_limit', '200M');
$oDB =& getDB();
@@ -67,14 +64,33 @@
$oPlaceLookup->setPlaceId($iPlaceID);
$aPlaceAddress = array_reverse($oPlaceLookup->getAddressDetails());
+
+ if (!sizeof($aPlaceAddress))
+ {
+ echo "Unknown place id.";
+ exit;
+ }
+
+ $aBreadcrums = array();
foreach($aPlaceAddress as $i => $aPlace)
{
if (!$aPlace['place_id']) continue;
- $sPlaceUrl = 'http://localhost/nominatim/details.php?place_id='.$aPlace['place_id'];
+ $aBreadcrums[] = array('placeId'=>$aPlace['place_id'], 'osmType'=>$aPlace['osm_type'], 'osmId'=>$aPlace['osm_id'], 'localName'=>$aPlace['localname']);
+ $sPlaceUrl = 'hierarchy.php?place_id='.$aPlace['place_id'];
$sOSMType = ($aPlace['osm_type'] == 'N'?'node':($aPlace['osm_type'] == 'W'?'way':($aPlace['osm_type'] == 'R'?'relation':'')));
- $sOSMUrl = 'http://www.openstreetmap.org/browse/'.$sOSMType.'/'.$aPlace['osm_id'];
- if ($i) echo " > ";
- echo ''.$aPlace['localname'].' (osm)';
+ $sOSMUrl = 'http://www.openstreetmap.org/browse/'.$sOSMType.'/'.$aPlace['osm_id'];
+ if ($sOutputFormat == 'html') if ($i) echo " > ";
+ if ($sOutputFormat == 'html') echo ''.$aPlace['localname'].' (osm)';
+ }
+
+ $aDetails = array();
+ $aDetails['breadcrumbs'] = $aBreadcrums;
+
+ if ($sOutputFormat == 'json')
+ {
+ header("content-type: application/json; charset=UTF-8");
+ javascript_renderData($aDetails);
+ exit;
}
$aRelatedPlaceIDs = $oDB->getCol($sSQL = "select place_id from placex where linked_place_id = $iPlaceID or place_id = $iPlaceID");
@@ -86,52 +102,52 @@
$sSQL .= " order by rank_address asc,rank_search asc,localname,class, type,housenumber";
$aParentOfLines = $oDB->getAll($sSQL);
- if (sizeof($aParentOfLines))
- {
- echo '
Parent Of:
';
+ if (sizeof($aParentOfLines))
+ {
+ echo 'Parent Of:
';
$aClassType = getClassTypesWithImportance();
- $aGroupedAddressLines = array();
- foreach($aParentOfLines as $aAddressLine)
- {
+ $aGroupedAddressLines = array();
+ foreach($aParentOfLines as $aAddressLine)
+ {
if (isset($aClassType[$aAddressLine['class'].':'.$aAddressLine['type'].':'.$aAddressLine['admin_level']]['label'])
- && $aClassType[$aAddressLine['class'].':'.$aAddressLine['type'].':'.$aAddressLine['admin_level']]['label'])
- {
- $aAddressLine['label'] = $aClassType[$aAddressLine['class'].':'.$aAddressLine['type'].':'.$aAddressLine['admin_level']]['label'];
- }
+ && $aClassType[$aAddressLine['class'].':'.$aAddressLine['type'].':'.$aAddressLine['admin_level']]['label'])
+ {
+ $aAddressLine['label'] = $aClassType[$aAddressLine['class'].':'.$aAddressLine['type'].':'.$aAddressLine['admin_level']]['label'];
+ }
elseif (isset($aClassType[$aAddressLine['class'].':'.$aAddressLine['type']]['label'])
- && $aClassType[$aAddressLine['class'].':'.$aAddressLine['type']]['label'])
- {
- $aAddressLine['label'] = $aClassType[$aAddressLine['class'].':'.$aAddressLine['type']]['label'];
- }
+ && $aClassType[$aAddressLine['class'].':'.$aAddressLine['type']]['label'])
+ {
+ $aAddressLine['label'] = $aClassType[$aAddressLine['class'].':'.$aAddressLine['type']]['label'];
+ }
else $aAddressLine['label'] = ucwords($aAddressLine['type']);
- if (!isset($aGroupedAddressLines[$aAddressLine['label']])) $aGroupedAddressLines[$aAddressLine['label']] = array();
- $aGroupedAddressLines[$aAddressLine['label']][] = $aAddressLine;
- }
- foreach($aGroupedAddressLines as $sGroupHeading => $aParentOfLines)
- {
- echo "$sGroupHeading
";
- foreach($aParentOfLines as $aAddressLine)
- {
- $aAddressLine['localname'] = $aAddressLine['localname']?$aAddressLine['localname']:$aAddressLine['housenumber'];
- $sOSMType = ($aAddressLine['osm_type'] == 'N'?'node':($aAddressLine['osm_type'] == 'W'?'way':($aAddressLine['osm_type'] == 'R'?'relation':'')));
-
- echo '';
- echo '
'.(trim($aAddressLine['localname'])?$aAddressLine['localname']:'No Name').'';
- echo ' (';
- echo '
'.($aAddressLine['isarea']=='t'?'Polygon':'Point').'';
- if ($sOSMType) echo ',
'.$sOSMType.' '.$aAddressLine['osm_id'].'';
- echo ',
GOTO';
- echo ', '.$aAddressLine['area'];
- echo ')';
- echo '
';
- }
- }
- if (sizeof($aParentOfLines) >= 500) {
- echo 'There are more child objects which are not shown.
';
- }
- echo '';
- }
+ if (!isset($aGroupedAddressLines[$aAddressLine['label']])) $aGroupedAddressLines[$aAddressLine['label']] = array();
+ $aGroupedAddressLines[$aAddressLine['label']][] = $aAddressLine;
+ }
+ foreach($aGroupedAddressLines as $sGroupHeading => $aParentOfLines)
+ {
+ echo "$sGroupHeading
";
+ foreach($aParentOfLines as $aAddressLine)
+ {
+ $aAddressLine['localname'] = $aAddressLine['localname']?$aAddressLine['localname']:$aAddressLine['housenumber'];
+ $sOSMType = ($aAddressLine['osm_type'] == 'N'?'node':($aAddressLine['osm_type'] == 'W'?'way':($aAddressLine['osm_type'] == 'R'?'relation':'')));
+
+ echo '';
+ echo '
'.(trim($aAddressLine['localname'])?$aAddressLine['localname']:'No Name').'';
+ echo ' (';
+ echo '
'.($aAddressLine['isarea']=='t'?'Polygon':'Point').'';
+ if ($sOSMType) echo ',
'.$sOSMType.' '.$aAddressLine['osm_id'].'';
+ echo ',
GOTO';
+ echo ', '.$aAddressLine['area'];
+ echo ')';
+ echo '
';
+ }
+ }
+ if (sizeof($aParentOfLines) >= 500) {
+ echo 'There are more child objects which are not shown.
';
+ }
+ echo '';
+ }
exit;