Commit f6fdcd5b1d4c92e42c4bdd66715f162de347803a

Authored by Edmar Moretti
1 parent db3e50b3

Atualização do repositorio

Showing 2 changed files with 621 additions and 623 deletions   Show diff stats
admin/admin.db
No preview for this file type
classesphp/mapa_openlayers.php
1   -<?php
2   -/*
3   -Title: mapa_openlayers.php
4   -
5   -Faz o processamento de um mapfile segundo as necessidades do i3geo, como por exemplo, fazendo a substitui&ccedil;&atilde;o
6   -das vari&aacute;veis de conex&atilde;o com banco e outras opera&ccedil;&otilde;es espec&iacute;ficas do i3Geo.
7   -
8   -&Eacute; utilizado especificamente nas interfaces que utilizam a biblioteca OpenLayers.
9   -
10   -
11   -Parametros:
12   -
13   -g_sid {string} - codigo da "section" PHP
14   -
15   -tipolayer {fundo|} - (opcional) indica que a imagem a ser produzida comp&otilde;e o fundo do mapa
16   -
17   -BBOX {xmin xmax ymin ymax} - extens&atilde;o geogr&aacute;fica a ser utilizada no desenho do mapa
18   -
19   -WIDTH {numeric} - largura do mapa
20   -
21   -HEIGHT {numeric} - altura do mapa
22   -
23   -layer {string} - codigo do layer existente no mapa que ser&aacute; desenhado
24   -
25   -DESLIGACACHE {sim|nao} - for&ccedil;a a n&atilde;o usar o cache de imagens qd definido como "sim", do contr&aacute;rio, o uso ou n&atilde;o do cache ser&aacute; definido automaticamente
26   -
27   -TIPOIMAGEM {cinza|sepiaclara|sepianormal|negativo|detectaBordas|embassa|gaussian_blur|selective_blur|mean_removal|pixelate
28   -} - filtro de imagem que ser&aacute; aplicado na imagem
29   -
30   -Licenca:
31   -
32   -GPL2
33   -
34   -i3Geo Interface Integrada de Ferramentas de Geoprocessamento para Internet
35   -
36   -Direitos Autorais Reservados (c) 2006 Minist&eacute;rio do Meio Ambiente Brasil
37   -Desenvolvedor: Edmar Moretti edmar.moretti@gmail.com
38   -
39   -Este programa &eacute; software livre; voc&ecirc; pode redistribu&iacute;-lo
40   -e/ou modific&aacute;-lo sob os termos da Licen&ccedil;a P&uacute;blica Geral
41   -GNU conforme publicada pela Free Software Foundation;
42   -
43   -Este programa &eacute; distribu&iacute;do na expectativa de que seja &uacute;til,
44   -por&eacute;m, SEM NENHUMA GARANTIA; nem mesmo a garantia impl&iacute;cita
45   -de COMERCIABILIDADE OU ADEQUA&Ccedil;&Atilde;O A UMA FINALIDADE ESPEC&Iacute;FICA.
46   -Consulte a Licen&ccedil;a P&uacute;blica Geral do GNU para mais detalhes.
47   -Voc&ecirc; deve ter recebido uma copia da Licen&ccedil;a P&uacute;blica Geral do
48   -GNU junto com este programa; se n&atilde;o, escreva para a
49   -Free Software Foundation, Inc., no endere&ccedil;o
50   -59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
51   -
52   -Arquivo:
53   -
54   -i3geo/classesphp/mapa_openlayers.php
55   -
56   -*/
57   -include("sani_request.php");
58   -//para efeitos de compatibilidade
59   -if (!function_exists('ms_GetVersion')){
60   - include_once ("carrega_ext.php");
61   -}
62   -//error_reporting(0);
63   -inicializa();
64   -//
65   -//calcula a extensao geografica com base no x,y,z
66   -//nos casos do modo notile, a requisicao e feita como se fosse um wms
67   -//quando for do tipo tms $_GET["tms"] contem os parametros do tile
68   -//
69   -
70   -if(isset($_GET["tms"])){
71   - $_GET["WIDTH"] = 256;
72   - $_GET["HEIGHT"] = 256;
73   - $temp = explode("/",$_GET["tms"]);
74   - $z = $temp[2];
75   - $x = $temp[3];
76   - $y = str_replace(".png","",$temp[4]);
77   -
78   - $n = pow(2,$z+1);
79   - $lon1 = $x / $n * 360.0 - 180.0;
80   - $lon2 = ($x+1) / $n * 360.0 - 180.0;
81   - $n = pow(2,$z);
82   - $lat1 = $y / $n * 180.0 - 90.0;
83   - $lat2 = ($y+1) / $n * 180.0 - 90;
84   - $_GET["BBOX"] = $lon1." ".$lat1." ".$lon2." ".$lat2;
85   -}
86   -
87   -//para o caso da versao 3 do OpenLayers
88   -if(isset($_GET["X"]) && !($_GET["REQUEST"] == "getfeatureinfo" || $_GET["REQUEST"] == "GetFeatureInfo" || strtolower($_GET["REQUEST"]) == "getfeature")){
89   - $box = str_replace(" ",",",$_GET["BBOX"]);
90   - $box = explode(",",$box);
91   - $res = ($box[2] + 180) - ($box[0] + 180);
92   - $res = $res / 256;
93   - $z = intval((0.703125 / $res) / 4) + 1;
94   - $x = floor((($box[0] + 180) / 360) * pow(2, $z));
95   - $y = floor((1 - log(tan(deg2rad($box[3])) + 1 / cos(deg2rad($box[3]))) / pi()) /2 * pow(2, $z));
96   -
97   - $_GET["WIDTH"] = 256;
98   - $_GET["HEIGHT"] = 256;
99   - $_GET["tms"] = "/".$_GET["layer"]."/".$z."/".$x."/".$y.".png";
100   -}
101   -
102   -if(isset($_GET["TileMatrix"])){
103   - $_GET["WIDTH"] = 256;
104   - $_GET["HEIGHT"] = 256;
105   - $z = $_GET["TileMatrix"];
106   - $x = $_GET["TileCol"];
107   - $y = $_GET["TileRow"];
108   - //calcula resolucoes
109   - $res = array();
110   - $temp = 0.703125;
111   - for($i = 0; $i < 40; $i++){
112   - $res[] = $temp;
113   - $temp = $temp / 2;
114   - }
115   - $_GET["tms"] = "/wmts/".$_GET["layer"]."/".$z."/".$x."/".$y.".png";
116   - if($z."/".$x."/".$y == "0/0/0" || $x == -1 || $y == -1){
117   - return;
118   - }
119   - $top_left_minx = -180;
120   - $top_left_maxy = 90;
121   -
122   - $x_size = $res[$z - 1] * 256;
123   - $y_size = $x_size;
124   -
125   - $lon1 = $top_left_minx + ($x * $x_size);
126   - $lat1 = $top_left_maxy - ($y * $y_size) - $y_size;
127   - $lon2 = $top_left_minx + ($x * $x_size) + $x_size;
128   - $lat2 = $top_left_maxy - ($y * $y_size);
129   -
130   - $_GET["BBOX"] = $lon1." ".$lat1." ".$lon2." ".$lat2;
131   -}
132   -
133   -$map_fileX = $_SESSION["map_file"];
134   -//
135   -//verifica se o request e OGC
136   -if(!empty($_GET["request"])){
137   - $_GET["REQUEST"] = $_GET["request"];
138   -}
  1 +<?php
  2 +/*
  3 + * Title: mapa_openlayers.php
  4 + *
  5 + * Faz o processamento de um mapfile segundo as necessidades do i3geo, como por exemplo, fazendo a substitui&ccedil;&atilde;o
  6 + * das vari&aacute;veis de conex&atilde;o com banco e outras opera&ccedil;&otilde;es espec&iacute;ficas do i3Geo.
  7 + *
  8 + * &Eacute; utilizado especificamente nas interfaces que utilizam a biblioteca OpenLayers.
  9 + *
  10 + *
  11 + * Parametros:
  12 + *
  13 + * g_sid {string} - codigo da "section" PHP
  14 + *
  15 + * tipolayer {fundo|} - (opcional) indica que a imagem a ser produzida comp&otilde;e o fundo do mapa
  16 + *
  17 + * BBOX {xmin xmax ymin ymax} - extens&atilde;o geogr&aacute;fica a ser utilizada no desenho do mapa
  18 + *
  19 + * WIDTH {numeric} - largura do mapa
  20 + *
  21 + * HEIGHT {numeric} - altura do mapa
  22 + *
  23 + * layer {string} - codigo do layer existente no mapa que ser&aacute; desenhado
  24 + *
  25 + * DESLIGACACHE {sim|nao} - for&ccedil;a a n&atilde;o usar o cache de imagens qd definido como "sim", do contr&aacute;rio, o uso ou n&atilde;o do cache ser&aacute; definido automaticamente
  26 + *
  27 + * TIPOIMAGEM {cinza|sepiaclara|sepianormal|negativo|detectaBordas|embassa|gaussian_blur|selective_blur|mean_removal|pixelate
  28 + * } - filtro de imagem que ser&aacute; aplicado na imagem
  29 + *
  30 + * Licenca:
  31 + *
  32 + * GPL2
  33 + *
  34 + * i3Geo Interface Integrada de Ferramentas de Geoprocessamento para Internet
  35 + *
  36 + * Direitos Autorais Reservados (c) 2006 Minist&eacute;rio do Meio Ambiente Brasil
  37 + * Desenvolvedor: Edmar Moretti edmar.moretti@gmail.com
  38 + *
  39 + * Este programa &eacute; software livre; voc&ecirc; pode redistribu&iacute;-lo
  40 + * e/ou modific&aacute;-lo sob os termos da Licen&ccedil;a P&uacute;blica Geral
  41 + * GNU conforme publicada pela Free Software Foundation;
  42 + *
  43 + * Este programa &eacute; distribu&iacute;do na expectativa de que seja &uacute;til,
  44 + * por&eacute;m, SEM NENHUMA GARANTIA; nem mesmo a garantia impl&iacute;cita
  45 + * de COMERCIABILIDADE OU ADEQUA&Ccedil;&Atilde;O A UMA FINALIDADE ESPEC&Iacute;FICA.
  46 + * Consulte a Licen&ccedil;a P&uacute;blica Geral do GNU para mais detalhes.
  47 + * Voc&ecirc; deve ter recebido uma copia da Licen&ccedil;a P&uacute;blica Geral do
  48 + * GNU junto com este programa; se n&atilde;o, escreva para a
  49 + * Free Software Foundation, Inc., no endere&ccedil;o
  50 + * 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
  51 + *
  52 + * Arquivo:
  53 + *
  54 + * i3geo/classesphp/mapa_openlayers.php
  55 + *
  56 + */
  57 +include ("sani_request.php");
  58 +// para efeitos de compatibilidade
  59 +if (! function_exists ( 'ms_GetVersion' )) {
  60 + include_once ("carrega_ext.php");
  61 +}
  62 +// error_reporting(0);
  63 +inicializa ();
