]> git.openstreetmap.org Git - nominatim.git/blob - website/lookup.php
make map tile layer configurable
[nominatim.git] / website / lookup.php
1 <?php
2         @define('CONST_ConnectionBucket_PageType', 'Reverse');
3
4         require_once(dirname(dirname(__FILE__)).'/lib/init-website.php');
5         require_once(CONST_BasePath.'/lib/log.php');
6         require_once(CONST_BasePath.'/lib/PlaceLookup.php');
7
8         if (strpos(CONST_BulkUserIPs, ','.$_SERVER["REMOTE_ADDR"].',') !== false)
9         {
10                 $fLoadAvg = getLoadAverage();
11                 if ($fLoadAvg > 2) sleep(60);
12                 if ($fLoadAvg > 4) sleep(120);
13                 if ($fLoadAvg > 6)
14                 {
15                         userError("Bulk User: Temporary block due to high server load");
16                         exit;
17                 }
18         }
19
20         $oDB =& getDB();
21         ini_set('memory_limit', '200M');
22
23         // Format for output
24         $sOutputFormat = 'xml';
25         if (isset($_GET['format']) && ($_GET['format'] == 'xml' || $_GET['format'] == 'json'))
26         {
27                 $sOutputFormat = $_GET['format'];
28         }
29
30         // Preferred language
31         $aLangPrefOrder = getPreferredLanguages();
32
33         $hLog = logStart($oDB, 'place', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
34
35         $aSearchResults = array();
36         $aCleanedQueryParts = array();
37         if (isset($_GET['osm_ids']))
38         {
39                 $oPlaceLookup = new PlaceLookup($oDB);
40                 $oPlaceLookup->setLanguagePreference($aLangPrefOrder);
41                 $oPlaceLookup->setIncludeAddressDetails(getParamBool('addressdetails', true));
42                 $oPlaceLookup->setIncludeExtraTags(getParamBool('extratags', false));
43                 $oPlaceLookup->setIncludeNameDetails(getParamBool('namedetails', false));
44                 
45                 $aOsmIds = explode(',', $_GET['osm_ids']);
46                 
47                 if ( count($aOsmIds) > CONST_Places_Max_ID_count ) 
48                 {
49                         userError('Bulk User: Only ' . CONST_Places_Max_ID_count . " ids are allowed in one request.");
50                         exit;
51                 }
52                 
53                 foreach ($aOsmIds AS $sItem) 
54                 {
55                         // Skip empty sItem
56                         if (empty($sItem)) continue;
57                         
58                         $sType = $sItem[0];
59                         $iId = (int) substr($sItem, 1);
60                         if ( $iId > 0 && ($sType == 'N' || $sType == 'W' || $sType == 'R') )
61                         {
62                                 $aCleanedQueryParts[] = $sType . $iId;
63                                 $oPlaceLookup->setOSMID($sType, $iId);
64                                 $oPlace = $oPlaceLookup->lookup();
65                                 if ($oPlace){
66                                         // we want to use the search-* output templates, so we need to fill
67                                         // $aSearchResults and slightly change the (reverse search) oPlace
68                                         // key names
69                                         $oResult = $oPlace;
70                                         unset($oResult['aAddress']);
71                                         if (isset($oPlace['aAddress'])) $oResult['address'] = $oPlace['aAddress'];
72                                         unset($oResult['langaddress']);
73                                         $oResult['name'] = $oPlace['langaddress'];
74                                         $aSearchResults[] = $oResult;
75                                 }
76                         }
77                 }
78         }
79
80
81         if (CONST_Debug) exit;
82
83         $sXmlRootTag = 'lookupresults';
84         $sQuery = join(',',$aCleanedQueryParts);
85         // we initialize these to avoid warnings in our logfile
86         $sViewBox = '';
87         $bShowPolygons = '';
88         $aExcludePlaceIDs = [];
89         $sMoreURL = '';
90
91         include(CONST_BasePath.'/lib/template/search-'.$sOutputFormat.'.php');