/
gridsearch.php
executable file
·153 lines (141 loc) · 3.58 KB
/
gridsearch.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/******************************************************************************
* phpGridServer
*
* GNU LESSER GENERAL PUBLIC LICENSE
* Version 2.1, February 1999
*
*/
set_include_path(dirname($_SERVER["SCRIPT_FILENAME"]).PATH_SEPARATOR.get_include_path());
require_once("lib/services.php");
$format = $_GET["format"];
$query = $_GET["q"];
if(isset($_GET["limit"]))
{
$limit = $_GET["limit"];
}
else
{
$limit = 0;
}
$gridService = getService("Grid");
$contentSearchService = getService("ContentSearch");
$json_entry = "";
$regioncache = array();
$objs = $contentSearchService->searchObjectsByName($query);
while($obj = $objs->getObject())
{
try
{
if(!isset($regioncache["".$obj->RegionID]))
{
$region = $gridService->getRegionByUuid(null, $obj->RegionID);
$regioncache["".$obj->RegionID] = $region;
}
}
catch(Exception $e)
{
continue;
}
$region = $regioncache["".$obj->RegionID];
$x = $region->LocX / 256.;
$y = $region->LocY / 256.;
$w = $region->SizeX / 256.;
$h = $region->SizeY / 256.;
$x2 = $x + $w;
$y2 = $y + $h;
$centerx = $obj->Location->X / 256. + $x;
$centery = $obj->Location->Y / 256. + $y;
if($json_entry != "")
{
$json_entry .= ",";
}
$json_entry .= "{\"place_id\":\"".$region->ID."-o-".$obj->ObjectID."\",".
"\"osm_type\":\"relation\",".
"\"osm_id\":\"".$region->ID."-o-".$obj->ObjectID."\",".
"\"boundingbox\":[\"$x\",\"$x2\",\"$y\",\"$y2\"],".
"\"lat\":\"$centerx\",".
"\"lon\":\"$centery\",".
"\"display_name\":\"".$obj->Name." @ ".$region->RegionName."\",".
"\"class\":\"object\",".
"\"type\":\"object\"}";
}
$objs->free();
$parcels = $contentSearchService->searchParcelsByName($query);
while($parcel = $parcels->getParcel())
{
try
{
if(!isset($regioncache["".$parcel->RegionID]))
{
$region = $gridService->getRegionByUuid(null, $parcel->RegionID);
$regioncache["".$parcel->RegionID] = $region;
}
}
catch(Exception $e)
{
continue;
}
$region = $regioncache["".$parcel->RegionID];
$x = $region->LocX / 256.;
$y = $region->LocY / 256.;
$w = $region->SizeX / 256.;
$h = $region->SizeY / 256.;
$x2 = $x + $w;
$y2 = $y + $h;
$centerx = $parcel->LandingPoint->X / 256. + $x;
$centery = $parcel->LandingPoint->Y / 256. + $y;
if($json_entry != "")
{
$json_entry .= ",";
}
$json_entry .= "{\"place_id\":\"".$region->ID."-p-".$parcel->ParcelID."\",".
"\"osm_type\":\"relation\",".
"\"osm_id\":\"".$region->ID."-p-".$parcel->ParcelID."\",".
"\"boundingbox\":[\"$x\",\"$x2\",\"$y\",\"$y2\"],".
"\"lat\":\"$centerx\",".
"\"lon\":\"$centery\",".
"\"display_name\":\"".$parcel->Name." , ".$region->RegionName."\",".
"\"class\":\"place\",".
"\"type\":\"region\"}";
}
$parcels->free();
$regions = $gridService->searchRegionsByName(UUID::ZERO(), $query);
while($region = $regions->getRegion())
{
$x = $region->LocX / 256.;
$y = $region->LocY / 256.;
$w = $region->SizeX / 256.;
$h = $region->SizeY / 256.;
$x2 = $x + $w;
$y2 = $y + $h;
$centerx = $x + $w / 2.;
$centery = $y + $h / 2.;
if($json_entry != "")
{
$json_entry .= ",";
}
$json_entry .= "{\"place_id\":\"".$region->ID."\",".
"\"osm_type\":\"relation\",".
"\"osm_id\":\"".$region->ID."\",".
"\"boundingbox\":[\"$x\",\"$x2\",\"$y\",\"$y2\"],".
"\"lat\":\"$centerx\",".
"\"lon\":\"$centery\",".
"\"display_name\":\"".$region->RegionName."\",".
"\"class\":\"place\",".
"\"type\":\"city\"}";
}
if(isset($_GET["json_callback"]))
{
header("Content-Type: text/javascript");
echo $_GET["json_callback"]."(";
}
else
{
header("Content-Type: application/json");
}
echo "[$json_entry]";
if(isset($_GET["json_callback"]))
{
echo ");";
}