139 64 //
140   -//resolve o problema da selecao nas versoes mais recentes nova do mapserver
  65 +// calcula a extensao geografica com base no x,y,z
  66 +// nos casos do modo notile, a requisicao e feita como se fosse um wms
  67 +// quando for do tipo tms $_GET["tms"] contem os parametros do tile
141 68 //
142   -$qyfile = dirname($map_fileX)."/".$_GET["layer"]."_qy.map";
143   -$qy = file_exists($qyfile);
144   -
145   -if($_GET["REQUEST"] == "getlegendgraphic" || $_GET["REQUEST"] == "getfeatureinfo" || $_GET["REQUEST"] == "GetFeatureInfo" || strtolower($_GET["REQUEST"]) == "getfeature"){
146   - $_GET["DESLIGACACHE"] = "sim";
147   -}
148   -else{
149   - if($qy == false && $_GET["cache"] == "sim" && $_GET["DESLIGACACHE"] != "sim"){
150   - carregaCacheImagem($_SESSION["cachedir"],$_SESSION["map_file"],$_GET["tms"],$_SESSION["i3georendermode"]);
151   - }
152   -}
153   -//
154   -//map_fileX e para o caso register_globals = On no PHP.INI
155   -//
156   -if(isset($_GET["tipolayer"]) && $_GET["tipolayer"] == "fundo"){
157   - $map_fileX = str_replace(".map","fundo.map",$map_fileX);
158   -}
159   -$postgis_mapa = $_SESSION["postgis_mapa"];
160   -
161   -//por seguranca
162   -include_once("funcoes_gerais.php");
163   -
164   -$logExec = $_SESSION["logExec"];
165   -
166   -if(isset($logExec) && $logExec["mapa_"] == true){
167   - i3GeoLog("prog: mapa_openlayers url: ".implode("&",array_merge($_GET,$_POST)),$_SESSION["dir_tmp"]);
168   -}
169   -
170   -restauraCon($map_fileX,$postgis_mapa);
171   -
172   -$cachedir = $_SESSION["cachedir"];
173   -if(isset($_GET["BBOX"])){
174   - $_GET["mapext"] = str_replace(","," ",$_GET["BBOX"]);
175   - $_GET["map_size"] = $_GET["WIDTH"]." ".$_GET["HEIGHT"];
176   -}
177   -$_GET["TIPOIMAGEM"] = trim($_GET["TIPOIMAGEM"]);
178   -$mapa = ms_newMapObj($map_fileX);
179   -//
180   -//processa os layers do mapfile
181   -//
182   - $numlayers = $mapa->numlayers;
183   - $cache = false;
184   - for($i = 0;$i < $numlayers;++$i){
185   - $l = $mapa->getLayer($i);
186   - $layerName = $l->name;
187   - if($layerName != $_GET["layer"]){
188   - $l->set("status",MS_OFF);
189   - }
190   - //no caso de haver uma mascara definida no layer
191   - if($versao["inteiro"] >= 60200){
192   - if($l->mask != ""){
193   - $lmask = $mapa->getlayerbyname($l->mask);
194   - if(!empty($postgis_mapa)){
195   - if($lmask->connectiontype == MS_POSTGIS){
196   - $lcon = $l->connection;
197   - if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))){
198   - if(($lcon == " ") || ($lcon == "")){
199   - $lmask->set("connection",$postgis_mapa);
200   - }
201   - else{
202   - $lmask->set("connection",$postgis_mapa[$lcon]);
203   - }
204   - }
205   - }
206   - }
207   - }
208   - }
209   - if($layerName == $_GET["layer"] || $l->group == $_GET["layer"] && $l->group != ""){
210   - if ($l->getmetadata("classesnome") != "" || $l->getmetadata("palletefile") != ""){
211   - if(!function_exists("autoClasses")){
212   - include_once("funcoes_gerais.php");
213   - }
214   - autoClasses($l,$mapa);
215   - }
216   - //
217   - //numero de pixels que serao considerados para corte da imagem no caso de cache ativo e tema de pontos
218   - //
219   - $cortePixels = 0;
220   - if ($l->getmetadata("cortepixels") != "" && $qy == false){
221   - $cortePixels = $l->getmetadata("cortepixels");
222   - }
223   - $l->set("status",MS_DEFAULT);
224   - $l->set("template","none.htm");
225   - if (!empty($postgis_mapa)){
226   - if ($l->connectiontype == MS_POSTGIS){
227   - $lcon = $l->connection;
228   - if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))){
229   - if(($lcon == " ") || ($lcon == ""))
230   - {$l->set("connection",$postgis_mapa);}
231   - else
232   - {$l->set("connection",$postgis_mapa[$lcon]);}
233   - }
234   - }
235   - }
236   - }
237   - if($_GET["REQUEST"] == "getlegendgraphic"){
238   - $nclass = $l->numclasses;
239   - for($ic=0;$ic<$nclass;$ic++){
240   - $classe = $l->getclass($ic);
241   - if($classe->title === ""){
242   - $classe->title = $classe->name;
243   - }
244   - }
245   - }
246   - if($layerName == $_GET["layer"]){
247   - if(strtolower($l->getmetadata("cache")) == "sim"){
248   - $cache = true;
249   - $nomecache = $l->getmetadata("nomeoriginal");
250   - if($nomecache == ""){
251   - $nomecache = $layerName;
252   - }
253   - }
254   - if($_GET["REQUEST"] == "getfeatureinfo" || $_GET["REQUEST"] == "GetFeatureInfo" || strtolower($_GET["REQUEST"]) == "getfeature" ){
255   - $l->setmetadata("gml_include_items","all");
256   - $l->set("template","none.htm");
257   - $l->setmetadata("WMS_INCLUDE_ITEMS","all");
258   - $l->setmetadata("WFS_INCLUDE_ITEMS","all");
259   - $l->setmetadata("ows_enable_request","*");
260   - $l->set("dump",MS_TRUE);
261   - $l->setmetadata("ows_srs","AUTO");
262   - if(strtolower($_GET["REQUEST"]) == "getfeature"){
263   - $_GET["TYPENAME"] = $l->name;
264   - }
265   - }
266   - }
267   - }
268   -if (!function_exists('imagepng')){
269   - $_GET["TIPOIMAGEM"] = "";
270   -}
271   -
272   -if($_GET["layer"] == ""){
273   - $cache = true;
274   -}
275   -if(($_GET == false) || ($qy) || (strtolower($_GET["DESLIGACACHE"]) == "sim")){
276   - $cache = false;
277   -}
278   -elseif($_GET["TIPOIMAGEM"] != "" && $_GET["TIPOIMAGEM"] != "nenhum"){
279   - $cache = false;
280   -}
281   -
282   -if($cache == true && $_GET["cache"] != "nao"){
283   - carregaCacheImagem($cachedir,$_SESSION["map_file"],$_GET["tms"]);
284   -}
285   -if(isset($_GET["map_size"])){
286   - $map_size = explode(" ",$_GET["map_size"]);
287   - $mapa->setsize($map_size[0],$map_size[1]);
288   -}
289   -
290   -if(isset($_GET["mapext"])){
291   - $mapext = explode(" ",$_GET["mapext"]);
292   - //para evitar erro quando o mapa e continuo
293   - if($mapext[0] == $mapext[2] && $mapext[1] == $mapext[3]){
294   - exit;
295   - }
296   - $mapa->setExtent($mapext[0],$mapext[1],$mapext[2],$mapext[3]);
297   -}
298   -//
299   -//qd a cahamda e para um WMS, redireciona para ogc.php
300   -//
301   -if($_GET["REQUEST"] == "getlegendgraphic" || $_GET["REQUEST"] == "getfeatureinfo" || $_GET["REQUEST"] == "GetFeatureInfo" || $_GET["REQUEST"] == "getfeature"){
302   - $req = ms_newowsrequestobj();
303   - if($_GET["BBOX"]){
304   - $_GET["BBOX"] = str_replace(" ",",",$_GET["BBOX"]);
305   - }
306   - $_GET = array_merge($_GET,$_POST);
307   -
308   - foreach ($_GET as $k=>$v){
309   - $req->setParameter($k, $v);
310   - }
311   - $proto = "http" . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "") . "://";
312   - $server = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
313   - $or = $proto.$server.$_SERVER['PHP_SELF'];
314   - $mapa->setmetadata("wfs_onlineresource",$or."?".$_SERVER["QUERY_STRING"]);
315   - ms_ioinstallstdouttobuffer();
316   - $mapa->owsdispatch($req);
317   - $contenttype = ms_iostripstdoutbuffercontenttype();
318   - header("Content-type: $contenttype");
319   - ms_iogetStdoutBufferBytes();
320   - ms_ioresethandlers();
321   - exit;
322   -}
323   -
324   -$o = $mapa->outputformat;
325   -$o->set("imagemode",MS_IMAGEMODE_RGBA);
326   - $legenda = $mapa->legend;
327   - $legenda->set("status",MS_OFF);
328   - $escala = $mapa->scalebar;
329   - $escala->set("status",MS_OFF);
330   -
331   -//
332   -//se o layer nao for do tipo fundo
333   -//
334   -if($_GET["tipolayer"] != "fundo"){
335   - $o->set("transparent",MS_TRUE);
336   -}
337   -
338   -//
339   -//se o layer foi marcado para corte altera os parametros para ampliar o mapa
340   -//antes de gerar a imagem
341   -//
342   -if($cortePixels > 0){
343   - //$mapa->prepareImage();
344   - //echo $mapa->scaledenom;exit;
345   - $escalaInicial = $mapa->scaledenom;
346   - $extensaoInicial = $mapa->extent;
347   - $wh = 256+($cortePixels*2);
348   - $mapa->setsize($wh,$wh);
349   - $ponto = new pointObj();
350   - $ponto->setxy(($wh/2),($wh/2));
351   - $mapa->zoomScale($escalaInicial, $ponto, $wh, $wh, $extensaoInicial);
352   -}
353   -
354   -//se nao houver selecao
355   -if($qy != true){
356   - $img = $mapa->draw();
357   -}
358   -else{
359   - $handle = fopen ($qyfile, "r");
360   - $conteudo = fread ($handle, filesize ($qyfile));
361   - fclose ($handle);
362   - $shp = unserialize($conteudo);
363   - $l = $mapa->getLayerByname($_GET["layer"]);
364   - if ($l->connectiontype != MS_POSTGIS){
365   - $indxlayer = $l->index;
366   - foreach ($shp as $indx)
367   - {$mapa->querybyindex($indxlayer,-1,$indx,MS_TRUE);}
368   - $qm = $mapa->querymap;
369   - $qm->set("width",$map_size[0]);
370   - $qm->set("height",$map_size[1]);
371   - $img = $mapa->drawQuery();
372   - }
373   - else{
374   - $img = $mapa->draw();
375   - $c = $mapa->querymap->color;
376   - $numclasses = $l->numclasses;
377   - if ($numclasses > 0)
378   - {
379   - $classe0 = $l->getClass(0);
380   - $classe0->setexpression("");
381   - $classe0->set("name"," ");
382   - for ($i=1; $i < $numclasses; ++$i)
383   - {
384   - $classe = $l->getClass($i);
385   - $classe->set("status",MS_DELETE);
386   - }
387   - }
388   - $cor = $classe0->getstyle(0)->color;
389   - $cor->setrgb($c->red,$c->green,$c->blue);
390   - //$cor = $classe0->getstyle(0)->outlinecolor;
391   - //$cor->setrgb($c->red,$c->green,$c->blue);
392   - $status = $l->open();
393   - $status = $l->whichShapes($mapa->extent);
394   - while ($shape = $l->nextShape())
395   - {
396   - if(in_array($shape->index,$shp))
397   - $shape->draw($mapa,$l,$img);
398   - }
399   - $l->close();
400   - }
401   - $cache = false;
402   -}
403   -//nao usa o cache pois e necessario processar a imagem com alguma rotina de filtro
404   -if($_GET["TIPOIMAGEM"] != "" && $_GET["TIPOIMAGEM"] != "nenhum"){
405   - if($img->imagepath == "")
406   - {echo "Erro IMAGEPATH vazio";exit;}
407   - $nomer = ($img->imagepath)."filtroimgtemp".nomeRand().".png";
408   - $img->saveImage($nomer);
409   - //
410   - //corta a imagem gerada para voltar ao tamanho normal
411   - //
412   - if($cortePixels > 0){
413   - cortaImagemDisco($nomer,$cortePixels,256);
414   - }
415   - filtraImg($nomer,$_GET["TIPOIMAGEM"]);
416   - $img = imagecreatefrompng($nomer);
417   - imagealphablending($img, false);
418   - imagesavealpha($img, true);
419   - cabecalhoImagem($nomer);
420   - imagepng($img);
421   - imagedestroy($img);
422   -}
423   -else{
424   - if($cache == true && $_GET["cache"] != "nao"){
425   - //cache ativo. Salva a imagem em cache
426   - $nomer = salvaCacheImagem($cachedir,$map_fileX,$_GET["tms"]);
427   - cabecalhoImagem($nomer);
428   - if($_SESSION["i3georendermode"] == 2){
429   - header("X-Sendfile: $nomer");
430   - }
431   - else{
432   - readfile($nomer);
433   - }
434   - }
435   - else{
436   - //cache inativo
437   - if($img->imagepath == ""){
438   - ilegal();
439   - }
440   - //se for necessario cortar a imagem, $img->saveImage() nao funciona
441   - if($_SESSION["i3georendermode"] == 0 || ($_SESSION["i3georendermode"] == 1 && $cortePixels > 0)){
442   - $nomer = ($img->imagepath)."temp".nomeRand().".png";
443   - $img->saveImage($nomer);
444   - //
445   - //corta a imagem gerada para voltar ao tamanho normal
446   - //
447   - if($cortePixels > 0){
448   - $img = cortaImagemDisco($nomer,$cortePixels,256);
449   - }
450   - else{
451   - $img = imagecreatefrompng($nomer);
452   - imagealphablending($img, false);
453   - imagesavealpha($img, true);
454   - }
455   - cabecalhoImagem($nomer);
456   - imagepng($img);
457   - imagedestroy($img);
458   - exit;
459   - }
460   - if($_SESSION["i3georendermode"] == 1){
461   - ob_clean();
462   - header('Content-Type: image/png');
463   - $img->saveImage();
464   - }
465   - if($_SESSION["i3georendermode"] == 2){
466   - $nomer = ($img->imagepath)."temp".nomeRand().".png";
467   - $img->saveImage($nomer);
468   - //
469   - //corta a imagem gerada para voltar ao tamanho normal
470   - //
471   - if($cortePixels > 0){
472   - $img = cortaImagemDisco($nomer,$cortePixels,256);
473   - }
474   - cabecalhoImagem($nomer);
475   - header("X-Sendfile: $nomer");
476   - }
477   - }
478   -}
479   -function cabecalhoImagem($nome){
480   - if(ob_get_contents()){
481   - ob_clean();
482   - }
483   - $lastModified=filemtime($nome);
484   - //set last-modified header
485   - header("Last-Modified: ".gmdate("D, d M Y H:i:s", $lastModified)." GMT");
486   - //make sure caching is turned on
487   - header('Cache-Control: public,max-age=86400'); //24 horas
488   - header("Content-type: image/png");
489   - header("Etag: " . md5($nome));
490   - //check if page has changed. If not, send 304 and exit
491   - if (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
492   - $if_modified_since = strtotime(preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']));
493   - if ($if_modified_since >= $lastModified) { // Is the Cached version the most recent?
494   - header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified');
495   - exit();
496   - }
497   - }
498   -}
499   -function salvaCacheImagem($cachedir,$map,$tms){
500   - global $img,$cortePixels;
501   - if($cachedir == ""){
502   - $nome = dirname(dirname($map))."/cache".$tms;
  69 +
  70 +if (isset ( $_GET ["tms"] )) {
  71 + $_GET ["WIDTH"] = 256;
  72 + $_GET ["HEIGHT"] = 256;
  73 + $temp = explode ( "/", $_GET ["tms"] );
  74 + $z = $temp [2];
  75 + $x = $temp [3];
  76 + $y = str_replace ( ".png", "", $temp [4] );
  77 +
  78 + $n = pow ( 2, $z + 1 );
  79 + $lon1 = $x / $n * 360.0 - 180.0;
  80 + $lon2 = ($x + 1) / $n * 360.0 - 180.0;
  81 + $n = pow ( 2, $z );
  82 + $lat1 = $y / $n * 180.0 - 90.0;
  83 + $lat2 = ($y + 1) / $n * 180.0 - 90;
  84 + $_GET ["BBOX"] = $lon1 . " " . $lat1 . " " . $lon2 . " " . $lat2;
  85 +}
  86 +
  87 +// para o caso da versao 3 do OpenLayers
  88 +if (isset ( $_GET ["X"] ) && ! ($_GET ["REQUEST"] == "getfeatureinfo" || $_GET ["REQUEST"] == "GetFeatureInfo" || strtolower ( $_GET ["REQUEST"] ) == "getfeature")) {
  89 + $box = str_replace ( " ", ",", $_GET ["BBOX"] );
  90 + $box = explode ( ",", $box );
  91 + $res = ($box [2] + 180) - ($box [0] + 180);
  92 + $res = $res / 256;
  93 + $z = intval ( (0.703125 / $res) / 4 ) + 1;
  94 + $x = floor ( (($box [0] + 180) / 360) * pow ( 2, $z ) );
  95 + $y = floor ( (1 - log ( tan ( deg2rad ( $box [3] ) ) + 1 / cos ( deg2rad ( $box [3] ) ) ) / pi ()) / 2 * pow ( 2, $z ) );
  96 +
  97 + $_GET ["WIDTH"] = 256;
  98 + $_GET ["HEIGHT"] = 256;
  99 + $_GET ["tms"] = "/" . $_GET ["layer"] . "/" . $z . "/" . $x . "/" . $y . ".png";
  100 +}
  101 +
  102 +if (isset ( $_GET ["TileMatrix"] )) {
  103 + $_GET ["WIDTH"] = 256;
  104 + $_GET ["HEIGHT"] = 256;
  105 + $z = $_GET ["TileMatrix"];
  106 + $x = $_GET ["TileCol"];
  107 + $y = $_GET ["TileRow"];
  108 + // calcula resolucoes
  109 + $res = array ();
  110 + $temp = 0.703125;
  111 + for($i = 0; $i < 40; $i ++) {
  112 + $res [] = $temp;
  113 + $temp = $temp / 2;
503 114 }
504   - else{
505   - $nome = $cachedir.$tms;
506   - }
507   - $nome = str_replace(".png","",$nome);
508   - $nome = $nome.".png";
509   - if(!file_exists($nome)){
510   - if(!file_exists(dirname($nome))){
511   - @mkdir(dirname($nome),0744,true);
512   - chmod(dirname($nome),0744);
513   - }
514   - error_log("salvando imagem");
515   - $img->saveImage($nome);
516   - //
517   - //corta a imagem gerada para voltar ao tamanho normal
518   - //
519   - if($cortePixels > 0){
520   - $img = cortaImagemDisco($nome,$cortePixels,256);
521   - }
522   - chmod($nome,0744);
  115 + $_GET ["tms"] = "/wmts/" . $_GET ["layer"] . "/" . $z . "/" . $x . "/" . $y . ".png";
  116 + if ($z . "/" . $x . "/" . $y == "0/0/0" || $x == - 1 || $y == - 1) {
  117 + return;
  118 + }
  119 + $top_left_minx = - 180;
  120 + $top_left_maxy = 90;
  121 +
  122 + $x_size = $res [$z - 1] * 256;
  123 + $y_size = $x_size;
  124 +
  125 + $lon1 = $top_left_minx + ($x * $x_size);
  126 + $lat1 = $top_left_maxy - ($y * $y_size) - $y_size;
  127 + $lon2 = $top_left_minx + ($x * $x_size) + $x_size;
  128 + $lat2 = $top_left_maxy - ($y * $y_size);
  129 +
  130 + $_GET ["BBOX"] = $lon1 . " " . $lat1 . " " . $lon2 . " " . $lat2;
  131 +}
  132 +
  133 +$map_fileX = $_SESSION ["map_file"];
  134 +//
  135 +// verifica se o request e OGC
  136 +if (! empty ( $_GET ["request"] )) {
  137 + $_GET ["REQUEST"] = $_GET ["request"];
  138 +}
  139 +//
  140 +// resolve o problema da selecao nas versoes mais recentes nova do mapserver
  141 +//
  142 +$qyfile = dirname ( $map_fileX ) . "/" . $_GET ["layer"] . "_qy.map";
  143 +$qy = file_exists ( $qyfile );
  144 +
  145 +if ($_GET ["REQUEST"] == "getlegendgraphic" || $_GET ["REQUEST"] == "getfeatureinfo" || $_GET ["REQUEST"] == "GetFeatureInfo" || strtolower ( $_GET ["REQUEST"] ) == "getfeature") {
  146 + $_GET ["DESLIGACACHE"] = "sim";
  147 +} else {
  148 + if ($qy == false && $_GET ["cache"] == "sim" && $_GET ["DESLIGACACHE"] != "sim") {
  149 + carregaCacheImagem ( $_SESSION ["cachedir"], $_SESSION ["map_file"], $_GET ["tms"], $_SESSION ["i3georendermode"] );
  150 + }
  151 +}
  152 +//
  153 +// map_fileX e para o caso register_globals = On no PHP.INI
  154 +//
  155 +if (isset ( $_GET ["tipolayer"] ) && $_GET ["tipolayer"] == "fundo") {
  156 + $map_fileX = str_replace ( ".map", "fundo.map", $map_fileX );
  157 +}
  158 +$postgis_mapa = $_SESSION ["postgis_mapa"];
  159 +
  160 +// por seguranca
  161 +include_once ("funcoes_gerais.php");
  162 +
  163 +$logExec = $_SESSION ["logExec"];
  164 +
  165 +if (isset ( $logExec ) && $logExec ["mapa_"] == true) {
  166 + i3GeoLog ( "prog: mapa_openlayers url: " . implode ( "&", array_merge ( $_GET, $_POST ) ), $_SESSION ["dir_tmp"] );
  167 +}
  168 +
  169 +//restauraCon ( $map_fileX, $postgis_mapa );
  170 +
  171 +$cachedir = $_SESSION ["cachedir"];
  172 +if (isset ( $_GET ["BBOX"] )) {
  173 + $_GET ["mapext"] = str_replace ( ",", " ", $_GET ["BBOX"] );
  174 + $_GET ["map_size"] = $_GET ["WIDTH"] . " " . $_GET ["HEIGHT"];
  175 +}
  176 +$_GET ["TIPOIMAGEM"] = trim ( $_GET ["TIPOIMAGEM"] );
  177 +$mapa = ms_newMapObj ( $map_fileX );
  178 +//
  179 +// processa os layers do mapfile
  180 +//
  181 +$numlayers = $mapa->numlayers;
  182 +$cache = false;
  183 +for($i = 0; $i < $numlayers; ++ $i) {
  184 + $l = $mapa->getLayer ( $i );
  185 + $layerName = $l->name;
  186 + if ($layerName != $_GET ["layer"]) {
  187 + $l->set ( "status", MS_OFF );
  188 + }
  189 + // no caso de haver uma mascara definida no layer
  190 + if ($versao ["inteiro"] >= 60200) {
  191 + if ($l->mask != "") {
  192 + $lmask = $mapa->getlayerbyname ( $l->mask );
  193 + if (! empty ( $postgis_mapa )) {
  194 + if ($lmask->connectiontype == MS_POSTGIS) {
  195 + $lcon = $l->connection;
  196 + if (($lcon == " ") || ($lcon == "") || (in_array ( $lcon, array_keys ( $postgis_mapa ) ))) {
  197 + if (($lcon == " ") || ($lcon == "")) {
  198 + $lmask->set ( "connection", $postgis_mapa );
  199 + } else {
  200 + $lmask->set ( "connection", $postgis_mapa [$lcon] );
  201 + }
  202 + }
  203 + }
  204 + }
  205 + }
  206 + }
  207 + if ($layerName == $_GET ["layer"] || $l->group == $_GET ["layer"] && $l->group != "") {
  208 + if ($l->getmetadata ( "classesnome" ) != "" || $l->getmetadata ( "palletefile" ) != "") {
  209 + if (! function_exists ( "autoClasses" )) {
  210 + include_once ("funcoes_gerais.php");
  211 + }
  212 + autoClasses ( $l, $mapa );
  213 + }
  214 + //
  215 + // numero de pixels que serao considerados para corte da imagem no caso de cache ativo e tema de pontos
  216 + //
  217 + $cortePixels = 0;
  218 + if ($l->getmetadata ( "cortepixels" ) != "" && $qy == false) {
  219 + $cortePixels = $l->getmetadata ( "cortepixels" );
  220 + }
  221 + $l->set ( "status", MS_DEFAULT );
  222 + $l->set ( "template", "none.htm" );
  223 + if (! empty ( $postgis_mapa )) {
  224 + if ($l->connectiontype == MS_POSTGIS) {
  225 + $lcon = $l->connection;
  226 + if (($lcon == " ") || ($lcon == "") || (in_array ( $lcon, array_keys ( $postgis_mapa ) ))) {
  227 + if (($lcon == " ") || ($lcon == "")) {
  228 + $l->set ( "connection", $postgis_mapa );
  229 + } else {
  230 + $l->set ( "connection", $postgis_mapa [$lcon] );
  231 + }
  232 + }
  233 + }
  234 + }
  235 + }
  236 + if ($_GET ["REQUEST"] == "getlegendgraphic") {
  237 + $nclass = $l->numclasses;
  238 + for($ic = 0; $ic < $nclass; $ic ++) {
  239 + $classe = $l->getclass ( $ic );
  240 + if ($classe->title === "") {
  241 + $classe->title = $classe->name;
  242 + }
  243 + }
  244 + }
  245 + if ($layerName == $_GET ["layer"]) {
  246 + if (strtolower ( $l->getmetadata ( "cache" ) ) == "sim") {
  247 + $cache = true;
  248 + $nomecache = $l->getmetadata ( "nomeoriginal" );
  249 + if ($nomecache == "") {
  250 + $nomecache = $layerName;
  251 + }
  252 + }
  253 + if ($_GET ["REQUEST"] == "getfeatureinfo" || $_GET ["REQUEST"] == "GetFeatureInfo" || strtolower ( $_GET ["REQUEST"] ) == "getfeature") {
  254 + $l->setmetadata ( "gml_include_items", "all" );
  255 + $l->set ( "template", "none.htm" );
  256 + $l->setmetadata ( "WMS_INCLUDE_ITEMS", "all" );
  257 + $l->setmetadata ( "WFS_INCLUDE_ITEMS", "all" );
  258 + $l->setmetadata ( "ows_enable_request", "*" );
  259 + $l->set ( "dump", MS_TRUE );
  260 + $l->setmetadata ( "ows_srs", "AUTO" );
  261 + if (strtolower ( $_GET ["REQUEST"] ) == "getfeature") {
  262 + $_GET ["TYPENAME"] = $l->name;
  263 + }
  264 + }
  265 + }
  266 +}
  267 +if (! function_exists ( 'imagepng' )) {
  268 + $_GET ["TIPOIMAGEM"] = "";
  269 +}
  270 +
  271 +if ($_GET ["layer"] == "") {
  272 + $cache = true;
  273 +}
  274 +if (($_GET == false) || ($qy) || (strtolower ( $_GET ["DESLIGACACHE"] ) == "sim")) {
  275 + $cache = false;
  276 +} elseif ($_GET ["TIPOIMAGEM"] != "" && $_GET ["TIPOIMAGEM"] != "nenhum") {
  277 + $cache = false;
  278 +}
  279 +
  280 +if ($cache == true && $_GET ["cache"] != "nao") {
  281 + carregaCacheImagem ( $cachedir, $_SESSION ["map_file"], $_GET ["tms"] );
  282 +}
  283 +if (isset ( $_GET ["map_size"] )) {
  284 + $map_size = explode ( " ", $_GET ["map_size"] );
  285 + $mapa->setsize ( $map_size [0], $map_size [1] );
  286 +}
  287 +
  288 +if (isset ( $_GET ["mapext"] )) {
  289 + $mapext = explode ( " ", $_GET ["mapext"] );
  290 + // para evitar erro quando o mapa e continuo
  291 + if ($mapext [0] == $mapext [2] && $mapext [1] == $mapext [3]) {
  292 + exit ();
  293 + }
  294 + $mapa->setExtent ( $mapext [0], $mapext [1], $mapext [2], $mapext [3] );
  295 +}
  296 +//
  297 +// qd a cahamda e para um WMS, redireciona para ogc.php
  298 +//
  299 +if ($_GET ["REQUEST"] == "getlegendgraphic" || $_GET ["REQUEST"] == "getfeatureinfo" || $_GET ["REQUEST"] == "GetFeatureInfo" || $_GET ["REQUEST"] == "getfeature") {
  300 + $req = ms_newowsrequestobj ();
  301 + if ($_GET ["BBOX"]) {
  302 + $_GET ["BBOX"] = str_replace ( " ", ",", $_GET ["BBOX"] );
  303 + }
  304 + $_GET = array_merge ( $_GET, $_POST );
  305 +
  306 + foreach ( $_GET as $k => $v ) {
  307 + $req->setParameter ( $k, $v );
  308 + }
  309 + $proto = "http" . ((isset ( $_SERVER ['HTTPS'] ) && $_SERVER ['HTTPS'] == "on") ? "s" : "") . "://";
  310 + $server = isset ( $_SERVER ['HTTP_HOST'] ) ? $_SERVER ['HTTP_HOST'] : $_SERVER ['SERVER_NAME'];
  311 + $or = $proto . $server . $_SERVER ['PHP_SELF'];
  312 + $mapa->setmetadata ( "wfs_onlineresource", $or . "?" . $_SERVER ["QUERY_STRING"] );
  313 + ms_ioinstallstdouttobuffer ();
  314 + $mapa->owsdispatch ( $req );
  315 + $contenttype = ms_iostripstdoutbuffercontenttype ();
  316 + header ( "Content-type: $contenttype" );
  317 + ms_iogetStdoutBufferBytes ();
  318 + ms_ioresethandlers ();
  319 + exit ();
  320 +}
  321 +
  322 +$o = $mapa->outputformat;
  323 +$o->set ( "imagemode", MS_IMAGEMODE_RGBA );
  324 +$legenda = $mapa->legend;
  325 +$legenda->set ( "status", MS_OFF );
  326 +$escala = $mapa->scalebar;
  327 +$escala->set ( "status", MS_OFF );
  328 +
  329 +//
  330 +// se o layer nao for do tipo fundo
  331 +//
  332 +if ($_GET ["tipolayer"] != "fundo") {
  333 + $o->set ( "transparent", MS_TRUE );
  334 +}
  335 +
  336 +//
  337 +// se o layer foi marcado para corte altera os parametros para ampliar o mapa
  338 +// antes de gerar a imagem
  339 +//
  340 +if ($cortePixels > 0) {
  341 + // $mapa->prepareImage();
  342 + // echo $mapa->scaledenom;exit;
  343 + $escalaInicial = $mapa->scaledenom;
  344 + $extensaoInicial = $mapa->extent;
  345 + $wh = 256 + ($cortePixels * 2);
  346 + $mapa->setsize ( $wh, $wh );
  347 + $ponto = new pointObj ();
  348 + $ponto->setxy ( ($wh / 2), ($wh / 2) );
  349 + $mapa->zoomScale ( $escalaInicial, $ponto, $wh, $wh, $extensaoInicial );
  350 +}
  351 +
  352 +// se nao houver selecao
  353 +if ($qy != true) {
  354 + $img = $mapa->draw ();
  355 +} else {
  356 + $handle = fopen ( $qyfile, "r" );
  357 + $conteudo = fread ( $handle, filesize ( $qyfile ) );
  358 + fclose ( $handle );
  359 + $shp = unserialize ( $conteudo );
  360 + $l = $mapa->getLayerByname ( $_GET ["layer"] );
  361 + if ($l->connectiontype != MS_POSTGIS) {
  362 + $indxlayer = $l->index;
  363 + foreach ( $shp as $indx ) {
  364 + $mapa->querybyindex ( $indxlayer, - 1, $indx, MS_TRUE );
  365 + }
  366 + $qm = $mapa->querymap;
  367 + $qm->set ( "width", $map_size [0] );
  368 + $qm->set ( "height", $map_size [1] );
  369 + $img = $mapa->drawQuery ();
  370 + } else {
  371 + $img = $mapa->draw ();
  372 + $c = $mapa->querymap->color;
  373 + $numclasses = $l->numclasses;
  374 + if ($numclasses > 0) {
  375 + $classe0 = $l->getClass ( 0 );
  376 + $classe0->setexpression ( "" );
  377 + $classe0->set ( "name", " " );
  378 + for($i = 1; $i < $numclasses; ++ $i) {
  379 + $classe = $l->getClass ( $i );
  380 + $classe->set ( "status", MS_DELETE );
  381 + }
  382 + }
  383 + $cor = $classe0->getstyle ( 0 )->color;
  384 + $cor->setrgb ( $c->red, $c->green, $c->blue );
  385 + // $cor = $classe0->getstyle(0)->outlinecolor;
  386 + // $cor->setrgb($c->red,$c->green,$c->blue);
  387 + $status = $l->open ();
  388 + $status = $l->whichShapes ( $mapa->extent );
  389 + while ( $shape = $l->nextShape () ) {
  390 + if (in_array ( $shape->index, $shp ))
  391 + $shape->draw ( $mapa, $l, $img );
  392 + }
  393 + $l->close ();
  394 + }
  395 + $cache = false;
  396 +}
  397 +// nao usa o cache pois e necessario processar a imagem com alguma rotina de filtro
  398 +if ($_GET ["TIPOIMAGEM"] != "" && $_GET ["TIPOIMAGEM"] != "nenhum") {
  399 + if ($img->imagepath == "") {
  400 + echo "Erro IMAGEPATH vazio";
  401 + exit ();
  402 + }
  403 + $nomer = ($img->imagepath) . "filtroimgtemp" . nomeRand () . ".png";
  404 + $img->saveImage ( $nomer );
  405 + //
  406 + // corta a imagem gerada para voltar ao tamanho normal
  407 + //
  408 + if ($cortePixels > 0) {
  409 + cortaImagemDisco ( $nomer, $cortePixels, 256 );
  410 + }
  411 + filtraImg ( $nomer, $_GET ["TIPOIMAGEM"] );
  412 + $img = imagecreatefrompng ( $nomer );
  413 + imagealphablending ( $img, false );
  414 + imagesavealpha ( $img, true );
  415 + cabecalhoImagem ( $nomer );
  416 + imagepng ( $img );
  417 + imagedestroy ( $img );
  418 +} else {
  419 + if ($cache == true && $_GET ["cache"] != "nao") {
  420 + // cache ativo. Salva a imagem em cache
  421 + $nomer = salvaCacheImagem ( $cachedir, $map_fileX, $_GET ["tms"] );
  422 + cabecalhoImagem ( $nomer );
  423 + if ($_SESSION ["i3georendermode"] == 2) {
  424 + header ( "X-Sendfile: $nomer" );
  425 + } else {
  426 + readfile ( $nomer );
  427 + }
  428 + } else {
  429 + // cache inativo
  430 + if ($img->imagepath == "") {
  431 + ilegal ();
  432 + }
  433 + // se for necessario cortar a imagem, $img->saveImage() nao funciona
  434 + if ($_SESSION ["i3georendermode"] == 0 || ($_SESSION ["i3georendermode"] == 1 && $cortePixels > 0)) {
  435 + $nomer = ($img->imagepath) . "temp" . nomeRand () . ".png";
  436 + $img->saveImage ( $nomer );
  437 + //
  438 + // corta a imagem gerada para voltar ao tamanho normal
  439 + //
  440 + if ($cortePixels > 0) {
  441 + $img = cortaImagemDisco ( $nomer, $cortePixels, 256 );
  442 + } else {
  443 + $img = imagecreatefrompng ( $nomer );
  444 + imagealphablending ( $img, false );
  445 + imagesavealpha ( $img, true );
  446 + }
  447 + cabecalhoImagem ( $nomer );
  448 + imagepng ( $img );
  449 + imagedestroy ( $img );
  450 + exit ();
  451 + }
  452 + if ($_SESSION ["i3georendermode"] == 1) {
  453 + ob_clean ();
  454 + header ( 'Content-Type: image/png' );
  455 + $img->saveImage ();
  456 + }
  457 + if ($_SESSION ["i3georendermode"] == 2) {
  458 + $nomer = ($img->imagepath) . "temp" . nomeRand () . ".png";
  459 + $img->saveImage ( $nomer );
  460 + //
  461 + // corta a imagem gerada para voltar ao tamanho normal
  462 + //
  463 + if ($cortePixels > 0) {
  464 + $img = cortaImagemDisco ( $nomer, $cortePixels, 256 );
  465 + }
  466 + cabecalhoImagem ( $nomer );
  467 + header ( "X-Sendfile: $nomer" );
  468 + }
  469 + }
  470 +}
  471 +function cabecalhoImagem($nome) {
  472 + if (ob_get_contents ()) {
  473 + ob_clean ();
  474 + }
  475 + $lastModified = filemtime ( $nome );
  476 + // set last-modified header
  477 + header ( "Last-Modified: " . gmdate ( "D, d M Y H:i:s", $lastModified ) . " GMT" );
  478 + // make sure caching is turned on
  479 + header ( 'Cache-Control: public,max-age=86400' ); // 24 horas
  480 + header ( "Content-type: image/png" );
  481 + header ( "Etag: " . md5 ( $nome ) );
  482 + // check if page has changed. If not, send 304 and exit
  483 + if (array_key_exists ( 'HTTP_IF_MODIFIED_SINCE', $_SERVER )) {
  484 + $if_modified_since = strtotime ( preg_replace ( '/;.*$/', '', $_SERVER ['HTTP_IF_MODIFIED_SINCE'] ) );
  485 + if ($if_modified_since >= $lastModified) { // Is the Cached version the most recent?
  486 + header ( $_SERVER ['SERVER_PROTOCOL'] . ' 304 Not Modified' );
  487 + exit ();
  488 + }
  489 + }
  490 +}
  491 +function salvaCacheImagem($cachedir, $map, $tms) {
  492 + global $img, $cortePixels;
  493 + if ($cachedir == "") {
  494 + $nome = dirname ( dirname ( $map ) ) . "/cache" . $tms;
  495 + } else {
  496 + $nome = $cachedir . $tms;
  497 + }
  498 + $nome = str_replace ( ".png", "", $nome );
  499 + $nome = $nome . ".png";
  500 + if (! file_exists ( $nome )) {
  501 + if (! file_exists ( dirname ( $nome ) )) {
  502 + @mkdir ( dirname ( $nome ), 0744, true );
  503 + chmod ( dirname ( $nome ), 0744 );
  504 + }
  505 + error_log ( "salvando imagem" );
  506 + $img->saveImage ( $nome );
  507 + //
  508 + // corta a imagem gerada para voltar ao tamanho normal
  509 + //
  510 + if ($cortePixels > 0) {
  511 + $img = cortaImagemDisco ( $nome, $cortePixels, 256 );
  512 + }
  513 + chmod ( $nome, 0744 );
523 514 }
524 515 return $nome;
525   -}
526   -function carregaCacheImagem($cachedir,$map,$tms,$i3georendermode=0){
527   - if($cachedir == ""){
528   - $nome = dirname(dirname($map))."/cache".$tms;
  516 +}
  517 +function carregaCacheImagem($cachedir, $map, $tms, $i3georendermode = 0) {
  518 + if ($cachedir == "") {
  519 + $nome = dirname ( dirname ( $map ) ) . "/cache" . $tms;
  520 + } else {
  521 + $nome = $cachedir . $tms;
  522 + }
  523 + $nome = $nome . ".png";
  524 + if (file_exists ( $nome )) {
  525 + cabecalhoImagem ( $nome );
  526 + if ($i3georendermode = 0 || $i3georendermode = 1 || empty ( $i3georendermode )) {
  527 + readfile ( $nome );
  528 + } else {
  529 + header ( "X-Sendfile: $nome" );
  530 + }
  531 + exit ();
  532 + }
  533 +}
  534 +function nomeRand($n = 10) {
  535 + $nomes = "";
  536 + $a = 'azertyuiopqsdfghjklmwxcvbnABCDEFGHIJKLMNOPQRSTUVWXYZ';
  537 + $max = 51;
  538 + for($i = 0; $i < $n; ++ $i) {
  539 + $nomes .= $a {mt_rand ( 0, $max )};
  540 + }
  541 + return $nomes;
  542 +}
  543 +function filtraImg($nomer, $tipoimagem) {
  544 + include_once ("classe_imagem.php");
  545 + $tiposImagem = explode ( " ", $tipoimagem );
  546 + foreach ( $tiposImagem as $tipoimagem ) {
  547 + $m = new Imagem ( $nomer );
  548 + if ($tipoimagem == "cinza") {
  549 + imagepng ( $m->cinzaNormal (), str_replace ( "\\", "/", $nomer ) );
  550 + }
  551 + if ($tipoimagem == "sepiaclara") {
  552 + imagepng ( $m->sepiaClara (), str_replace ( "\\", "/", $nomer ) );
  553 + }
  554 + if ($tipoimagem == "sepianormal") {
  555 + imagepng ( $m->sepiaNormal (), str_replace ( "\\", "/", $nomer ) );
  556 + }
  557 + if ($tipoimagem == "negativo") {
  558 + imagepng ( $m->negativo (), str_replace ( "\\", "/", $nomer ) );
  559 + }
  560 + if ($tipoimagem == "detectaBordas") {
  561 + imagepng ( $m->detectaBordas (), str_replace ( "\\", "/", $nomer ) );
  562 + }
  563 + if ($tipoimagem == "embassa") {
  564 + imagepng ( $m->embassa (), str_replace ( "\\", "/", $nomer ) );
  565 + }
  566 + if ($tipoimagem == "gaussian_blur") {
  567 + imagepng ( $m->gaussian_blur (), str_replace ( "\\", "/", $nomer ) );
  568 + }
  569 + if ($tipoimagem == "selective_blur") {
  570 + imagepng ( $m->selective_blur (), str_replace ( "\\", "/", $nomer ) );
  571 + }
  572 + if ($tipoimagem == "mean_removal") {
  573 + imagepng ( $m->mean_removal (), str_replace ( "\\", "/", $nomer ) );
  574 + }
  575 + if ($tipoimagem == "pixelate") {
  576 + imagepng ( $m->pixelate (), str_replace ( "\\", "/", $nomer ) );
  577 + }
  578 + }
  579 +}
  580 +function inicializa() {
  581 + ini_set ( "session.use_cookies", 0 );
  582 + session_name ( "i3GeoPHP" );
  583 + if (@$_GET ["g_sid"]) {
  584 + session_id ( $_GET ["g_sid"] );
  585 + } elseif (@$_COOKIE ["i3GeoPHP"]) {
  586 + session_id ( $_COOKIE ["i3GeoPHP"] );
  587 + } else {
  588 + ilegal ();
  589 + }
  590 + session_start ();
  591 + if ($_GET ["REQUEST"] == "getfeatureinfo" || $_GET ["REQUEST"] == "GetFeatureInfo" || strtolower ( $_GET ["REQUEST"] ) == "getfeature") {
  592 + return;
  593 + }
  594 + if (@$_SESSION ["fingerprint"]) {
  595 + $f = explode ( ",", $_SESSION ["fingerprint"] );
  596 + if (md5 ( 'I3GEOSEC' . $_SERVER ['HTTP_USER_AGENT'] . session_id () ) != $f [0]) {
  597 + ilegal ();
  598 + }
  599 + } else {
  600 + exit ();
529 601 }
530   - else{
531   - $nome = $cachedir.$tms;
532   - }
533   - $nome = $nome.".png";
534   - if(file_exists($nome)){
535   - cabecalhoImagem($nome);
536   - if($i3georendermode = 0 || $i3georendermode = 1 || empty($i3georendermode)){
537   - readfile($nome);
538   - }
539   - else{
540   - header("X-Sendfile: $nome");
541   - }
542   - exit;
  602 + if (! isset ( $_SESSION ["map_file"] )) {
  603 + exit ();
543 604 }
544   -}
545   -function nomeRand($n=10)
546   -{
547   - $nomes = "";
548   - $a = 'azertyuiopqsdfghjklmwxcvbnABCDEFGHIJKLMNOPQRSTUVWXYZ';
549   - $max = 51;
550   - for($i=0; $i < $n; ++$i)
551   - {$nomes .= $a{mt_rand(0, $max)};}
552   - return $nomes;
553   -}
554   -function filtraImg($nomer,$tipoimagem){
555   - include_once("classe_imagem.php");
556   - $tiposImagem = explode(" ",$tipoimagem);
557   - foreach ($tiposImagem as $tipoimagem){
558   - $m = new Imagem($nomer);
559   - if ($tipoimagem == "cinza")
560   - {imagepng($m->cinzaNormal(),str_replace("\\","/",$nomer));}
561   - if ($tipoimagem == "sepiaclara")
562   - {imagepng($m->sepiaClara(),str_replace("\\","/",$nomer));}
563   - if ($tipoimagem == "sepianormal")
564   - {imagepng($m->sepiaNormal(),str_replace("\\","/",$nomer));}
565   - if ($tipoimagem == "negativo")
566   - {imagepng($m->negativo(),str_replace("\\","/",$nomer));}
567   - if ($tipoimagem == "detectaBordas")
568   - {imagepng($m->detectaBordas(),str_replace("\\","/",$nomer));}
569   - if ($tipoimagem == "embassa")
570   - {imagepng($m->embassa(),str_replace("\\","/",$nomer));}
571   - if ($tipoimagem == "gaussian_blur")
572   - {imagepng($m->gaussian_blur(),str_replace("\\","/",$nomer));}
573   - if ($tipoimagem == "selective_blur")
574   - {imagepng($m->selective_blur(),str_replace("\\","/",$nomer));}
575   - if ($tipoimagem == "mean_removal")
576   - {imagepng($m->mean_removal(),str_replace("\\","/",$nomer));}
577   - if ($tipoimagem == "pixelate")
578   - {imagepng($m->pixelate(),str_replace("\\","/",$nomer));}
579   - }
580   -}
581   -function inicializa(){
582   - ini_set("session.use_cookies", 0);
583   - session_name("i3GeoPHP");
584   - if(@$_GET["g_sid"]){
585   - session_id($_GET["g_sid"]);
586   - }
587   - elseif (@$_COOKIE["i3GeoPHP"]){
588   - session_id($_COOKIE["i3GeoPHP"]);
589   - } else {
590   - ilegal();
591   - }
592   - session_start();
593   - if($_GET["REQUEST"] == "getfeatureinfo" || $_GET["REQUEST"] == "GetFeatureInfo" || strtolower($_GET["REQUEST"]) == "getfeature"){
594   - return;
595   - }
596   - if(@$_SESSION["fingerprint"]){
597   - $f = explode(",",$_SESSION["fingerprint"]);
598   - if (md5('I3GEOSEC' . $_SERVER['HTTP_USER_AGENT'] . session_id()) != $f[0] )
599   - {ilegal();}
600   - }
601   - else{
602   - exit;
603   - }
604   - if(!isset($_SESSION["map_file"])){
605   - exit;
606   - }
607   -}
608   -function ilegal(){
609   - $img = imagecreatefrompng("../imagens/ilegal.png");
610   - imagealphablending($img, false);
611   - imagesavealpha($img, true);
612   - ob_clean();
613   - echo header("Content-type: image/png \n\n");
614   - imagepng($img);
615   - exit;
616   -}
617   -/**
618   - * Corta uma imagem existente em disco
619   - */
620   -function cortaImagemDisco($arquivo,$cortePixels,$tamanhoFinal=256){
621   - $img = imagecreatefrompng($arquivo);
622   - $imgc = imagecreatetruecolor($tamanhoFinal,$tamanhoFinal);
623   - //necessario, sem isso algumas imagens sao geradas de forma errada
624   - imagesavealpha($imgc, true);
625   - $color = imagecolorallocatealpha($imgc,0x00,0x00,0x00,127);
626   - imagefill($imgc, 0, 0, $color);
627   - imagecopy( $imgc, $img, 0 , 0 , $cortePixels , $cortePixels , $tamanhoFinal, $tamanhoFinal );
628   - imagepng($imgc,$arquivo);
629   - return $imgc;
630   -}
  605 +}
  606 +function ilegal() {
  607 + $img = imagecreatefrompng ( "../imagens/ilegal.png" );
  608 + imagealphablending ( $img, false );
  609 + imagesavealpha ( $img, true );
  610 + ob_clean ();
  611 + echo header ( "Content-type: image/png \n\n" );
  612 + imagepng ( $img );
  613 + exit ();
  614 +}
  615 +/**
  616 + * Corta uma imagem existente em disco
  617 + */
  618 +function cortaImagemDisco($arquivo, $cortePixels, $tamanhoFinal = 256) {
  619 + $img = imagecreatefrompng ( $arquivo );
  620 + $imgc = imagecreatetruecolor ( $tamanhoFinal, $tamanhoFinal );
  621 + // necessario, sem isso algumas imagens sao geradas de forma errada
  622 + imagesavealpha ( $imgc, true );
  623 + $color = imagecolorallocatealpha ( $imgc, 0x00, 0x00, 0x00, 127 );
  624 + imagefill ( $imgc, 0, 0, $color );
  625 + imagecopy ( $imgc, $img, 0, 0, $cortePixels, $cortePixels, $tamanhoFinal, $tamanhoFinal );
  626 + imagepng ( $imgc, $arquivo );
  627 + return $imgc;
  628 +}
631 629 ?>
... ...