Commit 2034aebf96a35db3cf41ca380e36744bc991e014

Authored by Edmar Moretti
1 parent e31a03a6

-

classesphp/mapa_googlemaps.php
@@ -142,6 +142,7 @@ $mapa = ms_newMapObj($map_fileX); @@ -142,6 +142,7 @@ $mapa = ms_newMapObj($map_fileX);
142 $ret = $mapa->extent; 142 $ret = $mapa->extent;
143 143
144 $cache = false; 144 $cache = false;
  145 +$cortePixels = 0;
145 if(!isset($_GET["telaR"])){ 146 if(!isset($_GET["telaR"])){
146 //no caso de projecoes remotas, o mapfile nao e alterado 147 //no caso de projecoes remotas, o mapfile nao e alterado
147 $numlayers = $mapa->numlayers; 148 $numlayers = $mapa->numlayers;
@@ -155,7 +156,6 @@ if(!isset($_GET["telaR"])){ @@ -155,7 +156,6 @@ if(!isset($_GET["telaR"])){
155 // 156 //
156 //numero de pixels que serao considerados para corte da imagem no caso de cache ativo e tema de pontos 157 //numero de pixels que serao considerados para corte da imagem no caso de cache ativo e tema de pontos
157 // 158 //
158 - $cortePixels = 0;  
159 if ($l->getmetadata("cortepixels") != ""){ 159 if ($l->getmetadata("cortepixels") != ""){
160 $cortePixels = $l->getmetadata("cortepixels"); 160 $cortePixels = $l->getmetadata("cortepixels");
161 } 161 }
@@ -190,6 +190,12 @@ if(!isset($_GET["telaR"])){ @@ -190,6 +190,12 @@ if(!isset($_GET["telaR"])){
190 if(strtolower($l->getmetadata("cache")) == "sim"){ 190 if(strtolower($l->getmetadata("cache")) == "sim"){
191 $cache = true; 191 $cache = true;
192 } 192 }
  193 + //
  194 + //numero de pixels que serao considerados para corte da imagem no caso de cache ativo e tema de pontos
  195 + //
  196 + if ($l->getmetadata("cortepixels") != ""){
  197 + $cortePixels = $l->getmetadata("cortepixels");
  198 + }
193 if($_GET["REQUEST"] == "GetFeatureInfo" || strtolower($_GET["REQUEST"]) == "getfeature" ){ 199 if($_GET["REQUEST"] == "GetFeatureInfo" || strtolower($_GET["REQUEST"]) == "getfeature" ){
194 $l->setmetadata("gml_include_items","all"); 200 $l->setmetadata("gml_include_items","all");
195 $l->set("template","none.htm"); 201 $l->set("template","none.htm");
@@ -210,11 +216,11 @@ else{ @@ -210,11 +216,11 @@ else{
210 $numlayers = $mapa->numlayers; 216 $numlayers = $mapa->numlayers;
211 for ($i=0;$i < $numlayers;++$i){ 217 for ($i=0;$i < $numlayers;++$i){
212 $l = $mapa->getlayer($i); 218 $l = $mapa->getlayer($i);
213 - if($l->getProjection() == "" )  
214 - {$l->setProjection("proj=latlong,a=6378137,b=6378137");} 219 + if($l->getProjection() == "" ){
  220 + $l->setProjection("proj=latlong,a=6378137,b=6378137");
  221 + }
215 } 222 }
216 } 223 }
217 -  
218 // 224 //
219 //qd a cahamda e para um WMS, redireciona para ogc.php 225 //qd a cahamda e para um WMS, redireciona para ogc.php
220 // 226 //
@@ -247,14 +253,16 @@ if($_GET[&quot;REQUEST&quot;] == &quot;GetFeatureInfo&quot; || $_GET[&quot;REQUEST&quot;] == &quot;getfeature&quot;){ @@ -247,14 +253,16 @@ if($_GET[&quot;REQUEST&quot;] == &quot;GetFeatureInfo&quot; || $_GET[&quot;REQUEST&quot;] == &quot;getfeature&quot;){
247 exit; 253 exit;
248 } 254 }
249 255
250 -if($_GET["layer"] == "")  
251 -{$cache = true;}  
252 -  
253 -if(($_GET == false) || ($qy) || (strtolower($_GET["DESLIGACACHE"]) == "sim"))  
254 -{$cache = false;}  
255 -elseif(trim($_GET["TIPOIMAGEM"]) != "" && trim($_GET["TIPOIMAGEM"]) != "nenhum")  
256 -{$cache = false;} 256 +if($_GET["layer"] == ""){
  257 + $cache = true;
  258 +}
257 259
  260 +if(($_GET == false) || ($qy) || (strtolower($_GET["DESLIGACACHE"]) == "sim")){
  261 + $cache = false;
  262 +}
  263 +elseif(trim($_GET["TIPOIMAGEM"]) != "" && trim($_GET["TIPOIMAGEM"]) != "nenhum"){
  264 + $cache = false;
  265 +}
258 if($cache == true){ 266 if($cache == true){
259 carregaCacheImagem(); 267 carregaCacheImagem();
260 } 268 }
@@ -287,7 +295,6 @@ if($cortePixels &gt; 0){ @@ -287,7 +295,6 @@ if($cortePixels &gt; 0){
287 //$imagemBranco = $mapa->prepareImage(); 295 //$imagemBranco = $mapa->prepareImage();
288 $escalaInicial = $mapa->scaledenom; 296 $escalaInicial = $mapa->scaledenom;
289 $extensaoInicial = $mapa->extent; 297 $extensaoInicial = $mapa->extent;
290 -  
291 $wh = 256+($cortePixels*2); 298 $wh = 256+($cortePixels*2);
292 $mapa->setsize($wh,$wh); 299 $mapa->setsize($wh,$wh);
293 $ponto = new pointObj(); 300 $ponto = new pointObj();
@@ -360,10 +367,17 @@ if (!function_exists(&#39;imagepng&#39;)){ @@ -360,10 +367,17 @@ if (!function_exists(&#39;imagepng&#39;)){
360 {$_GET["TIPOIMAGEM"] = "";} 367 {$_GET["TIPOIMAGEM"] = "";}
361 } 368 }
362 if(trim($_GET["TIPOIMAGEM"]) != "" && trim($_GET["TIPOIMAGEM"]) != "nenhum"){ 369 if(trim($_GET["TIPOIMAGEM"]) != "" && trim($_GET["TIPOIMAGEM"]) != "nenhum"){
363 - if($img->imagepath == "")  
364 - {echo "Erro IMAGEPATH vazio";exit;} 370 + if($img->imagepath == ""){
  371 + echo "Erro IMAGEPATH vazio";exit;
  372 + }
365 $nomer = ($img->imagepath)."filtroimgtemp".nomeRand().".png"; 373 $nomer = ($img->imagepath)."filtroimgtemp".nomeRand().".png";
366 $img->saveImage($nomer); 374 $img->saveImage($nomer);
  375 + //
  376 + //corta a imagem gerada para voltar ao tamanho normal
  377 + //
  378 + if($cortePixels > 0){
  379 + cortaImagemDisco($nomer,$cortePixels,256);
  380 + }
367 filtraImg($nomer,trim($_GET["TIPOIMAGEM"])); 381 filtraImg($nomer,trim($_GET["TIPOIMAGEM"]));
368 $img = imagecreatefrompng($nomer); 382 $img = imagecreatefrompng($nomer);
369 imagealphablending($img, false); 383 imagealphablending($img, false);
@@ -376,31 +390,22 @@ else{ @@ -376,31 +390,22 @@ else{
376 if($cache == true){ 390 if($cache == true){
377 $nomer = salvaCacheImagem(); 391 $nomer = salvaCacheImagem();
378 carregaCacheImagem(); 392 carregaCacheImagem();
379 - /*  
380 - if($_SESSION["i3georendermode"] == 2){  
381 - ob_clean();  
382 - header('Cache-Control: public, max-age=22222222');  
383 - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+48*60*60) . ' GMT');  
384 - header("X-Sendfile: $nomer");  
385 - header("Content-type: image/png");  
386 - }  
387 - else{  
388 - ob_clean();  
389 - header('Content-Length: '.filesize($nomer));  
390 - header('Content-Type: image/png');  
391 - header('Cache-Control: public, max-age=22222222');  
392 - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+48*60*60) . ' GMT');  
393 - fpassthru(fopen($nomer, 'rb'));  
394 - }  
395 - */  
396 } 393 }
397 else{ 394 else{
398 - if($_SESSION["i3georendermode"] == 0){ 395 + if($_SESSION["i3georendermode"] == 0 || ($_SESSION["i3georendermode"] == 1 && $cortePixels > 0)){
399 $nomer = ($img->imagepath)."temp".nomeRand().".png"; 396 $nomer = ($img->imagepath)."temp".nomeRand().".png";
400 $img->saveImage($nomer); 397 $img->saveImage($nomer);
401 - $img = imagecreatefrompng($nomer);  
402 - imagealphablending($img, false);  
403 - imagesavealpha($img, true); 398 + //
  399 + //corta a imagem gerada para voltar ao tamanho normal
  400 + //
  401 + if($cortePixels > 0){
  402 + $img = cortaImagemDisco($nomer,$cortePixels,256);
  403 + }
  404 + else{
  405 + $img = imagecreatefrompng($nomer);
  406 + imagealphablending($img, false);
  407 + imagesavealpha($img, true);
  408 + }
404 ob_clean(); 409 ob_clean();
405 echo header("Content-type: image/png \n\n"); 410 echo header("Content-type: image/png \n\n");
406 imagepng($img); 411 imagepng($img);
@@ -415,6 +420,12 @@ else{ @@ -415,6 +420,12 @@ else{
415 if($_SESSION["i3georendermode"] == 2){ 420 if($_SESSION["i3georendermode"] == 2){
416 $nomer = ($img->imagepath)."temp".nomeRand().".png"; 421 $nomer = ($img->imagepath)."temp".nomeRand().".png";
417 $img->saveImage($nomer); 422 $img->saveImage($nomer);
  423 + //
  424 + //corta a imagem gerada para voltar ao tamanho normal
  425 + //
  426 + if($cortePixels > 0){
  427 + $img = cortaImagemDisco($nomer,$cortePixels,256);
  428 + }
418 ob_clean(); 429 ob_clean();
419 header('Cache-Control: public, max-age=22222222'); 430 header('Cache-Control: public, max-age=22222222');
420 header('Expires: ' . gmdate('D, d M Y H:i:s', time()+48*60*60) . ' GMT'); 431 header('Expires: ' . gmdate('D, d M Y H:i:s', time()+48*60*60) . ' GMT');
@@ -441,15 +452,13 @@ function salvaCacheImagem(){ @@ -441,15 +452,13 @@ function salvaCacheImagem(){
441 //corta a imagem gerada para voltar ao tamanho normal 452 //corta a imagem gerada para voltar ao tamanho normal
442 // 453 //
443 if($cortePixels > 0){ 454 if($cortePixels > 0){
444 - $img = imagecreatefrompng($c."/$y.png");  
445 - $imgc = imagecreate(256,256);  
446 - imagecopy( $imgc, $img, 0 , 0 , $cortePixels , $cortePixels , 256, 256 );  
447 - imagepng($imgc,$nome);  
448 - } 455 + $img = cortaImagemDisco($c."/$y.png",$cortePixels,256);
  456 + }
  457 +
449 chmod($cachedir."/googlemaps/$layer/$z/$x",0777); 458 chmod($cachedir."/googlemaps/$layer/$z/$x",0777);
450 chmod($c."/$y.png",0777); 459 chmod($c."/$y.png",0777);
451 } 460 }
452 - return $nome; 461 + return $c."/$y.png";
453 } 462 }
454 function carregaCacheImagem(){ 463 function carregaCacheImagem(){
455 global $img,$cachedir,$x,$y,$z,$map_fileX,$i3georendermode; 464 global $img,$cachedir,$x,$y,$z,$map_fileX,$i3georendermode;
@@ -540,4 +549,18 @@ function versaoMS() @@ -540,4 +549,18 @@ function versaoMS()
540 $versao["principal"] = $v[0]; 549 $versao["principal"] = $v[0];
541 return $versao; 550 return $versao;
542 } 551 }
  552 +/**
  553 + * Corta uma imagem existente em disco
  554 + */
  555 +function cortaImagemDisco($arquivo,$cortePixels,$tamanhoFinal=256){
  556 + $img = imagecreatefrompng($arquivo);
  557 + $imgc = imagecreate($tamanhoFinal,$tamanhoFinal);
  558 + //@FIXME necessario, sem isso algumas imagens sao geradas de forma errada
  559 + imagesavealpha($imgc, true);
  560 + $color = imagecolorallocatealpha($imgc,0x00,0x00,0x00,127);
  561 + imagefill($imgc, 0, 0, $color);
  562 + imagecopy( $imgc, $img, 0 , 0 , $cortePixels , $cortePixels , $tamanhoFinal, $tamanhoFinal );
  563 + imagepng($imgc,$arquivo);
  564 + return $imgc;
  565 +}
543 ?> 566 ?>
classesphp/mapa_openlayers.php
@@ -251,8 +251,8 @@ if($_GET[&quot;tipolayer&quot;] != &quot;fundo&quot;) @@ -251,8 +251,8 @@ if($_GET[&quot;tipolayer&quot;] != &quot;fundo&quot;)
251 //antes de gerar a imagem 251 //antes de gerar a imagem
252 // 252 //
253 if($cortePixels > 0){ 253 if($cortePixels > 0){
254 - $mapa->prepareImage();  
255 - echo $mapa->scaledenom;exit; 254 + //$mapa->prepareImage();
  255 + //echo $mapa->scaledenom;exit;
256 $escalaInicial = $mapa->scaledenom; 256 $escalaInicial = $mapa->scaledenom;
257 $extensaoInicial = $mapa->extent; 257 $extensaoInicial = $mapa->extent;
258 $wh = 256+($cortePixels*2); 258 $wh = 256+($cortePixels*2);
@@ -317,16 +317,14 @@ if($_GET[&quot;TIPOIMAGEM&quot;] != &quot;&quot; &amp;&amp; $_GET[&quot;TIPOIMAGEM&quot;] != &quot;nenhum&quot;){ @@ -317,16 +317,14 @@ if($_GET[&quot;TIPOIMAGEM&quot;] != &quot;&quot; &amp;&amp; $_GET[&quot;TIPOIMAGEM&quot;] != &quot;nenhum&quot;){
317 {echo "Erro IMAGEPATH vazio";exit;} 317 {echo "Erro IMAGEPATH vazio";exit;}
318 $nomer = ($img->imagepath)."filtroimgtemp".nomeRand().".png"; 318 $nomer = ($img->imagepath)."filtroimgtemp".nomeRand().".png";
319 $img->saveImage($nomer); 319 $img->saveImage($nomer);
320 - filtraImg($nomer,$_GET["TIPOIMAGEM"]);  
321 - $img = imagecreatefrompng($nomer);  
322 // 320 //
323 //corta a imagem gerada para voltar ao tamanho normal 321 //corta a imagem gerada para voltar ao tamanho normal
324 // 322 //
325 if($cortePixels > 0){ 323 if($cortePixels > 0){
326 - $imgc = imagecreate(256,256);  
327 - imagecopy( $imgc, $img, 0 , 0 , $cortePixels , $cortePixels , 255, 255 );  
328 - $img = $imgc; 324 + cortaImagemDisco($nomer,$cortePixels,256);
329 } 325 }
  326 + filtraImg($nomer,$_GET["TIPOIMAGEM"]);
  327 + $img = imagecreatefrompng($nomer);
330 imagealphablending($img, false); 328 imagealphablending($img, false);
331 imagesavealpha($img, true); 329 imagesavealpha($img, true);
332 ob_clean(); 330 ob_clean();
@@ -358,14 +356,24 @@ else{ @@ -358,14 +356,24 @@ else{
358 } 356 }
359 else{ 357 else{
360 //cache inativo 358 //cache inativo
361 - if($img->imagepath == "")  
362 - {echo "Erro IMAGEPATH vazio";exit;}  
363 - if($_SESSION["i3georendermode"] == 0){ 359 + if($img->imagepath == ""){
  360 + echo "Erro IMAGEPATH vazio";exit;
  361 + }
  362 + //se for necessario cortar a imagem, $img->saveImage() nao funciona
  363 + if($_SESSION["i3georendermode"] == 0 || ($_SESSION["i3georendermode"] == 1 && $cortePixels > 0)){
364 $nomer = ($img->imagepath)."temp".nomeRand().".png"; 364 $nomer = ($img->imagepath)."temp".nomeRand().".png";
365 $img->saveImage($nomer); 365 $img->saveImage($nomer);
366 - $img = imagecreatefrompng($nomer);  
367 - imagealphablending($img, false);  
368 - imagesavealpha($img, true); 366 + //
  367 + //corta a imagem gerada para voltar ao tamanho normal
  368 + //
  369 + if($cortePixels > 0){
  370 + $img = cortaImagemDisco($nomer,$cortePixels,256);
  371 + }
  372 + else{
  373 + $img = imagecreatefrompng($nomer);
  374 + imagealphablending($img, false);
  375 + imagesavealpha($img, true);
  376 + }
369 ob_clean(); 377 ob_clean();
370 echo header("Content-type: image/png \n\n"); 378 echo header("Content-type: image/png \n\n");
371 imagepng($img); 379 imagepng($img);
@@ -380,6 +388,12 @@ else{ @@ -380,6 +388,12 @@ else{
380 if($_SESSION["i3georendermode"] == 2){ 388 if($_SESSION["i3georendermode"] == 2){
381 $nomer = ($img->imagepath)."temp".nomeRand().".png"; 389 $nomer = ($img->imagepath)."temp".nomeRand().".png";
382 $img->saveImage($nomer); 390 $img->saveImage($nomer);
  391 + //
  392 + //corta a imagem gerada para voltar ao tamanho normal
  393 + //
  394 + if($cortePixels > 0){
  395 + $img = cortaImagemDisco($nomer,$cortePixels,256);
  396 + }
383 ob_clean(); 397 ob_clean();
384 header('Cache-Control: public, max-age=22222222'); 398 header('Cache-Control: public, max-age=22222222');
385 header('Expires: ' . gmdate('D, d M Y H:i:s', time()+48*60*60) . ' GMT'); 399 header('Expires: ' . gmdate('D, d M Y H:i:s', time()+48*60*60) . ' GMT');
@@ -404,15 +418,7 @@ function salvaCacheImagem($cachedir,$map,$tms){ @@ -404,15 +418,7 @@ function salvaCacheImagem($cachedir,$map,$tms){
404 //corta a imagem gerada para voltar ao tamanho normal 418 //corta a imagem gerada para voltar ao tamanho normal
405 // 419 //
406 if($cortePixels > 0){ 420 if($cortePixels > 0){
407 - $img = imagecreatefrompng($nome);  
408 - $imgc = imagecreate(256,256);  
409 - //@FIXME necessario, sem isso algumas imagens sao geradas de forma errada  
410 - imagesavealpha($imgc, true);  
411 - $color = imagecolorallocatealpha($imgc,0x00,0x00,0x00,127);  
412 - imagefill($imgc, 0, 0, $color);  
413 -  
414 - imagecopy( $imgc, $img, 0 , 0 , $cortePixels , $cortePixels , 256, 256 );  
415 - imagepng($imgc,$nome); 421 + $img = cortaImagemDisco($nome,$cortePixels,256);
416 } 422 }
417 chmod($nome,0777); 423 chmod($nome,0777);
418 } 424 }
@@ -511,4 +517,18 @@ function ilegal(){ @@ -511,4 +517,18 @@ function ilegal(){
511 imagepng($img); 517 imagepng($img);
512 exit; 518 exit;
513 } 519 }
  520 +/**
  521 + * Corta uma imagem existente em disco
  522 + */
  523 +function cortaImagemDisco($arquivo,$cortePixels,$tamanhoFinal=256){
  524 + $img = imagecreatefrompng($arquivo);
  525 + $imgc = imagecreate($tamanhoFinal,$tamanhoFinal);
  526 + //@FIXME necessario, sem isso algumas imagens sao geradas de forma errada
  527 + imagesavealpha($imgc, true);
  528 + $color = imagecolorallocatealpha($imgc,0x00,0x00,0x00,127);
  529 + imagefill($imgc, 0, 0, $color);
  530 + imagecopy( $imgc, $img, 0 , 0 , $cortePixels , $cortePixels , $tamanhoFinal, $tamanhoFinal );
  531 + imagepng($imgc,$arquivo);
  532 + return $imgc;
  533 +}
514 ?> 534 ?>