2 @define('CONST_ConnectionBucket_PageType', 'Reverse');
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 require_once(CONST_BasePath.'/lib/ReverseGeocode.php');
10 $bAsGeoJSON = (boolean)isset($_GET['polygon_geojson']) && $_GET['polygon_geojson'];
11 $bAsKML = (boolean)isset($_GET['polygon_kml']) && $_GET['polygon_kml'];
12 $bAsSVG = (boolean)isset($_GET['polygon_svg']) && $_GET['polygon_svg'];
13 $bAsText = (boolean)isset($_GET['polygon_text']) && $_GET['polygon_text'];
14 if ( ( ($bAsGeoJSON?1:0)
19 ) > CONST_PolygonOutput_MaximumTypes)
21 if (CONST_PolygonOutput_MaximumTypes)
23 userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
27 userError("Polygon output is disabled");
33 // Polygon simplification threshold (optional)
35 if (isset($_GET['polygon_threshold'])) $fThreshold = (float)$_GET['polygon_threshold'];
39 ini_set('memory_limit', '200M');
42 $sOutputFormat = 'xml';
43 if (isset($_GET['format']) && ( $_GET['format'] == 'html' || $_GET['format'] == 'xml' || $_GET['format'] == 'json' || $_GET['format'] == 'jsonv2'))
45 $sOutputFormat = $_GET['format'];
49 $aLangPrefOrder = getPreferredLanguages();
51 $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
54 if (isset($_GET['osm_type']) && isset($_GET['osm_id']) && (int)$_GET['osm_id'] && ($_GET['osm_type'] == 'N' || $_GET['osm_type'] == 'W' || $_GET['osm_type'] == 'R'))
56 $aLookup = array('osm_type' => $_GET['osm_type'], 'osm_id' => $_GET['osm_id']);
58 else if (isset($_GET['lat']) && isset($_GET['lon']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lat']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lon']))
60 $oReverseGeocode = new ReverseGeocode($oDB);
61 $oReverseGeocode->setLanguagePreference($aLangPrefOrder);
63 $oReverseGeocode->setLatLon($_GET['lat'], $_GET['lon']);
64 $oReverseGeocode->setZoom(@$_GET['zoom']);
66 $aLookup = $oReverseGeocode->lookup();
67 if (CONST_Debug) var_dump($aLookup);
76 $oPlaceLookup = new PlaceLookup($oDB);
77 $oPlaceLookup->setLanguagePreference($aLangPrefOrder);
78 $oPlaceLookup->setIncludeAddressDetails(getParamBool('addressdetails', true));
79 $oPlaceLookup->setIncludeExtraTags(getParamBool('extratags', false));
80 $oPlaceLookup->setIncludeNameDetails(getParamBool('namedetails', false));
82 $aPlace = $oPlaceLookup->lookupPlace($aLookup);
84 $oPlaceLookup->setIncludePolygonAsPoints($bAsPoints);
85 $oPlaceLookup->setIncludePolygonAsText($bAsText);
86 $oPlaceLookup->setIncludePolygonAsGeoJSON($bAsGeoJSON);
87 $oPlaceLookup->setIncludePolygonAsKML($bAsKML);
88 $oPlaceLookup->setIncludePolygonAsSVG($bAsSVG);
89 $oPlaceLookup->setPolygonSimplificationThreshold($fThreshold);
91 $fRadius = $fDiameter = getResultDiameter($aPlace);
92 $aOutlineResult = $oPlaceLookup->getOutlines($aPlace['place_id'],$aPlace['lon'],$aPlace['lat'],$fRadius);
94 $aPlace = array_merge($aPlace, $aOutlineResult);
101 logEnd($oDB, $hLog, sizeof($aPlace)?1:0);
109 if ($sOutputFormat=='html')
111 $sDataDate = $oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1");
112 $sTileURL = CONST_Map_Tile_URL;
113 $sTileAttribution = CONST_Map_Tile_Attribution;
115 include(CONST_BasePath.'/lib/template/address-'.$sOutputFormat.'.php');