-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathquerymap.php
More file actions
executable file
·219 lines (173 loc) · 5.9 KB
/
Copy pathquerymap.php
File metadata and controls
executable file
·219 lines (173 loc) · 5.9 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
require_once('config.php');
require_once('fileutils.php');
require_once('messagepump.php');
function MapQuery($userInfo,$bboxStr)
{
if (!isset($bboxStr)) {
if(DEBUG_MODE) debug_print_backtrace();
throw new Exception("missing bboxStr array in MapQuery");
}
if (count($bboxStr) <1 ) {
if(DEBUG_MODE) debug_print_backtrace();
throw new Exception("bboxStr array is empty in MapQuery");
}
if(DEBUG_MODE) dprint("bboxStr:",$bboxStr);
$bbox = explode(",",$bboxStr['bbox']);
$bbox = array_map('floatval', $bbox);
//Validate bbox
$ret = ValidateBbox($bbox);
if(!is_array($ret)) return array(0,Null,$ret);
$lock=GetReadDatabaseLock();
$ret = CallFuncByMessage(Message::MAP_QUERY, $bbox);
return array(1,array("Content-Type:text/xml"),$ret);
}
function GetObjectByIdMessage($type, $id, $version=null)
{
return CallFuncByMessage(Message::GET_OBJECT_BY_ID, array($type,(int)$id,$version));
}
function MapObjectQuery($userInfo,$expUrl)
{
$type=$expUrl[2];
$id=(int)$expUrl[3];
if(isset($expUrl[4])) $version=$expUrl[4];
else $version = Null;
$lock = GetReadDatabaseLock();
$obj = GetObjectByIdMessage($type, $id, $version);
if(!is_object($obj))
{
if($obj==0) return array(0,Null,"not-found");
if($obj==-1) return array(0,Null,"not-implemented");
if($obj==-2) return array(0,Null,"gone",$type,$id);
return $obj;
}
$out = '<?xml version="1.0" encoding="UTF-8"?>'."\n".
'<osm version="0.6" generator="'.SERVER_NAME.'">'.$obj->ToXmlString().'</osm>';
return array(1,array("Content-Type:text/xml"),$out);
}
function MapObjectFullHistory($userInfo,$expUrl)
{
$type=$expUrl[2];
$id=(int)$expUrl[3];
$lock=GetReadDatabaseLock();
$objs = CallFuncByMessage(Message::GET_FULL_HISTORY, array($type,(int)$id));
if(!is_array($objs))
{
if($objs==0 or is_null($objs)) return array(0,Null,"not-found");
if($objs==-1) return array(0,Null,"not-implemented");
throw new Exception("Unrecognised return code");
}
$out = '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<osm version="0.6" generator="'.SERVER_NAME.'">';
foreach($objs as $obj) $out = $out.$obj->ToXmlString();
$out = $out.'</osm>';
return array(1,array("Content-Type:text/xml"),$out);
}
function MultiFetch($userInfo, $args)
{
list($urlExp,$get) = $args;
$type = $urlExp[2];
if(!isset($get[$type])) return array(0,Null,"bad-arguments");
$ids = explode(",",$get[$type]);
$type = substr($type,0,-1); //Change to singular type
$lock=GetReadDatabaseLock();
$out = '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<osm version="0.6" generator="'.SERVER_NAME.'">';
$emptyQuery = 0;
if(count($ids)<1 or (count($ids)==1 and strlen($ids[0])==0))
$emptyQuery = 1;
if(!$emptyQuery)
foreach($ids as $id)
{
$object = GetObjectByIdMessage($type, (int)$id);
if($object==null) return array(0,Null,"not-found");
$out = $out.$object->ToXmlString()."\n";
}
$out = $out."</osm>";
return array(1,array("Content-Type:text/xml"),$out);
}
function GetRelationsForElement($userInfo,$urlExp)
{
$type = $urlExp[2];
$id = (int)$urlExp[3];
$lock=GetReadDatabaseLock();
$out = '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<osm version="0.6" generator="'.SERVER_NAME.'">';
$rels = CallFuncByMessage(Message::GET_RELATIONS_FOR_ELEMENT, array($type,(int)$id));
//For each relation found to match
foreach($rels as $id)
{
if(!is_integer($id)) throw new Exception("Values in relation array should be ID integers");
$object = GetObjectByIdMessage("relation", (int)$id);
if($object==null) return array(0,Null,"not-found");
$out = $out.$object->ToXmlString()."\n";
}
$out = $out."</osm>";
return array(1,array("Content-Type:text/xml"),$out);
}
function GetWaysForNode($userInfo,$urlExp)
{
$id = (int)$urlExp[3];
$lock=GetReadDatabaseLock();
$out = '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<osm version="0.6" generator="'.SERVER_NAME.'">';
$ways = CallFuncByMessage(Message::GET_WAY_IDS_FOR_NODE, (int)$id);
//For each relation found to match
foreach($ways as $id)
{
if(!is_integer($id)) throw new Exception("Values in way array should be ID integers");
$object = GetObjectByIdMessage("way", (int)$id);
if($object==null) return array(0,Null,"not-found");
$out = $out.$object->ToXmlString()."\n";
}
$out = $out."</osm>";
return array(1,array("Content-Type:text/xml"),$out);
}
function GetFullDetailsOfElement($userInfo,$urlExp)
{
//TODO: This really should be changed to use the GET_ELEMENT_FULL_DATA message...
$type=$urlExp[2];
$id=(int)$urlExp[3];
$lock=GetReadDatabaseLock();
$out = '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<osm version="0.6" generator="'.SERVER_NAME.'">';
$firstObj = GetObjectByIdMessage($type,(int)$id, Null);
//print_r($firstObj);
if($firstObj===null or $firstObj===0) return array(0,Null,"not-found");
if($firstObj===-2) return array(0,Null,"gone",$type,$id);
$out = $out.$firstObj->ToXmlString()."\n";
//Get relations but don't go recursively
foreach($firstObj->members as $data)
{
if($data[0] != "relation") continue;
$id = $data[1];
$obj = GetObjectByIdMessage("relation",(int)$id);
if($obj==null) return array(0,Null,"not-found");
$out = $out.$obj->ToXmlString()."\n";
}
//Get ways
foreach($firstObj->members as $data)
{
if($data[0] != "way") continue;
$id = $data[1];
$obj = GetObjectByIdMessage("way",(int)$id);
if($obj==null) return array(0,Null,"not-found");
$out = $out.$obj->ToXmlString()."\n";
//Get nodes of ways
foreach($obj->members as $mem)
{
if($mem[0] != "node") continue;
$nid = $mem[1];
$n = GetObjectByIdMessage("node",(int)$nid);
if($n==null) return array(0,Null,"not-found");
$out = $out.$n->ToXmlString()."\n";
}
}
//Get nodes of ways
foreach($firstObj->members as $nd)
{
if($data[0] != "node") continue;
$nid = $nd[1];
$n = GetObjectByIdMessage("node",(int)$nid);
if($n==null) return array(0,Null,"not-found");
$out = $out.$n->ToXmlString()."\n";
}
$out = $out."</osm>";
return array(1,array("Content-Type:text/xml"),$out);
}
?>