Commit 097441481312dec228fdddd90d2cc2c10b297d8e
1 parent
1e9c7de7
Exists in
master
and in
7 other branches
--no commit message
Showing
1 changed file
with
577 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,577 @@ | @@ -0,0 +1,577 @@ | ||
1 | +<?php | ||
2 | +$cache = true; | ||
3 | +require_once(dirname(__FILE__)."/../../classesphp/carrega_ext.php"); | ||
4 | +include(dirname(__FILE__)."/../../ms_configura.php"); | ||
5 | +include(dirname(__FILE__)."/../../classesphp/pega_variaveis.php"); | ||
6 | +include(dirname(__FILE__)."/../../classesphp/funcoes_gerais.php"); | ||
7 | +$temas = $tema; | ||
8 | +// | ||
9 | +//pega os endereços para compor a url de chamada do gerador de web services | ||
10 | +//ogc.php | ||
11 | +// | ||
12 | +$protocolo = explode("/",$_SERVER['SERVER_PROTOCOL']); | ||
13 | +$protocolo = $protocolo[0]; | ||
14 | +$protocolo1 = strtolower($protocolo) . '://'.$_SERVER['SERVER_NAME']; | ||
15 | +$protocolo = strtolower($protocolo) . '://'.$_SERVER['SERVER_NAME'] .":". $_SERVER['SERVER_PORT']; | ||
16 | +$urli3geo = str_replace("/ogc.php","",$protocolo.$_SERVER["PHP_SELF"]); | ||
17 | +// | ||
18 | +//cria o web service | ||
19 | +// | ||
20 | +error_reporting(0); | ||
21 | +$versao = versao(); | ||
22 | +$versao = $versao["principal"]; | ||
23 | +if($_GET["SRS"] == "EPSG:900913"){ | ||
24 | + $_GET["SRS"] = "EPSG:3857"; | ||
25 | +} | ||
26 | +$req = ms_newowsrequestobj(); | ||
27 | +$tipo = ""; | ||
28 | +$_GET = array_merge($_GET,$_POST); | ||
29 | +if(isset($_GET["sld"]) || isset($_GET["filter"])){ | ||
30 | + $cache = false; | ||
31 | +} | ||
32 | +if(!isset($_GET["srs"]) && !isset($_GET["SRS"])){ | ||
33 | + $_GET["srs"] = "EPSG:4326"; | ||
34 | +} | ||
35 | +foreach ($_GET as $k=>$v){ | ||
36 | + $req->setParameter(strtoupper($k), $v); | ||
37 | + if(strtolower($k) == "layers" && empty($_GET["tema"])){ | ||
38 | + $tema = $v; | ||
39 | + } | ||
40 | + if(strtolower($k) == "layer" && empty($_GET["tema"])){ | ||
41 | + $tema = $v; | ||
42 | + } | ||
43 | +} | ||
44 | +$req->setParameter("srsName",$req->getValueByName("SRS")); | ||
45 | +$listaepsg = $req->getValueByName("SRS")." EPSG:4618 EPSG:4291 EPSG:4326 EPSG:22521 EPSG:22522 EPSG:22523 EPSG:22524 EPSG:22525 EPSG:29101 EPSG:29119 EPSG:29120 EPSG:29121 EPSG:29122 EPSG:29177 EPSG:29178 EPSG:29179 EPSG:29180 EPSG:29181 EPSG:29182 EPSG:29183 EPSG:29184 EPSG:29185"; | ||
46 | +$tipo = ""; | ||
47 | +if(isset($version) && !isset($VERSION)){ | ||
48 | + $VERSION = $version; | ||
49 | +} | ||
50 | +if(!isset($VERSION)){ | ||
51 | + $req->setParameter("VeRsIoN","1.0.0"); | ||
52 | +} | ||
53 | +//compatibiliza chamadas fora do padrao | ||
54 | +// | ||
55 | +if(isset($_GET["outputFormat"]) && $_GET["outputFormat"] != ""){ | ||
56 | + $_GET["OUTPUTFORMAT"] = $_GET["outputFormat"]; | ||
57 | +} | ||
58 | +$_GET["DESLIGACACHE"] = "sim"; | ||
59 | +$agora = time(); | ||
60 | +$cache = false; | ||
61 | +$nomeMapfileTmp = $dir_tmp."/ogc_".md5($tema)."_".$agora.".map"; | ||
62 | +$nomeMapfileTmp = str_replace(",","",$nomeMapfileTmp); | ||
63 | +$nomeMapfileTmp = str_replace(" ","",$nomeMapfileTmp); | ||
64 | +//essa variavel e usada para definir se a imagem final gerada devera ser cortada ou nao | ||
65 | +$cortePixels = 0; | ||
66 | +if(file_exists($nomeMapfileTmp) && $tipo == ""){ | ||
67 | + $oMap = ms_newMapobj($nomeMapfileTmp); | ||
68 | +} | ||
69 | +else{ | ||
70 | + if(empty($ogcwsmap)){ | ||
71 | + $oMap = ms_newMapobj($locaplic."/aplicmap/ogcwsv".$versao.".map"); | ||
72 | + } | ||
73 | + else{ | ||
74 | + $oMap = ms_newMapobj($ogcwsmap); | ||
75 | + } | ||
76 | + $proto = "http" . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "") . "://"; | ||
77 | + $server = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']; | ||
78 | + $or = $proto.$server.$_SERVER['PHP_SELF']; | ||
79 | + if((isset($tema)) && ($tema != "") && ($tipo=="metadados")){ | ||
80 | + $or = $or."?tema=".$tema."&"; | ||
81 | + } | ||
82 | + // | ||
83 | + //parametros no nível maior | ||
84 | + // | ||
85 | + $oMap->setmetadata("ows_onlineresource",$or); | ||
86 | + $oMap->setmetadata("wms_onlineresource",$or); | ||
87 | + $oMap->setmetadata("wms_title",$tituloInstituicao." - i3geo"); | ||
88 | + $oMap->setmetadata("wfs_title",$tituloInstituicao." - i3geo"); | ||
89 | + $oMap->setmetadata("wms_attribution_logourl_format","image/png"); | ||
90 | + $oMap->setmetadata("wms_attribution_logourl_height","56"); | ||
91 | + $oMap->setmetadata("wms_attribution_logourl_width","85"); | ||
92 | + $oMap->setmetadata("wms_attribution_logourl_href",$proto.$server.dirname($_SERVER['PHP_SELF'])."/imagens/i3geo.png"); | ||
93 | + $oMap->setmetadata("wms_attribution_onlineresource",$proto.$server.dirname($_SERVER['PHP_SELF'])); | ||
94 | + $oMap->setmetadata("wms_attribution_title",$tituloInstituicao); | ||
95 | + $oMap->setmetadata("ows_enable_request","*"); | ||
96 | + //parametro mandatario | ||
97 | + if($oMap->getmetadata("wms_srs") == ""){ | ||
98 | + $oMap->setmetadata("wms_srs","EPSG:4326"); | ||
99 | + } | ||
100 | + $e = $oMap->extent; | ||
101 | + $extensaoMap = ($e->minx)." ".($e->miny)." ".($e->maxx)." ".($e->maxy); | ||
102 | + //gera o mapa | ||
103 | + if ($tipo == "" || $tipo == "metadados"){ | ||
104 | + $tema = explode(" ",$tema); | ||
105 | + //para o caso do tema ser um arquivo mapfile existente em uma pasta qualquer | ||
106 | + //$temai3geo = true indica que o layer será buscado na pasta i3geo/temas | ||
107 | + $temai3geo = true; | ||
108 | + if(file_exists($_GET["tema"]) && !isset($id_medida_variavel)){ | ||
109 | + $nmap = ms_newMapobj($_GET["tema"]); | ||
110 | + $temai3geo = false; | ||
111 | + $nmap->setmetadata("ows_enable_request","*"); | ||
112 | + } | ||
113 | + foreach ($tema as $tx){ | ||
114 | + $extensao = ".map"; | ||
115 | + if($temai3geo == true && file_exists($locaplic."/temas/".$tx.".php")){ | ||
116 | + $extensao = ".php"; | ||
117 | + } | ||
118 | + if($temai3geo == true && file_exists($locaplic."/temas/".$tx.".gvp")){ | ||
119 | + $extensao = ".gvp"; | ||
120 | + } | ||
121 | + if($extensao == ".map"){ | ||
122 | + //cria o mapfile com base no sistema de metadados estatisticos | ||
123 | + //verifica se o id_medida_variavel existe no mapfile e nao foi passado como um parametro | ||
124 | + if(!isset($id_medida_variavel) && $temai3geo == true){ | ||
125 | + $nmap = ms_newMapobj($locaplic."/temas/".$tx.".map"); | ||
126 | + $l = $nmap->getlayer(0); | ||
127 | + $teste = $l->getmetadata("METAESTAT_ID_MEDIDA_VARIAVEL"); | ||
128 | + if($teste != "" && $l->data == ""){ | ||
129 | + $id_medida_variavel = $teste; | ||
130 | + } | ||
131 | + } | ||
132 | + if(isset($id_medida_variavel)){ | ||
133 | + $temai3geo = false; | ||
134 | + include("admin/php/classe_metaestat.php"); | ||
135 | + $m = new Metaestat(); | ||
136 | + $m->nomecache = "ogcmetaestat".$id_medida_variavel; | ||
137 | + $mapfileMetaestat = $m->mapfileMedidaVariavel($id_medida_variavel,"",1,"","","","","","",true); | ||
138 | + $nmap = ms_newMapobj($mapfileMetaestat["mapfile"]); | ||
139 | + $nmap->setmetadata("ows_enable_request","*"); | ||
140 | + $req->setParameter("LAYERS", "ogcmetaestat".$id_medida_variavel); | ||
141 | + } | ||
142 | + if($temai3geo == true){ | ||
143 | + $nmap = ms_newMapobj($locaplic."/temas/".$tx.".map"); | ||
144 | + $nmap->setmetadata("ows_enable_request","*"); | ||
145 | + } | ||
146 | + if($temai3geo == false || empty($layers)) | ||
147 | + { | ||
148 | + $ts = $nmap->getalllayernames(); | ||
149 | + $nmap->setmetadata("ows_enable_request","*"); | ||
150 | + } | ||
151 | + else{ | ||
152 | + $ts = explode(",",str_replace(" ",",",$layers)); | ||
153 | + } | ||
154 | + foreach ($ts as $t){ | ||
155 | + $l = $nmap->getlayerbyname($t); | ||
156 | + $permite = $l->getmetadata("permiteogc"); | ||
157 | + if(strtolower($permite) != "nao"){ | ||
158 | + //necessário pq o mapfile pode ter todos os layers como default | ||
159 | + if($temai3geo == false){ | ||
160 | + $l->set("status",MS_OFF); | ||
161 | + } | ||
162 | + /* | ||
163 | + if($cache == true && strtolower($l->getmetadata('cache')) == 'sim' && $tipo == '' && count($tema) == 1){ | ||
164 | + carregaCacheImagem($_GET['BBOX'],$tx,$_GET['WIDTH'],$_GET['HEIGHT'],$cachedir); | ||
165 | + } | ||
166 | + */ | ||
167 | + $l->setmetadata("ows_title",pegaNome($l)); | ||
168 | + $l->setmetadata("ows_srs",$listaepsg); | ||
169 | + $l->set("group",""); | ||
170 | + //essa linha é necessária pq as vezes no mapfile não tem nenhum layer com o nome igual ao nome do mapfile | ||
171 | + if(count($ts)==1 && $temai3geo == true){ | ||
172 | + $l->set("name",$tx); | ||
173 | + } | ||
174 | + $l->setmetadata("gml_include_items","all"); | ||
175 | + $l->set("template","none.htm"); | ||
176 | + $l->set("dump",MS_TRUE); | ||
177 | + $l->setmetadata("WMS_INCLUDE_ITEMS","all"); | ||
178 | + $l->setmetadata("WFS_INCLUDE_ITEMS","all"); | ||
179 | + if(file_exists($locaplic."/temas/miniaturas/".$t.".map.mini.png")){ | ||
180 | + $mini = $proto.$server.dirname($_SERVER['PHP_SELF'])."/temas/miniaturas/".$t.".map.mini.png"; | ||
181 | + $l->setmetadata("wms_attribution_logourl_format","image/png"); | ||
182 | + $l->setmetadata("wms_attribution_logourl_height","50"); | ||
183 | + $l->setmetadata("wms_attribution_logourl_width","50"); | ||
184 | + $l->setmetadata("wms_attribution_logourl_href",$mini); | ||
185 | + } | ||
186 | + if($l->type == MS_LAYER_RASTER && $l->numclasses > 0){ | ||
187 | + $c = $l->getclass(0); | ||
188 | + if($c->name == ""){ | ||
189 | + $c->name = " "; | ||
190 | + } | ||
191 | + } | ||
192 | + //inclui extensao geografica | ||
193 | + $extensao = $l->getmetadata("EXTENSAO"); | ||
194 | + if($extensao == ""){ | ||
195 | + $extensao = $extensaoMap; | ||
196 | + } | ||
197 | + $l->setmetadata("wms_extent",$extensao); | ||
198 | + if (!empty($postgis_mapa)){ | ||
199 | + if ($l->connectiontype == MS_POSTGIS){ | ||
200 | + $lcon = $l->connection; | ||
201 | + if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))){ | ||
202 | + // | ||
203 | + //o metadata CONEXAOORIGINAL guarda o valor original para posterior substituição | ||
204 | + // | ||
205 | + if(($lcon == " ") || ($lcon == "")){ | ||
206 | + $l->set("connection",$postgis_mapa); | ||
207 | + $l->setmetadata("CONEXAOORIGINAL",$lcon); | ||
208 | + } | ||
209 | + else{ | ||
210 | + $l->set("connection",$postgis_mapa[$lcon]); | ||
211 | + $l->setmetadata("CONEXAOORIGINAL",$lcon); | ||
212 | + } | ||
213 | + } | ||
214 | + } | ||
215 | + } | ||
216 | + autoClasses($l,$oMap); | ||
217 | + if($versao > 5){ | ||
218 | + $pr = $l->getProcessing(); | ||
219 | + if(!in_array("LABEL_NO_CLIP=True",$pr)){ | ||
220 | + $l->setprocessing("LABEL_NO_CLIP=True"); | ||
221 | + } | ||
222 | + if(!in_array("POLYLINE_NO_CLIP=True",$pr)){ | ||
223 | + $l->setprocessing("POLYLINE_NO_CLIP=True"); | ||
224 | + } | ||
225 | + } | ||
226 | + // | ||
227 | + //verifica se existem parametros de substituicao passados via url | ||
228 | + // | ||
229 | + $parametro = $_GET["map_layer_".$l->name."_filter"]; | ||
230 | + //echo $parametro;exit; | ||
231 | + if(!empty($parametro)){ | ||
232 | + $l->setfilter($parametro); | ||
233 | + $cache = false; | ||
234 | + } | ||
235 | + | ||
236 | + ms_newLayerObj($oMap, $l); | ||
237 | + //$req->setParameter("LAYERS", "mundo"); | ||
238 | + } | ||
239 | + } | ||
240 | + } | ||
241 | + if($extensao == ".php"){ | ||
242 | + include_once($locaplic."/temas/".$tx.".php"); | ||
243 | + eval($tx."(\$oMap);"); | ||
244 | + } | ||
245 | + if($extensao == ".gvp"){ | ||
246 | + include_once($locaplic."/pacotes/gvsig/gvsig2mapfile/class.gvsig2mapfile.php"); | ||
247 | + $gm = new gvsig2mapfile($locaplic."/temas/".$tx.".gvp"); | ||
248 | + $gvsigview = $gm->getViewsNames(); | ||
249 | + foreach($gvsigview as $gv){ | ||
250 | + $dataView = $gm->getViewData($gv); | ||
251 | + $oMap = $gm->addLayers($oMap,$gv,$dataView["layerNames"]); | ||
252 | + } | ||
253 | + $numlayers = $oMap->numlayers; | ||
254 | + $layers = array(); | ||
255 | + //$layers[] = "default"; | ||
256 | + for ($i=0;$i < $numlayers;$i++){ | ||
257 | + $l = $oMap->getlayer($i); | ||
258 | + $l->setmetadata("gml_include_items","all"); | ||
259 | + $l->set("dump",MS_TRUE); | ||
260 | + $l->setmetadata("WMS_INCLUDE_ITEMS","all"); | ||
261 | + $l->setmetadata("WFS_INCLUDE_ITEMS","all"); | ||
262 | + $l->setmetadata("ows_srs",$listaepsg); | ||
263 | + $l->setmetadata("ows_title",$l->getmetadata("TEMA")); | ||
264 | + $l->set("status",MS_OFF); | ||
265 | + $layers[] = $l->name; | ||
266 | + if(file_exists($locaplic."/temas/miniaturas/".$tx.".map.mini.png")){ | ||
267 | + $mini = $proto.$server.dirname($_SERVER['PHP_SELF'])."/temas/miniaturas/".$tx.".map.mini.png"; | ||
268 | + $l->setmetadata("wms_attribution_logourl_format","image/png"); | ||
269 | + $l->setmetadata("wms_attribution_logourl_height","50"); | ||
270 | + $l->setmetadata("wms_attribution_logourl_width","50"); | ||
271 | + $l->setmetadata("wms_attribution_logourl_href",$mini); | ||
272 | + } | ||
273 | + if($l->type == MS_LAYER_RASTER && $l->numclasses > 0){ | ||
274 | + $c = $l->getclass(0); | ||
275 | + if($c->name == ""){ | ||
276 | + $c->name = " "; | ||
277 | + } | ||
278 | + } | ||
279 | + //inclui extensao geografica | ||
280 | + $extensao = $l->getmetadata("EXTENSAO"); | ||
281 | + if($extensao == ""){ | ||
282 | + $extensao = $extensaoMap; | ||
283 | + } | ||
284 | + $l->setmetadata("wms_extent",$extensao); | ||
285 | + // | ||
286 | + //numero de pixels que serao considerados para corte da imagem no caso de cache ativo e tema de pontos | ||
287 | + // | ||
288 | + if ($l->getmetadata("cortepixels") != ""){ | ||
289 | + $cortePixels = $l->getmetadata("cortepixels"); | ||
290 | + } | ||
291 | + } | ||
292 | + $req->setParameter("LAYERS", implode(",",$layers)); | ||
293 | + $req->setParameter("STYLES", ""); | ||
294 | + //r_dump($req);exit; | ||
295 | + } | ||
296 | + } | ||
297 | + } | ||
298 | + else{ | ||
299 | + $conta = 0; | ||
300 | + $int = explode(",",$intervalo); | ||
301 | + $codigosTema = array(); | ||
302 | + if(empty($perfil)){ | ||
303 | + $perfil = ""; | ||
304 | + } | ||
305 | + include("classesphp/classe_menutemas.php"); | ||
306 | + $m = new Menutemas("",$perfil,$locaplic,$urli3geo); | ||
307 | + $menus = $m->pegaListaDeMenus(); | ||
308 | + foreach ($menus as $menu){ | ||
309 | + $grupos = $m->pegaListaDeGrupos($menu["idmenu"],$listasistemas="nao",$listasgrupos="sim"); | ||
310 | + foreach($grupos as $grupo){ | ||
311 | + if(strtolower($grupo["ogc"]) == "sim"){ | ||
312 | + foreach($grupo["subgrupos"] as $sgrupo){ | ||
313 | + if(strtolower($sgrupo["ogc"]) == "sim"){ | ||
314 | + $temas = $m->pegaListaDeTemas($grupo["id_n1"],$sgrupo["id_n2"],$menu["idmenu"]); | ||
315 | + foreach($temas as $tema){ | ||
316 | + if(strtolower($tema["ogc"]) == "sim"){ | ||
317 | + $codigosTema[] = array("tema"=>$tema["tid"],"fonte"=>$tema["link"]); | ||
318 | + } | ||
319 | + } | ||
320 | + } | ||
321 | + } | ||
322 | + } | ||
323 | + } | ||
324 | + } | ||
325 | + //echo "<pre>"; | ||
326 | + //var_dump($codigosTema); | ||
327 | + //exit; | ||
328 | + | ||
329 | + foreach($codigosTema as $c){ | ||
330 | + $codigoTema = $c["tema"]; | ||
331 | + if(file_exists($locaplic."/temas/".$codigoTema.".map")){ | ||
332 | + if (@ms_newMapobj($locaplic."/temas/".$codigoTema.".map")){ | ||
333 | + $nmap = ms_newMapobj($locaplic."/temas/".$codigoTema.".map"); | ||
334 | + $nmap->setmetadata("ows_enable_request","*"); | ||
335 | + $ts = $nmap->getalllayernames(); | ||
336 | + if (count($ts) == 1){ | ||
337 | + foreach ($ts as $t){ | ||
338 | + if ($oMap->getlayerbyname($t) == ""){ | ||
339 | + $conta++; | ||
340 | + if (($conta >= $int[0]) && ($conta <= $int[1])){ | ||
341 | + $l = $nmap->getlayerbyname($t); | ||
342 | + $extensao = $l->getmetadata("EXTENSAO"); | ||
343 | + if($extensao == ""){ | ||
344 | + $extensao = $extensaoMap; | ||
345 | + } | ||
346 | + $l->setmetadata("wms_extent",$extensao); | ||
347 | + | ||
348 | + $l->setmetadata("ows_title",pegaNome($l)); | ||
349 | + $l->setmetadata("ows_srs",$listaepsg); | ||
350 | + $l->set("status",MS_OFF); | ||
351 | + $l->setmetadata("gml_include_items","all"); | ||
352 | + $l->set("dump",MS_TRUE); | ||
353 | + $l->setmetadata("WMS_INCLUDE_ITEMS","all"); | ||
354 | + $l->setmetadata("WFS_INCLUDE_ITEMS","all"); | ||
355 | + if($l->getmetadata("ows_metadataurl_href") == ""){ | ||
356 | + $l->setmetadata("ows_metadataurl_href",$c["fonte"]); | ||
357 | + $l->setmetadata("ows_metadataurl_type","TC211"); | ||
358 | + $l->setmetadata("ows_metadataurl_format","text/html"); | ||
359 | + } | ||
360 | + if(file_exists($locaplic."/temas/miniaturas/".$t.".map.mini.png")){ | ||
361 | + $mini = $proto.$server.dirname($_SERVER['PHP_SELF'])."/temas/miniaturas/".$t.".map.mini.png"; | ||
362 | + $l->setmetadata("wms_attribution_logourl_format","image/png"); | ||
363 | + $l->setmetadata("wms_attribution_logourl_height","50"); | ||
364 | + $l->setmetadata("wms_attribution_logourl_width","50"); | ||
365 | + $l->setmetadata("wms_attribution_logourl_href",$mini); | ||
366 | + } | ||
367 | + // | ||
368 | + //numero de pixels que serao considerados para corte da imagem no caso de cache ativo e tema de pontos | ||
369 | + // | ||
370 | + if ($l->getmetadata("cortepixels") != ""){ | ||
371 | + $cortePixels = $l->getmetadata("cortepixels"); | ||
372 | + } | ||
373 | + cloneInlineSymbol($l,$nmap,$oMap); | ||
374 | + ms_newLayerObj($oMap, $l); | ||
375 | + | ||
376 | + } | ||
377 | + } | ||
378 | + } | ||
379 | + } | ||
380 | + } | ||
381 | + else{ | ||
382 | + echo "Erro no arquivo ".$locaplic."/temas/".$codigoTema.".map <br>"; | ||
383 | + $error = ms_GetErrorObj(); | ||
384 | + while($error && $error->code != MS_NOERR){ | ||
385 | + printf("<br>Error in %s: %s<br>\n", $error->routine, $error->message); | ||
386 | + $error = $error->next(); | ||
387 | + } | ||
388 | + } | ||
389 | + } | ||
390 | + } | ||
391 | + } | ||
392 | + $oMap->setSymbolSet($locaplic."/symbols/".basename($oMap->symbolsetfilename)); | ||
393 | + $oMap->setFontSet($locaplic."/symbols/".basename($oMap->fontsetfilename)); | ||
394 | + $oMap->save($nomeMapfileTmp); | ||
395 | + $oMap = ms_newMapobj($nomeMapfileTmp); | ||
396 | +} | ||
397 | +if(ob_get_contents ()){ | ||
398 | + ob_end_clean(); | ||
399 | +} | ||
400 | + | ||
401 | +// | ||
402 | +//verifica se a chamada do servico e do tipo TILE no padrao do Google | ||
403 | +// | ||
404 | +if(isset($_GET["Z"]) && isset($_GET["X"])){ | ||
405 | + $x = $_GET["X"]; | ||
406 | + $y = $_GET["Y"]; | ||
407 | + $z = $_GET["Z"]; | ||
408 | + $layer0 = $oMap->getlayer(0); | ||
409 | + // | ||
410 | + //numero de pixels que serao considerados para corte da imagem no caso de cache ativo e tema de pontos | ||
411 | + // | ||
412 | + if ($layer0->getmetadata("cortepixels") != ""){ | ||
413 | + $cortePixels = $layer0->getmetadata("cortepixels"); | ||
414 | + } | ||
415 | + if($cache == true){ | ||
416 | + carregaCacheImagem($cachedir,$nomeMapfileTmp,"/googlemaps/$layer0->name/$z/$x/$y"); | ||
417 | + } | ||
418 | + $n = pow(2,$z); | ||
419 | + $lon1 = $x / $n * 360.0 - 180.0; | ||
420 | + $lat2 = rad2deg(atan(sinh(pi() * (1 - 2 * $y / $n)))); | ||
421 | + $x++; | ||
422 | + $y++; | ||
423 | + $lon2 = $x / $n * 360.0 - 180.0; | ||
424 | + $lat1 = rad2deg(atan(sinh(pi() * (1 - 2 * $y / $n)))); | ||
425 | + $x--; | ||
426 | + $y--; | ||
427 | + | ||
428 | + $projInObj = ms_newprojectionobj("proj=latlong,a=6378137,b=6378137"); | ||
429 | + $projOutObj = ms_newprojectionobj("proj=merc,a=6378137,b=6378137,lat_ts=0.0,lon_0=0.0,x_0=0.0,y_0=0,k=1.0,units=m"); | ||
430 | + | ||
431 | + $poPoint1 = ms_newpointobj(); | ||
432 | + $poPoint1->setXY($lon1, $lat1); | ||
433 | + $poPoint1->project($projInObj, $projOutObj); | ||
434 | + $poPoint2 = ms_newpointobj(); | ||
435 | + $poPoint2->setXY($lon2, $lat2); | ||
436 | + $poPoint2->project($projInObj, $projOutObj); | ||
437 | + $oMap->setsize(256,256); | ||
438 | + $oMap->setExtent($poPoint1->x,$poPoint1->y,$poPoint2->x,$poPoint2->y); | ||
439 | + | ||
440 | + $oMap->getlayer(0)->set("status",MS_DEFAULT); | ||
441 | + $oMap->setProjection("proj=merc,a=6378137,b=6378137,lat_ts=0.0,lon_0=0.0,x_0=0.0,y_0=0,k=1.0,units=m"); | ||
442 | + $layer0->setProjection("proj=latlong,a=6378137,b=6378137"); | ||
443 | + // | ||
444 | + //se o layer foi marcado para corte altera os parametros para ampliar o mapa | ||
445 | + //antes de gerar a imagem | ||
446 | + // | ||
447 | + if($cortePixels > 0){ | ||
448 | + //$oMap->prepareImage(); | ||
449 | + $escalaInicial = $oMap->scaledenom; | ||
450 | + $extensaoInicial = $oMap->extent; | ||
451 | + $wh = 256+($cortePixels*2); | ||
452 | + $oMap->setsize($wh,$wh); | ||
453 | + $ponto = new pointObj(); | ||
454 | + $ponto->setxy(($wh/2),($wh/2)); | ||
455 | + $oMap->zoomScale($escalaInicial, $ponto, $wh, $wh, $extensaoInicial); | ||
456 | + } | ||
457 | + $img = $oMap->draw(); | ||
458 | + if($img->imagepath == ""){ | ||
459 | + exit; | ||
460 | + } | ||
461 | + if($cache == true){ | ||
462 | + salvaCacheImagem($cachedir,$nomeMapfileTmp,"/googlemaps/$layer0->name/$z/$x/$y"); | ||
463 | + } | ||
464 | + renderNocacheTms(); | ||
465 | +} | ||
466 | + | ||
467 | +if(strtolower($req->getValueByName("REQUEST")) == "getlegendgraphic"){ | ||
468 | + $l = $oMap->getlayer(0); | ||
469 | + if($req->getValueByName("LAYER") == ""){ | ||
470 | + $req->setParameter("LAYER",$l->name); | ||
471 | + } | ||
472 | + //muda o title se for vazio | ||
473 | + $nclass = $l->numclasses; | ||
474 | + for($i=0;$i<$nclass;$i++){ | ||
475 | + $classe = $l->getclass($i); | ||
476 | + if($classe->title === ""){ | ||
477 | + $classe->title = $classe->name; | ||
478 | + } | ||
479 | + } | ||
480 | + if($req->getValueByName("FORMAT") == ""){ | ||
481 | + $req->setParameter("FORMAT","image/png"); | ||
482 | + } | ||
483 | + $legenda = $oMap->legend; | ||
484 | + $legenda->set("status",MS_DEFAULT); | ||
485 | + $l->set("minscaledenom",0); | ||
486 | + $l->set("maxscaledenom",0); | ||
487 | + if($req->getValueByName("FORMAT") == "text/html"){ | ||
488 | + //$req->setParameter("FORMAT","image/png"); | ||
489 | + $l = $oMap->getlayerbyname($req->getValueByName("LAYER")); | ||
490 | + $l->set("status",MS_DEFAULT); | ||
491 | + //remove offset de simbolos pontuais | ||
492 | + $nclass = $l->numclasses; | ||
493 | + for($cc = 0; $cc < $nclass; $cc++){ | ||
494 | + $classe = $l->getclass($cc); | ||
495 | + if($classe->numstyles > 0){ | ||
496 | + $estilo = $classe->getstyle(0); | ||
497 | + if($estilo->symbolname != "" && file_exists($estilo->symbolname)){ | ||
498 | + $estilo->set("offsetx",0); | ||
499 | + $estilo->set("offsety",0); | ||
500 | + } | ||
501 | + } | ||
502 | + } | ||
503 | + $legenda->set("template",$locaplic."/aplicmap/legendaOgc.html"); | ||
504 | + $tmparray["my_tag"] = "value_of_my_tag"; | ||
505 | + if($leg = @$oMap->processlegendtemplate($tmparray)){ | ||
506 | + if (function_exists("mb_convert_encoding")){ | ||
507 | + $leg = mb_convert_encoding($leg,"UTF-8","ISO-8859-1"); | ||
508 | + } | ||
509 | + echo $leg;exit; | ||
510 | + } | ||
511 | + } | ||
512 | + | ||
513 | +} | ||
514 | + | ||
515 | +if(strtolower($req->getValueByName("REQUEST")) == "getfeature"){ | ||
516 | + $l = $oMap->getlayer(0); | ||
517 | + if($req->getValueByName("TYPENAME") == "" || $req->getValueByName("TYPENAME") == "undefined"){ | ||
518 | + $req->setParameter("TYPENAME",$l->name); | ||
519 | + } | ||
520 | + if($l->getProjection() == "" ){ | ||
521 | + $l->setProjection("proj=latlong,a=6378137,b=6378137"); | ||
522 | + } | ||
523 | + if(strtolower($req->getValueByName("SRS")) == "epsg:900913"){ | ||
524 | + $req->setParameter("SRS","EPSG:3857"); | ||
525 | + } | ||
526 | +} | ||
527 | +if(strtolower($req->getValueByName("REQUEST")) == "getfeatureinfo"){ | ||
528 | + $l = $oMap->getlayer(0); | ||
529 | + $req->setParameter("LAYERS",$l->name); | ||
530 | + $req->setParameter("QUERY_LAYERS",$l->name); | ||
531 | + if(strtolower($req->getValueByName("SRS")) == "epsg:900913"){ | ||
532 | + $req->setParameter("SRS","EPSG:3857"); | ||
533 | + $_GET["SRS"] = "EPSG:3857"; | ||
534 | + } | ||
535 | +} | ||
536 | +// | ||
537 | +//altera os caminhos das imagens | ||
538 | +// | ||
539 | +if((isset($legenda)) && (strtolower($legenda) == "sim")){ | ||
540 | + $leg = $oMap->legend; | ||
541 | + $leg->set("status",MS_EMBED); | ||
542 | +} | ||
543 | + | ||
544 | +ms_ioinstallstdouttobuffer(); | ||
545 | +//verifica parametro outputformat | ||
546 | +if(strtolower($req->getValueByName("REQUEST")) == "getmap" && $req->getValueByName("format") == ""){ | ||
547 | + $req->setParameter("format","image/png"); | ||
548 | +} | ||
549 | +$oMap->owsdispatch($req); | ||
550 | +$contenttype = ms_iostripstdoutbuffercontenttype(); | ||
551 | + | ||
552 | +if(!isset($OUTPUTFORMAT)){ | ||
553 | + header("Content-type: $contenttype"); | ||
554 | +} | ||
555 | + | ||
556 | +$buffer = ms_iogetStdoutBufferBytes(); | ||
557 | +ms_ioresethandlers(); | ||
558 | + | ||
559 | +function texto2iso($texto){ | ||
560 | + if (function_exists("mb_convert_encoding")){ | ||
561 | + if (mb_detect_encoding($texto,"UTF-8",true)){ | ||
562 | + $texto = mb_convert_encoding($texto,"ISO-8859-1","UTF-8"); | ||
563 | + } | ||
564 | + } | ||
565 | + return $texto; | ||
566 | +} | ||
567 | +function nomeRand($n=10) | ||
568 | +{ | ||
569 | + $nomes = ""; | ||
570 | + $a = 'azertyuiopqsdfghjklmwxcvbnABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
571 | + $max = 51; | ||
572 | + for($i=0; $i < $n; ++$i) | ||
573 | + {$nomes .= $a{mt_rand(0, $max)};} | ||
574 | + return $nomes; | ||
575 | +} | ||
576 | + | ||
577 | +?> |