Commit 45f89db276132b4738ac98ac57701cc3d65dd58e

Authored by Edmar Moretti
1 parent 20bbc3e5

Atualização do leiame e inclusão de arquivos de renderização alternativos

classesphp/mapa_googlemaps_alternativo.php 0 → 100644
... ... @@ -0,0 +1,444 @@
  1 +<?php
  2 +/*
  3 +Title: mapa_googlemaps.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 Googlemaps.
  9 +
  10 +Precisa do codigo da "section" PHP aberta pelo i3Geo ou o codigo para acesso especial indicado no par&acirc;metro telaR
  11 +(veja a ferramenta TELAREMOTA).
  12 +
  13 +Parametros:
  14 +
  15 +g_sid {string} - codigo da "section" PHP
  16 +
  17 +telaR {string} - (opcional) utilizado para autorizar o uso do mapfile aberto (deve estar registrado em $fingerprint (vari&aacute;vel de se&ccedil;&atilde;o)
  18 +
  19 +tipolayer {fundo|} - (opcional) indica que a imagem a ser produzida comp&otilde;e o fundo do mapa
  20 +
  21 +BBOX {xmin xmax ymin ymax} - extens&atilde;o geogr&aacute;fica a ser utilizada no desenho do mapa
  22 +
  23 +WIDTH {numeric} - largura do mapa
  24 +
  25 +HEIGHT {numeric} - altura do mapa
  26 +
  27 +layer {string} - codigo do layer existente no mapa que ser&aacute; desenhado (ignorado quando telaR for definido)
  28 +
  29 +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
  30 +
  31 +TIPOIMAGEM {cinza|sepiaclara|sepianormal|negativo|detectaBordas|embassa|gaussian_blur|selective_blur|mean_removal|pixelate
  32 +} - filtro de imagem que ser&aacute; aplicado na imagem
  33 +
  34 +
  35 +Licenca:
  36 +
  37 +GPL2
  38 +
  39 +i3Geo Interface Integrada de Ferramentas de Geoprocessamento para Internet
  40 +
  41 +Direitos Autorais Reservados (c) 2006 Minist&eacute;rio do Meio Ambiente Brasil
  42 +Desenvolvedor: Edmar Moretti edmar.moretti@gmail.com
  43 +
  44 +Este programa &eacute; software livre; voc&ecirc; pode redistribu&iacute;-lo
  45 +e/ou modific&aacute;-lo sob os termos da Licen&ccedil;a P&uacute;blica Geral
  46 +GNU conforme publicada pela Free Software Foundation;
  47 +
  48 +Este programa &eacute; distribu&iacute;do na expectativa de que seja &uacute;til,
  49 +por&eacute;m, SEM NENHUMA GARANTIA; nem mesmo a garantia impl&iacute;cita
  50 +de COMERCIABILIDADE OU ADEQUA&Ccedil;&Atilde;O A UMA FINALIDADE ESPEC&Iacute;FICA.
  51 +Consulte a Licen&ccedil;a P&uacute;blica Geral do GNU para mais detalhes.
  52 +Voc&ecirc; deve ter recebido uma copia da Licen&ccedil;a P&uacute;blica Geral do
  53 +GNU junto com este programa; se n&atilde;o, escreva para a
  54 +Free Software Foundation, Inc., no endere&ccedil;o
  55 +59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
  56 +
  57 +Arquivo:
  58 +
  59 +i3geo/classesphp/mapa_googlemaps.php
  60 +
  61 +*/
  62 +//error_reporting(E_ALL);
  63 +error_reporting(0);
  64 +clearstatcache();
  65 +//verifica&ccedil;&atilde;o de seguran&ccedil;a
  66 +$_SESSION = array();
  67 +session_name("i3GeoPHP");
  68 +if(@$_GET["g_sid"]){
  69 + session_id($_GET["g_sid"]);
  70 +}
  71 +else{
  72 + ilegal();
  73 +}
  74 +session_start();
  75 +if(@$_SESSION["fingerprint"]){
  76 + $f = explode(",",$_SESSION["fingerprint"]);
  77 + if (md5('I3GEOSEC' . $_SERVER['HTTP_USER_AGENT'] . session_id()) != $f[0] && !in_array($_GET["telaR"],$f) ){
  78 + ilegal();
  79 + }
  80 +}
  81 +else{
  82 + exit;
  83 +}
  84 +if(!isset($_SESSION["map_file"])){
  85 + exit;
  86 +}
  87 +//
  88 +$map_fileX = $_SESSION["map_file"];
  89 +$postgis_mapa = $_SESSION["postgis_mapa"];
  90 +$cachedir = $_SESSION["cachedir"];
  91 +//
  92 +//converte a requisi&ccedil;&atilde;o do tile em coordenadas geo
  93 +//http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#tile_numbers_to_lon.2Flat_2
  94 +//
  95 +$x = $_GET["X"];
  96 +$y = $_GET["Y"];
  97 +$z = $_GET["Z"];
  98 +
  99 +$qyfile = dirname($map_fileX)."/".$_GET["layer"].".php";
  100 +$qy = file_exists($qyfile);
  101 +
  102 +if($qy == false && $_GET["cache"] == "sim" && $_GET["DESLIGACACHE"] != "sim"){
  103 + carregaCacheImagem($_SESSION["cachedir"],$_SESSION["map_file"],$_GET["tms"]);
  104 +}
  105 +
  106 +$n = pow(2,$z);
  107 +$lon1 = $x / $n * 360.0 - 180.0;
  108 +$lat2 = rad2deg(atan(sinh(pi() * (1 - 2 * $y / $n))));
  109 +$x++;
  110 +$y++;
  111 +$lon2 = $x / $n * 360.0 - 180.0;
  112 +$lat1 = rad2deg(atan(sinh(pi() * (1 - 2 * $y / $n))));
  113 +$x--;
  114 +$y--;
  115 +
  116 +$projInObj = ms_newprojectionobj("proj=latlong,a=6378137,b=6378137");
  117 +$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");
  118 +
  119 +$poPoint1 = ms_newpointobj();
  120 +$poPoint1->setXY($lon1, $lat1);
  121 +$poPoint1->project($projInObj, $projOutObj);
  122 +$poPoint2 = ms_newpointobj();
  123 +$poPoint2->setXY($lon2, $lat2);
  124 +$poPoint2->project($projInObj, $projOutObj);
  125 +$_GET["BBOX"] = $poPoint1->x." ".$poPoint1->y." ".$poPoint2->x." ".$poPoint2->y;
  126 +$_GET["mapext"] = str_replace(","," ",$_GET["BBOX"]);
  127 +
  128 +$mapa = ms_newMapObj($map_fileX);
  129 +$ret = $mapa->extent;
  130 +
  131 +$cache = false;
  132 +if(!isset($_GET["telaR"])){
  133 + //no caso de projecoes remotas, o mapfile nao e alterado
  134 + $numlayers = $mapa->numlayers;
  135 + for ($i=0;$i < $numlayers;++$i){
  136 + $l = $mapa->getlayer($i);
  137 + $layerName = $l->name;
  138 + $l->set("status",MS_OFF);
  139 + if($layerName == $_GET["layer"] || $l->group == $_GET["layer"] && $l->group != ""){
  140 + $l->set("template","none.htm");
  141 + $l->set("status",MS_DEFAULT);
  142 + if ($l->getmetadata("classesnome") != ""){
  143 + if(!function_exists("autoClasses")){
  144 + include_once("funcoes_gerais.php");
  145 + }
  146 + autoClasses($l,$mapa);
  147 + }
  148 + if(!empty($postgis_mapa)){
  149 + if($l->connectiontype == MS_POSTGIS){
  150 + $lcon = $l->connection;
  151 + if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))){
  152 + if(($lcon == " ") || ($lcon == "")){
  153 + $l->set("connection",$postgis_mapa);
  154 + }
  155 + else{
  156 + $l->set("connection",$postgis_mapa[$lcon]);
  157 + }
  158 + }
  159 + }
  160 + }
  161 + if($l->getProjection() == "" ){
  162 + $l->setProjection("proj=latlong,a=6378137,b=6378137");
  163 + }
  164 + }
  165 + if($layerName == $_GET["layer"]){
  166 + if(strtolower($l->getmetadata("cache")) == "sim"){
  167 + $cache = true;
  168 + }
  169 + }
  170 + }
  171 +}
  172 +else{
  173 + $mapa->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");
  174 + $numlayers = $mapa->numlayers;
  175 + for ($i=0;$i < $numlayers;++$i){
  176 + $l = $mapa->getlayer($i);
  177 + if($l->getProjection() == "" )
  178 + {$l->setProjection("proj=latlong,a=6378137,b=6378137");}
  179 + }
  180 +}
  181 +if($_GET["layer"] == "")
  182 +{$cache = true;}
  183 +
  184 +if(($_GET == false) || ($qy) || (strtolower($_GET["DESLIGACACHE"]) == "sim"))
  185 +{$cache = false;}
  186 +elseif(trim($_GET["TIPOIMAGEM"]) != "" && trim($_GET["TIPOIMAGEM"]) != "nenhum")
  187 +{$cache = false;}
  188 +
  189 +if($cache == true){
  190 + carregaCacheImagem();
  191 +}
  192 +$mapa->setsize(256,256);
  193 +$mapext = explode(" ",$_GET["mapext"]);
  194 +$mapa->setExtent($mapext[0],$mapext[1],$mapext[2],$mapext[3]);
  195 +
  196 +$o = $mapa->outputformat;
  197 +$o->set("imagemode",MS_IMAGEMODE_RGBA);
  198 +
  199 +if(!isset($_GET["telaR"])){
  200 + $legenda = $mapa->legend;
  201 + $legenda->set("status",MS_OFF);
  202 + $escala = $mapa->scalebar;
  203 + $escala->set("status",MS_OFF);
  204 +}
  205 +//
  206 +//se o layer nao for do tipo fundo
  207 +//
  208 +if($_GET["tipolayer"] != "fundo")
  209 +{$o->set("transparent",MS_TRUE);}
  210 +if(trim($_GET["TIPOIMAGEM"]) != "" && trim($_GET["TIPOIMAGEM"]) != "nenhum")
  211 +{$o->setOption("QUANTIZE_FORCE","OFF");}
  212 +if($qy != true){
  213 + $img = $mapa->draw();
  214 +}
  215 +else{
  216 + $handle = fopen ($qyfile, "r");
  217 + $conteudo = fread ($handle, filesize ($qyfile));
  218 + fclose ($handle);
  219 + $shp = unserialize($conteudo);
  220 + $l = $mapa->getLayerByname($_GET["layer"]);
  221 + $indxlayer = $l->index;
  222 + if ($l->connectiontype !== MS_POSTGIS){
  223 + foreach ($shp as $indx)
  224 + {$mapa->querybyindex($indxlayer,-1,$indx,MS_TRUE);}
  225 + $qm = $mapa->querymap;
  226 + $qm->set("width",255);
  227 + $qm->set("height",255);
  228 + $img = $mapa->drawQuery();
  229 + }
  230 + else{
  231 + $img = $mapa->draw();
  232 + $c = $mapa->querymap->color;
  233 + $numclasses = $l->numclasses;
  234 + if ($numclasses > 0)
  235 + {
  236 + $classe0 = $l->getClass(0);
  237 + $classe0->setexpression("");
  238 + $classe0->set("name"," ");
  239 + for ($i=1; $i < $numclasses; ++$i)
  240 + {
  241 + $classe = $l->getClass($i);
  242 + $classe->set("status",MS_DELETE);
  243 + }
  244 + }
  245 + $cor = $classe0->getstyle(0)->color;
  246 + $cor->setrgb($c->red,$c->green,$c->blue);
  247 + $cor = $classe0->getstyle(0)->outlinecolor;
  248 + $cor->setrgb($c->red,$c->green,$c->blue);
  249 + $v = versaoMS();
  250 + if($v["principal"] == 6){
  251 + $l->open();
  252 + foreach ($shp as $indx){
  253 + $shape = $l->getShape(new resultObj($indx));
  254 + $shape->draw($mapa,$l,$img);
  255 + }
  256 + $l->close();
  257 + }
  258 + else{
  259 + $l->open();
  260 + foreach ($shp as $indx){
  261 + $shape = $l->getfeature($indx,-1);
  262 + $shape->draw($mapa,$l,$img);
  263 + }
  264 + $l->close();
  265 + }
  266 + }
  267 +}
  268 +if (!function_exists('imagepng')){
  269 + $s = PHP_SHLIB_SUFFIX;
  270 + @dl( 'php_gd.'.$s );
  271 + if (!function_exists('imagepng'))
  272 + {@dl( 'php_gd2.'.$s );}
  273 + if (!function_exists('imagepng'))
  274 + {$_GET["TIPOIMAGEM"] = "";}
  275 +}
  276 +if(trim($_GET["TIPOIMAGEM"]) != "" && trim($_GET["TIPOIMAGEM"]) != "nenhum"){
  277 + if($img->imagepath == "")
  278 + {echo "Erro IMAGEPATH vazio";exit;}
  279 + $nomer = ($img->imagepath)."filtroimgtemp".nomeRand().".png";
  280 + $img->saveImage($nomer);
  281 + filtraImg($nomer,trim($_GET["TIPOIMAGEM"]));
  282 + $img = imagecreatefrompng($nomer);
  283 + imagealphablending($img, false);
  284 + imagesavealpha($img, true);
  285 + ob_clean();
  286 + echo header("Content-type: image/png \n\n");
  287 + imagepng($img);
  288 +}
  289 +else{
  290 + if($cache == true){
  291 + $nomer = salvaCacheImagem();
  292 + header('Content-Length: '.filesize($nomer));
  293 + header('Content-Type: image/png');
  294 + header('Cache-Control: max-age=3600, must-revalidate');
  295 + header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT');
  296 + header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nomer)).' GMT', true, 200);
  297 + fpassthru(fopen($nomer, 'rb'));
  298 + }
  299 + else{
  300 + $nomer = ($img->imagepath)."temp".nomeRand().".png";
  301 + $img->saveImage($nomer);
  302 + $img = imagecreatefrompng($nomer);
  303 + imagealphablending($img, false);
  304 + imagesavealpha($img, true);
  305 + ob_clean();
  306 + echo header("Content-type: image/png \n\n");
  307 + imagepng($img);
  308 + imagedestroy($img);
  309 + }
  310 + exit;
  311 +}
  312 +//$cachedir e definido no ms_configura.php
  313 +function salvaCacheImagem(){
  314 + global $img,$cachedir,$x,$y,$z,$map_fileX;
  315 + $layer = $_GET["layer"];
  316 + if($layer == "")
  317 + {$layer = "fundo";}
  318 + if($cachedir == ""){
  319 + $cachedir = dirname(dirname($map_fileX))."/cache";
  320 + }
  321 + $c = $cachedir."/googlemaps/$layer/$z/$x";
  322 + if(!file_exists($c."/$y.png")){
  323 + mkdir($cachedir."/googlemaps/$layer/$z/$x",0777,true);
  324 + $img->saveImage($c."/$y.png");
  325 + chmod($c."/$y.png",0777);
  326 + }
  327 + return $nome;
  328 +}
  329 +function carregaCacheImagem(){
  330 + global $img,$cachedir,$x,$y,$z,$map_fileX;
  331 + $layer = $_GET["layer"];
  332 + if($layer == "")
  333 + {$layer = "fundo";}
  334 + if($cachedir == ""){
  335 + $cachedir = dirname(dirname($map_fileX))."/cache";
  336 + }
  337 + $c = $cachedir."/googlemaps/$layer/$z/$x";
  338 + if(file_exists($c."/$y.png")){
  339 + header('Content-Length: '.filesize($c."/$y.png"));
  340 + header('Content-Type: image/png');
  341 + fpassthru(fopen($c."/$y.png", 'rb'));
  342 + exit;
  343 + }
  344 +}
  345 +/*
  346 +function salvaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){
  347 + global $img,$map_size;
  348 + //layers que s&atilde;o sempre iguais
  349 + //error_reporting(E_ALL);
  350 + if($layer == "copyright" || $layer == "")
  351 + {$bbox = "";}
  352 + if($layer == "")
  353 + {$layer = "fundo";}
  354 + if($cachedir == "")
  355 + {$cachedir = dirname(dirname($map))."/cache/googlemaps/".$layer;}
  356 + else
  357 + {$cachedir = $cachedir."/googlemaps/".$layer;}
  358 + @mkdir($cachedir,0777);
  359 + $nome = $cachedir."/".$w.$h.$bbox.".png";
  360 + if(!file_exists($nome))
  361 + {$img->saveImage($nome);}
  362 + return $nome;
  363 +}
  364 +function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){
  365 + if($layer == "copyright" || $layer == "")
  366 + {$bbox = "";}
  367 + if($layer == "")
  368 + {$layer = "fundo";}
  369 + $nome = $w.$h.$bbox.".png";
  370 + if($cachedir == "")
  371 + {$nome = dirname(dirname($map))."/cache/googlemaps/".$layer."/".$nome;}
  372 + else
  373 + {$nome = $cachedir."/googlemaps/".$layer."/".$nome;}
  374 + if(file_exists($nome)){
  375 + header('Content-Length: '.filesize($nome));
  376 + header('Content-Type: image/png');
  377 + fpassthru(fopen($nome, 'rb'));
  378 + exit;
  379 + }
  380 +}
  381 +*/
  382 +function nomeRand($n=10)
  383 +{
  384 + $nomes = "";
  385 + $a = 'azertyuiopqsdfghjklmwxcvbnABCDEFGHIJKLMNOPQRSTUVWXYZ';
  386 + $max = 51;
  387 + for($i=0; $i < $n; ++$i)
  388 + {$nomes .= $a{mt_rand(0, $max)};}
  389 + return $nomes;
  390 +}
  391 +function filtraImg($nomer,$tipoimagem){
  392 + include_once("classe_imagem.php");
  393 + $tiposImagem = explode(" ",$tipoimagem);
  394 + foreach ($tiposImagem as $tipoimagem){
  395 + $m = new Imagem($nomer);
  396 + if ($tipoimagem == "cinza")
  397 + {imagepng($m->cinzaNormal(),str_replace("\\","/",$nomer));}
  398 + if ($tipoimagem == "sepiaclara")
  399 + {imagepng($m->sepiaClara(),str_replace("\\","/",$nomer));}
  400 + if ($tipoimagem == "sepianormal")
  401 + {imagepng($m->sepiaNormal(),str_replace("\\","/",$nomer));}
  402 + if ($tipoimagem == "negativo")
  403 + {imagepng($m->negativo(),str_replace("\\","/",$nomer));}
  404 + if ($tipoimagem == "detectaBordas")
  405 + {imagepng($m->detectaBordas(),str_replace("\\","/",$nomer));}
  406 + if ($tipoimagem == "embassa")
  407 + {imagepng($m->embassa(),str_replace("\\","/",$nomer));}
  408 + if ($tipoimagem == "gaussian_blur")
  409 + {imagepng($m->gaussian_blur(),str_replace("\\","/",$nomer));}
  410 + if ($tipoimagem == "selective_blur")
  411 + {imagepng($m->selective_blur(),str_replace("\\","/",$nomer));}
  412 + if ($tipoimagem == "mean_removal")
  413 + {imagepng($m->mean_removal(),str_replace("\\","/",$nomer));}
  414 + if ($tipoimagem == "pixelate")
  415 + {imagepng($m->pixelate(),str_replace("\\","/",$nomer));}
  416 + }
  417 +}
  418 +function ilegal(){
  419 + $img = imagecreatefrompng("../imagens/ilegal.png");
  420 + imagealphablending($img, false);
  421 + imagesavealpha($img, true);
  422 + ob_clean();
  423 + echo header("Content-type: image/png \n\n");
  424 + imagepng($img);
  425 + exit;
  426 +}
  427 +function versaoMS()
  428 +{
  429 + $v = "5.0.0";
  430 + $vs = explode(" ",ms_GetVersion());
  431 + $cvs = count($vs);
  432 + for ($i=0;$i<$cvs;++$i)
  433 + {
  434 + if(trim(strtolower($vs[$i])) == "version")
  435 + {
  436 + $v = $vs[$i+1];
  437 + }
  438 + }
  439 + $versao["completa"] = $v;
  440 + $v = explode(".",$v);
  441 + $versao["principal"] = $v[0];
  442 + return $versao;
  443 +}
  444 +?>
