loadquery($qyfile);} */ // //resolve o problema da seleção na versão nova do mapserver // $qyfile = dirname($_GET["map"])."/".$_GET["layer"].".php"; $qy = file_exists($qyfile); if($qy) { $l = $mapa->getLayerByname($_GET["layer"]); $indxlayer = $l->index; $handle = fopen ($qyfile, "r"); $conteudo = fread ($handle, filesize ($qyfile)); fclose ($handle); $shp = unserialize($conteudo); foreach ($shp as $indx) {$mapa->querybyindex($indxlayer,-1,$indx,MS_TRUE);} } $layersNames = $mapa->getalllayernames(); $cache = false; foreach ($layersNames as $layerName) { $l = $mapa->getLayerByname($layerName); if ($l->getmetadata("classesnome") != "") { include_once("funcoes_gerais.php"); autoClasses(&$l,$mapa); } if($layerName != $_GET["layer"]) {$l->set("status",MS_OFF);} if($layerName == $_GET["layer"] || $l->group == $_GET["layer"] && $l->group != "") { $l->set("status",MS_DEFAULT); if (($postgis_mapa != "") && ($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($layerName == $_GET["layer"]) { if(strtolower($l->getmetadata("cache")) == "sim") { $cache = true; $nomecache = $l->getmetadata("nomeoriginal"); if($nomecache == "") {$nomecache = $layerName;} } } $l->set("template","none.htm"); } if($qy || $_GET["HEIGHT"] != 256 ) {$cache = false;} if($_GET["layer"] == "") {$cache = true;} if($_GET == false) {$cache = false;} if($_GET["DESLIGACACHE"] == "sim") {$cache = false;} if(trim($_GET["TIPOIMAGEM"]) != "" && trim($_GET["TIPOIMAGEM"]) != "nenhum") {$cache = false;} if($cache == true) {carregaCacheImagem($_GET["BBOX"],$nomecache,$_GET["map"],$_GET["WIDTH"],$_GET["HEIGHT"]);} $map_size = explode(" ",$_GET["map_size"]); $mapa->setsize($map_size[0],$map_size[1]); $mapext = explode(" ",$_GET["mapext"]); $mapa->setExtent($mapext[0],$mapext[1],$mapext[2],$mapext[3]); $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 não for do tipo fundo // if($_GET["tipolayer"] != "fundo") {$o->set("transparent",MS_TRUE);} if(!$qy) {$img = $mapa->draw();} else { $qm = $mapa->querymap; $qm->set("width",$map_size[0]); $qm->set("height",$map_size[1]); $img = $mapa->drawQuery(); } if (!function_exists('imagepng')) { $s = PHP_SHLIB_SUFFIX; @dl( 'php_gd.'.$s ); if (!function_exists('imagepng')) {@dl( 'php_gd2.'.$s );} if (!function_exists('imagepng')) {$_GET["TIPOIMAGEM"] = "";} } if(trim($_GET["TIPOIMAGEM"]) != "" && trim($_GET["TIPOIMAGEM"]) != "nenhum") { $nomer = ($img->imagepath)."filtroimgtemp".nomeRandomico(); $img->saveImage($nomer); filtraImagem($nomer,$_GET["TIPOIMAGEM"]); $img = imagecreatefrompng($nomer); imagealphablending($img, false); imagesavealpha($img, true); ob_clean(); echo header("Content-type: image/png \n\n"); imagepng($img); } else{ if($cache == true) {salvaCacheImagem($_GET["BBOX"],$nomecache,$_GET["map"],$_GET["WIDTH"],$_GET["HEIGHT"]);} ob_clean(); $nomer = ($img->imagepath)."imgtemp".nomeRandomico(); $img->saveImage($nomer); $img = imagecreatefrompng($nomer); imagealphablending($img, false); imagesavealpha($img, true); ob_clean(); echo header("Content-type: image/png \n\n"); imagepng($img); } function salvaCacheImagem($bbox,$layer,$map,$w,$h){ global $img,$map_size; //layers que são sempre iguais if($layer == "copyright" || $layer == "") {$bbox = "";} if($layer == "") {$layer = "fundo";} $nomedir = dirname(dirname($map))."/cache/".$layer; @mkdir($nomedir,0777); $nome = $nomedir."/".$w.$h.$bbox; if(!file_exists($nome)) { $img->saveImage($nome); } } function carregaCacheImagem($bbox,$layer,$map,$w,$h){ if($layer == "copyright" || $layer == "") {$bbox = "";} if($layer == "") {$layer = "fundo";} $nome = $w.$h.$bbox; $nome = dirname(dirname($map))."/cache/".$layer."/".$nome; if(file_exists($nome)) { if (!function_exists('imagepng')) { $s = PHP_SHLIB_SUFFIX; @dl( 'php_gd.'.$s ); if (!function_exists('imagepng')) {@dl( 'php_gd2.'.$s );} } @$img = imagecreatefrompng($nome); if(!$img) { /* Create a blank image */ $img = imagecreatetruecolor($w, $h); imagealphablending($img, false); imagesavealpha($img, true); $bgc = imagecolorallocatealpha($img, 255, 255, 255,127); $tc = imagecolorallocate($img, 255, 0, 0); imagefilledrectangle($img, 0, 0, $w, $h, $bgc); /* Output an error message */ imagestring($img, 3, 5, 5, 'Erro ao ler ' . $nome, $tc); } else { imagealphablending($img, false); imagesavealpha($img, true); } ob_clean(); error_reporting(0); echo header("Content-type: image/png \n\n"); imagepng($img); imagedestroy($img); exit; } } function nomeRandomico($n=10) { $nomes = ""; $a = 'azertyuiopqsdfghjklmwxcvbnABCDEFGHIJKLMNOPQRSTUVWXYZ'; $max = 51; for($i=0; $i < $n; ++$i) {$nomes .= $a{mt_rand(0, $max)};} return $nomes; } function filtraImagem($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));} } } ?>