2         @define('CONST_ConnectionBucket_PageType', 'Reverse');
 
   4         require_once(dirname(dirname(__FILE__)).'/settings/settings.php');
 
   5         require_once(CONST_BasePath.'/lib/init-website.php');
 
   6         require_once(CONST_BasePath.'/lib/log.php');
 
   7         require_once(CONST_BasePath.'/lib/PlaceLookup.php');
 
   8         require_once(CONST_BasePath.'/lib/ReverseGeocode.php');
 
   9         require_once(CONST_BasePath.'/lib/output.php');
 
  11         $bAsGeoJSON = getParamBool('polygon_geojson');
 
  12         $bAsKML = getParamBool('polygon_kml');
 
  13         $bAsSVG = getParamBool('polygon_svg');
 
  14         $bAsText = getParamBool('polygon_text');
 
  15         if ((($bAsGeoJSON?1:0) + ($bAsKML?1:0) + ($bAsSVG?1:0)
 
  16                 + ($bAsText?1:0)) > CONST_PolygonOutput_MaximumTypes)
 
  18                 if (CONST_PolygonOutput_MaximumTypes)
 
  20                         userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
 
  24                         userError("Polygon output is disabled");
 
  30         // Polygon simplification threshold (optional)
 
  31         $fThreshold = getParamFloat('polygon_threshold', 0.0);
 
  35         ini_set('memory_limit', '200M');
 
  38         $sOutputFormat = getParamSet('format', array('html', 'xml', 'json', 'jsonv2'), 'xml');
 
  41         $aLangPrefOrder = getPreferredLanguages();
 
  43         $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
 
  46         $oPlaceLookup = new PlaceLookup($oDB);
 
  47         $oPlaceLookup->setLanguagePreference($aLangPrefOrder);
 
  48         $oPlaceLookup->setIncludeAddressDetails(getParamBool('addressdetails', true));
 
  49         $oPlaceLookup->setIncludeExtraTags(getParamBool('extratags', false));
 
  50         $oPlaceLookup->setIncludeNameDetails(getParamBool('namedetails', false));
 
  52         $sOsmType = getParamSet('osm_type', array('N', 'W', 'R'));
 
  53         $iOsmId = getParamInt('osm_id', -1);
 
  54         $fLat = getParamFloat('lat');
 
  55         $fLon = getParamFloat('lon');
 
  56         if ($sOsmType && $iOsmId > 0)
 
  58                 $aPlace = $oPlaceLookup->lookupOSMID($sOsmType, $iOsmId);
 
  60         else if ($fLat !== false && $fLon !== false)
 
  62                 $oReverseGeocode = new ReverseGeocode($oDB);
 
  63                 $oReverseGeocode->setZoom(getParamInt('zoom', 18));
 
  65                 $aLookup = $oReverseGeocode->lookup($fLat, $fLon);
 
  66                 if (CONST_Debug) var_dump($aLookup);
 
  68                 $aPlace = $oPlaceLookup->lookup((int)$aLookup['place_id'],
 
  69                                                 $aLookup['type'], $aLookup['fraction']);
 
  71         else if ($sOutputFormat != 'html')
 
  73                 userError("Need coordinates or OSM object to lookup.");
 
  78                 $oPlaceLookup->setIncludePolygonAsPoints(false);
 
  79                 $oPlaceLookup->setIncludePolygonAsText($bAsText);
 
  80                 $oPlaceLookup->setIncludePolygonAsGeoJSON($bAsGeoJSON);
 
  81                 $oPlaceLookup->setIncludePolygonAsKML($bAsKML);
 
  82                 $oPlaceLookup->setIncludePolygonAsSVG($bAsSVG);
 
  83                 $oPlaceLookup->setPolygonSimplificationThreshold($fThreshold);
 
  85                 $fRadius = $fDiameter = getResultDiameter($aPlace);
 
  86                 $aOutlineResult = $oPlaceLookup->getOutlines($aPlace['place_id'],
 
  87                                                              $aPlace['lon'], $aPlace['lat'],
 
  92                         $aPlace = array_merge($aPlace, $aOutlineResult);
 
 103         if ($sOutputFormat=='html')
 
 105                 $sDataDate = chksql($oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1"));
 
 106                 $sTileURL = CONST_Map_Tile_URL;
 
 107                 $sTileAttribution = CONST_Map_Tile_Attribution;
 
 109         include(CONST_BasePath.'/lib/template/address-'.$sOutputFormat.'.php');