numlayers; $cache = false; for($i = 0; $i < $numlayers; ++ $i) { $l = $mapa->getLayer ( $i ); $layerName = $l->name; if ($layerName != $_GET ["layer"]) { $l->set ( "status", MS_OFF ); } // no caso de haver uma mascara definida no layer if ($versao ["inteiro"] >= 60200) { if ($l->mask != "") { $lmask = $mapa->getlayerbyname ( $l->mask ); if (! empty ( $postgis_mapa )) { if ($lmask->connectiontype == MS_POSTGIS) { $lcon = $l->connection; if (($lcon == " ") || ($lcon == "") || (in_array ( $lcon, array_keys ( $postgis_mapa ) ))) { if (($lcon == " ") || ($lcon == "")) { $lmask->set ( "connection", $postgis_mapa ); } else { $lmask->set ( "connection", $postgis_mapa [$lcon] ); } } } } } } if ($layerName == $_GET ["layer"] || $l->group == $_GET ["layer"] && $l->group != "") { if ($l->getmetadata ( "classesnome" ) != "" || $l->getmetadata ( "palletefile" ) != "") { if (! function_exists ( "autoClasses" )) { include_once ("funcoes_gerais.php"); } autoClasses ( $l, $mapa ); } // // numero de pixels que serao considerados para corte da imagem no caso de cache ativo e tema de pontos // $cortePixels = 0; if ($l->getmetadata ( "cortepixels" ) != "" && $qy == false) { $cortePixels = $l->getmetadata ( "cortepixels" ); } $l->set ( "status", MS_DEFAULT ); $l->set ( "template", "none.htm" ); if (! empty ( $postgis_mapa )) { if ($l->connectiontype == MS_POSTGIS) { $lcon = $l->connection; if (($lcon == " ") || ($lcon == "") || (in_array ( $lcon, array_keys ( $postgis_mapa ) ))) { if (($lcon == " ") || ($lcon == "")) { $l->set ( "connection", $postgis_mapa ); } else { $l->set ( "connection", $postgis_mapa [$lcon] ); } } } } } if ($_GET ["REQUEST"] == "getlegendgraphic") { $nclass = $l->numclasses; for($ic = 0; $ic < $nclass; $ic ++) { $classe = $l->getclass ( $ic ); if ($classe->title === "") { $classe->title = $classe->name; } } } if ($layerName == $_GET ["layer"]) { if (strtolower ( $l->getmetadata ( "cache" ) ) == "sim") { $cache = true; $nomecache = $l->getmetadata ( "nomeoriginal" ); if ($nomecache == "") { $nomecache = $layerName; } } if ($_GET ["REQUEST"] == "getfeatureinfo" || $_GET ["REQUEST"] == "GetFeatureInfo" || strtolower ( $_GET ["REQUEST"] ) == "getfeature") { $l->setmetadata ( "gml_include_items", "all" ); $l->set ( "template", "none.htm" ); $l->setmetadata ( "WMS_INCLUDE_ITEMS", "all" ); $l->setmetadata ( "WFS_INCLUDE_ITEMS", "all" ); $l->setmetadata ( "ows_enable_request", "*" ); $l->set ( "dump", MS_TRUE ); $l->setmetadata ( "ows_srs", "AUTO" ); if (strtolower ( $_GET ["REQUEST"] ) == "getfeature") { $_GET ["TYPENAME"] = $l->name; } } } } if (! function_exists ( 'imagepng' )) { $_GET ["TIPOIMAGEM"] = ""; } if ($_GET ["layer"] == "") { $cache = true; } if (($_GET == false) || ($qy) || (strtolower ( $_GET ["DESLIGACACHE"] ) == "sim")) { $cache = false; } elseif ($_GET ["TIPOIMAGEM"] != "" && $_GET ["TIPOIMAGEM"] != "nenhum") { $cache = false; } if ($cache == true && $_GET ["cache"] != "nao") { carregaCacheImagem ( $cachedir, $_SESSION ["map_file"], $_GET ["tms"] ); } if (isset ( $_GET ["map_size"] )) { $map_size = explode ( " ", $_GET ["map_size"] ); $mapa->setsize ( $map_size [0], $map_size [1] ); } if (isset ( $_GET ["mapext"] )) { $mapext = explode ( " ", $_GET ["mapext"] ); // para evitar erro quando o mapa e continuo if ($mapext [0] == $mapext [2] && $mapext [1] == $mapext [3]) { exit (); } $mapa->setExtent ( $mapext [0], $mapext [1], $mapext [2], $mapext [3] ); } // // qd a cahamda e para um WMS, redireciona para ogc.php // if ($_GET ["REQUEST"] == "getlegendgraphic" || $_GET ["REQUEST"] == "getfeatureinfo" || $_GET ["REQUEST"] == "GetFeatureInfo" || $_GET ["REQUEST"] == "getfeature") { $req = ms_newowsrequestobj (); if ($_GET ["BBOX"]) { $_GET ["BBOX"] = str_replace ( " ", ",", $_GET ["BBOX"] ); } $_GET = array_merge ( $_GET, $_POST ); foreach ( $_GET as $k => $v ) { $req->setParameter ( $k, $v ); } $proto = "http" . ((isset ( $_SERVER ['HTTPS'] ) && $_SERVER ['HTTPS'] == "on") ? "s" : "") . "://"; $server = isset ( $_SERVER ['HTTP_HOST'] ) ? $_SERVER ['HTTP_HOST'] : $_SERVER ['SERVER_NAME']; $or = $proto . $server . $_SERVER ['PHP_SELF']; $mapa->setmetadata ( "wfs_onlineresource", $or . "?" . $_SERVER ["QUERY_STRING"] ); ms_ioinstallstdouttobuffer (); $mapa->owsdispatch ( $req ); $contenttype = ms_iostripstdoutbuffercontenttype (); header ( "Content-type: $contenttype" ); ms_iogetStdoutBufferBytes (); ms_ioresethandlers (); exit (); } $o = $mapa->outputformat; $o->set ( "imagemode", MS_IMAGEMODE_RGBA ); $legenda = $mapa->legend; $legenda->set ( "status", MS_OFF ); $escala = $mapa->scalebar; $escala->set ( "status", MS_OFF ); // // se o layer nao for do tipo fundo // if ($_GET ["tipolayer"] != "fundo") { $o->set ( "transparent", MS_TRUE ); } // // se o layer foi marcado para corte altera os parametros para ampliar o mapa // antes de gerar a imagem // if ($cortePixels > 0) { // $mapa->prepareImage(); // echo $mapa->scaledenom;exit; $escalaInicial = $mapa->scaledenom; $extensaoInicial = $mapa->extent; $wh = 256 + ($cortePixels * 2); $mapa->setsize ( $wh, $wh ); $ponto = new pointObj (); $ponto->setxy ( ($wh / 2), ($wh / 2) ); $mapa->zoomScale ( $escalaInicial, $ponto, $wh, $wh, $extensaoInicial ); } // se nao houver selecao if ($qy != true) { $img = $mapa->draw (); } else { $handle = fopen ( $qyfile, "r" ); $conteudo = fread ( $handle, filesize ( $qyfile ) ); fclose ( $handle ); $shp = unserialize ( $conteudo ); $l = $mapa->getLayerByname ( $_GET ["layer"] ); if ($l->connectiontype != MS_POSTGIS) { $indxlayer = $l->index; foreach ( $shp as $indx ) { $mapa->querybyindex ( $indxlayer, - 1, $indx, MS_TRUE ); } $qm = $mapa->querymap; $qm->set ( "width", $map_size [0] ); $qm->set ( "height", $map_size [1] ); $img = $mapa->drawQuery (); } else { $img = $mapa->draw (); $c = $mapa->querymap->color; $numclasses = $l->numclasses; if ($numclasses > 0) { $classe0 = $l->getClass ( 0 ); $classe0->setexpression ( "" ); $classe0->set ( "name", " " ); for($i = 1; $i < $numclasses; ++ $i) { $classe = $l->getClass ( $i ); $classe->set ( "status", MS_DELETE ); } } $cor = $classe0->getstyle ( 0 )->color; $cor->setrgb ( $c->red, $c->green, $c->blue ); // $cor = $classe0->getstyle(0)->outlinecolor; // $cor->setrgb($c->red,$c->green,$c->blue); $status = $l->open (); $status = $l->whichShapes ( $mapa->extent ); while ( $shape = $l->nextShape () ) { if (in_array ( $shape->index, $shp )) $shape->draw ( $mapa, $l, $img ); } $l->close (); } $cache = false; } // nao usa o cache pois e necessario processar a imagem com alguma rotina de filtro if ($_GET ["TIPOIMAGEM"] != "" && $_GET ["TIPOIMAGEM"] != "nenhum") { if ($img->imagepath == "") { echo "Erro IMAGEPATH vazio"; exit (); } $nomer = ($img->imagepath) . "filtroimgtemp" . nomeRand () . ".png"; $img->saveImage ( $nomer ); // // corta a imagem gerada para voltar ao tamanho normal // if ($cortePixels > 0) { cortaImagemDisco ( $nomer, $cortePixels, 256 ); } filtraImg ( $nomer, $_GET ["TIPOIMAGEM"] ); $img = imagecreatefrompng ( $nomer ); imagealphablending ( $img, false ); imagesavealpha ( $img, true ); cabecalhoImagem ( $nomer ); imagepng ( $img ); imagedestroy ( $img ); } else { if ($cache == true && $_GET ["cache"] != "nao") { // cache ativo. Salva a imagem em cache $nomer = salvaCacheImagem ( $cachedir, $map_fileX, $_GET ["tms"] ); cabecalhoImagem ( $nomer ); if ($_SESSION ["i3georendermode"] == 2) { header ( "X-Sendfile: $nomer" ); } else { readfile ( $nomer ); } } else { // cache inativo if ($img->imagepath == "") { ilegal (); } // se for necessario cortar a imagem, $img->saveImage() nao funciona if ($_SESSION ["i3georendermode"] == 0 || ($_SESSION ["i3georendermode"] == 1 && $cortePixels > 0)) { $nomer = ($img->imagepath) . "temp" . nomeRand () . ".png"; $img->saveImage ( $nomer ); // // corta a imagem gerada para voltar ao tamanho normal // if ($cortePixels > 0) { $img = cortaImagemDisco ( $nomer, $cortePixels, 256 ); } else { $img = imagecreatefrompng ( $nomer ); imagealphablending ( $img, false ); imagesavealpha ( $img, true ); } cabecalhoImagem ( $nomer ); imagepng ( $img ); imagedestroy ( $img ); exit (); } if ($_SESSION ["i3georendermode"] == 1) { ob_clean (); header ( 'Content-Type: image/png' ); $img->saveImage (); } if ($_SESSION ["i3georendermode"] == 2) { $nomer = ($img->imagepath) . "temp" . nomeRand () . ".png"; $img->saveImage ( $nomer ); // // corta a imagem gerada para voltar ao tamanho normal // if ($cortePixels > 0) { $img = cortaImagemDisco ( $nomer, $cortePixels, 256 ); } cabecalhoImagem ( $nomer ); header ( "X-Sendfile: $nomer" ); } } } function cabecalhoImagem($nome) { if (ob_get_contents ()) { ob_clean (); } $lastModified = filemtime ( $nome ); // set last-modified header header ( "Last-Modified: " . gmdate ( "D, d M Y H:i:s", $lastModified ) . " GMT" ); // make sure caching is turned on header ( 'Cache-Control: public,max-age=86400' ); // 24 horas header ( "Content-type: image/png" ); header ( "Etag: " . md5 ( $nome ) ); // check if page has changed. If not, send 304 and exit if (array_key_exists ( 'HTTP_IF_MODIFIED_SINCE', $_SERVER )) { $if_modified_since = strtotime ( preg_replace ( '/;.*$/', '', $_SERVER ['HTTP_IF_MODIFIED_SINCE'] ) ); if ($if_modified_since >= $lastModified) { // Is the Cached version the most recent? header ( $_SERVER ['SERVER_PROTOCOL'] . ' 304 Not Modified' ); exit (); } } } function salvaCacheImagem($cachedir, $map, $tms) { global $img, $cortePixels; if ($cachedir == "") { $nome = dirname ( dirname ( $map ) ) . "/cache" . $tms; } else { $nome = $cachedir . $tms; } $nome = str_replace ( ".png", "", $nome ); $nome = $nome . ".png"; if (! file_exists ( $nome )) { if (! file_exists ( dirname ( $nome ) )) { @mkdir ( dirname ( $nome ), 0744, true ); chmod ( dirname ( $nome ), 0744 ); } error_log ( "salvando imagem" ); $img->saveImage ( $nome ); // // corta a imagem gerada para voltar ao tamanho normal // if ($cortePixels > 0) { $img = cortaImagemDisco ( $nome, $cortePixels, 256 ); } chmod ( $nome, 0744 ); } return $nome; } function carregaCacheImagem($cachedir, $map, $tms, $i3georendermode = 0) { if ($cachedir == "") { $nome = dirname ( dirname ( $map ) ) . "/cache" . $tms; } else { $nome = $cachedir . $tms; } $nome = $nome . ".png"; if (file_exists ( $nome )) { cabecalhoImagem ( $nome ); if ($i3georendermode = 0 || $i3georendermode = 1 || empty ( $i3georendermode )) { readfile ( $nome ); } else { header ( "X-Sendfile: $nome" ); } exit (); } } function nomeRand($n = 10) { $nomes = ""; $a = 'azertyuiopqsdfghjklmwxcvbnABCDEFGHIJKLMNOPQRSTUVWXYZ'; $max = 51; for($i = 0; $i < $n; ++ $i) { $nomes .= $a {mt_rand ( 0, $max )}; } return $nomes; } function filtraImg($nomer, $tipoimagem) { include_once ("classe_imagem.php"); $tiposImagem = explode ( " ", $tipoimagem ); foreach ( $tiposImagem as $tipoimagem ) { $m = new Imagem ( $nomer ); if ($tipoimagem == "cinza") { imagepng ( $m->cinzaNormal (), str_replace ( "\\", "/", $nomer ) ); } if ($tipoimagem == "sepiaclara") { imagepng ( $m->sepiaClara (), str_replace ( "\\", "/", $nomer ) ); } if ($tipoimagem == "sepianormal") { imagepng ( $m->sepiaNormal (), str_replace ( "\\", "/", $nomer ) ); } if ($tipoimagem == "negativo") { imagepng ( $m->negativo (), str_replace ( "\\", "/", $nomer ) ); } if ($tipoimagem == "detectaBordas") { imagepng ( $m->detectaBordas (), str_replace ( "\\", "/", $nomer ) ); } if ($tipoimagem == "embassa") { imagepng ( $m->embassa (), str_replace ( "\\", "/", $nomer ) ); } if ($tipoimagem == "gaussian_blur") { imagepng ( $m->gaussian_blur (), str_replace ( "\\", "/", $nomer ) ); } if ($tipoimagem == "selective_blur") { imagepng ( $m->selective_blur (), str_replace ( "\\", "/", $nomer ) ); } if ($tipoimagem == "mean_removal") { imagepng ( $m->mean_removal (), str_replace ( "\\", "/", $nomer ) ); } if ($tipoimagem == "pixelate") { imagepng ( $m->pixelate (), str_replace ( "\\", "/", $nomer ) ); } } } function inicializa() { ini_set ( "session.use_cookies", 0 ); session_name ( "i3GeoPHP" ); if (@$_GET ["g_sid"]) { session_id ( $_GET ["g_sid"] ); } elseif (@$_COOKIE ["i3GeoPHP"]) { session_id ( $_COOKIE ["i3GeoPHP"] ); } else { ilegal (); } session_start (); if ($_GET ["REQUEST"] == "getfeatureinfo" || $_GET ["REQUEST"] == "GetFeatureInfo" || strtolower ( $_GET ["REQUEST"] ) == "getfeature") { return; } if (@$_SESSION ["fingerprint"]) { $f = explode ( ",", $_SESSION ["fingerprint"] ); if (md5 ( 'I3GEOSEC' . $_SERVER ['HTTP_USER_AGENT'] . session_id () ) != $f [0]) { ilegal (); } } else { exit (); } if (! isset ( $_SESSION ["map_file"] )) { exit (); } } function ilegal() { $img = imagecreatefrompng ( "../imagens/ilegal.png" ); imagealphablending ( $img, false ); imagesavealpha ( $img, true ); ob_clean (); echo header ( "Content-type: image/png \n\n" ); imagepng ( $img ); exit (); } /** * Corta uma imagem existente em disco */ function cortaImagemDisco($arquivo, $cortePixels, $tamanhoFinal = 256) { $img = imagecreatefrompng ( $arquivo ); $imgc = imagecreatetruecolor ( $tamanhoFinal, $tamanhoFinal ); // necessario, sem isso algumas imagens sao geradas de forma errada imagesavealpha ( $imgc, true ); $color = imagecolorallocatealpha ( $imgc, 0x00, 0x00, 0x00, 127 ); imagefill ( $imgc, 0, 0, $color ); imagecopy ( $imgc, $img, 0, 0, $cortePixels, $cortePixels, $tamanhoFinal, $tamanhoFinal ); imagepng ( $imgc, $arquivo ); return $imgc; } ?>