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 (ms_GetVersionInt() >= 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); //a opacidade e controlada pela aplicacao //a renderiazacao e sempre com opacidade 1 $l->updateFromString('LAYER COMPOSITE OPACITY 100 END END'); $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 (isset($_GET["REQUEST"])) { 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 (isset($_GET["REQUEST"])) { 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 ($layerName == $_GET["layer"] && ($_GET["FORMAT"] == "utfgrid")) { $_GET["SRS"] = "EPSG:4326"; $mapa->setProjection("proj=latlong,a=6378137,b=6378137"); include ("mapa_utfgrid.php"); exit(); } } 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 (isset($_GET["REQUEST"])) { 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); $o->set("transparent", MS_TRUE); $legenda = $mapa->legend; $legenda->set("status", MS_OFF); $escala = $mapa->scalebar; $escala->set("status", MS_OFF); // // 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; if(empty($_GET["WIDTH"])){ $_GET["WIDTH"] = 256; } $wh = $_GET["WIDTH"] + ($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, $_GET["WIDTH"]); } 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, $_GET["WIDTH"]); } 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, $_GET["WIDTH"]); } cabecalhoImagem($nomer); header("X-Sendfile: ".$nomer); } } } function cabecalhoImagem($nome,$tipo="image/png") { 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: " . $tipo); 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, $_GET["WIDTH"]); } chmod($nome, 0744); } return $nome; } function carregaCacheImagem($cachedir, $map, $tms, $i3georendermode = 0, $format = "") { if ($cachedir == "") { $nome = dirname(dirname($map)) . "/cache" . $tms; } else { $nome = $cachedir . $tms; } if($format == "utfgrid"){ $nome = str_replace(".png","",$nome) . ".json"; $tipo = "application/json; subtype=json"; } else { $nome = str_replace(".png","",$nome) . ".png"; $tipo = "image/png"; } if (file_exists($nome)) { cabecalhoImagem($nome,$tipo); 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([ 'read_and_close' => true ]); if (isset($_GET["REQUEST"])) { 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; } ?>