0 445 \ No newline at end of file
... ...
classesphp/mapa_openlayers_alternativo.php 0 → 100644
... ... @@ -0,0 +1,425 @@
  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 em LAYERS do tipo WMS.
  9 +
  10 +Precisa do codigo da "section" PHP aberta pelo i3Geo ou o codigo para acesso especial indicado no par&acirc;metro telaR
  11 +(veja a ferramenta TELAREMOTA).
  12 +
  13 +Parametros:
  14 +
  15 +g_sid {string} - codigo da "section" PHP
  16 +
  17 +telaR {string} - (opcional) utilizado para autorizar o uso do mapfile aberto (deve estar registrado em $fingerprint (vari&aacute;vel de se&ccedil;&atilde;o)
  18 +
  19 +tipolayer {fundo|} - (opcional) indica que a imagem a ser produzida comp&otilde;e o fundo do mapa
  20 +
  21 +BBOX {xmin xmax ymin ymax} - extens&atilde;o geogr&aacute;fica a ser utilizada no desenho do mapa
  22 +
  23 +WIDTH {numeric} - largura do mapa
  24 +
  25 +HEIGHT {numeric} - altura do mapa
  26 +
  27 +layer {string} - codigo do layer existente no mapa que ser&aacute; desenhado (ignorado quando telaR for definido)
  28 +
  29 +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
  30 +
  31 +TIPOIMAGEM {cinza|sepiaclara|sepianormal|negativo|detectaBordas|embassa|gaussian_blur|selective_blur|mean_removal|pixelate
  32 +} - filtro de imagem que ser&aacute; aplicado na imagem
  33 +
  34 +Licenca:
  35 +
  36 +GPL2
  37 +
  38 +i3Geo Interface Integrada de Ferramentas de Geoprocessamento para Internet
  39 +
  40 +Direitos Autorais Reservados (c) 2006 Minist&eacute;rio do Meio Ambiente Brasil
  41 +Desenvolvedor: Edmar Moretti edmar.moretti@gmail.com
  42 +
  43 +Este programa &eacute; software livre; voc&ecirc; pode redistribu&iacute;-lo
  44 +e/ou modific&aacute;-lo sob os termos da Licen&ccedil;a P&uacute;blica Geral
  45 +GNU conforme publicada pela Free Software Foundation;
  46 +
  47 +Este programa &eacute; distribu&iacute;do na expectativa de que seja &uacute;til,
  48 +por&eacute;m, SEM NENHUMA GARANTIA; nem mesmo a garantia impl&iacute;cita
  49 +de COMERCIABILIDADE OU ADEQUA&Ccedil;&Atilde;O A UMA FINALIDADE ESPEC&Iacute;FICA.
  50 +Consulte a Licen&ccedil;a P&uacute;blica Geral do GNU para mais detalhes.
  51 +Voc&ecirc; deve ter recebido uma cópia da Licen&ccedil;a P&uacute;blica Geral do
  52 +GNU junto com este programa; se n&atilde;o, escreva para a
  53 +Free Software Foundation, Inc., no endere&ccedil;o
  54 +59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
  55 +
  56 +Arquivo:
  57 +
  58 +i3geo/classesphp/mapa_openlayers.php
  59 +
  60 +*/
  61 +error_reporting(0);
  62 +//carrega dados da se&ccedil;&atilde;o, verifica seguran&ccedil;a
  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 +if(isset($_GET["tms"])){
  69 + $_GET["WIDTH"] = 256;
  70 + $_GET["HEIGHT"] = 256;
  71 + $temp = explode("/",$_GET["tms"]);
  72 + $z = $temp[2];
  73 + $x = $temp[3];
  74 + $y = str_replace(".png","",$temp[4]);
  75 +
  76 + $n = pow(2,$z+1);
  77 + $lon1 = $x / $n * 360.0 - 180.0;
  78 + $lon2 = ($x+1) / $n * 360.0 - 180.0;
  79 + $n = pow(2,$z);
  80 + $lat1 = $y / $n * 180.0 - 90.0;
  81 + $lat2 = ($y+1) / $n * 180.0 - 90.0;
  82 + $_GET["BBOX"] = $lon1." ".$lat1." ".$lon2." ".$lat2;
  83 +}
  84 +$map_fileX = $_SESSION["map_file"];
  85 +//
  86 +//resolve o problema da sele&ccedil;&atilde;o na vers&atilde;o nova do mapserver
  87 +//
  88 +$qyfile = dirname($map_fileX)."/".$_GET["layer"].".php";
  89 +$qy = file_exists($qyfile);
  90 +
  91 +if($qy == false && $_GET["cache"] == "sim" && $_GET["DESLIGACACHE"] != "sim"){
  92 + carregaCacheImagem($_SESSION["cachedir"],$_SESSION["map_file"],$_GET["tms"]);
  93 +}
  94 +//
  95 +//map_fileX e para o caso register_globals = On no PHP.INI
  96 +
  97 +if(isset($_GET["tipolayer"]) && $_GET["tipolayer"] == "fundo"){
  98 + $map_fileX = str_replace(".map","fundo.map",$map_fileX);
  99 +}
  100 +$postgis_mapa = $_SESSION["postgis_mapa"];
  101 +$cachedir = $_SESSION["cachedir"];
  102 +if(isset($_GET["BBOX"])){
  103 + $_GET["mapext"] = str_replace(","," ",$_GET["BBOX"]);
  104 + $_GET["map_size"] = $_GET["WIDTH"]." ".$_GET["HEIGHT"];
  105 +}
  106 +$_GET["TIPOIMAGEM"] = trim($_GET["TIPOIMAGEM"]);
  107 +$mapa = ms_newMapObj($map_fileX);
  108 +
  109 +//
  110 +//processa os layers do mapfile
  111 +//
  112 +if(!isset($_GET["telaR"])){//no caso de projecoes remotas, o mapfile nao e alterado
  113 + $numlayers = $mapa->numlayers;
  114 + $cache = false;
  115 + for($i = 0;$i < $numlayers;++$i){
  116 + $l = $mapa->getLayer($i);
  117 + $layerName = $l->name;
  118 + if($layerName != $_GET["layer"]){
  119 + $l->set("status",MS_OFF);
  120 + }
  121 + if($layerName == $_GET["layer"] || $l->group == $_GET["layer"] && $l->group != ""){
  122 + if ($l->getmetadata("classesnome") != ""){
  123 + if(!function_exists("autoClasses"))
  124 + {include_once("funcoes_gerais.php");}
  125 + autoClasses($l,$mapa);
  126 + }
  127 + $l->set("status",MS_DEFAULT);
  128 + $l->set("template","none.htm");
  129 + if (!empty($postgis_mapa)){
  130 + if ($l->connectiontype == MS_POSTGIS){
  131 + $lcon = $l->connection;
  132 + if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))){
  133 + if(($lcon == " ") || ($lcon == ""))
  134 + {$l->set("connection",$postgis_mapa);}
  135 + else
  136 + {$l->set("connection",$postgis_mapa[$lcon]);}
  137 + }
  138 + }
  139 + }
  140 + }
  141 + if($layerName == $_GET["layer"]){
  142 + if(strtolower($l->getmetadata("cache")) == "sim"){
  143 + $cache = true;
  144 + $nomecache = $l->getmetadata("nomeoriginal");
  145 + if($nomecache == ""){
  146 + $nomecache = $layerName;
  147 + }
  148 + }
  149 + }
  150 + if($_GET["REQUEST"] == "GetFeatureInfo" || $_GET["REQUEST"] == "getfeature"){
  151 + $l->setmetadata("gml_include_items","all");
  152 + $l->setmetadata("WMS_INCLUDE_ITEMS","all");
  153 + $l->setmetadata("WFS_INCLUDE_ITEMS","all");
  154 + $l->setmetadata("ows_enable_request","*");
  155 + $l->set("dump",MS_TRUE);
  156 + $l->setmetadata("ows_srs","AUTO");
  157 + }
  158 + }
  159 +}
  160 +if (!function_exists('imagepng'))
  161 +{$_GET["TIPOIMAGEM"] = "";}
  162 +
  163 +if($_GET["layer"] == "")
  164 +{$cache = true;}
  165 +
  166 +if(($_GET == false) || ($qy) || (strtolower($_GET["DESLIGACACHE"]) == "sim")){
  167 + $cache = false;
  168 +}
  169 +elseif($_GET["TIPOIMAGEM"] != "" && $_GET["TIPOIMAGEM"] != "nenhum")
  170 +{$cache = false;}
  171 +
  172 +if($cache == true && $_GET["cache"] != "nao"){
  173 + //carregaCacheImagem($cachedir,$_GET["BBOX"],$nomecache,$map_fileX,$_GET["WIDTH"],$_GET["HEIGHT"]);
  174 + carregaCacheImagem($cachedir,$map,$tms);
  175 +}
  176 +$map_size = explode(" ",$_GET["map_size"]);
  177 +$mapa->setsize($map_size[0],$map_size[1]);
  178 +if(isset($_GET["mapext"])){
  179 + $mapext = explode(" ",$_GET["mapext"]);
  180 + $mapa->setExtent($mapext[0],$mapext[1],$mapext[2],$mapext[3]);
  181 +}
  182 +//
  183 +//qd a cahamda e para um WMS, redireciona para ogc.php
  184 +//
  185 +if($_GET["REQUEST"] == "GetFeatureInfo" || $_GET["request"] == "getfeature"){
  186 + $req = ms_newowsrequestobj();
  187 + $_GET = array_merge($_GET,$_POST);
  188 + foreach ($_GET as $k=>$v){
  189 + $req->setParameter($k, $v);
  190 + }
  191 + $proto = "http" . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "") . "://";
  192 + $server = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
  193 + $or = $proto.$server.$_SERVER['PHP_SELF'];
  194 + $mapa->setmetadata("wfs_onlineresource",$or."?".$_SERVER["QUERY_STRING"]);
  195 +
  196 + ms_ioinstallstdouttobuffer();
  197 + $mapa->owsdispatch($req);
  198 + $contenttype = ms_iostripstdoutbuffercontenttype();
  199 + header("Content-type: $contenttype");
  200 + ms_iogetStdoutBufferBytes();
  201 + ms_ioresethandlers();
  202 + exit;
  203 +}
  204 +
  205 +$o = $mapa->outputformat;
  206 +$o->set("imagemode",MS_IMAGEMODE_RGBA);
  207 +if(!isset($_GET["telaR"])){
  208 + $legenda = $mapa->legend;
  209 + $legenda->set("status",MS_OFF);
  210 + $escala = $mapa->scalebar;
  211 + $escala->set("status",MS_OFF);
  212 +}
  213 +//
  214 +//se o layer n&atilde;o for do tipo fundo
  215 +//
  216 +if($_GET["tipolayer"] != "fundo")
  217 +{$o->set("transparent",MS_TRUE);}
  218 +if($qy != true)
  219 +{$img = $mapa->draw();}
  220 +else{
  221 + $handle = fopen ($qyfile, "r");
  222 + $conteudo = fread ($handle, filesize ($qyfile));
  223 + fclose ($handle);
  224 + $shp = unserialize($conteudo);
  225 + $l = $mapa->getLayerByname($_GET["layer"]);
  226 + if ($l->connectiontype != MS_POSTGIS){
  227 + $indxlayer = $l->index;
  228 + foreach ($shp as $indx)
  229 + {$mapa->querybyindex($indxlayer,-1,$indx,MS_TRUE);}
  230 + $qm = $mapa->querymap;
  231 + $qm->set("width",$map_size[0]);
  232 + $qm->set("height",$map_size[1]);
  233 + $img = $mapa->drawQuery();
  234 + }
  235 + else{
  236 + $img = $mapa->draw();
  237 + $c = $mapa->querymap->color;
  238 + $numclasses = $l->numclasses;
  239 + if ($numclasses > 0)
  240 + {
  241 + $classe0 = $l->getClass(0);
  242 + $classe0->setexpression("");
  243 + $classe0->set("name"," ");
  244 + for ($i=1; $i < $numclasses; ++$i)
  245 + {
  246 + $classe = $l->getClass($i);
  247 + $classe->set("status",MS_DELETE);
  248 + }
  249 + }
  250 + $cor = $classe0->getstyle(0)->color;
  251 + $cor->setrgb($c->red,$c->green,$c->blue);
  252 + $cor = $classe0->getstyle(0)->outlinecolor;
  253 + $cor->setrgb($c->red,$c->green,$c->blue);
  254 + $status = $l->open();
  255 + $status = $l->whichShapes($mapa->extent);
  256 + while ($shape = $l->nextShape())
  257 + {
  258 + if(in_array($shape->index,$shp))
  259 + $shape->draw($mapa,$l,$img);
  260 + }
  261 + $l->close();
  262 + }
  263 + $cache = false;
  264 +}
  265 +if($_GET["TIPOIMAGEM"] != "" && $_GET["TIPOIMAGEM"] != "nenhum"){
  266 + if($img->imagepath == "")
  267 + {echo "Erro IMAGEPATH vazio";exit;}
  268 + $nomer = ($img->imagepath)."filtroimgtemp".nomeRand().".png";
  269 + $img->saveImage($nomer);
  270 + filtraImg($nomer,$_GET["TIPOIMAGEM"]);
  271 + $img = imagecreatefrompng($nomer);
  272 + imagealphablending($img, false);
  273 + imagesavealpha($img, true);
  274 + ob_clean();
  275 + echo header("Content-type: image/png \n\n");
  276 + imagepng($img);
  277 + imagedestroy($img);
  278 +}
  279 +else{
  280 + if($cache == true && $_GET["cache"] != "nao"){
  281 + //$nomer = salvaCacheImagem($cachedir,$_GET["BBOX"],$nomecache,$map_fileX,$_GET["WIDTH"],$_GET["HEIGHT"]);
  282 + $nomer = salvaCacheImagem($cachedir,$map_fileX,$_GET["tms"]);
  283 + header('Content-Length: '.filesize($nomer));
  284 + header('Content-Type: image/png');
  285 + header('Cache-Control: max-age=3600, must-revalidate');
  286 + header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT');
  287 + header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nomer)).' GMT', true, 200);
  288 + fpassthru(fopen($nomer, 'rb'));
  289 + }
  290 + else{
  291 + if($img->imagepath == "")
  292 + {echo "Erro IMAGEPATH vazio";exit;}
  293 + $nomer = ($img->imagepath)."temp".nomeRand().".png";
  294 + $img->saveImage($nomer);
  295 + $img = imagecreatefrompng($nomer);
  296 + imagealphablending($img, false);
  297 + imagesavealpha($img, true);
  298 + ob_clean();
  299 + echo header("Content-type: image/png \n\n");
  300 + imagepng($img);
  301 + imagedestroy($img);
  302 + }
  303 +}
  304 +function salvaCacheImagem($cachedir,$map,$tms){
  305 + global $img;
  306 + if($cachedir == ""){
  307 + $nome = dirname(dirname($map))."/cache".$tms;
  308 + }
  309 + else{
  310 + $nome = $cachedir.$tms;
  311 + }
  312 + if(!file_exists($nome)){
  313 + @mkdir(dirname($nome),0777,true);
  314 + $img->saveImage($nome);
  315 + chmod($nome,0777);
  316 + }
  317 + return $nome;
  318 +}
  319 +function carregaCacheImagem($cachedir,$map,$tms){
  320 + if($cachedir == ""){
  321 + $nome = dirname(dirname($map))."/cache".$tms;
  322 + }
  323 + else{
  324 + $nome = $cachedir.$tms;
  325 + }
  326 + if(file_exists($nome)){
  327 + header('Content-Length: '.filesize($nome));
  328 + header('Content-Type: image/png');
  329 + header('Cache-Control: max-age=3600, must-revalidate');
  330 + header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT');
  331 + header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nome)).' GMT', true, 200);
  332 + $etag = md5_file($nome);
  333 + header('Etag: '.$etag);
  334 + fpassthru(fopen($nome, 'rb'));
  335 + exit;
  336 + }
  337 +}
  338 +function XcarregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){
  339 + if($layer == "copyright" || $layer == "")
  340 + {$bbox = "";}
  341 + if($layer == "")
  342 + {$layer = "fundo";}
  343 + $nome = $w.$h.$bbox.".png";
  344 + if($cachedir == "")
  345 + {$nome = dirname(dirname($map))."/cache/".$layer."/".$nome;}
  346 + else
  347 + {$nome = $cachedir."/".$layer."/".$nome;}
  348 + if(file_exists($nome)){
  349 + header('Content-Length: '.filesize($nome));
  350 + header('Content-Type: image/png');
  351 + header('Cache-Control: max-age=3600, must-revalidate');
  352 + header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT');
  353 + header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nome)).' GMT', true, 200);
  354 + $etag = md5_file($nome);
  355 + header('Etag: '.$etag);
  356 + fpassthru(fopen($nome, 'rb'));
  357 + exit;
  358 + }
  359 +}
  360 +function nomeRand($n=10)
  361 +{
  362 + $nomes = "";
  363 + $a = 'azertyuiopqsdfghjklmwxcvbnABCDEFGHIJKLMNOPQRSTUVWXYZ';
  364 + $max = 51;
  365 + for($i=0; $i < $n; ++$i)
  366 + {$nomes .= $a{mt_rand(0, $max)};}
  367 + return $nomes;
  368 +}
  369 +function filtraImg($nomer,$tipoimagem){
  370 + include_once("classe_imagem.php");
  371 + $tiposImagem = explode(" ",$tipoimagem);
  372 + foreach ($tiposImagem as $tipoimagem){
  373 + $m = new Imagem($nomer);
  374 + if ($tipoimagem == "cinza")
  375 + {imagepng($m->cinzaNormal(),str_replace("\\","/",$nomer));}
  376 + if ($tipoimagem == "sepiaclara")
  377 + {imagepng($m->sepiaClara(),str_replace("\\","/",$nomer));}
  378 + if ($tipoimagem == "sepianormal")
  379 + {imagepng($m->sepiaNormal(),str_replace("\\","/",$nomer));}
  380 + if ($tipoimagem == "negativo")
  381 + {imagepng($m->negativo(),str_replace("\\","/",$nomer));}
  382 + if ($tipoimagem == "detectaBordas")
  383 + {imagepng($m->detectaBordas(),str_replace("\\","/",$nomer));}
  384 + if ($tipoimagem == "embassa")
  385 + {imagepng($m->embassa(),str_replace("\\","/",$nomer));}
  386 + if ($tipoimagem == "gaussian_blur")
  387 + {imagepng($m->gaussian_blur(),str_replace("\\","/",$nomer));}
  388 + if ($tipoimagem == "selective_blur")
  389 + {imagepng($m->selective_blur(),str_replace("\\","/",$nomer));}
  390 + if ($tipoimagem == "mean_removal")
  391 + {imagepng($m->mean_removal(),str_replace("\\","/",$nomer));}
  392 + if ($tipoimagem == "pixelate")
  393 + {imagepng($m->pixelate(),str_replace("\\","/",$nomer));}
  394 + }
  395 +}
  396 +function inicializa(){
  397 + clearstatcache();
  398 + session_name("i3GeoPHP");
  399 + if(@$_GET["g_sid"]){
  400 + session_id($_GET["g_sid"]);
  401 + }
  402 + else{
  403 + ilegal();
  404 + }
  405 + session_start();
  406 + if(@$_SESSION["fingerprint"]){
  407 + $f = explode(",",$_SESSION["fingerprint"]);
  408 + if (md5('I3GEOSEC' . $_SERVER['HTTP_USER_AGENT'] . session_id()) != $f[0] && !in_array($_GET["telaR"],$f) )
  409 + {ilegal();}
  410 + }
  411 + else
  412 + {exit;}
  413 + if(!isset($_SESSION["map_file"]))
  414 + {exit;}
  415 +}
  416 +function ilegal(){
  417 + $img = imagecreatefrompng("../imagens/ilegal.png");
  418 + imagealphablending($img, false);
  419 + imagesavealpha($img, true);
  420 + ob_clean();
  421 + echo header("Content-type: image/png \n\n");
  422 + imagepng($img);
  423 + exit;
  424 +}
  425 +?>
0 426 \ No newline at end of file
... ...
leiame.txt
... ... @@ -22,13 +22,6 @@ as instruções que ficam no item &quot;documentacao&quot;. Para ter acesso ao portal, vc te
22 22  
23 23 ---------
24 24  
25   -Se vc é usuário windows, descompacte o arquivo do i3geo adequado na raiz do drive "c". No final vc terá
26   -um diretório c:\ms4w
27   -Clique duas vezes em c:\ms4w\apache-install.bat para ativar o servidor Apache. Depois, abra o navegador
28   -para internet e digite o endereço http://localhost/i3geo ou http://localhost/i3geo/principal.htm
29   -
30   ----------
31   -
32 25 A partir da versão 3.9 do i3geo foi incluida uma página principal com endereços para
33 26 os aplicativos que vêm com o i3geo (não esqueça de dar uma olhada):
34 27 http://localhost/i3geo/principal.htm
... ... @@ -36,21 +29,13 @@ http://localhost/i3geo/principal.htm
36 29 ---------
37 30  
38 31 Se vc é usuário linux, dê preferência para instalar o i3geo no diretório:
39   -/opt/www/html/i3geo
  32 +/var/www/i3geo
40 33 e o diretório temporário em
41   -/var/tmp/ms_tmp
  34 +/tmp/ms_tmp
42 35 Assim vc não precisará alterar os arquivos de configuração.
43 36  
44 37 ---------
45 38  
46   -Se vc não seguiu essa última dica, pode ser necessário editar alguns arquivos, como:
47   -
48   -ms_configura.php
49   -aplicmap/geral1.map
50   -aplicmap/ogcws.map
51   -
52   ----------
53   -
54 39 A interface padrão utilizada pelo i3geo utiliza o html interface/openlayers.htm.
55 40 Para customizar essa interface, edite o arquivo html conforme a documentação
56 41 existente no próprio arquivo.
... ... @@ -80,3 +65,40 @@ o fórum da comunidade i3geo.
80 65  
81 66 Edite o arquivo aplicmap/ogcws.map para incluir os dados da sua instituição que serão mostrados
82 67 nos web services automáticos gerados com i3geo/ogc.php
  68 +
  69 +---------
  70 +
  71 +Se vc é usuário windows, descompacte o arquivo do i3geo adequado na raiz do drive "c". No final vc terá
  72 +um diretório c:\ms4w
  73 +Clique duas vezes em c:\ms4w\apache-install.bat para ativar o servidor Apache. Depois, abra o navegador
  74 +para internet e digite o endereço http://localhost/i3geo
  75 +
  76 +---------
  77 +
  78 +Se vc é usuário Ubuntu, siga o seguinte roteiro:
  79 +
  80 +http://edmarmoretti.blogspot.com.br/2013/03/instalacao-do-i3geo-no-ubuntu-12-ou.html
  81 +
  82 +---------
  83 +
  84 +Após instalar utilize o localhost/i3geo/testainstal.php para ver se está tudo certo.
  85 +
  86 +---------
  87 +
  88 +Se o testaisntal.php estiver mostrando os mapas e mesmo assim ao abrir o i3Geo as camadas não são mostradas, considere o seguinte:
  89 +
  90 +Alguns usuários reportaram problemas em algumas instalações do Mapserver. Esses usuários conseguem adicionar camadas
  91 +ao mapa mas nada é mostrado, mesmo quando as questões de projeção e outras estão todas configuradas de acordo. Se esse for o seu caso,
  92 +experimente trocar os arquivos de renderização fazendo o seguinte:
  93 +
  94 +altere os nomes dos seguintes arquivos para mantê-los como cópia:
  95 +
  96 +i3geo/classesphp/mapa_openlayers.php -> mapa_openlayers_original.php
  97 +i3geo/classesphp/mapa_googlemaps.php -> mapa_googlemaps_original.php
  98 +
  99 +altere os nomes dos arquivos alternativos:
  100 +
  101 +i3geo/classesphp/mapa_openlayers_alternativo.php -> mapa_openlayers.php
  102 +i3geo/classesphp/mapa_googlemaps_alternativo.php -> mapa_googlemaps.php
  103 +
  104 +
... ...